Review report

bitcoin/bitcoin: PR #36002

1 minor finding · 4 suggestions

Earlier concerns neither republished nor resolved: 1 minor finding. See the Run archive for their assessments.

Findings

Link

[minor] · A readable stale copy hides the pruned active-chain block

When an indexed active copy is pruned but a stale copy remains readable, lookups discard the active-block hint and can report zero confirmations or return a proof that verifytxoutproof rejects.

Location: src/index/txindex.cpp:196 (head).

Details and suggested fix

With -txindex and pruning enabled, this can happen after a transaction is connected and indexed on both branches of a reorg and the node returns to the original branch, if pruning deletes the active copy's blk file while leaving the stale copy's file. FindTx collects the active hash, but returning TxFound for the stale copy discards it. A lookup without a blockhash then returns the stale hash through verbose getrawtransaction (confirmations: 0) or REST JSON. For a fully spent transaction, gettxoutproof also builds a stale-block proof that verifytxoutproof rejects with "Block not found in chain". Retain the pruned active-chain candidates alongside the readable transaction and let chain-sensitive callers surface the fetch-and-retry hint. Keep those candidates qualified as possible prefix collisions rather than treating them as confirmed inclusions. No production instance of this pruning order was found, so its practical frequency remains unconfirmed.


Optional improvements

Link

[suggestion] · The prune test never exercises saved-position catch-up

The txindex-disabled interval contains no chain advancement, so the new test misses successful disk-backed catch-up and its block-data-only startup availability check.

Location: test/functional/feature_txindex_prune.py:56 (head).

Details and suggested fix

The initial clean-chain build indexes live block connections, while the -txindex=0 interval only calls gettxoutproof; neither restart puts the index behind the chain. This leaves successful saved-position catch-up through the block_start/BLOCK_HAVE_DATA startup path untested in this fixture. Existing prune-index recovery scenarios use blockfilterindex and coinstatsindex, both of which require undo data. Add a txindex-disabled interval with chain advancement, prune older files while retaining the saved index block and every block needed for catch-up, then re-enable txindex and wait for synchronization. Assert that newly indexed transactions are found and older pruned ones still return block hints. Optionally fetch an over-pruned gap before re-enabling to cover recovery without undo data.


Link

[suggestion] · Fetched blocks are not guaranteed 288 blocks of retention

Automatic pruning uses historical block heights, not fetch time, so a sufficiently large recovery batch can lose earlier blocks before retrying; the new help omits the existing getblockfrompeer re-pruning caveat.

Location: src/rpc/rawtransaction.cpp:264 (head).

Details and suggested fix

The PR rationale's 288-block retention claim does not follow from the storage path. AcceptBlock writes the fetched block at its historical height, and file metadata and pruning use those heights. A single fetch generally shares the current file with recent blocks and survives. But under automatic pruning, a batch that fills a historical-only blk file can make it eligible as soon as a later file opens and the target is exceeded. The allocation-triggered flush can remove it without any new tip, so an earlier fetch may be gone before the retry. Repeat getblockfrompeer's existing "could be re-pruned as soon as it is received" caveat next to this fetch-and-retry advice and remove the minimum-retention claim from the rationale. The manual-pruning test does not exercise this case.


Link

[suggestion] · Fetch-and-retry advice omits the peer privacy caveat

Following the new fetch-and-retry advice discloses a specific historical block hash to the chosen peer, which can reveal transaction interest even though the lookup itself makes no network request.

Location: src/rpc/rawtransaction.cpp:264 (head).

Details and suggested fix

When the user explicitly follows this advice with getblockfrompeer, FetchBlock sends that exact historical block hash in getdata to the selected peer. The peer can infer interest in transactions in that block, although this does not prove ownership. Neither the getrawtransaction and gettxoutproof help texts nor getblockfrompeer's help mentions that disclosure. Add a short note to both new instructions recommending a trusted peer when looking up the user's own transactions.


Link

[suggestion] · The PSBT check misses the SegWit UTXO fallback

Because the pre-fetch PSBT spends only a legacy output, it cannot detect loss of witness_utxo enrichment when a previous-transaction lookup returns pruned-block hints.

Location: test/functional/feature_txindex_prune.py:80 (head).

Details and suggested fix

The current ProcessPSBT adds every TxMiss to the coins map and can fill witness_utxo from FindCoins. This test only checks absent non_witness_utxo for the legacy sent_vout, so skipping that coins lookup specifically for pruned-hash misses would still satisfy the assertion; the post-fetch check uses the found path. Add the transaction's unspent MiniWallet change output as a second PSBT input and, before fetching the block, assert that it has no non_witness_utxo but has witness_utxo with the expected amount and script. That output is native SegWit and already sits in the same pruned block, so this needs no extra mining or restarts.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.