Skip to content

Commit ff274ca

Browse files
karlbalecpspiersy
authored
Stop at configured block (#2330)
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]>
1 parent db4e4db commit ff274ca

File tree

11 files changed

+340
-46
lines changed

11 files changed

+340
-46
lines changed

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ var (
7474
utils.USBFlag,
7575
// utils.SmartCardDaemonPathFlag,
7676
utils.OverrideHForkFlag,
77+
utils.L2MigrationBlockFlag,
7778
utils.TxPoolLocalsFlag,
7879
utils.TxPoolNoLocalsFlag,
7980
utils.TxPoolJournalFlag,

cmd/utils/flags.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ var (
243243
Usage: "Manually specify the hfork block, overriding the bundled setting",
244244
}
245245

246+
L2MigrationBlockFlag = cli.Uint64Flag{
247+
Name: "l2migrationblock",
248+
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.",
249+
}
250+
246251
BloomFilterSizeFlag = cli.Uint64Flag{
247252
Name: "bloomfilter.size",
248253
Usage: "Megabytes of memory allocated to bloom-filter for pruning",
@@ -1723,6 +1728,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
17231728
log.Debug("Sanitizing Go's GC trigger", "percent", int(gogc))
17241729
godebug.SetGCPercent(int(gogc))
17251730

1731+
if ctx.GlobalIsSet(L2MigrationBlockFlag.Name) {
1732+
cfg.L2MigrationBlock = new(big.Int).SetUint64(ctx.GlobalUint64(L2MigrationBlockFlag.Name))
1733+
}
17261734
if ctx.GlobalIsSet(SyncModeFlag.Name) {
17271735
cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode)
17281736
}

consensus/istanbul/backend/engine.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ func (sb *Backend) verifyHeader(chain consensus.ChainHeaderReader, header *types
125125
if header.Number == nil {
126126
return errUnknownBlock
127127
}
128+
if chain.Config().IsL2Migration(header.Number) {
129+
sb.logger.Trace("Reject block after L2 migration", "num", header.Number)
130+
return fmt.Errorf("Block number %d is after the L2 migration.", header.Number)
131+
}
128132

129133
// If the full chain isn't available (as on mobile devices), don't reject future blocks
130134
// This is due to potential clock skew

core/forkid/forkid.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ func gatherForks(config *params.ChainConfig) []uint64 {
224224
if !strings.HasSuffix(field.Name, "Block") {
225225
continue
226226
}
227+
// Do not include L2MigrationBlock in forkid as doing so will prevent syncing with nodes that have not set the L2MigrationBlock flag
228+
if field.Name == "L2MigrationBlock" {
229+
continue
230+
}
227231
if field.Type != reflect.TypeOf(new(big.Int)) {
228232
continue
229233
}

e2e_test/e2e_bench_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func BenchmarkNet100EmptyBlocks(b *testing.B) {
1919
for i := 0; i < b.N; i++ {
2020
ac := test.AccountConfig(n, 0)
2121
gingerbreadBlock := common.Big0
22-
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
22+
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
2323
require.NoError(b, err)
2424
network, shutdown, err := test.NewNetwork(ac, gc, ec)
2525
require.NoError(b, err)
@@ -45,7 +45,7 @@ func BenchmarkNet1000Txs(b *testing.B) {
4545

4646
ac := test.AccountConfig(n, n)
4747
gingerbreadBlock := common.Big0
48-
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock)
48+
gc, ec, err := test.BuildConfig(ac, gingerbreadBlock, nil)
4949
require.NoError(b, err)
5050
accounts := test.Accounts(ac.DeveloperAccounts(), gc.ChainConfig())
5151
network, shutdown, err := test.NewNetwork(ac, gc, ec)

0 commit comments

Comments
 (0)