Skip to content

Commit

Permalink
core: skip importing blocks that below finalized height
Browse files Browse the repository at this point in the history
  • Loading branch information
buddh0 committed Mar 29, 2024
1 parent 5d51873 commit e2abf95
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1938,6 +1938,16 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
}
// Falls through to the block import
}

// Left-trim all the blocks that below finalized height
if posa, ok := bc.Engine().(consensus.PoSA); ok {
if finalizedHeader := posa.GetFinalizedHeader(bc, bc.CurrentBlock()); finalizedHeader != nil {
for block != nil && block.NumberU64() <= finalizedHeader.Number.Uint64() {
block, err = it.next()
}
}
}

switch {
// First block is pruned
case errors.Is(err, consensus.ErrPrunedAncestor):
Expand Down

0 comments on commit e2abf95

Please sign in to comment.