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.
This commit is contained in:
marcofleon
2026-04-27 18:16:44 +01:00
parent ad3f73862b
commit 0e4b0bacec

View File

@@ -487,7 +487,9 @@ bool BlockManager::LoadBlockIndex(const std::optional<uint256>& snapshot_blockha
pindex->m_chain_tx_count = pindex->pprev->m_chain_tx_count + pindex->nTx;
} else {
pindex->m_chain_tx_count = 0;
m_blocks_unlinked.insert(std::make_pair(pindex->pprev, pindex));
if (pindex->nStatus & BLOCK_HAVE_DATA) {
m_blocks_unlinked.insert(std::make_pair(pindex->pprev, pindex));
}
}
} else {
pindex->m_chain_tx_count = pindex->nTx;