Skip to content

Commit

Permalink
Discard blocks after migration during validation
Browse files Browse the repository at this point in the history
  • Loading branch information
karlb committed Sep 17, 2024
1 parent 7c56668 commit 90dbc6c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
4 changes: 4 additions & 0 deletions consensus/istanbul/backend/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ func (sb *Backend) verifyHeader(chain consensus.ChainHeaderReader, header *types
if header.Number == nil {
return errUnknownBlock
}
if chain.Config().IsL2Migration(header.Number) {
sb.logger.Trace("Reject block after L2 migration", "num", header.Number)
return fmt.Errorf("Block number %d is after the L2 migration.", header.Number)
}

// If the full chain isn't available (as on mobile devices), don't reject future blocks
// This is due to potential clock skew
Expand Down
15 changes: 0 additions & 15 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,14 +811,6 @@ func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error {
//
// Note, this function assumes that the `mu` mutex is held!
func (bc *BlockChain) writeHeadBlock(block *types.Block) {
// Normally the check at the end of the function will pass first, but if a node is restarted
// with the same l2-migration-block configured after already reaching and stopping on l2-migration-block,
// this check will pass first and log an error.
if bc.Config().IsL2Migration(block.Number()) {
log.Error("Attempt to insert block number >= l2MigrationBlock, stopping block insertion", "block", block.NumberU64(), "hash", block.Hash())
bc.StopInsert()
return
}
// If the block is on a side chain or an unknown one, force other heads onto it too
updateHeads := rawdb.ReadCanonicalHash(bc.db, block.NumberU64()) != block.Hash()

Expand All @@ -845,13 +837,6 @@ func (bc *BlockChain) writeHeadBlock(block *types.Block) {
}
bc.currentBlock.Store(block)
headBlockGauge.Update(int64(block.NumberU64()))

nextBlockNum := new(big.Int).Add(block.Number(), big.NewInt(1))
if bc.Config().IsL2Migration(nextBlockNum) {
log.Info("The next block is the L2 migration block, stopping block insertion", "currentBlock", block.NumberU64(), "hash", block.Hash(), "nextBlock", nextBlockNum.Uint64())
bc.StopInsert()
return
}
}

// Genesis retrieves the chain's genesis block.
Expand Down

0 comments on commit 90dbc6c

Please sign in to comment.