diff --git a/core/blockchain.go b/core/blockchain.go index e27b9420dc..9c12424852 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -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) } diff --git a/params/config.go b/params/config.go index b4a10cd6c5..c4b36dd157 100644 --- a/params/config.go +++ b/params/config.go @@ -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