txindex: allow running in pruned mode

bitcoin/bitcoin: PR #36002

1 minor finding · 3 suggestions

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

Findings

Link

[minor] · FindTx reports an I/O error after a concurrent prune and refetch

If pruning and a user-requested refetch complete between FindTx copying and opening a position, a readable transaction receives a transient lookup error; this interleaving has not been reproduced.

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

Details and suggested fix

FindTx copies each candidate's physical position under cs_main and opens it after releasing the lock. Pruning can delete that file, then a refetch through getblockfrompeer or submitblock can install a new position and restore BLOCK_HAVE_DATA. Opening the old position fails, but IsBlockPruned now returns false, so the recovery branch warns and throws. Consequently, getrawtransaction returns RPC_MISC_ERROR without pruned_block_hashes, and REST returns HTTP 500, even though retrying can read the replacement position. Retain the indexed transaction offset and, on a failed open, re-read the block's position under cs_main. Retry the candidate when that position changed, keeping the existing classification otherwise.


Optional improvements

Link

[suggestion] · txindex pruning is enabled before pruned lookups are handled

Commit 9ad5fff enables pruning before 0bf8319 adds pruned-block handling to FindTx, leaving an intermediate revision that warns about corruption for ordinary pruned-block lookups; the final tree already handles these misses.

Location: src/index/txindex.cpp:152 at 9ad5fffab44f (commit) (commit).

Details and suggested fix

9ad5fffab44fc7873f0e18184b6837cde729d741 enables pruning for nonlegacy indexes, but its FindTx still warns and throws when an active-chain candidate lacks BLOCK_HAVE_DATA. The next commit, 0bf8319d032e0b40866534d10bca204fd0df8da7, adds the IsBlockPruned branches and TxMiss results. Move that lookup-handling commit before the enabling commit so reviewers can validate the handling before pruning becomes usable. Its temporary GetTransaction adapter already converts TxMiss to an ordinary miss, and its tests simulate pruning by editing block status directly. The overlap needs textual rebasing, but the final tree stays unchanged.


Link

[suggestion] · PSBT updaters omit pruned-block recovery guidance

utxoupdatepsbt and descriptorprocesspsbt omit recovery guidance for legacy inputs left without non_witness_utxo when previous transactions are pruned; this best-effort behavior is not a regression.

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

Details and suggested fix

Both RPCs share ProcessPSBT, which discards TxMiss::pruned_block_hashes and falls back to the UTXO set. That fallback supplies witness_utxo only for segwit outputs, so it cannot fill a legacy input's missing previous-transaction data. Document in their help or the release note that users with -txindex can obtain candidate block hashes from getrawtransaction, fetch them with getblockfrompeer, and retry the PSBT operation. This preserves partial updates and the existing return types.


Link

[suggestion] · getblockfrompeer recovery advice omits the privacy tradeoff

The new recovery advice omits that explicitly calling getblockfrompeer reveals interest in the returned historical block to the chosen peer.

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

Details and suggested fix

The transaction lookup stays local, but FetchBlock sends the requested block hash in GETDATA when the user chooses to fetch it. For users looking up their own transactions, repeated recovery requests let the peer link their node's interest in those historical blocks. Add a short caution to the new getrawtransaction and gettxoutproof recovery instructions, and preferably the release note, explaining that fetching reveals the request to the selected peer and that a trusted peer may be preferable for sensitive lookups.


Coverage details

Earlier concerns

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

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

Pruned-node transaction recovery was historically proposed as retaining a logical block identifier and fetching the missing block on demand. The motivation was low-storage, self-validated transaction access for workloads such as personal explorers, accepting network latency instead of retaining all block bodies.

The current hash-hint-and-explicit-refetch workflow follows that recovery model. Earlier proposals anticipated preserving transaction lookup metadata across pruning; they did not promise that every transaction would remain immediately readable or that a newly enabled index could reconstruct already-deleted history without obtaining the blocks.

Source 1 · Source 2 · Source 3

Unresolved disagreements

Historical discussion disagreed about the utility and API expectations of pruned transaction lookup. Objections emphasized unpredictable availability and the application's continuing need for a fallback; supporters valued recent-history access, manual pruning, or on-demand recovery on low-storage hardware. The inspected record does not resolve that product tradeoff.

Returning recoverable block hints addresses a different contract from promising that getrawtransaction always succeeds. The earlier objections remain context about application expectations, not evidence that the current recovery design is incorrect.

Source 1 · Source 2 · Source 3 · Source 4

The genesis-lock discussion separately raised whether prune locks should follow the committed locator rather than an in-memory tip that can advance ahead of it. The response treated this as outside the startup fix's scope; the inspected discussion did not resolve it.

The documented lock-publication ordering guarantees callback completion and updated locks. It should not be conflated with a separately established crash-recovery guarantee covering every relationship between persisted index checkpoints and pruning.

Source 1 · Source 2 · Source 3