diff options
author | obscuren <geffobscura@gmail.com> | 2015-05-03 22:09:10 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-05-03 22:27:03 +0800 |
commit | 1470b22e9051f48fbbeb136cc4c0be0877e9f9a7 (patch) | |
tree | 8b88f38edd9cf61073bee7253a2a8033042b25ae /eth/downloader/downloader_test.go | |
parent | ba2236fa513e06603d3fa2a6d721be3879d7f50e (diff) | |
download | dexon-1470b22e9051f48fbbeb136cc4c0be0877e9f9a7.tar dexon-1470b22e9051f48fbbeb136cc4c0be0877e9f9a7.tar.gz dexon-1470b22e9051f48fbbeb136cc4c0be0877e9f9a7.tar.bz2 dexon-1470b22e9051f48fbbeb136cc4c0be0877e9f9a7.tar.lz dexon-1470b22e9051f48fbbeb136cc4c0be0877e9f9a7.tar.xz dexon-1470b22e9051f48fbbeb136cc4c0be0877e9f9a7.tar.zst dexon-1470b22e9051f48fbbeb136cc4c0be0877e9f9a7.zip |
downloader: hash downloading recovery
If a peer fails to respond (disconnect, etc) during hash downloading
switch to a different peer which has it's current_hash in the queue's
peer set.
Diffstat (limited to 'eth/downloader/downloader_test.go')
-rw-r--r-- | eth/downloader/downloader_test.go | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go index fe68ea914..872ea02eb 100644 --- a/eth/downloader/downloader_test.go +++ b/eth/downloader/downloader_test.go @@ -42,12 +42,13 @@ func createBlocksFromHashes(hashes []common.Hash) map[common.Hash]*types.Block { } type downloadTester struct { - downloader *Downloader - hashes []common.Hash - blocks map[common.Hash]*types.Block - t *testing.T - pcount int - done chan bool + downloader *Downloader + hashes []common.Hash + blocks map[common.Hash]*types.Block + t *testing.T + pcount int + done chan bool + activePeerId string } func newTester(t *testing.T, hashes []common.Hash, blocks map[common.Hash]*types.Block) *downloadTester { @@ -58,6 +59,11 @@ func newTester(t *testing.T, hashes []common.Hash, blocks map[common.Hash]*types return tester } +func (dl *downloadTester) sync(peerId string, hash common.Hash) error { + dl.activePeerId = peerId + return dl.downloader.Synchronise(peerId, hash) +} + func (dl *downloadTester) hasBlock(hash common.Hash) bool { if knownHash == hash { return true @@ -70,7 +76,7 @@ func (dl *downloadTester) getBlock(hash common.Hash) *types.Block { } func (dl *downloadTester) getHashes(hash common.Hash) error { - dl.downloader.hashCh <- dl.hashes + dl.downloader.AddHashes(dl.activePeerId, dl.hashes) return nil } @@ -115,8 +121,9 @@ func TestDownload(t *testing.T) { tester.newPeer("peer2", big.NewInt(0), common.Hash{}) tester.badBlocksPeer("peer3", big.NewInt(0), common.Hash{}) tester.badBlocksPeer("peer4", big.NewInt(0), common.Hash{}) + tester.activePeerId = "peer1" - err := tester.downloader.Synchronise("peer1", hashes[0]) + err := tester.sync("peer1", hashes[0]) if err != nil { t.Error("download error", err) } @@ -139,7 +146,7 @@ func TestMissing(t *testing.T) { hashes = append(extraHashes, hashes[:len(hashes)-1]...) tester.newPeer("peer2", big.NewInt(0), common.Hash{}) - err := tester.downloader.Synchronise("peer1", hashes[0]) + err := tester.sync("peer1", hashes[0]) if err != nil { t.Error("download error", err) } @@ -164,7 +171,7 @@ func TestTaking(t *testing.T) { tester.badBlocksPeer("peer3", big.NewInt(0), common.Hash{}) tester.badBlocksPeer("peer4", big.NewInt(0), common.Hash{}) - err := tester.downloader.Synchronise("peer1", hashes[0]) + err := tester.sync("peer1", hashes[0]) if err != nil { t.Error("download error", err) } |