cmd, core, eth, els, params: disallow setheads below genesis, tweaks
This commit is contained in:
+3
-8
@@ -269,8 +269,7 @@ func (e *GenesisMismatchError) Error() string {
|
||||
|
||||
// ChainOverrides contains the changes to chain config.
|
||||
type ChainOverrides struct {
|
||||
OverrideTerminalTotalDifficulty *big.Int
|
||||
OverrideTerminalTotalDifficultyPassed *bool
|
||||
OverrideShanghai *big.Int
|
||||
}
|
||||
|
||||
// SetupGenesisBlock writes or updates the genesis block in db.
|
||||
@@ -296,15 +295,11 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *trie.Database, gen
|
||||
}
|
||||
applyOverrides := func(config *params.ChainConfig) {
|
||||
if config != nil {
|
||||
if overrides != nil && overrides.OverrideTerminalTotalDifficulty != nil {
|
||||
config.TerminalTotalDifficulty = overrides.OverrideTerminalTotalDifficulty
|
||||
}
|
||||
if overrides != nil && overrides.OverrideTerminalTotalDifficultyPassed != nil {
|
||||
config.TerminalTotalDifficultyPassed = *overrides.OverrideTerminalTotalDifficultyPassed
|
||||
if overrides != nil && overrides.OverrideShanghai != nil {
|
||||
config.ShanghaiTime = overrides.OverrideShanghai
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Just commit the new block if there is no stored genesis block.
|
||||
stored := rawdb.ReadCanonicalHash(db, 0)
|
||||
if (stored == common.Hash{}) {
|
||||
|
||||
@@ -578,6 +578,19 @@ func (hc *HeaderChain) SetHeadWithTimestamp(time uint64, updateFn UpdateHeadBloc
|
||||
// setHead rewinds the local chain to a new head block or a head timestamp.
|
||||
// Everything above the new head will be deleted and the new one set.
|
||||
func (hc *HeaderChain) setHead(headBlock uint64, headTime uint64, updateFn UpdateHeadBlocksCallback, delFn DeleteBlockContentCallback) {
|
||||
// Sanity check that there's no attempt to undo the genesis block. This is
|
||||
// a fairly synthetic case where someone enables a timestamp based fork
|
||||
// below the genesis timestamp. It's nice to not allow that instead of the
|
||||
// entire chain getting deleted.
|
||||
if headTime > 0 && hc.genesisHeader.Time > headTime {
|
||||
// Note, a critical error is quite brutal, but we should really not reach
|
||||
// this point. Since pre-timestamp based forks it was impossible to have
|
||||
// a fork before block 0, the setHead would always work. With timestamp
|
||||
// forks it becomes possible to specify below the genesis. That said, the
|
||||
// only time we setHead via timestamp is with chain config changes on the
|
||||
// startup, so failing hard there is ok.
|
||||
log.Crit("Rejecting genesis rewind via timestamp", "target", headTime, "genesis", hc.genesisHeader.Time)
|
||||
}
|
||||
var (
|
||||
parentHash common.Hash
|
||||
batch = hc.chainDb.NewBatch()
|
||||
|
||||
Reference in New Issue
Block a user