Skip to content

Commit 9787b34

Browse files
committed
core: update the externHash along with externTd while inserting side chain
1 parent 4703e66 commit 9787b34

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

core/blockchain.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
17621762
// The method writes all (header-and-body-valid) blocks to disk, then tries to
17631763
// switch over to the new chain if the TD exceeded the current chain.
17641764
func (bc *BlockChain) insertSideChain(block *types.Block, it *insertIterator) (int, []interface{}, []*types.Log, error) {
1765-
externTd := bc.GetTd(block.ParentHash(), block.NumberU64()-1)
1765+
externHash := block.ParentHash()
1766+
externTd := bc.GetTd(externHash, block.NumberU64()-1)
17661767
current := bc.CurrentBlock()
17671768
// The first sidechain block error is already verified to be ErrPrunedAncestor.
17681769
// Since we don't import them here, we expect ErrUnknownAncestor for the remaining
@@ -1798,6 +1799,7 @@ func (bc *BlockChain) insertSideChain(block *types.Block, it *insertIterator) (i
17981799
return it.index, nil, nil, errors.New("sidechain ghost-state attack")
17991800
}
18001801
}
1802+
externHash = block.Hash()
18011803
externTd = new(big.Int).Add(externTd, block.Difficulty())
18021804

18031805
if !bc.HasBlock(block.Hash(), block.NumberU64()) {
@@ -1818,7 +1820,7 @@ func (bc *BlockChain) insertSideChain(block *types.Block, it *insertIterator) (i
18181820
// If the externTd was larger than our local TD, we now need to reimport the previous
18191821
// blocks to regenerate the required state
18201822
localTd := bc.GetTd(current.Hash(), current.NumberU64())
1821-
if ChainCompare(localTd, externTd, current.Hash(), block.Hash()) > 0 {
1823+
if ChainCompare(localTd, externTd, current.Hash(), externHash) > 0 {
18221824
log.Info("Sidechain written to disk", "start", it.first().NumberU64(), "end", it.previous().Number, "sidetd", externTd, "localtd", localTd)
18231825
return it.index, nil, nil, err
18241826
}

0 commit comments

Comments
 (0)