OSDN Git Service

fix bug (#412)
authorwz <mars@bytom.io>
Wed, 16 Oct 2019 05:58:51 +0000 (13:58 +0800)
committerPaladz <yzhu101@uottawa.ca>
Wed, 16 Oct 2019 05:58:51 +0000 (13:58 +0800)
* fix bug

* fix

* fix name

* fix func name

* fix

application/mov/database/mov_store.go

index 4aa831a..896f504 100644 (file)
@@ -140,8 +140,12 @@ func (m *MovStore) ProcessOrders(addOrders []*common.Order, delOreders []*common
                return err
        }
 
-       hash := blockHeader.Hash()
-       if err := m.saveMovDatabaseState(batch, &common.MovDatabaseState{Height: blockHeader.Height, Hash: &hash}); err != nil {
+       state, err := m.calcNextDatabaseState(blockHeader)
+       if err != nil {
+               return err
+       }
+
+       if err := m.saveMovDatabaseState(batch, state); err != nil {
                return err
        }
 
@@ -248,8 +252,7 @@ func (m *MovStore) checkMovDatabaseState(header *types.BlockHeader) error {
                return err
        }
 
-       blockHash := header.Hash()
-       if (state.Hash.String() == header.PreviousBlockHash.String() && (state.Height+1) == header.Height) || state.Hash.String() == blockHash.String() {
+       if (*state.Hash == header.PreviousBlockHash && (state.Height+1) == header.Height) || *state.Hash == header.Hash() {
                return nil
        }
 
@@ -265,3 +268,20 @@ func (m *MovStore) saveMovDatabaseState(batch dbm.Batch, state *common.MovDataba
        batch.Set(bestMatchStore, value)
        return nil
 }
+
+func (m *MovStore) calcNextDatabaseState(blockHeader *types.BlockHeader) (*common.MovDatabaseState, error) {
+       hash := blockHeader.Hash()
+       height := blockHeader.Height
+
+       state, err := m.GetMovDatabaseState()
+       if err != nil {
+               return nil, err
+       }
+
+       if *state.Hash == hash {
+               hash = blockHeader.PreviousBlockHash
+               height = blockHeader.Height - 1
+       }
+
+       return &common.MovDatabaseState{Height: height, Hash: &hash}, nil
+}