mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Fix #19198 - Be defensive in handling getBlock result, it can be nil
This commit is contained in:
parent
8657a0d6b5
commit
8c37494b7f
1 changed files with 6 additions and 0 deletions
|
|
@ -875,12 +875,18 @@ func (bc *BlockChain) Rollback(chain []common.Hash) {
|
|||
}
|
||||
if currentFastBlock := bc.CurrentFastBlock(); currentFastBlock.Hash() == hash {
|
||||
newFastBlock := bc.GetBlock(currentFastBlock.ParentHash(), currentFastBlock.NumberU64()-1)
|
||||
if newFastBlock == nil {
|
||||
log.Crit("Failed to retrieve previous fastBlock during rollback")
|
||||
}
|
||||
rawdb.WriteHeadFastBlockHash(bc.db, newFastBlock.Hash())
|
||||
bc.currentFastBlock.Store(newFastBlock)
|
||||
headFastBlockGauge.Update(int64(newFastBlock.NumberU64()))
|
||||
}
|
||||
if currentBlock := bc.CurrentBlock(); currentBlock.Hash() == hash {
|
||||
newBlock := bc.GetBlock(currentBlock.ParentHash(), currentBlock.NumberU64()-1)
|
||||
if newBlock == nil {
|
||||
log.Crit("Failed to retrieve previous block during rollback")
|
||||
}
|
||||
rawdb.WriteHeadBlockHash(bc.db, newBlock.Hash())
|
||||
bc.currentBlock.Store(newBlock)
|
||||
headBlockGauge.Update(int64(newBlock.NumberU64()))
|
||||
|
|
|
|||
Loading…
Reference in a new issue