Skip to content

Commit

Permalink
Stop at configured block (#2330)
Browse files Browse the repository at this point in the history
Adds a flag that fails validation for all blocks later than a specific block.
This prevents nodes from accepting and producing blocks after that point.

Also adds an e2e test that verifies the effectiveness of the stopping.

Co-authored-by: alecps <[email protected]>
Co-authored-by: Piers Powlesland <[email protected]>
  • Loading branch information
3 people authored Sep 19, 2024
1 parent db4e4db commit ff274ca
Show file tree
Hide file tree
Showing 11 changed files with 340 additions and 46 deletions.
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ var (
utils.USBFlag,
// utils.SmartCardDaemonPathFlag,
utils.OverrideHForkFlag,
utils.L2MigrationBlockFlag,
utils.TxPoolLocalsFlag,
utils.TxPoolNoLocalsFlag,
utils.TxPoolJournalFlag,
Expand Down
8 changes: 8 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ var (
Usage: "Manually specify the hfork block, overriding the bundled setting",
}

L2MigrationBlockFlag = cli.Uint64Flag{
Name: "l2migrationblock",
Usage: "Block number at which to halt the network for Celo L2 migration. This is the first block of Celo as an L2, and one after the last block of Celo as an L1. If unset or set to 0, no halt will occur.",
}

BloomFilterSizeFlag = cli.Uint64Flag{
Name: "bloomfilter.size",
Usage: "Megabytes of memory allocated to bloom-filter for pruning",
Expand Down Expand Up @@ -1723,6 +1728,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
log.Debug("Sanitizing Go's GC trigger", "percent", int(gogc))
godebug.SetGCPercent(int(gogc))

if ctx.GlobalIsSet(L2MigrationBlockFlag.Name) {
cfg.L2MigrationBlock = new(big.Int).SetUint64(ctx.GlobalUint64(L2MigrationBlockFlag.Name))
}
if ctx.GlobalIsSet(SyncModeFlag.Name) {
cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode)
}
Expand Down
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
4 changes: 4 additions & 0 deletions core/forkid/forkid.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ func gatherForks(config *params.ChainConfig) []uint64 {
if !strings.HasSuffix(field.Name, "Block") {
continue
}
// Do not include L2MigrationBlock in forkid as doing so will prevent syncing with nodes that have not set the L2MigrationBlock flag
if field.Name == "L2MigrationBlock" {
continue
}
if field.Type != reflect.TypeOf(new(big.Int)) {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions e2e_test/e2e_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func BenchmarkNet100EmptyBlocks(b *testing.B) {
for i := 0; i < b.N; i++ {
ac := test.AccountConfig(n, 0)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(b, err)
network, shutdown, err := test.NewNetwork(ac, gc, ec)
require.NoError(b, err)
Expand All @@ -45,7 +45,7 @@ func BenchmarkNet1000Txs(b *testing.B) {

ac := test.AccountConfig(n, n)
gingerbreadBlock := common.Big0
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
require.NoError(b, err)
accounts := test.Accounts(ac.DeveloperAccounts(), gc.ChainConfig())
network, shutdown, err := test.NewNetwork(ac, gc, ec)
Expand Down
Loading

0 comments on commit ff274ca

Please sign in to comment.