Skip to content

Commit 104dbf7

Browse files
jwasingerfjl
andauthored
cmd/utils: validate pre-existing genesis in --dev mode (#28468)
geth --dev can be used with an existing data directory and genesis block. Since dev mode only works with PoS, we need to verify that the merge has happened. Co-authored-by: Felix Lange <fjl@twurst.com>
1 parent d6cea48 commit 104dbf7

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

cmd/utils/flags.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,21 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
18701870
chaindb := tryMakeReadOnlyDatabase(ctx, stack)
18711871
if rawdb.ReadCanonicalHash(chaindb, 0) != (common.Hash{}) {
18721872
cfg.Genesis = nil // fallback to db content
1873+
1874+
//validate genesis has PoS enabled in block 0
1875+
genesis, err := core.ReadGenesis(chaindb)
1876+
if err != nil {
1877+
Fatalf("Could not read genesis from database: %v", err)
1878+
}
1879+
if !genesis.Config.TerminalTotalDifficultyPassed {
1880+
Fatalf("Bad developer-mode genesis configuration: terminalTotalDifficultyPassed must be true in developer mode")
1881+
}
1882+
if genesis.Config.TerminalTotalDifficulty == nil {
1883+
Fatalf("Bad developer-mode genesis configuration: terminalTotalDifficulty must be specified.")
1884+
}
1885+
if genesis.Difficulty.Cmp(genesis.Config.TerminalTotalDifficulty) != 1 {
1886+
Fatalf("Bad developer-mode genesis configuration: genesis block difficulty must be > terminalTotalDifficulty")
1887+
}
18731888
}
18741889
chaindb.Close()
18751890
}

core/genesis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ func DeveloperGenesisBlock(gasLimit uint64, faucet common.Address) *Genesis {
589589
Config: &config,
590590
GasLimit: gasLimit,
591591
BaseFee: big.NewInt(params.InitialBaseFee),
592-
Difficulty: big.NewInt(0),
592+
Difficulty: big.NewInt(1),
593593
Alloc: map[common.Address]GenesisAccount{
594594
common.BytesToAddress([]byte{1}): {Balance: big.NewInt(1)}, // ECRecover
595595
common.BytesToAddress([]byte{2}): {Balance: big.NewInt(1)}, // SHA256

eth/catalyst/simulated_beacon.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ type SimulatedBeacon struct {
8282
}
8383

8484
func NewSimulatedBeacon(period uint64, eth *eth.Ethereum) (*SimulatedBeacon, error) {
85-
chainConfig := eth.APIBackend.ChainConfig()
86-
if !chainConfig.IsDevMode {
87-
return nil, errors.New("incompatible pre-existing chain configuration")
88-
}
8985
block := eth.BlockChain().CurrentBlock()
9086
current := engine.ForkchoiceStateV1{
9187
HeadBlockHash: block.Hash(),

params/config.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ var (
180180
ShanghaiTime: newUint64(0),
181181
TerminalTotalDifficulty: big.NewInt(0),
182182
TerminalTotalDifficultyPassed: true,
183-
IsDevMode: true,
184183
}
185184

186185
// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
@@ -329,9 +328,8 @@ type ChainConfig struct {
329328
TerminalTotalDifficultyPassed bool `json:"terminalTotalDifficultyPassed,omitempty"`
330329

331330
// Various consensus engines
332-
Ethash *EthashConfig `json:"ethash,omitempty"`
333-
Clique *CliqueConfig `json:"clique,omitempty"`
334-
IsDevMode bool `json:"isDev,omitempty"`
331+
Ethash *EthashConfig `json:"ethash,omitempty"`
332+
Clique *CliqueConfig `json:"clique,omitempty"`
335333
}
336334

337335
// EthashConfig is the consensus engine configs for proof-of-work based sealing.

0 commit comments

Comments
 (0)