OSDN Git Service

fix rollback fix_rollback
authoripqhjjybj <250657661@qq.com>
Thu, 13 Aug 2020 03:04:43 +0000 (11:04 +0800)
committeripqhjjybj <250657661@qq.com>
Thu, 13 Aug 2020 03:04:43 +0000 (11:04 +0800)
protocol/block.go

index 52eab1b..1b9b7c5 100644 (file)
@@ -224,15 +224,26 @@ func (c *Chain) Rollback(targetHeight uint64) error {
        }
 
        startSeq := state.CalcVoteSeq(c.bestBlockHeader.Height)
-
        if err = c.setState(targetBlockHeader, setIrrBlockHeader, nil, utxoView, []*state.ConsensusResult{consensusResult.Fork()}); err != nil {
                return err
        }
 
        for _, block := range deletedBlocks {
-               if err := c.store.DeleteBlock(block); err != nil {
+               hashes, err := c.store.GetBlockHashesByHeight(block.Height)
+               if err != nil{
                        return err
                }
+
+               for _, hash := range hashes{
+                       block, err := c.store.GetBlock(hash)
+                       if err != nil{
+                               return err
+                       }
+
+                       if err := c.store.DeleteBlock(block); err != nil{
+                               return err
+                       }
+               }
        }
 
        endSeq := state.CalcVoteSeq(targetHeight)