[31.x] Backport #35168 #36361

pull fametrano wants to merge 2 commits into bitcoin:31.x from fametrano:31.x-backport-35168 changing 3 files +43 −1
  1. fametrano commented at 9:35 PM on September 27, 2026: contributor

    Backports:

    v31.1 still carries the pre-fix LoadBlockIndex, which re-adds a pruned block to m_blocks_unlinked when its parent is header-only (#35050). On the next block connected, CheckBlockIndex hits Assertion failed: (!foundInUnlinked). -checkblockindex is on by default only on regtest, so this crashes functional-test suites run against 31.x, not mainnet nodes.

    Both commits cherry-pick cleanly with -x. The only difference from master is the surrounding context in test_runner.py. The added feature_prune_stale_fork.py fails against the v31.1 release binary on the assertion above and passes on this branch (2/2 each, macOS arm64, built from depends).

    I left the release-notes entry to whoever assembles the 31.x notes.

  2. validation: Don't add pruned blocks to m_blocks_unlinked on startup
    LoadBlockIndex() adds to m_blocks_unlinked based only on nTx > 0, without
    checking BLOCK_HAVE_DATA. Pruning preserves nTx but clears BLOCK_HAVE_DATA,
    so a pruned block whose parent was header-only gets re-added on every
    restart, causing the CheckBlockIndex() assertion that entries must have
    data on disk to fail.
    
    Check that BLOCK_HAVE_DATA is set before inserting into m_blocks_unlinked.
    
    Fixes #35050.
    
    (cherry picked from commit 0e4b0bacecf94063342c7f9eb9b03dac8a7a7936)
    6cedc5d47e
  3. test: Add coverage for m_blocks_unlinked invariant in LoadBlockIndex
    A pruned stale-fork block whose parent doesn't have any transactions
    shouldn't be added to m_blocks_unlinked when starting up a node.
    
    (cherry picked from commit 3f44f9aef7ccd0417fcd0c2f33f20615ea5c11e6)
    5ec487b9ae
  4. DrahtBot added the label Backport on Sep 27, 2026
  5. DrahtBot commented at 9:35 PM on September 27, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/36361.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->


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-09-28 10:51 UTC

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