Using full sync for genesis block

This commit is contained in:
Monkey 2025-05-11 19:28:31 +08:00 committed by Guillaume Ballet
parent e67761ef35
commit 58bdd555c7
2 changed files with 11 additions and 1 deletions

View file

@ -485,6 +485,12 @@ func (d *Downloader) syncToHead() (err error) {
if mode == ethconfig.SnapSync { if mode == ethconfig.SnapSync {
if height <= uint64(fsMinFullBlocks) { if height <= uint64(fsMinFullBlocks) {
origin = 0 origin = 0
// For genesis block, switch to full sync
if height == 0 {
mode = ethconfig.FullSync
d.mode.Store(uint32(mode))
log.Info("Switching to full sync for genesis block")
}
} else { } else {
pivotNumber := pivot.Number.Uint64() pivotNumber := pivot.Number.Uint64()
if pivotNumber <= origin { if pivotNumber <= origin {

View file

@ -177,7 +177,11 @@ func newHandler(config *handlerConfig) (*handler, error) {
} }
} else { } else {
head := h.chain.CurrentBlock() head := h.chain.CurrentBlock()
if head.Number.Uint64() > 0 && h.chain.HasState(head.Root) { if head.Number.Uint64() == 0 {
// For genesis block, always use full sync
h.snapSync.Store(false)
log.Info("Using full sync for genesis block")
} else if head.Number.Uint64() > 0 && h.chain.HasState(head.Root) {
// Print warning log if database is not empty to run snap sync. // Print warning log if database is not empty to run snap sync.
log.Warn("Switch sync mode from snap sync to full sync", "reason", "snap sync complete") log.Warn("Switch sync mode from snap sync to full sync", "reason", "snap sync complete")
} else { } else {