Tests that if a block is empty (i.e. header only), no body request should be made, and instead the header should be assembled into a whole block in itself.
(t *testing.T)
| 604 | // Tests that if a block is empty (i.e. header only), no body request should be |
| 605 | // made, and instead the header should be assembled into a whole block in itself. |
| 606 | func TestEmptyBlockShortCircuit(t *testing.T) { |
| 607 | // Create a chain of blocks to import |
| 608 | hashes, blocks := makeChain(32, 0, genesis) |
| 609 | |
| 610 | tester := newTester() |
| 611 | headerFetcher := tester.makeHeaderFetcher("valid", blocks, -gatherSlack) |
| 612 | bodyFetcher := tester.makeBodyFetcher("valid", blocks, 0) |
| 613 | |
| 614 | // Add a monitoring hook for all internal events |
| 615 | fetching := make(chan []common.Hash) |
| 616 | tester.fetcher.fetchingHook = func(hashes []common.Hash) { fetching <- hashes } |
| 617 | |
| 618 | completing := make(chan []common.Hash) |
| 619 | tester.fetcher.completingHook = func(hashes []common.Hash) { completing <- hashes } |
| 620 | |
| 621 | imported := make(chan *types.Block) |
| 622 | tester.fetcher.importedHook = func(block *types.Block) { imported <- block } |
| 623 | |
| 624 | // Iteratively announce blocks until all are imported |
| 625 | for i := len(hashes) - 2; i >= 0; i-- { |
| 626 | tester.fetcher.Notify("valid", hashes[i], uint64(len(hashes)-i-1), time.Now().Add(-arriveTimeout), headerFetcher, bodyFetcher) |
| 627 | |
| 628 | // All announces should fetch the header |
| 629 | verifyFetchingEvent(t, fetching, true) |
| 630 | |
| 631 | // Only blocks with data contents should request bodies |
| 632 | verifyCompletingEvent(t, completing, len(blocks[hashes[i]].Transactions()) > 0) |
| 633 | |
| 634 | // Irrelevant of the construct, import should succeed |
| 635 | verifyImportEvent(t, imported, true) |
| 636 | } |
| 637 | verifyImportDone(t, imported) |
| 638 | } |
| 639 | |
| 640 | // Tests that a peer is unable to use unbounded memory with sending infinite |
| 641 | // block announcements to a node, but that even in the face of such an attack, |
nothing calls this directly
no test coverage detected