aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgary rong <garyrong0905@gmail.com>2019-03-14 18:19:03 +0800
committerPéter Szilágyi <peterke@gmail.com>2019-03-14 18:19:03 +0800
commit6c312a24b6041385c33eca066ff5604af315a41e (patch)
tree53285692db42f1352b0ca8a557aa883dd4fddd35
parent95b2ec7169c0f3052df3230ce027d36ca225fa2d (diff)
downloadgo-tangerine-6c312a24b6041385c33eca066ff5604af315a41e.tar
go-tangerine-6c312a24b6041385c33eca066ff5604af315a41e.tar.gz
go-tangerine-6c312a24b6041385c33eca066ff5604af315a41e.tar.bz2
go-tangerine-6c312a24b6041385c33eca066ff5604af315a41e.tar.lz
go-tangerine-6c312a24b6041385c33eca066ff5604af315a41e.tar.xz
go-tangerine-6c312a24b6041385c33eca066ff5604af315a41e.tar.zst
go-tangerine-6c312a24b6041385c33eca066ff5604af315a41e.zip
eth/downloader: fix ancestor searching for light syncing (#19136)
-rw-r--r--eth/downloader/downloader.go36
1 files changed, 19 insertions, 17 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index b8eaa6a5e..d926d7aad 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -665,30 +665,32 @@ func (d *Downloader) findAncestor(p *peerConnection, remoteHeader *types.Header)
localHeight = d.lightchain.CurrentHeader().Number.Uint64()
}
p.log.Debug("Looking for common ancestor", "local", localHeight, "remote", remoteHeight)
+
+ // Recap floor value for binary search
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)
+ }
+ // 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
}
- }
- // We already know the "genesis" block number, cap floor to that
- if floor < int64(d.genesis)-1 {
- floor = int64(d.genesis) - 1
+ 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)
p.log.Trace("Span searching for common ancestor", "count", count, "from", from, "skip", skip)