|
|
@ -1688,7 +1688,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool, makeWitness |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// We're post-merge and the parent is pruned, try to recover the parent state
|
|
|
|
// We're post-merge and the parent is pruned, try to recover the parent state
|
|
|
|
log.Debug("Pruned ancestor", "number", block.Number(), "hash", block.Hash()) |
|
|
|
log.Debug("Pruned ancestor", "number", block.Number(), "hash", block.Hash()) |
|
|
|
_, err := bc.recoverAncestors(block) |
|
|
|
_, err := bc.recoverAncestors(block, makeWitness) |
|
|
|
return nil, it.index, err |
|
|
|
return nil, it.index, err |
|
|
|
} |
|
|
|
} |
|
|
|
// Some other error(except ErrKnownBlock) occurred, abort.
|
|
|
|
// Some other error(except ErrKnownBlock) occurred, abort.
|
|
|
@ -2110,7 +2110,7 @@ func (bc *BlockChain) insertSideChain(block *types.Block, it *insertIterator, ma |
|
|
|
// all the ancestor blocks since that.
|
|
|
|
// all the ancestor blocks since that.
|
|
|
|
// recoverAncestors is only used post-merge.
|
|
|
|
// recoverAncestors is only used post-merge.
|
|
|
|
// We return the hash of the latest block that we could correctly validate.
|
|
|
|
// We return the hash of the latest block that we could correctly validate.
|
|
|
|
func (bc *BlockChain) recoverAncestors(block *types.Block) (common.Hash, error) { |
|
|
|
func (bc *BlockChain) recoverAncestors(block *types.Block, makeWitness bool) (common.Hash, error) { |
|
|
|
// Gather all the sidechain hashes (full blocks may be memory heavy)
|
|
|
|
// Gather all the sidechain hashes (full blocks may be memory heavy)
|
|
|
|
var ( |
|
|
|
var ( |
|
|
|
hashes []common.Hash |
|
|
|
hashes []common.Hash |
|
|
@ -2150,7 +2150,7 @@ func (bc *BlockChain) recoverAncestors(block *types.Block) (common.Hash, error) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
b = bc.GetBlock(hashes[i], numbers[i]) |
|
|
|
b = bc.GetBlock(hashes[i], numbers[i]) |
|
|
|
} |
|
|
|
} |
|
|
|
if _, _, err := bc.insertChain(types.Blocks{b}, false, false); err != nil { |
|
|
|
if _, _, err := bc.insertChain(types.Blocks{b}, false, makeWitness && i == 0); err != nil { |
|
|
|
return b.ParentHash(), err |
|
|
|
return b.ParentHash(), err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -2387,7 +2387,7 @@ func (bc *BlockChain) SetCanonical(head *types.Block) (common.Hash, error) { |
|
|
|
|
|
|
|
|
|
|
|
// Re-execute the reorged chain in case the head state is missing.
|
|
|
|
// Re-execute the reorged chain in case the head state is missing.
|
|
|
|
if !bc.HasState(head.Root()) { |
|
|
|
if !bc.HasState(head.Root()) { |
|
|
|
if latestValidHash, err := bc.recoverAncestors(head); err != nil { |
|
|
|
if latestValidHash, err := bc.recoverAncestors(head, false); err != nil { |
|
|
|
return latestValidHash, err |
|
|
|
return latestValidHash, err |
|
|
|
} |
|
|
|
} |
|
|
|
log.Info("Recovered head state", "number", head.Number(), "hash", head.Hash()) |
|
|
|
log.Info("Recovered head state", "number", head.Number(), "hash", head.Hash()) |
|
|
|