aboutsummaryrefslogtreecommitdiffstats
path: root/les/fetcher.go
diff options
context:
space:
mode:
authorFelföldi Zsolt <zsfelfoldi@gmail.com>2018-07-04 18:40:20 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-07-04 18:40:20 +0800
commit51df1c1f20201b3ba6fba6e874a3c72f5d2a9123 (patch)
tree2546488b202f3ff1af010b9d1f1c36a6f99ec2b2 /les/fetcher.go
parentf524ec4326ab58355bc2b3bc237ec7441c206713 (diff)
downloadgo-tangerine-51df1c1f20201b3ba6fba6e874a3c72f5d2a9123.tar
go-tangerine-51df1c1f20201b3ba6fba6e874a3c72f5d2a9123.tar.gz
go-tangerine-51df1c1f20201b3ba6fba6e874a3c72f5d2a9123.tar.bz2
go-tangerine-51df1c1f20201b3ba6fba6e874a3c72f5d2a9123.tar.lz
go-tangerine-51df1c1f20201b3ba6fba6e874a3c72f5d2a9123.tar.xz
go-tangerine-51df1c1f20201b3ba6fba6e874a3c72f5d2a9123.tar.zst
go-tangerine-51df1c1f20201b3ba6fba6e874a3c72f5d2a9123.zip
les: add announcement safety check to light fetcher (#17034)
Diffstat (limited to 'les/fetcher.go')
-rw-r--r--les/fetcher.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/les/fetcher.go b/les/fetcher.go
index 59d3a2aa3..cc539c42b 100644
--- a/les/fetcher.go
+++ b/les/fetcher.go
@@ -267,9 +267,16 @@ func (f *lightFetcher) announce(p *peer, head *announceData) {
}
n = n.parent
}
+ // n is now the reorg common ancestor, add a new branch of nodes
+ if n != nil && (head.Number >= n.number+maxNodeCount || head.Number <= n.number) {
+ // if announced head block height is lower or same as n or too far from it to add
+ // intermediate nodes then discard previous announcement info and trigger a resync
+ n = nil
+ fp.nodeCnt = 0
+ fp.nodeByHash = make(map[common.Hash]*fetcherTreeNode)
+ }
if n != nil {
- // n is now the reorg common ancestor, add a new branch of nodes
- // check if the node count is too high to add new nodes
+ // check if the node count is too high to add new nodes, discard oldest ones if necessary
locked := false
for uint64(fp.nodeCnt)+head.Number-n.number > maxNodeCount && fp.root != nil {
if !locked {