Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Karlb/stop #2330

Merged
merged 24 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 23 additions & 0 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/celo-org/celo-blockchain/ethdb"
"github.com/celo-org/celo-blockchain/params"
"github.com/celo-org/celo-blockchain/trie"
"github.com/stretchr/testify/require"
)

// So we can deterministically seed different blockchains
Expand Down Expand Up @@ -205,6 +206,28 @@ func TestLastBlock(t *testing.T) {
}
}

func TestNoInsertPastL2MigrationBlock(t *testing.T) {
_, blockchain, err := newCanonical(mockEngine.NewFaker(), 0, true)
if err != nil {
t.Fatalf("failed to create pristine chain: %v", err)
}
defer blockchain.Stop()

blockchain.chainConfig = blockchain.chainConfig.DeepCopy()
migrationBlock := 2
blockchain.chainConfig.L2MigrationBlock = big.NewInt(int64(migrationBlock))

blocks := makeBlockChain(blockchain.CurrentBlock(), 100000, mockEngine.NewFullFaker(), blockchain.db, 0)
failedBlock, err := blockchain.InsertChain(blocks)
require.EqualError(t, err, errInsertionInterrupted.Error())
// Compare with migrationBlock-1 because failedBlock is the index of the failed block in the blocks[] array, not in the actual blockchain.
require.EqualValues(t, migrationBlock-1, failedBlock)
// Only the first block in blocks[] should be inserted
if blocks[migrationBlock-2].Hash() != rawdb.ReadHeadBlockHash(blockchain.db) {
t.Fatalf("Write/Get HeadBlockHash failed")
}
}

// Tests that given a starting canonical chain of a given size, it can be extended
// with various length chains.
func TestExtendCanonicalHeaders(t *testing.T) { testExtendCanonical(t, false) }
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