mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
eth/downloader: return error only if master peer
This commit is contained in:
parent
f0869777e7
commit
2b183c8355
2 changed files with 18 additions and 4 deletions
|
|
@ -559,6 +559,14 @@ func (d *Downloader) spawnSync(fetchers []func() error) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isMaster returns an indicator whether the given peer id is master peer
|
||||||
|
// used for syncing.
|
||||||
|
func (d *Downloader) isMaster(id string) bool {
|
||||||
|
d.cancelLock.Lock()
|
||||||
|
defer d.cancelLock.Unlock()
|
||||||
|
return d.cancelPeer == id
|
||||||
|
}
|
||||||
|
|
||||||
// cancel aborts all of the operations and resets the queue. However, cancel does
|
// cancel aborts all of the operations and resets the queue. However, cancel does
|
||||||
// not wait for the running download goroutines to finish. This method should be
|
// not wait for the running download goroutines to finish. This method should be
|
||||||
// used when cancelling the downloads from inside the downloader.
|
// used when cancelling the downloads from inside the downloader.
|
||||||
|
|
@ -1284,13 +1292,16 @@ func (d *Downloader) fetchParts(deliveryCh chan dataPack, deliver func(dataPack)
|
||||||
peer.log.Warn("Downloader wants to drop peer, but peerdrop-function is not set", "peer", pid)
|
peer.log.Warn("Downloader wants to drop peer, but peerdrop-function is not set", "peer", pid)
|
||||||
} else {
|
} else {
|
||||||
// In dropPeer function, a callback will be called which aborts
|
// In dropPeer function, a callback will be called which aborts
|
||||||
// the sync immediately. Here return the timeout error explicitly.
|
// the sync immediately if the unregisted peer is master peer.
|
||||||
|
// If the peer is master one, return concrete error here.
|
||||||
d.dropPeer(pid)
|
d.dropPeer(pid)
|
||||||
|
if d.isMaster(pid) {
|
||||||
return errTimeout
|
return errTimeout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// If there's nothing more to fetch, wait or terminate
|
// If there's nothing more to fetch, wait or terminate
|
||||||
if pending() == 0 {
|
if pending() == 0 {
|
||||||
if !inFlight() && finished {
|
if !inFlight() && finished {
|
||||||
|
|
|
||||||
|
|
@ -317,11 +317,14 @@ func (s *stateSync) loop() (err error) {
|
||||||
req.peer.log.Warn("Downloader wants to drop peer, but peerdrop-function is not set", "peer", req.peer.id)
|
req.peer.log.Warn("Downloader wants to drop peer, but peerdrop-function is not set", "peer", req.peer.id)
|
||||||
} else {
|
} else {
|
||||||
// In dropPeer function, a callback will be called which aborts
|
// In dropPeer function, a callback will be called which aborts
|
||||||
// the sync immediately. Here return the timeout error explicitly.
|
// the sync immediately if the unregisted peer is master peer.
|
||||||
|
// If the peer is master one, return concrete error here.
|
||||||
s.d.dropPeer(req.peer.id)
|
s.d.dropPeer(req.peer.id)
|
||||||
|
if s.d.isMaster(req.peer.id) {
|
||||||
return errTimeout
|
return errTimeout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Process all the received blobs and check for stale delivery
|
// Process all the received blobs and check for stale delivery
|
||||||
delivered, err := s.process(req)
|
delivered, err := s.process(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue