Skip to content

Commit 3cfcd25

Browse files
jwasingerfjllightclient
authored
cmd/geth: add support for --dev flag in dumpgenesis (#28463)
Co-authored-by: Felix Lange <[email protected]> Co-authored-by: lightclient <[email protected]>
1 parent 104dbf7 commit 3cfcd25

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

cmd/geth/chaincmd.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,21 @@ func initGenesis(ctx *cli.Context) error {
224224
}
225225

226226
func dumpGenesis(ctx *cli.Context) error {
227-
// if there is a testnet preset enabled, dump that
227+
// check if there is a testnet preset enabled
228+
var genesis *core.Genesis
228229
if utils.IsNetworkPreset(ctx) {
229-
genesis := utils.MakeGenesis(ctx)
230+
genesis = utils.MakeGenesis(ctx)
231+
} else if ctx.IsSet(utils.DeveloperFlag.Name) && !ctx.IsSet(utils.DataDirFlag.Name) {
232+
genesis = core.DeveloperGenesisBlock(11_500_000, nil)
233+
}
234+
235+
if genesis != nil {
230236
if err := json.NewEncoder(os.Stdout).Encode(genesis); err != nil {
231237
utils.Fatalf("could not encode genesis: %s", err)
232238
}
233239
return nil
234240
}
241+
235242
// dump whatever already exists in the datadir
236243
stack, _ := makeConfigNode(ctx)
237244
for _, name := range []string{"chaindata", "lightchaindata"} {
@@ -256,7 +263,7 @@ func dumpGenesis(ctx *cli.Context) error {
256263
if ctx.IsSet(utils.DataDirFlag.Name) {
257264
utils.Fatalf("no existing datadir at %s", stack.Config().DataDir)
258265
}
259-
utils.Fatalf("no network preset provided, no existing genesis in the default datadir")
266+
utils.Fatalf("no network preset provided, and no genesis exists in the default datadir")
260267
return nil
261268
}
262269

cmd/utils/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
18651865
log.Info("Using developer account", "address", developer.Address)
18661866

18671867
// Create a new developer genesis block or reuse existing one
1868-
cfg.Genesis = core.DeveloperGenesisBlock(ctx.Uint64(DeveloperGasLimitFlag.Name), developer.Address)
1868+
cfg.Genesis = core.DeveloperGenesisBlock(ctx.Uint64(DeveloperGasLimitFlag.Name), &developer.Address)
18691869
if ctx.IsSet(DataDirFlag.Name) {
18701870
chaindb := tryMakeReadOnlyDatabase(ctx, stack)
18711871
if rawdb.ReadCanonicalHash(chaindb, 0) != (common.Hash{}) {

console/console_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func newTester(t *testing.T, confOverride func(*ethconfig.Config)) *tester {
9494
t.Fatalf("failed to create node: %v", err)
9595
}
9696
ethConf := &ethconfig.Config{
97-
Genesis: core.DeveloperGenesisBlock(11_500_000, common.Address{}),
97+
Genesis: core.DeveloperGenesisBlock(11_500_000, nil),
9898
Miner: miner.Config{
9999
Etherbase: common.HexToAddress(testAddress),
100100
},

core/genesis.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,12 +580,12 @@ func DefaultHoleskyGenesisBlock() *Genesis {
580580
}
581581

582582
// DeveloperGenesisBlock returns the 'geth --dev' genesis block.
583-
func DeveloperGenesisBlock(gasLimit uint64, faucet common.Address) *Genesis {
583+
func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) *Genesis {
584584
// Override the default period to the user requested one
585585
config := *params.AllDevChainProtocolChanges
586586

587587
// Assemble and return the genesis with the precompiles and faucet pre-funded
588-
return &Genesis{
588+
genesis := &Genesis{
589589
Config: &config,
590590
GasLimit: gasLimit,
591591
BaseFee: big.NewInt(params.InitialBaseFee),
@@ -600,9 +600,12 @@ func DeveloperGenesisBlock(gasLimit uint64, faucet common.Address) *Genesis {
600600
common.BytesToAddress([]byte{7}): {Balance: big.NewInt(1)}, // ECScalarMul
601601
common.BytesToAddress([]byte{8}): {Balance: big.NewInt(1)}, // ECPairing
602602
common.BytesToAddress([]byte{9}): {Balance: big.NewInt(1)}, // BLAKE2b
603-
faucet: {Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))},
604603
},
605604
}
605+
if faucet != nil {
606+
genesis.Alloc[*faucet] = GenesisAccount{Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))}
607+
}
608+
return genesis
606609
}
607610

608611
func decodePrealloc(data string) GenesisAlloc {

eth/catalyst/simulated_beacon_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func TestSimulatedBeaconSendWithdrawals(t *testing.T) {
8585

8686
// short period (1 second) for testing purposes
8787
var gasLimit uint64 = 10_000_000
88-
genesis := core.DeveloperGenesisBlock(gasLimit, testAddr)
88+
genesis := core.DeveloperGenesisBlock(gasLimit, &testAddr)
8989
node, ethService, mock := startSimulatedBeaconEthService(t, genesis)
9090
_ = mock
9191
defer node.Close()

0 commit comments

Comments
 (0)