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,params: Don't rewind chain on pre-genesis time changes #257

Draft
wants to merge 1 commit into
base: optimism
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
13 changes: 9 additions & 4 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,16 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis

// Rewind the chain in case of an incompatible config upgrade.
if compat, ok := genesisErr.(*params.ConfigCompatError); ok {
log.Warn("Rewinding chain to upgrade configuration", "err", compat)
if compat.RewindToTime > 0 {
bc.SetHeadWithTimestamp(compat.RewindToTime)
if compat.NewTime != nil && compat.StoredTime != nil &&
genesis.Timestamp > *compat.NewTime && genesis.Timestamp > *compat.StoredTime {
log.Warn("Ignoring chain rewind because of pre-genesis timestamp changes", "err", compat)
} else {
bc.SetHead(compat.RewindToBlock)
log.Warn("Rewinding chain to upgrade configuration", "err", compat)
if compat.NewTime != nil {
bc.SetHeadWithTimestamp(compat.RewindToTime)
} else {
bc.SetHead(compat.RewindToBlock)
}
}
rawdb.WriteChainConfig(db, genesisHash, chainConfig)
}
Expand Down
3 changes: 2 additions & 1 deletion params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,8 @@ func newTimestampCompatError(what string, storedtime, newtime *uint64) *ConfigCo
NewTime: newtime,
RewindToTime: 0,
}
if rew != nil {
if rew != nil && *rew > 0 {
// if *rew == 0 this would cause an underflow
err.RewindToTime = *rew - 1
}
return err
Expand Down
Loading