revert & fix

This commit is contained in:
Monkey 2025-05-19 20:06:32 +08:00 committed by Guillaume Ballet
parent 9645d9b1d6
commit 3890069976

View file

@ -175,7 +175,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
// Here we determine genesis hash and active ChainConfig.
// We need these to figure out the consensus parameters and to set up history pruning.
chainConfig, _, err := core.LoadChainConfig(chainDb, config.Genesis)
chainConfig, ghash, err := core.LoadChainConfig(chainDb, config.Genesis)
if err != nil {
return nil, err
}
@ -189,6 +189,21 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
networkID = chainConfig.ChainID.Uint64()
}
// Switch to full sync if we're in snap sync and genesis block is in the future.
if config.SyncMode == ethconfig.SnapSync {
genesisTime := uint64(0)
now := uint64(time.Now().Unix())
if config.Genesis != nil {
genesisTime = config.Genesis.Timestamp
} else if genesis := rawdb.ReadBlock(chainDb, ghash, 0); genesis != nil {
genesisTime = genesis.Time()
}
if genesisTime > uint64(now) {
log.Warn("Genesis block is in the future, switching from snap sync to full sync")
config.SyncMode = ethconfig.FullSync
}
}
// Assemble the Ethereum object.
eth := &Ethereum{
config: config,