aboutsummaryrefslogtreecommitdiffstats
path: root/les/fetcher.go
diff options
context:
space:
mode:
authorFelföldi Zsolt <zsfelfoldi@gmail.com>2018-10-01 21:14:53 +0800
committerMartin Holst Swende <martin@swende.se>2018-10-01 21:14:53 +0800
commitb7bbe66b19fb19b95053977586e619a40478a7d8 (patch)
treeea51832839f8bd17a8c3c8774866da5ed3260c29 /les/fetcher.go
parent96fd50be10885c9b3033404df698177fdb63d036 (diff)
downloaddexon-b7bbe66b19fb19b95053977586e619a40478a7d8.tar
dexon-b7bbe66b19fb19b95053977586e619a40478a7d8.tar.gz
dexon-b7bbe66b19fb19b95053977586e619a40478a7d8.tar.bz2
dexon-b7bbe66b19fb19b95053977586e619a40478a7d8.tar.lz
dexon-b7bbe66b19fb19b95053977586e619a40478a7d8.tar.xz
dexon-b7bbe66b19fb19b95053977586e619a40478a7d8.tar.zst
dexon-b7bbe66b19fb19b95053977586e619a40478a7d8.zip
les: limit state ODR retrievals to the last 100 blocks (#17744)
Diffstat (limited to 'les/fetcher.go')
-rw-r--r--les/fetcher.go27
1 files changed, 17 insertions, 10 deletions
diff --git a/les/fetcher.go b/les/fetcher.go
index cc539c42b..f0d3b188d 100644
--- a/les/fetcher.go
+++ b/les/fetcher.go
@@ -32,8 +32,9 @@ import (
)
const (
- blockDelayTimeout = time.Second * 10 // timeout for a peer to announce a head that has already been confirmed by others
- maxNodeCount = 20 // maximum number of fetcherTreeNode entries remembered for each peer
+ blockDelayTimeout = time.Second * 10 // timeout for a peer to announce a head that has already been confirmed by others
+ maxNodeCount = 20 // maximum number of fetcherTreeNode entries remembered for each peer
+ serverStateAvailable = 100 // number of recent blocks where state availability is assumed
)
// lightFetcher implements retrieval of newly announced headers. It also provides a peerHasBlock function for the
@@ -215,8 +216,8 @@ func (f *lightFetcher) syncLoop() {
// registerPeer adds a new peer to the fetcher's peer set
func (f *lightFetcher) registerPeer(p *peer) {
p.lock.Lock()
- p.hasBlock = func(hash common.Hash, number uint64) bool {
- return f.peerHasBlock(p, hash, number)
+ p.hasBlock = func(hash common.Hash, number uint64, hasState bool) bool {
+ return f.peerHasBlock(p, hash, number, hasState)
}
p.lock.Unlock()
@@ -344,21 +345,27 @@ func (f *lightFetcher) announce(p *peer, head *announceData) {
// peerHasBlock returns true if we can assume the peer knows the given block
// based on its announcements
-func (f *lightFetcher) peerHasBlock(p *peer, hash common.Hash, number uint64) bool {
+func (f *lightFetcher) peerHasBlock(p *peer, hash common.Hash, number uint64, hasState bool) bool {
f.lock.Lock()
defer f.lock.Unlock()
+ fp := f.peers[p]
+ if fp == nil || fp.root == nil {
+ return false
+ }
+
+ if hasState {
+ if fp.lastAnnounced == nil || fp.lastAnnounced.number > number+serverStateAvailable {
+ return false
+ }
+ }
+
if f.syncing {
// always return true when syncing
// false positives are acceptable, a more sophisticated condition can be implemented later
return true
}
- fp := f.peers[p]
- if fp == nil || fp.root == nil {
- return false
- }
-
if number >= fp.root.number {
// it is recent enough that if it is known, is should be in the peer's block tree
return fp.nodeByHash[hash] != nil