From b02b46dd5a05006299597da0848462541dcf13b3 Mon Sep 17 00:00:00 2001 From: lightclient Date: Mon, 6 Oct 2025 22:33:33 -0400 Subject: [PATCH 1/3] cmd/geth: add flag to override genesis --- cmd/geth/main.go | 1 + cmd/utils/flags.go | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 2465b52ad1f0..de0ad2b099a2 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -84,6 +84,7 @@ var ( utils.SyncModeFlag, utils.SyncTargetFlag, utils.ExitWhenSyncedFlag, + utils.GenesisFlag, utils.GCModeFlag, utils.SnapshotFlag, utils.TxLookupLimitFlag, // deprecated diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index c9da08578c96..34ea56acbcdf 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -190,6 +190,11 @@ var ( Usage: "Exits after block synchronisation completes", Category: flags.EthCategory, } + GenesisFlag = &cli.StringFlag{ + Name: "genesis", + Usage: "Load genesis block and configuration from file at this path.", + Category: flags.EthCategory, + } // Dump command options. IterativeOutputFlag = &cli.BoolFlag{ @@ -1593,7 +1598,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) + flags.CheckExclusive(ctx, MainnetFlag, DeveloperFlag, SepoliaFlag, HoleskyFlag, HoodiFlag, NetworkIdFlag, GenesisFlag) flags.CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer // Set configurations from CLI flags @@ -1873,6 +1878,18 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { if !ctx.IsSet(MinerGasPriceFlag.Name) { cfg.Miner.GasPrice = big.NewInt(1) } + case ctx.String(GenesisFlag.Name) != "": + f, err := os.Open(ctx.String(GenesisFlag.Name)) + if err != nil { + Fatalf("Failed to read genesis file: %v", err) + } + defer f.Close() + + genesis := new(core.Genesis) + if err := json.NewDecoder(f).Decode(genesis); err != nil { + Fatalf("Invalid genesis file: %v", err) + } + cfg.Genesis = genesis default: if cfg.NetworkId == 1 { SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash) From caf1b2a7a3e0b878cf8f3bd31c2c9d9ae80347a4 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Tue, 21 Oct 2025 10:15:31 +0800 Subject: [PATCH 2/3] Update GenesisFlag usage description Removed the period at the end of the usage description for the GenesisFlag. --- cmd/utils/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 34ea56acbcdf..ad30eefe5d79 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -192,7 +192,7 @@ var ( } GenesisFlag = &cli.StringFlag{ Name: "genesis", - Usage: "Load genesis block and configuration from file at this path.", + Usage: "Load genesis block and configuration from file at this path", Category: flags.EthCategory, } From 23740764e73911fc8cc860705fb9ff4b1b373382 Mon Sep 17 00:00:00 2001 From: lightclient Date: Tue, 21 Oct 2025 07:16:43 -0600 Subject: [PATCH 3/3] cmd: rename genesis flag to override.genesis --- cmd/geth/main.go | 2 +- cmd/utils/flags.go | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index de0ad2b099a2..6fb031197efb 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -66,6 +66,7 @@ var ( utils.OverrideBPO1, utils.OverrideBPO2, utils.OverrideVerkle, + utils.OverrideGenesisFlag, utils.EnablePersonal, // deprecated utils.TxPoolLocalsFlag, utils.TxPoolNoLocalsFlag, @@ -84,7 +85,6 @@ var ( utils.SyncModeFlag, utils.SyncTargetFlag, utils.ExitWhenSyncedFlag, - utils.GenesisFlag, utils.GCModeFlag, utils.SnapshotFlag, utils.TxLookupLimitFlag, // deprecated diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index ad30eefe5d79..a8336f7fa4c2 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -190,11 +190,6 @@ var ( Usage: "Exits after block synchronisation completes", Category: flags.EthCategory, } - GenesisFlag = &cli.StringFlag{ - Name: "genesis", - Usage: "Load genesis block and configuration from file at this path", - Category: flags.EthCategory, - } // Dump command options. IterativeOutputFlag = &cli.BoolFlag{ @@ -267,6 +262,11 @@ var ( Usage: "Manually specify the Verkle fork timestamp, overriding the bundled setting", Category: flags.EthCategory, } + OverrideGenesisFlag = &cli.StringFlag{ + Name: "override.genesis", + Usage: "Load genesis block and configuration from file at this path", + Category: flags.EthCategory, + } SyncModeFlag = &cli.StringFlag{ Name: "syncmode", Usage: `Blockchain sync mode ("snap" or "full")`, @@ -1598,7 +1598,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, GenesisFlag) + flags.CheckExclusive(ctx, MainnetFlag, DeveloperFlag, SepoliaFlag, HoleskyFlag, HoodiFlag, NetworkIdFlag, OverrideGenesisFlag) flags.CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer // Set configurations from CLI flags @@ -1878,8 +1878,8 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { if !ctx.IsSet(MinerGasPriceFlag.Name) { cfg.Miner.GasPrice = big.NewInt(1) } - case ctx.String(GenesisFlag.Name) != "": - f, err := os.Open(ctx.String(GenesisFlag.Name)) + case ctx.String(OverrideGenesisFlag.Name) != "": + f, err := os.Open(ctx.String(OverrideGenesisFlag.Name)) if err != nil { Fatalf("Failed to read genesis file: %v", err) }