test: add getblockfilter test coverage for header-only blocks #36613

pull aaron-leeb wants to merge 1 commits into bitcoin:master from aaron-leeb:test/getblockfilter-header-only changing 1 files +15 −0
  1. aaron-leeb commented at 5:34 PM on October 22, 2026: contributor

    Add functional coverage for the getblockfilter error raised when a node has a known block header, but the block has never been connected.

    This gap in test coverage was identified by a coverage report generated while exploring BIP 157/158. The branch in src/rpc/blockchain.cpp was never executed in the measured tests: https://github.com/bitcoin/bitcoin/blob/64cf455b481d36182957bdcfcae7c411a7879897/src/rpc/blockchain.cpp#L3054-L3056

    The existing getblockfilter functional test checks unknown block hashes and filter retrieval for active and stale blocks, but doesn’t check a known header whose block has never been connected.

    This change submits only the block header of a newly mined block to a node using submitheader and verifies that in this expected state, getblockfilter returns error -5 with "Filter not found. Block was not connected to active chain." This adds coverage for the RPC’s distinction between an unknown block and a known block for which no filter has been constructed.

    rpc_getblockfilter.py passes, and changing the error message makes the new assertion fail as expected.

  2. test: add getblockfilter test coverage for header-only blocks 64cf455b48
  3. DrahtBot added the label Tests on Oct 22, 2026
  4. DrahtBot commented at 5:34 PM on October 22, 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 Zippo76, sedited

    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-->

  5. Zippo76 commented at 9:22 AM on November 1, 2026: none

    tACK 64cf455b48

    Tested on macOS 27.0.1 (Apple Silicon arm64). rpc_getblockfilter.py passes. Replacing if (!block_was_connected) with if (block_was_connected) in getblockfilter in src/rpc/blockchain.cpp makes the PR's test fail, while the test from master 6c01bd0b2d still passes with the same mutation:

    Expected: Filter not found. Block was not connected to active chain. Actual: Filter not found. This error is unexpected and indicates index corruption. The code implies that the header-only block has not reached BLOCK_VALID_SCRIPTS on node 0, so the new assertion exercises the intended -5 error path.

  6. sedited approved
  7. sedited commented at 1:23 PM on November 6, 2026: contributor

    ACK 64cf455b481d36182957bdcfcae7c411a7879897

  8. sedited merged this on Nov 6, 2026
  9. sedited closed this on Nov 6, 2026

  10. maflcko approved
  11. maflcko commented at 1:33 PM on November 6, 2026: member

    lgtm

  12. in test/functional/rpc_getblockfilter.py:57 in 64cf455b48
      49 | @@ -50,6 +50,21 @@ def run_test(self):
      50 |          bad_block_hash = "0123456789abcdef" * 4
      51 |          assert_raises_rpc_error(-5, "Block not found", self.nodes[0].getblockfilter, bad_block_hash, "basic")
      52 |  
      53 | +        self.disconnect_nodes(0, 1)
      54 | +
      55 | +        # Test getblockfilter for a known header before connecting its block
      56 | +        block_hash = self.generate(self.nodes[1], 1, sync_fun=self.no_op)[0]
      57 | +        self.nodes[0].submitheader(self.nodes[1].getblockheader(block_hash, False))
    


    maflcko commented at 1:33 PM on November 6, 2026:

    pm nit: I think all of the disconnect+sync+reconnect can be skipped by using the pattern:

            block = self.generateblock(node1, output="raw(55)", transactions=[], submit=False)
            node0.submitheader(block["hex"][:160])
    

    E.g. fa2986921cd53146fb8a1fc9585714a064a137d9


    aaron-leeb commented at 3:03 PM on November 6, 2026:

    Thanks for sharing this!

  13. maflcko commented at 1:34 PM on November 6, 2026: member

    .


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