aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader/downloader.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-06-11 23:13:13 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-06-15 14:22:37 +0800
commit80833f813715cb151bbf165f462e38930fc4fccd (patch)
treed12b3a45f81646b5134ad73748572b51ded3434e /eth/downloader/downloader.go
parentfaae8b7dd844f4faa2b9e2c8ce76246341ed7357 (diff)
downloadgo-tangerine-80833f813715cb151bbf165f462e38930fc4fccd.tar
go-tangerine-80833f813715cb151bbf165f462e38930fc4fccd.tar.gz
go-tangerine-80833f813715cb151bbf165f462e38930fc4fccd.tar.bz2
go-tangerine-80833f813715cb151bbf165f462e38930fc4fccd.tar.lz
go-tangerine-80833f813715cb151bbf165f462e38930fc4fccd.tar.xz
go-tangerine-80833f813715cb151bbf165f462e38930fc4fccd.tar.zst
go-tangerine-80833f813715cb151bbf165f462e38930fc4fccd.zip
eth/downloader: instreument and test the sync peer drop
Diffstat (limited to 'eth/downloader/downloader.go')
-rw-r--r--eth/downloader/downloader.go14
1 files changed, 9 insertions, 5 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index 499b3a585..88ceeb5ac 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -31,7 +31,6 @@ var (
)
var (
- errLowTd = errors.New("peers TD is too low")
errBusy = errors.New("busy")
errUnknownPeer = errors.New("peer is unknown or unhealthy")
errBadPeer = errors.New("action from bad peer ignored")
@@ -94,8 +93,9 @@ type Downloader struct {
dropPeer peerDropFn // Retrieved the TD of our own chain
// Status
- synchronising int32
- notified int32
+ synchroniseMock func(id string, hash common.Hash) error // Replacement for synchronise during testing
+ synchronising int32
+ notified int32
// Channels
newPeerCh chan *peer
@@ -202,7 +202,7 @@ func (d *Downloader) Synchronise(id string, head common.Hash) {
case errBusy:
glog.V(logger.Detail).Infof("Synchronisation already in progress")
- case errTimeout, errBadPeer, errEmptyHashSet, errInvalidChain, errCrossCheckFailed:
+ case errTimeout, errBadPeer, errStallingPeer, errBannedHead, errEmptyHashSet, errPeersUnavailable, errInvalidChain, errCrossCheckFailed:
glog.V(logger.Debug).Infof("Removing peer %v: %v", id, err)
d.dropPeer(id)
@@ -218,6 +218,10 @@ func (d *Downloader) Synchronise(id string, head common.Hash) {
// it will use the best peer possible and synchronize if it's TD is higher than our own. If any of the
// checks fail an error will be returned. This method is synchronous
func (d *Downloader) synchronise(id string, hash common.Hash) error {
+ // Mock out the synchonisation if testing
+ if d.synchroniseMock != nil {
+ return d.synchroniseMock(id, hash)
+ }
// Make sure only one goroutine is ever allowed past this point at once
if !atomic.CompareAndSwapInt32(&d.synchronising, 0, 1) {
return errBusy
@@ -226,7 +230,7 @@ func (d *Downloader) synchronise(id string, hash common.Hash) error {
// If the head hash is banned, terminate immediately
if d.banned.Has(hash) {
- return errInvalidChain
+ return errBannedHead
}
// Post a user notification of the sync (only once per session)
if atomic.CompareAndSwapInt32(&d.notified, 0, 1) {