aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader/downloader.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-05-21 13:07:58 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-05-21 13:07:58 +0800
commite8b22b9253da400cc350dbc673d07789f93f57bc (patch)
tree1adbaecbf50945f6bf913ceba8cbee2ad386068e /eth/downloader/downloader.go
parent79042223dc5f2ae5d4a2ed73d18907440a963093 (diff)
downloaddexon-e8b22b9253da400cc350dbc673d07789f93f57bc.tar
dexon-e8b22b9253da400cc350dbc673d07789f93f57bc.tar.gz
dexon-e8b22b9253da400cc350dbc673d07789f93f57bc.tar.bz2
dexon-e8b22b9253da400cc350dbc673d07789f93f57bc.tar.lz
dexon-e8b22b9253da400cc350dbc673d07789f93f57bc.tar.xz
dexon-e8b22b9253da400cc350dbc673d07789f93f57bc.tar.zst
dexon-e8b22b9253da400cc350dbc673d07789f93f57bc.zip
eth/downloader: prevent a peer from dripping bad hashes
Diffstat (limited to 'eth/downloader/downloader.go')
-rw-r--r--eth/downloader/downloader.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index d817b223c..f3a866441 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -28,10 +28,11 @@ var (
)
var (
- errLowTd = errors.New("peer's TD is too low")
+ errLowTd = errors.New("peers TD is too low")
ErrBusy = errors.New("busy")
- errUnknownPeer = errors.New("peer's unknown or unhealthy")
+ errUnknownPeer = errors.New("peer is unknown or unhealthy")
ErrBadPeer = errors.New("action from bad peer ignored")
+ ErrStallingPeer = errors.New("peer is stalling")
errNoPeers = errors.New("no peers to keep download active")
ErrPendingQueue = errors.New("pending items in queue")
ErrTimeout = errors.New("timeout")
@@ -283,15 +284,18 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
return ErrBadPeer
}
if !done {
+ // Check that the peer is not stalling the sync
+ if len(inserts) < maxHashFetch {
+ return ErrStallingPeer
+ }
// Try and fetch a random block to verify the hash batch
// Skip the last hash as the cross check races with the next hash fetch
- if len(inserts) > 1 {
- cross := inserts[rand.Intn(len(inserts)-1)]
- glog.V(logger.Detail).Infof("Cross checking (%s) with %x", active.id, cross)
+ cross := inserts[rand.Intn(len(inserts)-1)]
+ glog.V(logger.Detail).Infof("Cross checking (%s) with %x", active.id, cross)
+
+ d.checks[cross] = time.Now().Add(blockTTL)
+ active.getBlocks([]common.Hash{cross})
- d.checks[cross] = time.Now().Add(blockTTL)
- active.getBlocks([]common.Hash{cross})
- }
// Also fetch a fresh
active.getHashes(head)
continue