Skip to content

[31.x] Backport #35168 - #36361

Closed
fametrano wants to merge 2 commits into
bitcoin:31.xfrom
fametrano:31.x-backport-35168
Closed

fametrano wants to merge 2 commits into
bitcoin:31.xfrom
fametrano:31.x-backport-35168

Conversation

@fametrano

@fametrano fametrano commented Sep 27, 2026 •

Copy link
Copy Markdown

Backports:

v31.1 still has the pre-fix LoadBlockIndex. It re-adds a pruned block to m_blocks_unlinked when its parent is header-only (#35050). When the next block connects, CheckBlockIndex fails with Assertion failed: (!foundInUnlinked). -checkblockindex is on by default only on regtest, so this crashes functional-test suites run against 31.x. With default settings, nodes on mainnet, testnet and signet do not run this check, so they do not crash.

Both commits are clean cherry-picks (-x). The only difference from master is context in test_runner.py. The new feature_prune_stale_fork.py fails on the v31.1 release binary with the assertion above. It passes on this branch, built from depends. Two runs each, on macOS arm64.

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

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 bitcoin#35050.

(cherry picked from commit 0e4b0ba)
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 3f44f9a)
@DrahtBot

DrahtBot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

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

Code Coverage & Benchmarks

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

Reviews

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

@fanquake fanquake modified the milestone: 31.2 Oct 21, 2026
@fanquake

Copy link
Copy Markdown
Member

This is missing the backport metadata, so I've added that (and release notes in #36662)

@fanquake fanquake closed this Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants