m_blocks_unlinked serves two purposes:
- finding blocks to
setBlockIndexCandidatesonce their parents are received - setting
m_chain_tx_countonce the parents are received
In case the parent block of a previously pruned block is received, 2. is currently not being done, because pruning removed the entries from m_blocks_unlinked.
This can result in CheckBlockIndex failures (#31512, #36021) and incorrect rpc results, plus we are in a temporarily inconsistent state (m_chain_tx_count is currently not set, but would get set if we restarted).
This scenario is unlikely to happen during normal node operation unless there are huge reorgs, but it can happen, for example, in getblockfrompeer scenarios.
Fix this by leaving pruned blocks in m_chain_tx_count, and also adding them on restart.
This was one of two reasons, the fuzz target block_index_tree couldn't cover pruning of blocks not in the main chain.
The other one is similar to #34521 and #35070 - if we receive a block a second time (after pruning), we could change nSequenceId while the block is in setBlockIndexCandidates - fix this by attempting to remove it from the set before re-adding it.
After the two issues are fixed, the restriction from block_index_tree fuzz target is removed.