@@ -1762,7 +1762,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
1762
1762
// The method writes all (header-and-body-valid) blocks to disk, then tries to
1763
1763
// switch over to the new chain if the TD exceeded the current chain.
1764
1764
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 )
1766
1767
current := bc .CurrentBlock ()
1767
1768
// The first sidechain block error is already verified to be ErrPrunedAncestor.
1768
1769
// 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
1798
1799
return it .index , nil , nil , errors .New ("sidechain ghost-state attack" )
1799
1800
}
1800
1801
}
1802
+ externHash = block .Hash ()
1801
1803
externTd = new (big.Int ).Add (externTd , block .Difficulty ())
1802
1804
1803
1805
if ! bc .HasBlock (block .Hash (), block .NumberU64 ()) {
@@ -1818,7 +1820,7 @@ func (bc *BlockChain) insertSideChain(block *types.Block, it *insertIterator) (i
1818
1820
// If the externTd was larger than our local TD, we now need to reimport the previous
1819
1821
// blocks to regenerate the required state
1820
1822
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 {
1822
1824
log .Info ("Sidechain written to disk" , "start" , it .first ().NumberU64 (), "end" , it .previous ().Number , "sidetd" , externTd , "localtd" , localTd )
1823
1825
return it .index , nil , nil , err
1824
1826
}
0 commit comments