Skip to content

Commit b56c796

Browse files
committed
cmd, core, eth, els, params: disallow setheads below genesis, tweaks
1 parent fcf3d00 commit b56c796

File tree

10 files changed

+147
-157
lines changed

10 files changed

+147
-157
lines changed

cmd/geth/config.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,9 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
158158
// makeFullNode loads geth configuration and creates the Ethereum backend.
159159
func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
160160
stack, cfg := makeConfigNode(ctx)
161-
if ctx.IsSet(utils.OverrideTerminalTotalDifficulty.Name) {
162-
cfg.Eth.OverrideTerminalTotalDifficulty = flags.GlobalBig(ctx, utils.OverrideTerminalTotalDifficulty.Name)
161+
if ctx.IsSet(utils.OverrideShanghai.Name) {
162+
cfg.Eth.OverrideShanghai = flags.GlobalBig(ctx, utils.OverrideShanghai.Name)
163163
}
164-
if ctx.IsSet(utils.OverrideTerminalTotalDifficultyPassed.Name) {
165-
override := ctx.Bool(utils.OverrideTerminalTotalDifficultyPassed.Name)
166-
cfg.Eth.OverrideTerminalTotalDifficultyPassed = &override
167-
}
168-
169164
backend, eth := utils.RegisterEthService(stack, &cfg.Eth)
170165

171166
// Configure log filter RPC API.

cmd/geth/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ var (
6464
utils.NoUSBFlag,
6565
utils.USBFlag,
6666
utils.SmartCardDaemonPathFlag,
67-
utils.OverrideTerminalTotalDifficulty,
68-
utils.OverrideTerminalTotalDifficultyPassed,
67+
utils.OverrideShanghai,
6968
utils.EthashCacheDirFlag,
7069
utils.EthashCachesInMemoryFlag,
7170
utils.EthashCachesOnDiskFlag,

cmd/utils/flags.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,9 @@ var (
271271
Value: 2048,
272272
Category: flags.EthCategory,
273273
}
274-
OverrideTerminalTotalDifficulty = &flags.BigFlag{
275-
Name: "override.terminaltotaldifficulty",
276-
Usage: "Manually specify TerminalTotalDifficulty, overriding the bundled setting",
277-
Category: flags.EthCategory,
278-
}
279-
OverrideTerminalTotalDifficultyPassed = &cli.BoolFlag{
280-
Name: "override.terminaltotaldifficultypassed",
281-
Usage: "Manually specify TerminalTotalDifficultyPassed, overriding the bundled setting",
274+
OverrideShanghai = &flags.BigFlag{
275+
Name: "override.shanghai",
276+
Usage: "Manually specify the Shanghai fork timestamp, overriding the bundled setting",
282277
Category: flags.EthCategory,
283278
}
284279
// Light server and client settings

core/genesis.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ func (e *GenesisMismatchError) Error() string {
269269

270270
// ChainOverrides contains the changes to chain config.
271271
type ChainOverrides struct {
272-
OverrideTerminalTotalDifficulty *big.Int
273-
OverrideTerminalTotalDifficultyPassed *bool
272+
OverrideShanghai *big.Int
274273
}
275274

276275
// SetupGenesisBlock writes or updates the genesis block in db.
@@ -296,15 +295,11 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *trie.Database, gen
296295
}
297296
applyOverrides := func(config *params.ChainConfig) {
298297
if config != nil {
299-
if overrides != nil && overrides.OverrideTerminalTotalDifficulty != nil {
300-
config.TerminalTotalDifficulty = overrides.OverrideTerminalTotalDifficulty
301-
}
302-
if overrides != nil && overrides.OverrideTerminalTotalDifficultyPassed != nil {
303-
config.TerminalTotalDifficultyPassed = *overrides.OverrideTerminalTotalDifficultyPassed
298+
if overrides != nil && overrides.OverrideShanghai != nil {
299+
config.ShanghaiTime = overrides.OverrideShanghai
304300
}
305301
}
306302
}
307-
308303
// Just commit the new block if there is no stored genesis block.
309304
stored := rawdb.ReadCanonicalHash(db, 0)
310305
if (stored == common.Hash{}) {

core/headerchain.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,19 @@ func (hc *HeaderChain) SetHeadWithTimestamp(time uint64, updateFn UpdateHeadBloc
578578
// setHead rewinds the local chain to a new head block or a head timestamp.
579579
// Everything above the new head will be deleted and the new one set.
580580
func (hc *HeaderChain) setHead(headBlock uint64, headTime uint64, updateFn UpdateHeadBlocksCallback, delFn DeleteBlockContentCallback) {
581+
// Sanity check that there's no attempt to undo the genesis block. This is
582+
// a fairly synthetic case where someone enables a timestamp based fork
583+
// below the genesis timestamp. It's nice to not allow that instead of the
584+
// entire chain getting deleted.
585+
if headTime > 0 && hc.genesisHeader.Time > headTime {
586+
// Note, a critical error is quite brutal, but we should really not reach
587+
// this point. Since pre-timestamp based forks it was impossible to have
588+
// a fork before block 0, the setHead would always work. With timestamp
589+
// forks it becomes possible to specify below the genesis. That said, the
590+
// only time we setHead via timestamp is with chain config changes on the
591+
// startup, so failing hard there is ok.
592+
log.Crit("Rejecting genesis rewind via timestamp", "target", headTime, "genesis", hc.genesisHeader.Time)
593+
}
581594
var (
582595
parentHash common.Hash
583596
batch = hc.chainDb.NewBatch()

eth/backend.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,8 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
195195
)
196196
// Override the chain config with provided settings.
197197
var overrides core.ChainOverrides
198-
if config.OverrideTerminalTotalDifficulty != nil {
199-
overrides.OverrideTerminalTotalDifficulty = config.OverrideTerminalTotalDifficulty
200-
}
201-
if config.OverrideTerminalTotalDifficultyPassed != nil {
202-
overrides.OverrideTerminalTotalDifficultyPassed = config.OverrideTerminalTotalDifficultyPassed
198+
if config.OverrideShanghai != nil {
199+
overrides.OverrideShanghai = config.OverrideShanghai
203200
}
204201
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, config.Genesis, &overrides, eth.engine, vmConfig, eth.shouldPreserve, &config.TxLookupLimit)
205202
if err != nil {

eth/ethconfig/config.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,8 @@ type Config struct {
206206
// CheckpointOracle is the configuration for checkpoint oracle.
207207
CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"`
208208

209-
// OverrideTerminalTotalDifficulty (TODO: remove after the fork)
210-
OverrideTerminalTotalDifficulty *big.Int `toml:",omitempty"`
211-
212-
// OverrideTerminalTotalDifficultyPassed (TODO: remove after the fork)
213-
OverrideTerminalTotalDifficultyPassed *bool `toml:",omitempty"`
209+
// OverrideShanghai (TODO: remove after the fork)
210+
OverrideShanghai *big.Int `toml:",omitempty"`
214211
}
215212

216213
// CreateConsensusEngine creates a consensus engine for the given chain configuration.

eth/ethconfig/gen_config.go

Lines changed: 89 additions & 95 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

les/client.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,8 @@ func New(stack *node.Node, config *ethconfig.Config) (*LightEthereum, error) {
9494
return nil, err
9595
}
9696
var overrides core.ChainOverrides
97-
if config.OverrideTerminalTotalDifficulty != nil {
98-
overrides.OverrideTerminalTotalDifficulty = config.OverrideTerminalTotalDifficulty
99-
}
100-
if config.OverrideTerminalTotalDifficultyPassed != nil {
101-
overrides.OverrideTerminalTotalDifficultyPassed = config.OverrideTerminalTotalDifficultyPassed
97+
if config.OverrideShanghai != nil {
98+
overrides.OverrideShanghai = config.OverrideShanghai
10299
}
103100
chainConfig, genesisHash, genesisErr := core.SetupGenesisBlockWithOverride(chainDb, trie.NewDatabase(chainDb), config.Genesis, &overrides)
104101
if _, isCompat := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !isCompat {

0 commit comments

Comments
 (0)