From 1b8ee6dc2b27f58ad3a71d824676edb1998d9c7f Mon Sep 17 00:00:00 2001 From: lightclient Date: Wed, 22 Oct 2025 09:27:47 -0600 Subject: [PATCH 1/4] cmd: allow --networkid to override other config options --- cmd/utils/flags.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 9f695817545..df37d02b49b 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1616,7 +1616,7 @@ func setRequiredBlocks(ctx *cli.Context, cfg *ethconfig.Config) { // SetEthConfig applies eth-related command line flags to the config. func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { // Avoid conflicting network flags, don't allow network id override on preset networks - flags.CheckExclusive(ctx, MainnetFlag, DeveloperFlag, SepoliaFlag, HoleskyFlag, HoodiFlag, NetworkIdFlag, OverrideGenesisFlag) + flags.CheckExclusive(ctx, MainnetFlag, DeveloperFlag, SepoliaFlag, HoleskyFlag, HoodiFlag, OverrideGenesisFlag) flags.CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer // Set configurations from CLI flags @@ -1663,9 +1663,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { } } - if ctx.IsSet(NetworkIdFlag.Name) { - cfg.NetworkId = ctx.Uint64(NetworkIdFlag.Name) - } if ctx.IsSet(CacheFlag.Name) || ctx.IsSet(CacheDatabaseFlag.Name) { cfg.DatabaseCache = ctx.Int(CacheFlag.Name) * ctx.Int(CacheDatabaseFlag.Name) / 100 } @@ -1915,10 +1912,15 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { } cfg.Genesis = genesis default: - if cfg.NetworkId == 1 { + if ctx.Uint64(NetworkIdFlag.Name) == 1 { SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash) } } + if ctx.IsSet(NetworkIdFlag.Name) { + id := ctx.Uint64(NetworkIdFlag.Name) + log.Warn("Setting network id with flag", "id", id) + cfg.NetworkId = id + } // Set any dangling config values if ctx.String(CryptoKZGFlag.Name) != "gokzg" && ctx.String(CryptoKZGFlag.Name) != "ckzg" { Fatalf("--%s flag must be 'gokzg' or 'ckzg'", CryptoKZGFlag.Name) From 68ad6ac0dd8361a58505b84ec4b781dbf7a488f2 Mon Sep 17 00:00:00 2001 From: lightclient Date: Wed, 22 Oct 2025 09:38:25 -0600 Subject: [PATCH 2/4] cmd: revert further changes from #31630 --- cmd/geth/consolecmd_test.go | 3 ++- cmd/utils/flags.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/geth/consolecmd_test.go b/cmd/geth/consolecmd_test.go index 4e1f6340a00..871e8c175fc 100644 --- a/cmd/geth/consolecmd_test.go +++ b/cmd/geth/consolecmd_test.go @@ -39,8 +39,9 @@ const ( // child g gets a temporary data directory. func runMinimalGeth(t *testing.T, args ...string) *testgeth { // --holesky to make the 'writing genesis to disk' faster (no accounts) + // --networkid=1337 to avoid cache bump // --syncmode=full to avoid allocating fast sync bloom - allArgs := []string{"--holesky", "--authrpc.port", "0", "--syncmode=full", "--port", "0", + allArgs := []string{"--holesky", "--networkid", "1337", "--authrpc.port", "0", "--syncmode=full", "--port", "0", "--nat", "none", "--nodiscover", "--maxpeers", "0", "--cache", "64", "--datadir.minfreedisk", "0"} return runGeth(t, append(allArgs, args...)...) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index df37d02b49b..c2414d9ca7a 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1615,7 +1615,7 @@ func setRequiredBlocks(ctx *cli.Context, cfg *ethconfig.Config) { // SetEthConfig applies eth-related command line flags to the config. func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { - // Avoid conflicting network flags, don't allow network id override on preset networks + // Avoid conflicting network flags flags.CheckExclusive(ctx, MainnetFlag, DeveloperFlag, SepoliaFlag, HoleskyFlag, HoodiFlag, OverrideGenesisFlag) flags.CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer From 131fc21458882298b1f343f3bca30b8c2e208537 Mon Sep 17 00:00:00 2001 From: lightclient Date: Wed, 22 Oct 2025 09:50:30 -0600 Subject: [PATCH 3/4] cmd/utils: add comment about overriding network id --- cmd/utils/flags.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index c2414d9ca7a..98313beb21c 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1917,6 +1917,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { } } if ctx.IsSet(NetworkIdFlag.Name) { + // Typically it's best to automatically set the network id to the chain id, + // by not passing the network id flag at all. Emit a warning when set + // explicitly in case overriding the network id is not the user's intention. id := ctx.Uint64(NetworkIdFlag.Name) log.Warn("Setting network id with flag", "id", id) cfg.NetworkId = id From 7fb54af40483417cf4bc7e0279af24d56159d9dd Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 28 Nov 2025 14:17:15 +0100 Subject: [PATCH 4/4] Correct usage of 'network id' to 'network ID' --- cmd/utils/flags.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 98313beb21c..49d8677ca23 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -137,7 +137,7 @@ var ( } NetworkIdFlag = &cli.Uint64Flag{ Name: "networkid", - Usage: "Explicitly set network id (integer)(For testnets: use --sepolia, --holesky, --hoodi instead)", + Usage: "Explicitly set network ID (integer)(For testnets: use --sepolia, --holesky, --hoodi instead)", Value: ethconfig.Defaults.NetworkId, Category: flags.EthCategory, } @@ -1917,11 +1917,11 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { } } if ctx.IsSet(NetworkIdFlag.Name) { - // Typically it's best to automatically set the network id to the chain id, - // by not passing the network id flag at all. Emit a warning when set - // explicitly in case overriding the network id is not the user's intention. + // Typically it's best to automatically set the network ID to the chainID, + // by not passing the --networkid flag at all. Emit a warning when set + // explicitly in case overriding the network ID is not the user's intention. id := ctx.Uint64(NetworkIdFlag.Name) - log.Warn("Setting network id with flag", "id", id) + log.Warn("Setting network ID with command-line flag", "id", id) cfg.NetworkId = id } // Set any dangling config values