This commit is contained in:
Felix Lange 2018-01-22 22:50:53 +00:00 committed by GitHub
commit 4e0ee2a9e9

View file

@ -993,15 +993,12 @@ func (d *Downloader) fetchParts(errCancel error, deliveryCh chan dataPack, deliv
ticker := time.NewTicker(100 * time.Millisecond) ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop() defer ticker.Stop()
update := make(chan struct{}, 1)
// Prepare the queue and fetch block parts until the block header fetcher's done // Prepare the queue and fetch block parts until the block header fetcher's done
finished := false finished := false
for { for {
select { select {
case <-d.cancelCh: case <-d.cancelCh:
return errCancel return errCancel
case packet := <-deliveryCh: case packet := <-deliveryCh:
// If the peer was previously banned and failed to deliver its pack // If the peer was previously banned and failed to deliver its pack
// in a reasonable time frame, ignore its message. // 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) 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: case cont := <-wakeCh:
// The header fetcher sent a continuation flag, check if it's done // The header fetcher sent a continuation flag, check if it's done
if !cont { if !cont {
finished = true finished = true
} }
// Headers arrive, try to update the progress
select {
case update <- struct{}{}:
default:
}
case <-ticker.C: case <-ticker.C:
// Sanity check update the progress
select {
case update <- struct{}{}:
default:
} }
case <-update:
// Short circuit if we lost all our peers // Short circuit if we lost all our peers
if d.peers.Len() == 0 { if d.peers.Len() == 0 {
return errNoPeers return errNoPeers
@ -1081,12 +1061,11 @@ func (d *Downloader) fetchParts(errCancel error, deliveryCh chan dataPack, deliv
log.Debug("Data fetching completed", "type", kind) log.Debug("Data fetching completed", "type", kind)
return nil return nil
} }
break continue
} }
// Send a download request to all idle peers, until throttled // Send a download request to all idle peers, until throttled
progressed, throttled, running := false, false, inFlight() progressed, throttled, running := false, false, inFlight()
idles, total := idle() idles, total := idle()
for _, peer := range idles { for _, peer := range idles {
// Short circuit if throttling activated // Short circuit if throttling activated
if throttle() { if throttle() {
@ -1138,7 +1117,6 @@ func (d *Downloader) fetchParts(errCancel error, deliveryCh chan dataPack, deliv
} }
} }
} }
}
// processHeaders takes batches of retrieved headers from an input channel and // processHeaders takes batches of retrieved headers from an input channel and
// keeps processing and scheduling them into the header chain and downloader's // keeps processing and scheduling them into the header chain and downloader's