aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMartin Holst Swende <martin@swende.se>2019-02-04 20:30:19 +0800
committerMartin Holst Swende <martin@swende.se>2019-02-10 00:36:20 +0800
commit3a95128b22a239c8e7b878a40bb36b003ec36267 (patch)
tree3615ccb2b42cb30197ed6c6b902145318fc767f9 /core
parent631e2f07f62372106964352a03a2f793d2fe94dc (diff)
downloadgo-tangerine-3a95128b22a239c8e7b878a40bb36b003ec36267.tar
go-tangerine-3a95128b22a239c8e7b878a40bb36b003ec36267.tar.gz
go-tangerine-3a95128b22a239c8e7b878a40bb36b003ec36267.tar.bz2
go-tangerine-3a95128b22a239c8e7b878a40bb36b003ec36267.tar.lz
go-tangerine-3a95128b22a239c8e7b878a40bb36b003ec36267.tar.xz
go-tangerine-3a95128b22a239c8e7b878a40bb36b003ec36267.tar.zst
go-tangerine-3a95128b22a239c8e7b878a40bb36b003ec36267.zip
core: fix error in block iterator (#18986)
Diffstat (limited to 'core')
-rw-r--r--core/blockchain.go6
-rw-r--r--core/blockchain_insert.go8
2 files changed, 3 insertions, 11 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 49aedf669..fa1c254b3 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -1136,7 +1136,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
switch {
// First block is pruned, insert as sidechain and reorg only if TD grows enough
case err == consensus.ErrPrunedAncestor:
- return bc.insertSidechain(it)
+ return bc.insertSidechain(block, it)
// First block is future, shove it (and all children) to the future queue (unknown ancestor)
case err == consensus.ErrFutureBlock || (err == consensus.ErrUnknownAncestor && bc.futureBlocks.Contains(it.first().ParentHash())):
@@ -1278,7 +1278,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
//
// The method writes all (header-and-body-valid) blocks to disk, then tries to
// switch over to the new chain if the TD exceeded the current chain.
-func (bc *BlockChain) insertSidechain(it *insertIterator) (int, []interface{}, []*types.Log, error) {
+func (bc *BlockChain) insertSidechain(block *types.Block, it *insertIterator) (int, []interface{}, []*types.Log, error) {
var (
externTd *big.Int
current = bc.CurrentBlock().NumberU64()
@@ -1287,7 +1287,7 @@ func (bc *BlockChain) insertSidechain(it *insertIterator) (int, []interface{}, [
// Since we don't import them here, we expect ErrUnknownAncestor for the remaining
// ones. Any other errors means that the block is invalid, and should not be written
// to disk.
- block, err := it.current(), consensus.ErrPrunedAncestor
+ err := consensus.ErrPrunedAncestor
for ; block != nil && (err == consensus.ErrPrunedAncestor); block, err = it.next() {
// Check the canonical state root for that number
if number := block.NumberU64(); current >= number {
diff --git a/core/blockchain_insert.go b/core/blockchain_insert.go
index 70bea3544..cfa32c5aa 100644
--- a/core/blockchain_insert.go
+++ b/core/blockchain_insert.go
@@ -111,14 +111,6 @@ func (it *insertIterator) next() (*types.Block, error) {
return it.chain[it.index], it.validator.ValidateBody(it.chain[it.index])
}
-// current returns the current block that's being processed.
-func (it *insertIterator) current() *types.Block {
- if it.index < 0 || it.index+1 >= len(it.chain) {
- return nil
- }
- return it.chain[it.index]
-}
-
// previous returns the previous block was being processed, or nil
func (it *insertIterator) previous() *types.Block {
if it.index < 1 {