Skip to content

Commit 5a88a7c

Browse files
core: use errors.Is for consensus errors check (#21095)
1 parent 1d25039 commit 5a88a7c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

core/blockchain.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,13 +1706,13 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er
17061706
}
17071707
switch {
17081708
// First block is pruned, insert as sidechain and reorg only if TD grows enough
1709-
case err == consensus.ErrPrunedAncestor:
1709+
case errors.Is(err, consensus.ErrPrunedAncestor):
17101710
log.Debug("Pruned ancestor, inserting as sidechain", "number", block.Number(), "hash", block.Hash())
17111711
return bc.insertSideChain(block, it)
17121712

17131713
// First block is future, shove it (and all children) to the future queue (unknown ancestor)
1714-
case err == consensus.ErrFutureBlock || (err == consensus.ErrUnknownAncestor && bc.futureBlocks.Contains(it.first().ParentHash())):
1715-
for block != nil && (it.index == 0 || err == consensus.ErrUnknownAncestor) {
1714+
case errors.Is(err, consensus.ErrFutureBlock) || (errors.Is(err, consensus.ErrUnknownAncestor) && bc.futureBlocks.Contains(it.first().ParentHash())):
1715+
for block != nil && (it.index == 0 || errors.Is(err, consensus.ErrUnknownAncestor)) {
17161716
log.Debug("Future block, postponing import", "number", block.Number(), "hash", block.Hash())
17171717
if err := bc.addFutureBlock(block); err != nil {
17181718
return it.index, err
@@ -1895,13 +1895,13 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er
18951895
stats.report(chain, it.index, dirty)
18961896
}
18971897
// Any blocks remaining here? The only ones we care about are the future ones
1898-
if block != nil && err == consensus.ErrFutureBlock {
1898+
if block != nil && errors.Is(err, consensus.ErrFutureBlock) {
18991899
if err := bc.addFutureBlock(block); err != nil {
19001900
return it.index, err
19011901
}
19021902
block, err = it.next()
19031903

1904-
for ; block != nil && err == consensus.ErrUnknownAncestor; block, err = it.next() {
1904+
for ; block != nil && errors.Is(err, consensus.ErrUnknownAncestor); block, err = it.next() {
19051905
if err := bc.addFutureBlock(block); err != nil {
19061906
return it.index, err
19071907
}
@@ -1929,7 +1929,7 @@ func (bc *BlockChain) insertSideChain(block *types.Block, it *insertIterator) (i
19291929
// ones. Any other errors means that the block is invalid, and should not be written
19301930
// to disk.
19311931
err := consensus.ErrPrunedAncestor
1932-
for ; block != nil && (err == consensus.ErrPrunedAncestor); block, err = it.next() {
1932+
for ; block != nil && errors.Is(err, consensus.ErrPrunedAncestor); block, err = it.next() {
19331933
// Check the canonical state root for that number
19341934
if number := block.NumberU64(); current.NumberU64() >= number {
19351935
canonical := bc.GetBlockByNumber(number)

0 commit comments

Comments
 (0)