Skip to content

Commit b02b46d

Browse files
committed
cmd/geth: add flag to override genesis
1 parent 891bbad commit b02b46d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ var (
8484
utils.SyncModeFlag,
8585
utils.SyncTargetFlag,
8686
utils.ExitWhenSyncedFlag,
87+
utils.GenesisFlag,
8788
utils.GCModeFlag,
8889
utils.SnapshotFlag,
8990
utils.TxLookupLimitFlag, // deprecated

cmd/utils/flags.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ var (
190190
Usage: "Exits after block synchronisation completes",
191191
Category: flags.EthCategory,
192192
}
193+
GenesisFlag = &cli.StringFlag{
194+
Name: "genesis",
195+
Usage: "Load genesis block and configuration from file at this path.",
196+
Category: flags.EthCategory,
197+
}
193198

194199
// Dump command options.
195200
IterativeOutputFlag = &cli.BoolFlag{
@@ -1593,7 +1598,7 @@ func setRequiredBlocks(ctx *cli.Context, cfg *ethconfig.Config) {
15931598
// SetEthConfig applies eth-related command line flags to the config.
15941599
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
15951600
// Avoid conflicting network flags, don't allow network id override on preset networks
1596-
flags.CheckExclusive(ctx, MainnetFlag, DeveloperFlag, SepoliaFlag, HoleskyFlag, HoodiFlag, NetworkIdFlag)
1601+
flags.CheckExclusive(ctx, MainnetFlag, DeveloperFlag, SepoliaFlag, HoleskyFlag, HoodiFlag, NetworkIdFlag, GenesisFlag)
15971602
flags.CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer
15981603

15991604
// Set configurations from CLI flags
@@ -1873,6 +1878,18 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
18731878
if !ctx.IsSet(MinerGasPriceFlag.Name) {
18741879
cfg.Miner.GasPrice = big.NewInt(1)
18751880
}
1881+
case ctx.String(GenesisFlag.Name) != "":
1882+
f, err := os.Open(ctx.String(GenesisFlag.Name))
1883+
if err != nil {
1884+
Fatalf("Failed to read genesis file: %v", err)
1885+
}
1886+
defer f.Close()
1887+
1888+
genesis := new(core.Genesis)
1889+
if err := json.NewDecoder(f).Decode(genesis); err != nil {
1890+
Fatalf("Invalid genesis file: %v", err)
1891+
}
1892+
cfg.Genesis = genesis
18761893
default:
18771894
if cfg.NetworkId == 1 {
18781895
SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash)

0 commit comments

Comments
 (0)