test: cover compact blocks far ahead of the tip #36410

pull fametrano wants to merge 1 commits into bitcoin:master from fametrano:test-cmpctblock-revert-to-headers changing 2 files +85 −0
  1. fametrano commented at 7:15 AM on October 2, 2026: contributor

    This adds a test that passes on master and fails with the diff from #34618 applied, as davidgumberg asked in #34722. It covers both things that diff removes for a compact block more than two blocks ahead of the tip.

    If the node already requested the block from this peer, it sends another getdata for the full block. Without that getdata, the block stays in flight from this peer and nothing requests it again until the block download timeout disconnects the peer. This check is the one shuv-amp proposed in #34722.

    Otherwise, from a high-bandwidth peer, the node handles the header as a headers message (fRevertToHeaderProcessing). Most of that work is done anyway. As 151henry151 pointed out in #34618, one part is not: protecting an outbound peer from eviction (m_chain_sync.m_protect). The test checks for the "Protecting outbound peer" debug log line.

    Each check fails when only its branch is disabled: fRevertToHeaderProcessing = false fails the protection check, and if (false) in place of if (requested_block_from_this_peer) makes the getdata check time out. shuv-amp first tested the two branches separately in #34618.

    Fixes #34618.

    Made with my usual tools: a computer, the Internet and an LLM. The mistakes, as usual, are all mine.

  2. DrahtBot added the label Tests on Oct 2, 2026
  3. DrahtBot commented at 7:15 AM on October 2, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK Pranav-error

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. fametrano force-pushed on Oct 6, 2026
  5. fametrano force-pushed on Oct 7, 2026
  6. fametrano force-pushed on Oct 10, 2026
  7. fametrano force-pushed on Oct 13, 2026
  8. DrahtBot added the label Needs rebase on Oct 20, 2026
  9. test: cover compact blocks far ahead of the tip
    A compact block more than two blocks ahead of the tip is not
    reconstructed. If the node requested it from that peer, it asks for the
    full block again. Otherwise it handles the header as a headers message
    (fRevertToHeaderProcessing). No test checked what either branch does,
    so removing both made no test fail.
    
    The new test checks that the node sends a second getdata for a requested
    block, and that an outbound high-bandwidth peer announcing such a block
    is protected from eviction. Only the headers path sets that protection.
    
    Each check fails if its branch in net_processing.cpp is disabled.
    de16833975
  10. fametrano force-pushed on Oct 20, 2026
  11. DrahtBot removed the label Needs rebase on Oct 20, 2026
  12. Pranav-error commented at 7:44 PM on November 12, 2026: none

    crACK de16833975f3ec98dc96120e9b6e905709453aec

    Nicely closes the gap from #34618 — both uncovered sub-branches of the "more than two blocks ahead of the tip" path are exercised:

    • test_requested → the requested_block_from_this_peer branch: the still-in-flight block triggers the GETDATA MSG_BLOCK re-request, caught by wait_for_getdata([blocks[-1].hash_int]). Deleting that branch makes the re-request vanish and the wait time out.
    • test_unrequested_from_hb_peer → the fRevertToHeaderProcessing = true → ProcessHeadersMessage(…, via_compact_block=true) branch. I traced the asserted log: Protecting outbound peer=%d from eviction is emitted only inside ProcessHeadersMessage (net_processing.cpp:3209, under IsFullOutboundConn()), and for this compact-block message that function is reachable only via fRevertToHeaderProcessing. The inbound peer's msg_headers(blocks[:2]) can't produce it (not an outbound conn), and the earlier full msg_block doesn't pass through ProcessHeadersMessage, so m_chain_sync.m_protect is still false when the cmpctblock arrives — the log is a genuine regression signal for this branch.

    Non-blocking suggestion: the header path is asserted indirectly via the eviction-protection log, so a future refactor that moves that logic could let the test keep passing while silently no longer covering fRevertToHeaderProcessing. Additionally asserting the header was accepted (e.g. it appears as a headers-only tip in getchaintips) would make the coverage robust to that.

    Code-review only — didn't build/run locally.

  13. fametrano commented at 2:00 AM on November 13, 2026: contributor

    A headers-only tip in getchaintips would not show that the header-processing branch ran: the compact block handler accepts the header with ProcessNewBlockHeaders before it branches, so the tip is there either way. Thanks for tracing the eviction log to ProcessHeadersMessage; only this branch produces it, which is why I check it.

    With fRevertToHeaderProcessing = false, or return; in place of the ProcessHeadersMessage call, the getchaintips check alone passes and the log check fails: https://gist.github.com/fametrano/d9df2459d1f407f128ce5a922d79d39e/01d2880c53a78bec2f820863bf3ccc00cedeac11

  14. Pranav-error commented at 2:54 AM on November 13, 2026: none

    You're right, thanks — I'd missed that ProcessNewBlockHeaders({{cmpctblock.header}}) (net_processing.cpp:4831) accepts the header before the fRevertToHeaderProcessing branch (4848+), so the headers-only tip shows in getchaintips either way and wouldn't discriminate the branch. Your mutation confirms it: the eviction-log check is the right — and only — discriminating signal here. Nit withdrawn; the existing assertion is correct. crACK stands.

  15. maflcko commented at 6:55 AM on November 13, 2026: member

    @Pranav-error Using AI to write your comments violates https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md and will get you blocked


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-18 16:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me