aboutsummaryrefslogtreecommitdiffstats
path: root/eth/fetcher/fetcher_test.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-06-17 04:18:01 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-06-18 20:56:08 +0800
commit497a7f1717a798e59c9550fbb58504b08fe13b21 (patch)
tree458d972505f6214acfb0597f3b4e56d3f01982b7 /eth/fetcher/fetcher_test.go
parent026ee40650bde909c962f15e32bdea6c1d6e978a (diff)
downloadgo-tangerine-497a7f1717a798e59c9550fbb58504b08fe13b21.tar.gz
go-tangerine-497a7f1717a798e59c9550fbb58504b08fe13b21.tar.zst
go-tangerine-497a7f1717a798e59c9550fbb58504b08fe13b21.zip
eth, eth/fetcher: define and enforce propagation boundaries
Diffstat (limited to 'eth/fetcher/fetcher_test.go')
-rw-r--r--eth/fetcher/fetcher_test.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/eth/fetcher/fetcher_test.go b/eth/fetcher/fetcher_test.go
index e11a211a1..af2652a86 100644
--- a/eth/fetcher/fetcher_test.go
+++ b/eth/fetcher/fetcher_test.go
@@ -335,3 +335,31 @@ func TestImportDeduplication(t *testing.T) {
t.Fatalf("import invocation count mismatch: have %v, want %v", counter, 2)
}
}
+
+// Tests that blocks with numbers much lower or higher than out current head get
+// discarded no prevent wasting resources on useless blocks from faulty peers.
+func TestDistantDiscarding(t *testing.T) {
+ // Create a long chain to import
+ hashes := createHashes(3*maxQueueDist, knownHash)
+ blocks := createBlocksFromHashes(hashes)
+
+ head := hashes[len(hashes)/2]
+
+ // Create a tester and simulate a head block being the middle of the above chain
+ tester := newTester()
+ tester.ownHashes = []common.Hash{head}
+ tester.ownBlocks = map[common.Hash]*types.Block{head: blocks[head]}
+
+ // Ensure that a block with a lower number than the threshold is discarded
+ tester.fetcher.Enqueue("lower", blocks[hashes[0]])
+ time.Sleep(10 * time.Millisecond)
+ if !tester.fetcher.queue.Empty() {
+ t.Fatalf("fetcher queued stale block")
+ }
+ // Ensure that a block with a higher number than the threshold is discarded
+ tester.fetcher.Enqueue("higher", blocks[hashes[len(hashes)-1]])
+ time.Sleep(10 * time.Millisecond)
+ if !tester.fetcher.queue.Empty() {
+ t.Fatalf("fetcher queued future block")
+ }
+}