3 suggestions
Optional improvements
[suggestion] · Fuzz re-downloads bypass the known-invalid block guard
Off-chain pruning lets the fuzz target re-download an index still marked BLOCK_FAILED_VALID, a receipt transition that production rejects before ReceivedBlockTransactions.
Location: src/test/fuzz/block_index_tree.cpp:156 (head).
Details and suggested fix
The target can receive a block, mark it failed during the simplified connection action, then select it for pruning and re-download. Pruning preserves BLOCK_FAILED_VALID, but the re-download action calls ReceivedBlockTransactions without checking it. That call can change the sequence ID and reinsert the failed index into the candidate set. Production rejects the same direct receipt as duplicate-invalid in AcceptBlockHeader. Failed candidate entries themselves are allowed; the cost here is spending fuzz inputs on an unreachable receipt transition, not a demonstrated assertion failure. Skip indexes with nStatus & BLOCK_FAILED_VALID in the re-download action. Check there rather than only when pruning, because an invalid ancestor can mark an already-pruned descendant failed.
[suggestion] · Sequence-ID re-receipt fix lacks a direct regression oracle
The added functional test never re-receives an existing candidate, and the fuzz target lacks ordering and pointer-uniqueness checks for the repaired sequence-ID invariant.
Location: src/validation.cpp:3821 (head).
Details and suggested fix
The functional fixture links its three-block fork only after advancing the active tip by more than 500 blocks. None of those lower-work fork blocks can enter the candidate set then, and the pruned child is never re-downloaded. The fuzz extension can prune and re-receive an existing candidate, but its final CheckBlockIndex() checks membership, not sorted iteration or pointer uniqueness. Some corruptions already fail those lookups, so detection depends on the input and container layout. Add a focused unit test with several equal-work candidates above the tip, received in a known order. Prune the earliest-received candidate without removing it from the set, then call ReceivedBlockTransactions on it again. Assert comparator-consistent order, exactly one occurrence of every pointer, and successful lookup and erasure of the other entries. This directly tests the repaired invariant instead of relying on incidental symptoms of undefined behavior.
[suggestion] · Fuzz pruning duplicates the production retention rule
The fuzz target applies its own copy of the new HaveNumChainTxs() retention condition, so later production changes can leave it exercising a different pruning rule.
Location: src/test/fuzz/block_index_tree.cpp:164 (head).
Details and suggested fix
Extract the per-index operations into a BlockManager helper used by both PruneOneBlockFile and the fuzz action: clear the data and undo flags, reset the file positions, dirty the index, and conditionally remove the unlinked entry. Leave file-level bookkeeping and deletion scheduling in the existing file-level path. Including the dirty-index insert is compatible with the harness lifecycle because CleanupForFuzzing() clears that set before deleting block-index entries. The copies agree today, and the functional test separately exercises real pruning; sharing this rule would keep fuzz coverage tied to the production implementation.