@@ -99,6 +99,7 @@ type Downloader struct {
99
99
mode SyncMode // Synchronisation mode defining the strategy used (per sync cycle)
100
100
mux * event.TypeMux // Event multiplexer to announce sync operation events
101
101
102
+ genesis uint64 // Genesis block number to limit sync to (e.g. light client CHT)
102
103
queue * queue // Scheduler for selecting the hashes to download
103
104
peers * peerSet // Set of active peers from which download can proceed
104
105
stateDB ethdb.Database
@@ -664,7 +665,28 @@ func (d *Downloader) findAncestor(p *peerConnection, remoteHeader *types.Header)
664
665
}
665
666
p .log .Debug ("Looking for common ancestor" , "local" , localHeight , "remote" , remoteHeight )
666
667
if localHeight >= MaxForkAncestry {
668
+ // We're above the max reorg threshold, find the earliest fork point
667
669
floor = int64 (localHeight - MaxForkAncestry )
670
+
671
+ // If we're doing a light sync, ensure the floor doesn't go below the CHT, as
672
+ // all headers before that point will be missing.
673
+ if d .mode == LightSync {
674
+ // If we dont know the current CHT position, find it
675
+ if d .genesis == 0 {
676
+ header := d .lightchain .CurrentHeader ()
677
+ for header != nil {
678
+ d .genesis = header .Number .Uint64 ()
679
+ if floor >= int64 (d .genesis )- 1 {
680
+ break
681
+ }
682
+ header = d .lightchain .GetHeaderByHash (header .ParentHash )
683
+ }
684
+ }
685
+ // We already know the "genesis" block number, cap floor to that
686
+ if floor < int64 (d .genesis )- 1 {
687
+ floor = int64 (d .genesis ) - 1
688
+ }
689
+ }
668
690
}
669
691
from , count , skip , max := calculateRequestSpan (remoteHeight , localHeight )
670
692
0 commit comments