core: using the cached prev for comparisons, fix XFN-96

This commit is contained in:
Daniel Liu 2025-11-20 15:53:21 +08:00 committed by benjamin202410
parent 0ed20eface
commit 2726509176

View file

@ -1585,7 +1585,7 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) {
// Do a sanity check that the provided chain is actually ordered and linked // Do a sanity check that the provided chain is actually ordered and linked
for i := 1; i < len(chain); i++ { for i := 1; i < len(chain); i++ {
block, prev := chain[i], chain[i-1] block, prev := chain[i], chain[i-1]
if block.NumberU64() != chain[i-1].NumberU64()+1 || block.ParentHash() != chain[i-1].Hash() { if block.NumberU64() != prev.NumberU64()+1 || block.ParentHash() != prev.Hash() {
// Chain broke ancestry, log a messge (programming error) and skip insertion // Chain broke ancestry, log a messge (programming error) and skip insertion
log.Error("Non contiguous block insert", log.Error("Non contiguous block insert",
"number", block.Number(), "number", block.Number(),