cmd, core: allow --dev to use persistent storage too

This commit is contained in:
Péter Szilágyi 2017-10-24 12:22:11 +03:00
parent 53ff59b8a0
commit ffbb83802c
No known key found for this signature in database
GPG key ID: E9AE538CEDF8293D
3 changed files with 29 additions and 20 deletions

View file

@ -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)
}

View file

@ -94,7 +94,7 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester {
t.Fatalf("failed to create node: %v", err)
}
ethConf := &eth.Config{
Genesis: core.DefaultDeveloperGenesisBlock(15, common.Address{}),
Genesis: core.DeveloperGenesisBlock(15, common.Address{}),
Etherbase: common.HexToAddress(testAddress),
PowTest: true,
}

View file

@ -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))},
},
}
}