diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 4215403234..739317595b 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -20,6 +20,7 @@ import ( "bufio" "errors" "fmt" + "github.com/ethereum/go-ethereum/crypto" "os" "reflect" "runtime" @@ -239,6 +240,31 @@ func makeFullNode(ctx *cli.Context) *node.Node { } catalyst.RegisterSimulatedBeaconAPIs(stack, simBeacon) stack.RegisterLifecycle(simBeacon) + + devModeBanner := `You are running Geth in development mode. Please note the following: + 1. Unless --dev.period is specified, the client will mine blocks as soon as there + are transactions in the pool. It will mine as fast as possible until the pool is empty. + 2. Networking is disabled.` + // if we are running in ephemeral dev mode and a keystore is not set, + // the default developer address will be prefunded. Let the user know + // about this account and its corresponding private key. + if !ctx.IsSet(utils.DataDirFlag.Name) && cfg.Eth.Miner.PendingFeeRecipient == utils.DeveloperAddr { + devModeBanner += fmt.Sprintf(` + 3. --datadir has not been specified. The chain will be kept in memory and not persisted + after client shutdown. The following account has been prefunded in the Genesis: + + Account + ------------------ + 0x%x (10^49 ETH) + + Private Key + ------------------ + 0x%x +`, utils.DeveloperAddr, crypto.FromECDSA(utils.DeveloperKey)) + } + for _, line := range strings.Split(devModeBanner, "\n") { + log.Warn(line) + } } else if ctx.IsSet(utils.BeaconApiFlag.Name) { // Start blsync mode. srv := rpc.NewServer() diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index cd0cd71609..bbc56d79b7 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -984,6 +984,12 @@ var ( } ) +// default account to prefund when running Geth in ephemeral development mode +var ( + DeveloperKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") + DeveloperAddr = crypto.PubkeyToAddress(DeveloperKey.PublicKey) +) + // MakeDataDir retrieves the currently requested data directory, terminating // if none (or the empty string) is specified. If the node is starting a testnet, // then a subdirectory of the specified datadir will be used. @@ -1769,7 +1775,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { } else if accs := ks.Accounts(); len(accs) > 0 { developer = ks.Accounts()[0] } else { - developer, err = ks.NewAccount(passphrase) + developer, err = ks.ImportECDSA(DeveloperKey, passphrase) if err != nil { Fatalf("Failed to create developer account: %v", err) } @@ -1808,30 +1814,7 @@ 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 - var ( - devAddr = developer.Address - devKey *ecdsa.PrivateKey - ) - if devAddr != (common.Address{}) { - devKey, err = crypto.GenerateKey() - if err != nil { - panic(fmt.Errorf("failed to generate dev mode prefunded account key: %v", err)) - } - devAddr = crypto.PubkeyToAddress(devKey.PublicKey) - - devModeAccountsDescr := fmt.Sprintf(`Available Accounts\n -================== -(0) 0x%x (10000.000000000000000000 ETH) - -Private Keys -================== -(0) 0x%x (10000.000000000000000000 ETH) -`, devAddr, crypto.FromECDSA(devKey)) - for _, line := range strings.Split(devModeAccountsDescr, "\n") { - log.Info(line) - } - } - cfg.Genesis = core.DeveloperGenesisBlock(ctx.Uint64(DeveloperGasLimitFlag.Name), &devAddr) + cfg.Genesis = core.DeveloperGenesisBlock(ctx.Uint64(DeveloperGasLimitFlag.Name), &developer.Address) } if !ctx.IsSet(MinerGasPriceFlag.Name) { cfg.Miner.GasPrice = big.NewInt(1)