mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core: stop rewinding if chain is gapped or genesis is reached
This commit is contained in:
parent
3784c6caee
commit
ad7ac99e70
1 changed files with 15 additions and 2 deletions
|
|
@ -662,7 +662,7 @@ func (bc *BlockChain) rewindHashHead(root common.Hash) (*types.Header, uint64) {
|
||||||
if !bc.HasState(head.Root) {
|
if !bc.HasState(head.Root) {
|
||||||
// If search limit is reached, return the genesis block as
|
// If search limit is reached, return the genesis block as
|
||||||
// the new chain head.
|
// the new chain head.
|
||||||
if head.Number.Uint64() < limit {
|
if head.Number.Uint64() <= limit {
|
||||||
log.Info("Rewinding limit reached, resetting to genesis", "number", head.Number, "hash", head.Hash(), "limit", limit)
|
log.Info("Rewinding limit reached, resetting to genesis", "number", head.Number, "hash", head.Hash(), "limit", limit)
|
||||||
return bc.genesisBlock.Header(), rootNumber
|
return bc.genesisBlock.Header(), rootNumber
|
||||||
}
|
}
|
||||||
|
|
@ -744,7 +744,20 @@ func (bc *BlockChain) rewindPathHead(root common.Hash) (*types.Header, uint64) {
|
||||||
log.Info("Pivot block reached, resetting to genesis", "number", head.Number, "hash", head.Hash())
|
log.Info("Pivot block reached, resetting to genesis", "number", head.Number, "hash", head.Hash())
|
||||||
return bc.genesisBlock.Header(), rootNumber
|
return bc.genesisBlock.Header(), rootNumber
|
||||||
}
|
}
|
||||||
head = bc.GetHeader(head.ParentHash, head.Number.Uint64()-1) // Keep rewinding
|
// If the chain is gapped in the middle, return the genesis
|
||||||
|
// block as the new chain head
|
||||||
|
parent := bc.GetHeader(head.ParentHash, head.Number.Uint64()-1) // Keep rewinding
|
||||||
|
if parent == nil {
|
||||||
|
log.Error("Missing block in the middle, resetting to genesis", "number", head.Number.Uint64()-1, "hash", head.ParentHash)
|
||||||
|
return bc.genesisBlock.Header(), rootNumber
|
||||||
|
}
|
||||||
|
head = parent
|
||||||
|
|
||||||
|
// If the genesis block is reached, stop searching.
|
||||||
|
if head.Number.Uint64() == 0 {
|
||||||
|
log.Info("Genesis block reached", "number", head.Number, "hash", head.Hash())
|
||||||
|
return head, rootNumber
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Recover if the target state if it's not available yet.
|
// Recover if the target state if it's not available yet.
|
||||||
if !bc.HasState(head.Root) {
|
if !bc.HasState(head.Root) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue