mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
les: simplify requesting/syncing logic
This commit is contained in:
parent
70ff967f7a
commit
e40fe2117b
1 changed files with 5 additions and 10 deletions
|
|
@ -55,7 +55,7 @@ type lightFetcher struct {
|
||||||
requested map[uint64]fetchRequest
|
requested map[uint64]fetchRequest
|
||||||
deliverChn chan fetchResponse
|
deliverChn chan fetchResponse
|
||||||
timeoutChn chan uint64
|
timeoutChn chan uint64
|
||||||
requesting bool
|
requestTriggered bool
|
||||||
requestTrigger chan struct{}
|
requestTrigger chan struct{}
|
||||||
lastTrustedHeader *types.Header
|
lastTrustedHeader *types.Header
|
||||||
}
|
}
|
||||||
|
|
@ -152,14 +152,13 @@ func (f *lightFetcher) syncLoop() {
|
||||||
if !f.syncing {
|
if !f.syncing {
|
||||||
rq, reqID, syncing = f.nextRequest()
|
rq, reqID, syncing = f.nextRequest()
|
||||||
}
|
}
|
||||||
f.requesting = rq != nil
|
f.requestTriggered = rq != nil
|
||||||
f.lock.Unlock()
|
f.lock.Unlock()
|
||||||
|
|
||||||
if rq != nil {
|
if rq != nil {
|
||||||
if _, ok := <-f.pm.reqDist.queue(rq); ok {
|
if _, ok := <-f.pm.reqDist.queue(rq); ok {
|
||||||
if syncing {
|
if syncing {
|
||||||
f.lock.Lock()
|
f.lock.Lock()
|
||||||
f.requesting = false
|
|
||||||
f.syncing = true
|
f.syncing = true
|
||||||
f.lock.Unlock()
|
f.lock.Unlock()
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -216,12 +215,8 @@ func (f *lightFetcher) syncLoop() {
|
||||||
p.Log().Debug("Done synchronising with peer")
|
p.Log().Debug("Done synchronising with peer")
|
||||||
f.checkSyncedHeaders(p)
|
f.checkSyncedHeaders(p)
|
||||||
f.syncing = false
|
f.syncing = false
|
||||||
r := f.requesting
|
|
||||||
f.requesting = true
|
|
||||||
f.lock.Unlock()
|
f.lock.Unlock()
|
||||||
if !r {
|
f.requestTrigger <- struct{}{} // f.requestTriggered is always true here
|
||||||
f.requestTrigger <- struct{}{}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -355,8 +350,8 @@ func (f *lightFetcher) announce(p *peer, head *announceData) {
|
||||||
fp.lastAnnounced = n
|
fp.lastAnnounced = n
|
||||||
p.lock.Unlock()
|
p.lock.Unlock()
|
||||||
f.checkUpdateStats(p, nil)
|
f.checkUpdateStats(p, nil)
|
||||||
if !f.requesting {
|
if !f.requestTriggered {
|
||||||
f.requesting = true
|
f.requestTriggered = true
|
||||||
f.requestTrigger <- struct{}{}
|
f.requestTrigger <- struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue