Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: fix when db empty on startup overrides for TTD and gray glacier do not work #25146

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
if err != nil {
return genesis.Config, common.Hash{}, err
}
performConfigOverride(genesis.Config, overrideGrayGlacier, overrideTerminalTotalDifficulty)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we should clone genesis.Config before overriding it?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0x62044d2cab405388891ee6d53747817f34c0f00341cde548c0ce9834e9718f27

return genesis.Config, block.Hash(), nil
}
// We have the genesis block in database(perhaps in ancient database)
Expand Down Expand Up @@ -279,12 +280,7 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
}
// Get the existing chain configuration.
newcfg := genesis.configOrDefault(stored)
if overrideGrayGlacier != nil {
newcfg.GrayGlacierBlock = overrideGrayGlacier
}
if overrideTerminalTotalDifficulty != nil {
newcfg.TerminalTotalDifficulty = overrideTerminalTotalDifficulty
}
performConfigOverride(newcfg, overrideGrayGlacier, overrideTerminalTotalDifficulty)
if err := newcfg.CheckConfigForkOrder(); err != nil {
return newcfg, common.Hash{}, err
}
Expand All @@ -301,12 +297,7 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
// apply the overrides.
if genesis == nil && stored != params.MainnetGenesisHash {
newcfg = storedcfg
if overrideGrayGlacier != nil {
newcfg.GrayGlacierBlock = overrideGrayGlacier
}
if overrideTerminalTotalDifficulty != nil {
newcfg.TerminalTotalDifficulty = overrideTerminalTotalDifficulty
}
performConfigOverride(newcfg, overrideGrayGlacier, overrideTerminalTotalDifficulty)
}
// Check config compatibility and write the config. Compatibility errors
// are returned to the caller unless we're already at block zero.
Expand All @@ -322,6 +313,15 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, override
return newcfg, stored, nil
}

func performConfigOverride(cfg *params.ChainConfig, overrideGrayGlacier *big.Int, overrideTerminalTotalDifficulty *big.Int) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps there is a better place for this function? should I make it a unexported method of Genesis? Does it need documentation, other private methods don't have?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0x62044d2cab405388891ee6d53747817f34c0f00341cde548c0ce9834e9718f27

if overrideGrayGlacier != nil {
cfg.GrayGlacierBlock = overrideGrayGlacier
}
if overrideTerminalTotalDifficulty != nil {
cfg.TerminalTotalDifficulty = overrideTerminalTotalDifficulty
}
}

func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig {
switch {
case g != nil:
Expand Down