From 934749ecbe7a67935b123ead93f19c1dc9dde1da Mon Sep 17 00:00:00 2001 From: JamesRay <66258875@qq.com> Date: Mon, 4 Nov 2019 18:05:36 +0800 Subject: [PATCH] fix SetHead func to call repair func --- core/blockchain.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 9fb02b1482..76058c173d 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -400,8 +400,9 @@ func (bc *BlockChain) SetHead(head uint64) error { if newHeadBlock == nil { newHeadBlock = bc.genesisBlock } else { - if _, err := state.New(newHeadBlock.Root(), bc.stateCache); err != nil { - // Rewound state missing, rolled back to before pivot, reset to genesis + err := bc.repair(&newHeadBlock) + if err != nil { + // Rewound block missing, rolled back to genesis newHeadBlock = bc.genesisBlock } } @@ -868,7 +869,7 @@ func (bc *BlockChain) procFutureBlocks() { type WriteStatus byte const ( - NonStatTy WriteStatus = iota + NonStatTy WriteStatus = iota CanonStatTy SideStatTy ) @@ -1538,7 +1539,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, [] log.Debug("Pruned ancestor, inserting as sidechain", "number", block.Number(), "hash", block.Hash()) return bc.insertSideChain(block, it) - // First block is future, shove it (and all children) to the future queue (unknown ancestor) + // First block is future, shove it (and all children) to the future queue (unknown ancestor) case err == consensus.ErrFutureBlock || (err == consensus.ErrUnknownAncestor && bc.futureBlocks.Contains(it.first().ParentHash())): for block != nil && (it.index == 0 || err == consensus.ErrUnknownAncestor) { log.Debug("Future block, postponing import", "number", block.Number(), "hash", block.Hash()) @@ -1553,7 +1554,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, [] // If there are any still remaining, mark as ignored return it.index, events, coalescedLogs, err - // Some other error occurred, abort + // Some other error occurred, abort case err != nil: bc.futureBlocks.Remove(block.Hash()) stats.ignored += len(it.chain)