Skip to content

Commit 1904272

Browse files
authored
eth/downloader: refactor snap sync handling when pivot is nil (#535)
1 parent 764632b commit 1904272

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

eth/downloader/downloader.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -486,21 +486,15 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td, ttd *
486486
if err != nil {
487487
return err
488488
}
489-
if d.blockchain.TrieDB().Scheme() == rawdb.PathScheme && mode == SnapSync {
490-
// Ensure the pivot is above the minimum full block threshold
491-
pivotNumber := uint64(0)
492-
if pivot != nil {
493-
pivotNumber = pivot.Number.Uint64()
494-
}
495-
if pivotNumber < uint64(fsMinFullBlocks) {
496-
block := d.blockchain.CurrentBlock()
497-
if err = d.blockchain.TrieDB().Enable(block.Root); err != nil {
498-
return fmt.Errorf("failed to enable trie db: %v", err)
489+
if mode == SnapSync {
490+
// If snap sync is not available (head below threshold), commit head and exit
491+
if pivot == nil || pivot.Number.Uint64() < uint64(fsMinFullBlocks) {
492+
header := d.blockchain.CurrentHeader()
493+
if err := d.blockchain.SnapSyncCommitHead(header.Hash()); err != nil {
494+
return err
499495
}
500-
log.Info("Disabling snap sync of the db on the path scheme due to the pivot header being positioned too low",
501-
"pivot", pivotNumber)
502-
<-time.After(3 * time.Second)
503-
return errCanceled
496+
d.committed.Store(true)
497+
return nil
504498
}
505499
}
506500
} else {

0 commit comments

Comments
 (0)