Skip to content

Commit 0b53e48

Browse files
authored
Merge pull request #21352 from karalabe/dev-noinit-genesis
cmd/utils: reuse existing genesis in persistent dev mode
2 parents 123864f + 9e22e91 commit 0b53e48

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

cmd/utils/flags.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"github.com/ethereum/go-ethereum/consensus/clique"
4141
"github.com/ethereum/go-ethereum/consensus/ethash"
4242
"github.com/ethereum/go-ethereum/core"
43+
"github.com/ethereum/go-ethereum/core/rawdb"
4344
"github.com/ethereum/go-ethereum/core/vm"
4445
"github.com/ethereum/go-ethereum/crypto"
4546
"github.com/ethereum/go-ethereum/eth"
@@ -1627,7 +1628,17 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
16271628
}
16281629
log.Info("Using developer account", "address", developer.Address)
16291630

1631+
// Create a new developer genesis block or reuse existing one
16301632
cfg.Genesis = core.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address)
1633+
if ctx.GlobalIsSet(DataDirFlag.Name) {
1634+
// Check if we have an already initialized chain and fall back to
1635+
// that if so. Otherwise we need to generate a new genesis spec.
1636+
chaindb := MakeChainDatabase(ctx, stack)
1637+
if rawdb.ReadCanonicalHash(chaindb, 0) != (common.Hash{}) {
1638+
cfg.Genesis = nil // fallback to db content
1639+
}
1640+
chaindb.Close()
1641+
}
16311642
if !ctx.GlobalIsSet(MinerGasPriceFlag.Name) && !ctx.GlobalIsSet(LegacyMinerGasPriceFlag.Name) {
16321643
cfg.Miner.GasPrice = big.NewInt(1)
16331644
}

0 commit comments

Comments
 (0)