diff options
author | Péter Szilágyi <peterke@gmail.com> | 2018-11-28 19:31:42 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-11-28 19:46:13 +0800 |
commit | 174083c3ae0b6217dff0ced98ec7f73e53e24b04 (patch) | |
tree | 8ec6df143e336091581b58b8c6b6c9468242f897 /eth/downloader/downloader.go | |
parent | bfed28a42187c7bf7b8f50401fe239278a4ed530 (diff) | |
download | dexon-174083c3ae0b6217dff0ced98ec7f73e53e24b04.tar dexon-174083c3ae0b6217dff0ced98ec7f73e53e24b04.tar.gz dexon-174083c3ae0b6217dff0ced98ec7f73e53e24b04.tar.bz2 dexon-174083c3ae0b6217dff0ced98ec7f73e53e24b04.tar.lz dexon-174083c3ae0b6217dff0ced98ec7f73e53e24b04.tar.xz dexon-174083c3ae0b6217dff0ced98ec7f73e53e24b04.tar.zst dexon-174083c3ae0b6217dff0ced98ec7f73e53e24b04.zip |
eth/downloader: fix light client cht binary search issue
Diffstat (limited to 'eth/downloader/downloader.go')
-rw-r--r-- | eth/downloader/downloader.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index f81a5cbac..3a177ab9d 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -99,6 +99,7 @@ type Downloader struct { mode SyncMode // Synchronisation mode defining the strategy used (per sync cycle) mux *event.TypeMux // Event multiplexer to announce sync operation events + genesis uint64 // Genesis block number to limit sync to (e.g. light client CHT) queue *queue // Scheduler for selecting the hashes to download peers *peerSet // Set of active peers from which download can proceed stateDB ethdb.Database @@ -664,7 +665,28 @@ func (d *Downloader) findAncestor(p *peerConnection, remoteHeader *types.Header) } p.log.Debug("Looking for common ancestor", "local", localHeight, "remote", remoteHeight) if localHeight >= MaxForkAncestry { + // We're above the max reorg threshold, find the earliest fork point floor = int64(localHeight - MaxForkAncestry) + + // If we're doing a light sync, ensure the floor doesn't go below the CHT, as + // all headers before that point will be missing. + if d.mode == LightSync { + // If we dont know the current CHT position, find it + if d.genesis == 0 { + header := d.lightchain.CurrentHeader() + for header != nil { + d.genesis = header.Number.Uint64() + if floor >= int64(d.genesis)-1 { + break + } + header = d.lightchain.GetHeaderByHash(header.ParentHash) + } + } + // We already know the "genesis" block number, cap floor to that + if floor < int64(d.genesis)-1 { + floor = int64(d.genesis) - 1 + } + } } from, count, skip, max := calculateRequestSpan(remoteHeight, localHeight) |