aboutsummaryrefslogtreecommitdiffstats
path: root/les/fetcher.go
diff options
context:
space:
mode:
authorZsolt Felfoldi <zsfelfoldi@gmail.com>2016-12-10 13:50:36 +0800
committerZsolt Felfoldi <zsfelfoldi@gmail.com>2016-12-10 16:53:25 +0800
commitf12f8a6c14dbaf6e6531cea1b0cf169b851e1894 (patch)
tree41f0d7dd9f5fe21cbb8615a59cc08b9594f83770 /les/fetcher.go
parentc57c54ce96628aeb6345776310123a80593f0143 (diff)
downloaddexon-f12f8a6c14dbaf6e6531cea1b0cf169b851e1894.tar
dexon-f12f8a6c14dbaf6e6531cea1b0cf169b851e1894.tar.gz
dexon-f12f8a6c14dbaf6e6531cea1b0cf169b851e1894.tar.bz2
dexon-f12f8a6c14dbaf6e6531cea1b0cf169b851e1894.tar.lz
dexon-f12f8a6c14dbaf6e6531cea1b0cf169b851e1894.tar.xz
dexon-f12f8a6c14dbaf6e6531cea1b0cf169b851e1894.tar.zst
dexon-f12f8a6c14dbaf6e6531cea1b0cf169b851e1894.zip
les, light: add block availability check for ODR requests
Diffstat (limited to 'les/fetcher.go')
-rw-r--r--les/fetcher.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/les/fetcher.go b/les/fetcher.go
index 00cb31dfb..c23af8da3 100644
--- a/les/fetcher.go
+++ b/les/fetcher.go
@@ -200,6 +200,12 @@ func (f *lightFetcher) syncLoop() {
// addPeer adds a new peer to the fetcher's peer set
func (f *lightFetcher) addPeer(p *peer) {
+ p.lock.Lock()
+ p.hasBlock = func(hash common.Hash, number uint64) bool {
+ return f.peerHasBlock(p, hash, number)
+ }
+ p.lock.Unlock()
+
f.lock.Lock()
defer f.lock.Unlock()
@@ -208,6 +214,10 @@ func (f *lightFetcher) addPeer(p *peer) {
// removePeer removes a new peer from the fetcher's peer set
func (f *lightFetcher) removePeer(p *peer) {
+ p.lock.Lock()
+ p.hasBlock = nil
+ p.lock.Unlock()
+
f.lock.Lock()
defer f.lock.Unlock()
@@ -315,7 +325,7 @@ func (f *lightFetcher) announce(p *peer, head *announceData) {
// based on its announcements
func (f *lightFetcher) peerHasBlock(p *peer, hash common.Hash, number uint64) bool {
f.lock.Lock()
- defer f.lock.Lock()
+ defer f.lock.Unlock()
fp := f.peers[p]
if fp == nil || fp.root == nil {