OSDN Git Service

fix rollback (#543) master
authoripqhjjybj <250657661@qq.com>
Thu, 12 Nov 2020 02:51:41 +0000 (10:51 +0800)
committerGitHub <noreply@github.com>
Thu, 12 Nov 2020 02:51:41 +0000 (10:51 +0800)
Co-authored-by: Paladz <yzhu101@uottawa.ca>
protocol/block.go

index 862c01a..ab690ba 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)