Skip to content

Commit

Permalink
More nil checking in InsertReceiptChain
Browse files Browse the repository at this point in the history
Fixes #1920
  • Loading branch information
karlb committed Mar 10, 2023
1 parent 43d9795 commit e343bf3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,21 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
// Rewind may have occurred, skip in that case.
if bc.CurrentHeader().Number.Cmp(head.Number()) >= 0 {
currentFastBlock, td := bc.CurrentFastBlock(), bc.GetTd(head.Hash(), head.NumberU64())
if bc.GetTd(currentFastBlock.Hash(), currentFastBlock.NumberU64()).Cmp(td) < 0 {
fastBlockTd := bc.GetTd(currentFastBlock.Hash(), currentFastBlock.NumberU64())

// These two should not be nil under normal circumstances,
// but it apparently can happen in edge cases. See
// https://github.com/celo-org/celo-blockchain/issues/1920
if fastBlockTd == nil {
log.Warn("InsertReceiptChain: fastBlockTd is nil")
return false
}
if td == nil {
log.Warn("InsertReceiptChain: td is nil")
return false
}

if fastBlockTd.Cmp(td) < 0 {
rawdb.WriteHeadFastBlockHash(bc.db, head.Hash())
bc.currentFastBlock.Store(head)
headFastBlockGauge.Update(int64(head.NumberU64()))
Expand Down

0 comments on commit e343bf3

Please sign in to comment.