Skip to content

Commit 08dbbe7

Browse files
committed
core: fix error in block iterator ethereum#18986
1 parent ff435e0 commit 08dbbe7

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

core/blockchain.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
16721672
switch {
16731673
// First block is pruned, insert as sidechain and reorg only if TD grows enough
16741674
case err == consensus.ErrPrunedAncestor:
1675-
return bc.insertSidechain(it)
1675+
return bc.insertSidechain(block, it)
16761676

16771677
// First block is future, shove it (and all children) to the future queue (unknown ancestor)
16781678
case err == consensus.ErrFutureBlock || (err == consensus.ErrUnknownAncestor && bc.futureBlocks.Contains(it.first().ParentHash())):
@@ -1854,7 +1854,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
18541854
//
18551855
// The method writes all (header-and-body-valid) blocks to disk, then tries to
18561856
// switch over to the new chain if the TD exceeded the current chain.
1857-
func (bc *BlockChain) insertSidechain(it *insertIterator) (int, []interface{}, []*types.Log, error) {
1857+
func (bc *BlockChain) insertSidechain(block *types.Block, it *insertIterator) (int, []interface{}, []*types.Log, error) {
18581858
var (
18591859
externTd *big.Int
18601860
current = bc.CurrentBlock().NumberU64()
@@ -1863,7 +1863,7 @@ func (bc *BlockChain) insertSidechain(it *insertIterator) (int, []interface{}, [
18631863
// Since we don't import them here, we expect ErrUnknownAncestor for the remaining
18641864
// ones. Any other errors means that the block is invalid, and should not be written
18651865
// to disk.
1866-
block, err := it.current(), consensus.ErrPrunedAncestor
1866+
err := consensus.ErrPrunedAncestor
18671867
for ; block != nil && (err == consensus.ErrPrunedAncestor); block, err = it.next() {
18681868
// Check the canonical state root for that number
18691869
if number := block.NumberU64(); current >= number {

core/blockchain_insert.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,6 @@ func (it *insertIterator) next() (*types.Block, error) {
111111
return it.chain[it.index], it.validator.ValidateBody(it.chain[it.index])
112112
}
113113

114-
// current returns the current block that's being processed.
115-
func (it *insertIterator) current() *types.Block {
116-
if it.index < 0 || it.index+1 >= len(it.chain) {
117-
return nil
118-
}
119-
return it.chain[it.index]
120-
}
121-
122114
// previous returns the previous block was being processed, or nil
123115
func (it *insertIterator) previous() *types.Block {
124116
if it.index < 1 {

0 commit comments

Comments
 (0)