Skip to content

Commit 9aedb67

Browse files
MariusVanDerWijdenjagdeep sidhu
authored andcommitted
core: apply ttd override to uninitialized db (ethereum#25136)
* core: apply ttd override to genesis block * core: apply overrides properly
1 parent 7c55d82 commit 9aedb67

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

core/genesis.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,18 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
242242
if genesis != nil && genesis.Config == nil {
243243
return params.AllEthashProtocolChanges, common.Hash{}, errGenesisNoConfig
244244
}
245+
246+
applyOverrides := func(config *params.ChainConfig) {
247+
if config != nil {
248+
if overrideTerminalTotalDifficulty != nil {
249+
config.TerminalTotalDifficulty = overrideTerminalTotalDifficulty
250+
}
251+
if overrideGrayGlacier != nil {
252+
config.GrayGlacierBlock = overrideGrayGlacier
253+
}
254+
}
255+
}
256+
245257
// Just commit the new block if there is no stored genesis block.
246258
stored := rawdb.ReadCanonicalHash(db, 0)
247259
if (stored == common.Hash{}) {
@@ -255,6 +267,7 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
255267
if err != nil {
256268
return genesis.Config, common.Hash{}, err
257269
}
270+
applyOverrides(genesis.Config)
258271
return genesis.Config, block.Hash(), nil
259272
}
260273
// We have the genesis block in database(perhaps in ancient database)
@@ -273,6 +286,7 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
273286
if err != nil {
274287
return genesis.Config, hash, err
275288
}
289+
applyOverrides(genesis.Config)
276290
return genesis.Config, block.Hash(), nil
277291
}
278292
// Check whether the genesis block is already written.
@@ -284,12 +298,7 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
284298
}
285299
// Get the existing chain configuration.
286300
newcfg := genesis.configOrDefault(stored)
287-
if overrideGrayGlacier != nil {
288-
newcfg.GrayGlacierBlock = overrideGrayGlacier
289-
}
290-
if overrideTerminalTotalDifficulty != nil {
291-
newcfg.TerminalTotalDifficulty = overrideTerminalTotalDifficulty
292-
}
301+
applyOverrides(newcfg)
293302
if err := newcfg.CheckConfigForkOrder(); err != nil {
294303
return newcfg, common.Hash{}, err
295304
}
@@ -306,12 +315,7 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
306315
// apply the overrides.
307316
if genesis == nil && stored != params.MainnetGenesisHash {
308317
newcfg = storedcfg
309-
if overrideGrayGlacier != nil {
310-
newcfg.GrayGlacierBlock = overrideGrayGlacier
311-
}
312-
if overrideTerminalTotalDifficulty != nil {
313-
newcfg.TerminalTotalDifficulty = overrideTerminalTotalDifficulty
314-
}
318+
applyOverrides(newcfg)
315319
}
316320
// Check config compatibility and write the config. Compatibility errors
317321
// are returned to the caller unless we're already at block zero.

0 commit comments

Comments
 (0)