From 2f82dee875229f4cd1b1e7888640dec1c7fe9307 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Wed, 28 May 2025 18:24:16 +0800 Subject: [PATCH] fix dev mode instantiation with preexisting datadir and add docs to clarify the code that was broken. --- cmd/geth/main.go | 18 ------------------ cmd/utils/flags.go | 12 ++++++------ 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index b3cbb06be5..ce33e3378a 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -294,24 +294,6 @@ func prepare(ctx *cli.Context) { case ctx.IsSet(utils.HoodiFlag.Name): log.Info("Starting Geth on Hoodi testnet...") - case ctx.IsSet(utils.DeveloperFlag.Name): - log.Info("Starting Geth in ephemeral dev mode...") - log.Warn(`You are running Geth in --dev mode. Please note the following: - - 1. This mode is only intended for fast, iterative development without assumptions on - security or persistence. - 2. The database is created in memory unless specified otherwise. Therefore, shutting down - your computer or losing power will wipe your entire block data and chain state for - your dev environment. - 3. A random, pre-allocated developer account will be available and unlocked as - eth.coinbase, which can be used for testing. The random dev account is temporary, - stored on a ramdisk, and will be lost if your machine is restarted. - 4. Mining is enabled by default. However, the client will only seal blocks if transactions - are pending in the mempool. The miner's minimum accepted gas price is 1. - 5. Networking is disabled; there is no listen-address, the maximum number of peers is set - to 0, and discovery is disabled. -`) - case !ctx.IsSet(utils.NetworkIdFlag.Name): log.Info("Starting Geth on Ethereum mainnet...") } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index bbc56d79b7..fb674b5f04 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1792,12 +1792,15 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { } log.Info("Using developer account", "address", developer.Address) - // Create a new developer genesis block or reuse existing one + // configure default developer genesis which will be used unless a + // datadir is specified and a chain is preexisting at that location. + cfg.Genesis = core.DeveloperGenesisBlock(ctx.Uint64(DeveloperGasLimitFlag.Name), &developer.Address) + + // If a datadir is specified, ensure that any preexisting chain in that location + // has a configuration that is compatible with dev mode: it must be merged at genesis. if ctx.IsSet(DataDirFlag.Name) { chaindb := tryMakeReadOnlyDatabase(ctx, stack) if rawdb.ReadCanonicalHash(chaindb, 0) != (common.Hash{}) { - // validate that the stored genesis config compatible with dev-mode: - // it must be merged at genesis genesis, err := core.ReadGenesis(chaindb) if err != nil { Fatalf("Could not read genesis from database: %v", err) @@ -1812,9 +1815,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { } } chaindb.Close() - } else { - // if no datadir is specified, dev mode runs ephemerally in memory - cfg.Genesis = core.DeveloperGenesisBlock(ctx.Uint64(DeveloperGasLimitFlag.Name), &developer.Address) } if !ctx.IsSet(MinerGasPriceFlag.Name) { cfg.Miner.GasPrice = big.NewInt(1)