Skip to content

Commit d821f7f

Browse files
cmd/geth, cmd/utils: log prefunded account/key in ephemeral development mode (#31898)
This PR modifies the disclaimer/banner that is printed when starting up Geth in dev mode: * if the client is spun up in ephemeral dev mode with a keystore override, the address of the first (prefunded) account is printed. * if the client is spun up in ephemeral mode without a keystore override, the genesis allocation contains a single static prefunded EOA account. It's address and private key are logged. * the banner is printed at the end of client initialization to make it more prominent. Previously, it was logged towards the beginning of client initialization and subsequent logging from startup filled the terminal, pushing it out of view of the user. Other change is that we now use a static prefunded dev account instead of generating a random one when instantiating a new dev mode chain. This is an example of what the banner looks like: ``` WARN [05-28|23:05:16.475] You are running Geth in --dev mode. Please note the following: WARN [05-28|23:05:16.475] WARN [05-28|23:05:16.475] 1. This mode is only intended for fast, iterative development without assumptions on WARN [05-28|23:05:16.475] security or persistence. WARN [05-28|23:05:16.475] 2. The database is created in memory unless specified otherwise. Therefore, shutting down WARN [05-28|23:05:16.475] your computer or losing power will wipe your entire block data and chain state for WARN [05-28|23:05:16.475] your dev environment. WARN [05-28|23:05:16.475] 3. A random, pre-allocated developer account will be available and unlocked as WARN [05-28|23:05:16.475] eth.coinbase, which can be used for testing. The random dev account is temporary, WARN [05-28|23:05:16.475] stored on a ramdisk, and will be lost if your machine is restarted. WARN [05-28|23:05:16.475] 4. Mining is enabled by default. However, the client will only seal blocks if transactions WARN [05-28|23:05:16.475] are pending in the mempool. The miner's minimum accepted gas price is 1. WARN [05-28|23:05:16.475] 5. Networking is disabled; there is no listen-address, the maximum number of peers is set WARN [05-28|23:05:16.475] to 0, and discovery is disabled. WARN [05-28|23:05:16.475] WARN [05-28|23:05:16.475] WARN [05-28|23:05:16.475] Running in ephemeral mode. The following account has been prefunded in the genesis: WARN [05-28|23:05:16.475] WARN [05-28|23:05:16.475] Account WARN [05-28|23:05:16.475] ------------------ WARN [05-28|23:05:16.475] 0x71562b71999873db5b286df957af199ec94617f7 (10^49 ETH) WARN [05-28|23:05:16.475] WARN [05-28|23:05:16.475] Private Key WARN [05-28|23:05:16.475] ------------------ WARN [05-28|23:05:16.475] 0xb71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291 WARN [05-28|23:05:16.475] ``` closes #31796 --------- Co-authored-by: jwasinger <[email protected]>
1 parent e9e4e8b commit d821f7f

File tree

3 files changed

+60
-23
lines changed

3 files changed

+60
-23
lines changed

cmd/geth/config.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/ethereum/go-ethereum/cmd/utils"
3737
"github.com/ethereum/go-ethereum/common"
3838
"github.com/ethereum/go-ethereum/common/hexutil"
39+
"github.com/ethereum/go-ethereum/crypto"
3940
"github.com/ethereum/go-ethereum/eth/catalyst"
4041
"github.com/ethereum/go-ethereum/eth/ethconfig"
4142
"github.com/ethereum/go-ethereum/internal/flags"
@@ -180,6 +181,45 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
180181
return stack, cfg
181182
}
182183

184+
// constructs the disclaimer text block which will be printed in the logs upon
185+
// startup when Geth is running in dev mode.
186+
func constructDevModeBanner(ctx *cli.Context, cfg gethConfig) string {
187+
devModeBanner := `You are running Geth in --dev mode. Please note the following:
188+
189+
1. This mode is only intended for fast, iterative development without assumptions on
190+
security or persistence.
191+
2. The database is created in memory unless specified otherwise. Therefore, shutting down
192+
your computer or losing power will wipe your entire block data and chain state for
193+
your dev environment.
194+
3. A random, pre-allocated developer account will be available and unlocked as
195+
eth.coinbase, which can be used for testing. The random dev account is temporary,
196+
stored on a ramdisk, and will be lost if your machine is restarted.
197+
4. Mining is enabled by default. However, the client will only seal blocks if transactions
198+
are pending in the mempool. The miner's minimum accepted gas price is 1.
199+
5. Networking is disabled; there is no listen-address, the maximum number of peers is set
200+
to 0, and discovery is disabled.
201+
`
202+
if !ctx.IsSet(utils.DataDirFlag.Name) {
203+
devModeBanner += fmt.Sprintf(`
204+
205+
Running in ephemeral mode. The following account has been prefunded in the genesis:
206+
207+
Account
208+
------------------
209+
0x%x (10^49 ETH)
210+
`, cfg.Eth.Miner.PendingFeeRecipient)
211+
if cfg.Eth.Miner.PendingFeeRecipient == utils.DeveloperAddr {
212+
devModeBanner += fmt.Sprintf(`
213+
Private Key
214+
------------------
215+
0x%x
216+
`, crypto.FromECDSA(utils.DeveloperKey))
217+
}
218+
}
219+
220+
return devModeBanner
221+
}
222+
183223
// makeFullNode loads geth configuration and creates the Ethereum backend.
184224
func makeFullNode(ctx *cli.Context) *node.Node {
185225
stack, cfg := makeConfigNode(ctx)
@@ -239,6 +279,11 @@ func makeFullNode(ctx *cli.Context) *node.Node {
239279
}
240280
catalyst.RegisterSimulatedBeaconAPIs(stack, simBeacon)
241281
stack.RegisterLifecycle(simBeacon)
282+
283+
banner := constructDevModeBanner(ctx, cfg)
284+
for _, line := range strings.Split(banner, "\n") {
285+
log.Warn(line)
286+
}
242287
} else if ctx.IsSet(utils.BeaconApiFlag.Name) {
243288
// Start blsync mode.
244289
srv := rpc.NewServer()

cmd/geth/main.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -294,24 +294,6 @@ func prepare(ctx *cli.Context) {
294294
case ctx.IsSet(utils.HoodiFlag.Name):
295295
log.Info("Starting Geth on Hoodi testnet...")
296296

297-
case ctx.IsSet(utils.DeveloperFlag.Name):
298-
log.Info("Starting Geth in ephemeral dev mode...")
299-
log.Warn(`You are running Geth in --dev mode. Please note the following:
300-
301-
1. This mode is only intended for fast, iterative development without assumptions on
302-
security or persistence.
303-
2. The database is created in memory unless specified otherwise. Therefore, shutting down
304-
your computer or losing power will wipe your entire block data and chain state for
305-
your dev environment.
306-
3. A random, pre-allocated developer account will be available and unlocked as
307-
eth.coinbase, which can be used for testing. The random dev account is temporary,
308-
stored on a ramdisk, and will be lost if your machine is restarted.
309-
4. Mining is enabled by default. However, the client will only seal blocks if transactions
310-
are pending in the mempool. The miner's minimum accepted gas price is 1.
311-
5. Networking is disabled; there is no listen-address, the maximum number of peers is set
312-
to 0, and discovery is disabled.
313-
`)
314-
315297
case !ctx.IsSet(utils.NetworkIdFlag.Name):
316298
log.Info("Starting Geth on Ethereum mainnet...")
317299
}

cmd/utils/flags.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,12 @@ var (
984984
}
985985
)
986986

987+
// default account to prefund when running Geth in dev mode
988+
var (
989+
DeveloperKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
990+
DeveloperAddr = crypto.PubkeyToAddress(DeveloperKey.PublicKey)
991+
)
992+
987993
// MakeDataDir retrieves the currently requested data directory, terminating
988994
// if none (or the empty string) is specified. If the node is starting a testnet,
989995
// then a subdirectory of the specified datadir will be used.
@@ -1769,9 +1775,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
17691775
} else if accs := ks.Accounts(); len(accs) > 0 {
17701776
developer = ks.Accounts()[0]
17711777
} else {
1772-
developer, err = ks.NewAccount(passphrase)
1778+
developer, err = ks.ImportECDSA(DeveloperKey, passphrase)
17731779
if err != nil {
1774-
Fatalf("Failed to create developer account: %v", err)
1780+
Fatalf("Failed to import developer account: %v", err)
17751781
}
17761782
}
17771783
// Make sure the address is configured as fee recipient, otherwise
@@ -1786,14 +1792,18 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
17861792
}
17871793
log.Info("Using developer account", "address", developer.Address)
17881794

1789-
// Create a new developer genesis block or reuse existing one
1795+
// configure default developer genesis which will be used unless a
1796+
// datadir is specified and a chain is preexisting at that location.
17901797
cfg.Genesis = core.DeveloperGenesisBlock(ctx.Uint64(DeveloperGasLimitFlag.Name), &developer.Address)
1798+
1799+
// If a datadir is specified, ensure that any preexisting chain in that location
1800+
// has a configuration that is compatible with dev mode: it must be merged at genesis.
17911801
if ctx.IsSet(DataDirFlag.Name) {
17921802
chaindb := tryMakeReadOnlyDatabase(ctx, stack)
17931803
if rawdb.ReadCanonicalHash(chaindb, 0) != (common.Hash{}) {
1794-
cfg.Genesis = nil // fallback to db content
1804+
// signal fallback to preexisting chain on disk
1805+
cfg.Genesis = nil
17951806

1796-
//validate genesis has PoS enabled in block 0
17971807
genesis, err := core.ReadGenesis(chaindb)
17981808
if err != nil {
17991809
Fatalf("Could not read genesis from database: %v", err)

0 commit comments

Comments
 (0)