From 07fa2a0f7c07b4bb341fdac56b08716f664511df Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Wed, 28 May 2025 18:57:52 +0800 Subject: [PATCH] move devmode banner construction into its own function. remove uneccessary TODO --- cmd/geth/config.go | 77 ++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 36f1131009..b63eafe531 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -181,6 +181,45 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) { return stack, cfg } +// constructs the disclaimer text block which will be printed in the logs upon +// startup when Geth is running in dev mode. +func constructDevModeBanner(ctx *cli.Context, cfg gethConfig) string { + devModeBanner := `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. +` + if !ctx.IsSet(utils.DataDirFlag.Name) { + devModeBanner += fmt.Sprintf(` + + Running in ephemeral mode. The following account has been prefunded in the genesis: + + Account + ------------------ + 0x%x (10^49 ETH) +`, cfg.Eth.Miner.PendingFeeRecipient) + if cfg.Eth.Miner.PendingFeeRecipient == utils.DeveloperAddr { + devModeBanner += fmt.Sprintf(` + Private Key + ------------------ + 0x%x +`, crypto.FromECDSA(utils.DeveloperKey)) + } + } + + return devModeBanner +} + // makeFullNode loads geth configuration and creates the Ethereum backend. func makeFullNode(ctx *cli.Context) *node.Node { stack, cfg := makeConfigNode(ctx) @@ -241,42 +280,8 @@ func makeFullNode(ctx *cli.Context) *node.Node { catalyst.RegisterSimulatedBeaconAPIs(stack, simBeacon) stack.RegisterLifecycle(simBeacon) - // TODO: move banner construction into its own function - devModeBanner := `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. -` - if !ctx.IsSet(utils.DataDirFlag.Name) { - devModeBanner += fmt.Sprintf(` - - Running in ephemeral mode. The following account has been prefunded in the genesis: - - Account - ------------------ - 0x%x (10^49 ETH) -`, cfg.Eth.Miner.PendingFeeRecipient) - // TODO: check that pendingfeerecipient is overriden when custom keystore is specifieid, - // and that it is the developer addr otherwise. - if cfg.Eth.Miner.PendingFeeRecipient == utils.DeveloperAddr { - devModeBanner += fmt.Sprintf(` - Private Key - ------------------ - 0x%x -`, crypto.FromECDSA(utils.DeveloperKey)) - } - } - for _, line := range strings.Split(devModeBanner, "\n") { + banner := constructDevModeBanner(ctx, cfg) + for _, line := range strings.Split(banner, "\n") { log.Warn(line) } } else if ctx.IsSet(utils.BeaconApiFlag.Name) {