eth/downloader: return error only if master peer

This commit is contained in:
rjl493456442 2019-09-25 16:54:18 +08:00
parent f0869777e7
commit 2b183c8355
2 changed files with 18 additions and 4 deletions

View file

@ -559,6 +559,14 @@ func (d *Downloader) spawnSync(fetchers []func() error) error {
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
// not wait for the running download goroutines to finish. This method should be
// used when cancelling the downloads from inside the downloader.
@ -1284,9 +1292,12 @@ 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)
} else {
// 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)
return errTimeout
if d.isMaster(pid) {
return errTimeout
}
}
}
}

View file

@ -317,9 +317,12 @@ 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)
} else {
// 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)
return errTimeout
if s.d.isMaster(req.peer.id) {
return errTimeout
}
}
}
// Process all the received blobs and check for stale delivery