From a8a2b2a488f7433abc09c51b751556875c9107a9 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 13 Apr 2015 16:38:32 +0200 Subject: downloader: added missing blocks catchup functionality When a parent is missing in the block list an attempt should be made to fetch the missing parent and grandparents. --- eth/downloader/downloader_test.go | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'eth/downloader/downloader_test.go') diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go index 64bf9b096..6cf99b678 100644 --- a/eth/downloader/downloader_test.go +++ b/eth/downloader/downloader_test.go @@ -14,7 +14,7 @@ import ( var knownHash = common.Hash{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -func createHashes(amount int) (hashes []common.Hash) { +func createHashes(start, amount int) (hashes []common.Hash) { hashes = make([]common.Hash, amount+1) hashes[len(hashes)-1] = knownHash @@ -49,7 +49,7 @@ type downloadTester struct { func newTester(t *testing.T, hashes []common.Hash, blocks map[common.Hash]*types.Block) *downloadTester { tester := &downloadTester{t: t, hashes: hashes, blocks: blocks, done: make(chan bool)} - downloader := New(tester.hasBlock, tester.insertChain) + downloader := New(tester.hasBlock, tester.insertChain, func() *big.Int { return new(big.Int) }) tester.downloader = downloader return tester @@ -84,7 +84,7 @@ func (dl *downloadTester) getBlocks(id string) func([]common.Hash) error { blocks[i] = dl.blocks[hash] } - go dl.downloader.DeliverBlocks(id, blocks) + go dl.downloader.DeliverChunk(id, blocks) return nil } @@ -109,11 +109,11 @@ func TestDownload(t *testing.T) { glog.SetV(logger.Detail) glog.SetToStderr(true) - hashes := createHashes(1000) + hashes := createHashes(0, 1000) blocks := createBlocksFromHashes(hashes) tester := newTester(t, hashes, blocks) - tester.newPeer("peer1", big.NewInt(10000), hashes[len(hashes)-1]) + tester.newPeer("peer1", big.NewInt(10000), hashes[0]) tester.newPeer("peer2", big.NewInt(0), common.Hash{}) tester.badBlocksPeer("peer3", big.NewInt(0), common.Hash{}) tester.badBlocksPeer("peer4", big.NewInt(0), common.Hash{}) @@ -126,3 +126,30 @@ success: t.Error("timout") } } + +func TestMissing(t *testing.T) { + t.Skip() + + glog.SetV(logger.Detail) + glog.SetToStderr(true) + + hashes := createHashes(0, 1000) + extraHashes := createHashes(1001, 1003) + blocks := createBlocksFromHashes(append(extraHashes, hashes...)) + tester := newTester(t, hashes, blocks) + + tester.newPeer("peer1", big.NewInt(10000), hashes[len(hashes)-1]) + + hashes = append(extraHashes, hashes[:len(hashes)-1]...) + tester.newPeer("peer2", big.NewInt(0), common.Hash{}) + +success1: + select { + case <-tester.done: + break success1 + case <-time.After(10 * time.Second): // XXX this could actually fail on a slow computer + t.Error("timout") + } + + tester.downloader.AddBlock("peer2", blocks[hashes[len(hashes)-1]], big.NewInt(10001)) +} -- cgit v1.2.3