mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
Merge aa11910842 into 5d4267911a
This commit is contained in:
commit
4e0ee2a9e9
1 changed files with 77 additions and 99 deletions
|
|
@ -993,15 +993,12 @@ func (d *Downloader) fetchParts(errCancel error, deliveryCh chan dataPack, deliv
|
|||
ticker := time.NewTicker(100 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
|
||||
update := make(chan struct{}, 1)
|
||||
|
||||
// Prepare the queue and fetch block parts until the block header fetcher's done
|
||||
finished := false
|
||||
for {
|
||||
select {
|
||||
case <-d.cancelCh:
|
||||
return errCancel
|
||||
|
||||
case packet := <-deliveryCh:
|
||||
// If the peer was previously banned and failed to deliver its pack
|
||||
// in a reasonable time frame, ignore its message.
|
||||
|
|
@ -1027,31 +1024,14 @@ func (d *Downloader) fetchParts(errCancel error, deliveryCh chan dataPack, deliv
|
|||
peer.log.Trace("Failed to deliver retrieved data", "type", kind, "err", err)
|
||||
}
|
||||
}
|
||||
// Blocks assembled, try to update the progress
|
||||
select {
|
||||
case update <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
|
||||
case cont := <-wakeCh:
|
||||
// The header fetcher sent a continuation flag, check if it's done
|
||||
if !cont {
|
||||
finished = true
|
||||
}
|
||||
// Headers arrive, try to update the progress
|
||||
select {
|
||||
case update <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
|
||||
case <-ticker.C:
|
||||
// Sanity check update the progress
|
||||
select {
|
||||
case update <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
|
||||
case <-update:
|
||||
// Short circuit if we lost all our peers
|
||||
if d.peers.Len() == 0 {
|
||||
return errNoPeers
|
||||
|
|
@ -1081,12 +1061,11 @@ func (d *Downloader) fetchParts(errCancel error, deliveryCh chan dataPack, deliv
|
|||
log.Debug("Data fetching completed", "type", kind)
|
||||
return nil
|
||||
}
|
||||
break
|
||||
continue
|
||||
}
|
||||
// Send a download request to all idle peers, until throttled
|
||||
progressed, throttled, running := false, false, inFlight()
|
||||
idles, total := idle()
|
||||
|
||||
for _, peer := range idles {
|
||||
// Short circuit if throttling activated
|
||||
if throttle() {
|
||||
|
|
@ -1137,7 +1116,6 @@ func (d *Downloader) fetchParts(errCancel error, deliveryCh chan dataPack, deliv
|
|||
return errPeersUnavailable
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// processHeaders takes batches of retrieved headers from an input channel and
|
||||
|
|
|
|||
Loading…
Reference in a new issue