Tests that blocks with numbers much lower or higher than out current head get discarded to prevent wasting resources on useless blocks from faulty peers.
(t *testing.T)
| 492 | // Tests that blocks with numbers much lower or higher than out current head get |
| 493 | // discarded to prevent wasting resources on useless blocks from faulty peers. |
| 494 | func TestDistantPropagationDiscarding(t *testing.T) { |
| 495 | // Create a long chain to import and define the discard boundaries |
| 496 | hashes, blocks := makeChain(3*maxQueueDist, 0, genesis) |
| 497 | head := hashes[len(hashes)/2] |
| 498 | |
| 499 | low, high := len(hashes)/2+maxUncleDist+1, len(hashes)/2-maxQueueDist-1 |
| 500 | |
| 501 | // Create a tester and simulate a head block being the middle of the above chain |
| 502 | tester := newTester() |
| 503 | |
| 504 | tester.lock.Lock() |
| 505 | tester.hashes = []common.Hash{head} |
| 506 | tester.blocks = map[common.Hash]*types.Block{head: blocks[head]} |
| 507 | tester.lock.Unlock() |
| 508 | |
| 509 | // Ensure that a block with a lower number than the threshold is discarded |
| 510 | tester.fetcher.Enqueue("lower", blocks[hashes[low]]) |
| 511 | time.Sleep(10 * time.Millisecond) |
| 512 | if !tester.fetcher.queue.Empty() { |
| 513 | t.Fatalf("fetcher queued stale block") |
| 514 | } |
| 515 | // Ensure that a block with a higher number than the threshold is discarded |
| 516 | tester.fetcher.Enqueue("higher", blocks[hashes[high]]) |
| 517 | time.Sleep(10 * time.Millisecond) |
| 518 | if !tester.fetcher.queue.Empty() { |
| 519 | t.Fatalf("fetcher queued future block") |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | // Tests that announcements with numbers much lower or higher than out current |
| 524 | // head get discarded to prevent wasting resources on useless blocks from faulty |