fix SetHead func to call repair func

This commit is contained in:
JamesRay 2019-11-04 18:05:36 +08:00
parent b566cfdffd
commit 934749ecbe

View file

@ -400,8 +400,9 @@ func (bc *BlockChain) SetHead(head uint64) error {
if newHeadBlock == nil { if newHeadBlock == nil {
newHeadBlock = bc.genesisBlock newHeadBlock = bc.genesisBlock
} else { } else {
if _, err := state.New(newHeadBlock.Root(), bc.stateCache); err != nil { err := bc.repair(&newHeadBlock)
// Rewound state missing, rolled back to before pivot, reset to genesis if err != nil {
// Rewound block missing, rolled back to genesis
newHeadBlock = bc.genesisBlock newHeadBlock = bc.genesisBlock
} }
} }
@ -868,7 +869,7 @@ func (bc *BlockChain) procFutureBlocks() {
type WriteStatus byte type WriteStatus byte
const ( const (
NonStatTy WriteStatus = iota NonStatTy WriteStatus = iota
CanonStatTy CanonStatTy
SideStatTy 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()) log.Debug("Pruned ancestor, inserting as sidechain", "number", block.Number(), "hash", block.Hash())
return bc.insertSideChain(block, it) 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())): case err == consensus.ErrFutureBlock || (err == consensus.ErrUnknownAncestor && bc.futureBlocks.Contains(it.first().ParentHash())):
for block != nil && (it.index == 0 || err == consensus.ErrUnknownAncestor) { for block != nil && (it.index == 0 || err == consensus.ErrUnknownAncestor) {
log.Debug("Future block, postponing import", "number", block.Number(), "hash", block.Hash()) 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 // If there are any still remaining, mark as ignored
return it.index, events, coalescedLogs, err return it.index, events, coalescedLogs, err
// Some other error occurred, abort // Some other error occurred, abort
case err != nil: case err != nil:
bc.futureBlocks.Remove(block.Hash()) bc.futureBlocks.Remove(block.Hash())
stats.ignored += len(it.chain) stats.ignored += len(it.chain)