OSDN Git Service

fix bug
authorwz <mars@bytom.io>
Tue, 15 Oct 2019 06:52:26 +0000 (14:52 +0800)
committerwz <mars@bytom.io>
Tue, 15 Oct 2019 06:56:01 +0000 (14:56 +0800)
application/mov/database/mov_store.go

index 4aa831a..3f3f38a 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.getCurrentState(blockHeader)
+       if err != nil {
+               return err
+       }
+
+       if err := m.saveMovDatabaseState(batch, state); err != nil {
                return err
        }
 
@@ -265,3 +269,19 @@ func (m *MovStore) saveMovDatabaseState(batch dbm.Batch, state *common.MovDataba
        batch.Set(bestMatchStore, value)
        return nil
 }
+
+func (m *MovStore) getCurrentState(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.String() == hash.String() {
+               hash = blockHeader.PreviousBlockHash
+               height = blockHeader.Height - 1
+       }
+       return &common.MovDatabaseState{Height: height, Hash: &hash}, nil
+}