From ffbb83802cb069594658c00acefa9652287917eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 24 Oct 2017 12:22:11 +0300 Subject: [PATCH] cmd, core: allow --dev to use persistent storage too --- cmd/utils/flags.go | 21 +++++++++++++++------ console/console_test.go | 2 +- core/genesis.go | 26 +++++++++++++------------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 3af625a6ac..a996b9d0a4 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -990,16 +990,25 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { } cfg.Genesis = core.DefaultRinkebyGenesisBlock() case ctx.GlobalBool(DeveloperFlag.Name): - faucet, err := ks.NewAccount("") - if err != nil { - Fatalf("Failed to create developer account: %v", err) + // Create new developer account or reuse existing one + var ( + developer accounts.Account + err error + ) + if accs := ks.Accounts(); len(accs) > 0 { + developer = ks.Accounts()[0] + } else { + developer, err = ks.NewAccount("") + if err != nil { + Fatalf("Failed to create developer account: %v", err) + } } - if err := ks.Unlock(faucet, ""); err != nil { + if err := ks.Unlock(developer, ""); err != nil { Fatalf("Failed to unlock developer account: %v", err) } - log.Info("Created developer account", "address", faucet.Address) + log.Info("Using developer account", "address", developer.Address) - cfg.Genesis = core.DefaultDeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), faucet.Address) + cfg.Genesis = core.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address) if !ctx.GlobalIsSet(GasPriceFlag.Name) { cfg.GasPrice = big.NewInt(1) } diff --git a/console/console_test.go b/console/console_test.go index 0bc3d436e5..a159b62bbf 100644 --- a/console/console_test.go +++ b/console/console_test.go @@ -94,7 +94,7 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester { t.Fatalf("failed to create node: %v", err) } ethConf := ð.Config{ - Genesis: core.DefaultDeveloperGenesisBlock(15, common.Address{}), + Genesis: core.DeveloperGenesisBlock(15, common.Address{}), Etherbase: common.HexToAddress(testAddress), PowTest: true, } diff --git a/core/genesis.go b/core/genesis.go index 01ae8e9088..26b1c9f63f 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -342,9 +342,9 @@ func DefaultRinkebyGenesisBlock() *Genesis { } } -// DefaultDeveloperGenesisBlock returns the 'geth --dev' genesis block. Note, this -// must be seeded with the -func DefaultDeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis { +// DeveloperGenesisBlock returns the 'geth --dev' genesis block. Note, this must +// be seeded with the +func DeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis { // Override the default period to the user requested one config := *params.AllCliqueProtocolChanges config.Clique.Period = period @@ -353,18 +353,18 @@ func DefaultDeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis return &Genesis{ Config: &config, ExtraData: append(append(make([]byte, 32), faucet[:]...), make([]byte, 65)...), - GasLimit: 4712388, + GasLimit: 6283185, Difficulty: big.NewInt(1), Alloc: map[common.Address]GenesisAccount{ - common.Address{1}: GenesisAccount{Balance: big.NewInt(1)}, // ECRecover - common.Address{2}: GenesisAccount{Balance: big.NewInt(1)}, // SHA256 - common.Address{3}: GenesisAccount{Balance: big.NewInt(1)}, // RIPEMD - common.Address{4}: GenesisAccount{Balance: big.NewInt(1)}, // Identity - common.Address{5}: GenesisAccount{Balance: big.NewInt(1)}, // ModExp - common.Address{6}: GenesisAccount{Balance: big.NewInt(1)}, // ECAdd - common.Address{7}: GenesisAccount{Balance: big.NewInt(1)}, // ECScalarMul - common.Address{8}: GenesisAccount{Balance: big.NewInt(1)}, // ECPairing - faucet: GenesisAccount{Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(8))}, + common.BytesToAddress([]byte{1}): GenesisAccount{Balance: big.NewInt(1)}, // ECRecover + common.BytesToAddress([]byte{2}): GenesisAccount{Balance: big.NewInt(1)}, // SHA256 + common.BytesToAddress([]byte{3}): GenesisAccount{Balance: big.NewInt(1)}, // RIPEMD + common.BytesToAddress([]byte{4}): GenesisAccount{Balance: big.NewInt(1)}, // Identity + common.BytesToAddress([]byte{5}): GenesisAccount{Balance: big.NewInt(1)}, // ModExp + common.BytesToAddress([]byte{6}): GenesisAccount{Balance: big.NewInt(1)}, // ECAdd + common.BytesToAddress([]byte{7}): GenesisAccount{Balance: big.NewInt(1)}, // ECScalarMul + common.BytesToAddress([]byte{8}): GenesisAccount{Balance: big.NewInt(1)}, // ECPairing + faucet: GenesisAccount{Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))}, }, } }