blockstorage: fix partial-mask assertions and genesis availability checks #36971

pull l0rinc wants to merge 5 commits into bitcoin:master from l0rinc:l0rinc/block-data-availability-mask changing 3 files +26 −10
  1. l0rinc commented at 8:26 PM on November 24, 2026: contributor

    Problem: CheckBlockDataAvailability checks whether the upper block has any requested bit. GetFirstBlock requires every requested bit, so a partial match can reach its assertion. At genesis, the existing undo exception can reject an undo-only request or accept a request with missing block data. It also misses ranges containing only genesis.

    Fix: Require every requested bit on each block in the range, except that genesis needs no undo data. An empty mask now succeeds for a valid range because it requests no bits. Both index-startup calls supply nonempty masks.

  2. test: characterize block data availability masks
    Record the availability results for genesis and partially available blocks before fixing the mask checks.
    Use `Assert` for the full-mask precondition in `GetFirstBlock` so the unit test can observe which availability requests violate it.
    bb84dda2fe
  3. blockstorage: reject missing data at the lower block
    The genesis undo exception accepts any matching requested flag, so `BLOCK_OPT_WITNESS` can hide missing block data at genesis.
    Check the lower block for missing requested bits before walking the range, exempting only genesis undo data.
    When both endpoints are the same pruned block with only undo data, a request for block data and undo data now returns `false` before reaching the walker assertion.
    Assert the existing `cs_main` requirement on entry so it also covers the early returns.
    6f4519c466
  4. blockstorage: honor the undo exception for genesis-only ranges
    When the endpoints coincide, checking the lower block covers the whole range.
    Return early in that case so neither the upper block check nor `GetFirstBlock` requires undo data from genesis.
    This also accepts an empty mask on a single-block range because it requests no bits.
    dbd2c96276
  5. blockstorage: reject partial upper-block matches before GetFirstBlock
    `GetFirstBlock` requires every requested bit on its starting block.
    Reject an upper block missing any of those bits before calling the walker.
    This also accepts an empty mask on a multi-block range because it requests no bits.
    08ec1a6685
  6. blockstorage: honor undo-only requests down to genesis
    The old genesis branch rejected undo-only requests because it looked for a matching flag after removing the only requested bit.
    Genesis has already passed the lower block check.
    If the walk stops at its child because genesis lacks undo data, the whole range is available.
    Every other lower block has already passed the full mask check, so the walk cannot stop at its child.
    41851dc3c3
  7. DrahtBot added the label Block storage on Nov 24, 2026
  8. DrahtBot commented at 8:26 PM on November 24, 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 jeanpablojp

    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.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #36946 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36946.svg"></sub> (scripted-diff: [test] Add util/check.h includes for assertions by maflcko)
    • #35731 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35731.svg"></sub> (Indexes: Harden the flush-error notification invariant by arejula27)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  9. jeanpablojp commented at 7:33 PM on November 26, 2026: contributor

    tACK 41851dc3c325d656e33d72b79f3770a801f923e7

    Left 2 small nits.

  10. in src/node/blockstorage.h:417 in 41851dc3c3
     414 | @@ -415,6 +415,7 @@ class BlockManager
     415 |  
     416 |      //! Check if all blocks in the [upper_block, lower_block] range have data available as
     417 |      //! defined by the status mask.
    


    jeanpablojp commented at 7:33 PM on November 26, 2026:

    nit: could the comment say every flag is required, like the PR description does?

        //! Check if all blocks in the [upper_block, lower_block] range have all
        //! block_status flags set.
    
  11. in src/test/blockmanager_tests.cpp:164 in 41851dc3c3
     159 | @@ -146,6 +160,8 @@ BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_availability, TestChain100Setup)
     160 |      BOOST_CHECK_EQUAL(&blockman.GetFirstBlock(tip, BLOCK_HAVE_DATA), first_available_block);
     161 |      BOOST_CHECK(blockman.CheckBlockDataAvailability(tip, *first_available_block));
     162 |      BOOST_CHECK(!blockman.CheckBlockDataAvailability(tip, *last_pruned_block));
     163 | +    BOOST_REQUIRE_EQUAL(last_pruned_block->nStatus & BLOCK_HAVE_MASK, BLOCK_HAVE_UNDO);
     164 | +    BOOST_CHECK(!blockman.CheckBlockDataAvailability(*last_pruned_block, *last_pruned_block, BLOCK_HAVE_MASK));
    


    jeanpablojp commented at 7:33 PM on November 26, 2026:

    I think the two empty-mask checks Ralph suggested make sense here. Feel free to ignore, though.

        BOOST_CHECK(!blockman.CheckBlockDataAvailability(*last_pruned_block, *last_pruned_block, BLOCK_HAVE_MASK));
        BOOST_CHECK(blockman.CheckBlockDataAvailability(*last_pruned_block, *last_pruned_block, BlockStatus{}));
        BOOST_CHECK(blockman.CheckBlockDataAvailability(tip, *last_pruned_block, BlockStatus{}));
    

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-12-04 01:52 UTC

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