eth/downloader: prevent a peer from dripping bad hashes

This commit is contained in:
Péter Szilágyi
2015-05-21 08:07:58 +03:00
parent 79042223dc
commit e8b22b9253
2 changed files with 36 additions and 9 deletions

View File

@ -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