diff options
Diffstat (limited to 'eth/downloader/downloader.go')
-rw-r--r-- | eth/downloader/downloader.go | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 6768c3e67..2b9d1cbee 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -18,14 +18,15 @@ import ( ) const ( - maxBlockFetch = 256 // Amount of max blocks to be fetched per chunk - minDesiredPeerCount = 5 // Amount of peers desired to start syncing - peerCountTimeout = 12 * time.Second // Amount of time it takes for the peer handler to ignore minDesiredPeerCount - blockTtl = 15 * time.Second // The amount of time it takes for a block request to time out - hashTtl = 20 * time.Second // The amount of time it takes for a hash request to time out + maxBlockFetch = 256 // Amount of max blocks to be fetched per chunk + peerCountTimeout = 12 * time.Second // Amount of time it takes for the peer handler to ignore minDesiredPeerCount + blockTtl = 20 * time.Second // The amount of time it takes for a block request to time out + hashTtl = 20 * time.Second // The amount of time it takes for a hash request to time out ) var ( + minDesiredPeerCount = 5 // Amount of peers desired to start syncing + errLowTd = errors.New("peer's TD is too low") errBusy = errors.New("busy") errUnknownPeer = errors.New("peer's unknown or unhealthy") @@ -127,11 +128,11 @@ out: for { select { case <-d.newPeerCh: - itimer.Stop() // Meet the `minDesiredPeerCount` before we select our best peer if len(d.peers) < minDesiredPeerCount { break } + itimer.Stop() d.selectPeer(d.peers.bestPeer()) case <-itimer.C: @@ -154,17 +155,18 @@ func (d *Downloader) selectPeer(p *peer) { // Make sure it's doing neither. Once done we can restart the // downloading process if the TD is higher. For now just get on // with whatever is going on. This prevents unecessary switching. - if !d.isBusy() { - // selected peer must be better than our own - // XXX we also check the peer's recent hash to make sure we - // don't have it. Some peers report (i think) incorrect TD. - if p.td.Cmp(d.currentTd()) <= 0 || d.hasBlock(p.recentHash) { - return - } - - glog.V(logger.Detail).Infoln("New peer with highest TD =", p.td) - d.syncCh <- syncPack{p, p.recentHash, false} + if d.isBusy() { + return } + // selected peer must be better than our own + // XXX we also check the peer's recent hash to make sure we + // don't have it. Some peers report (i think) incorrect TD. + if p.td.Cmp(d.currentTd()) <= 0 || d.hasBlock(p.recentHash) { + return + } + + glog.V(logger.Detail).Infoln("New peer with highest TD =", p.td) + d.syncCh <- syncPack{p, p.recentHash, false} } @@ -307,7 +309,7 @@ out: if len(d.queue.fetching) == 0 { d.queue.reset() - return fmt.Errorf("%v avaialable = %d. total = %d", errPeersUnavailable, len(availablePeers), len(d.peers)) + return fmt.Errorf("%v peers avaialable = %d. total peers = %d. hashes needed = %d", errPeersUnavailable, len(availablePeers), len(d.peers), d.queue.hashPool.Size()) } } else if len(d.queue.fetching) == 0 { |