Review report

bitcoin/bitcoin: PR #35728

2 minor findings · 5 suggestions

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

Findings

Link

[minor] · An unreadable txindex candidate prevents otherwise answerable lookups

With -txindex, local damage to one candidate can now fail a transaction lookup even when another candidate or the explicitly requested block is readable.

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

Details and suggested fix

FindTx now throws on the first candidate it cannot open or deserialize, before checking its full txid. Candidates are ordered active-chain first, then by sequence, and share five-byte salted prefixes. The failing candidate can therefore be another occurrence of the requested transaction or an unrelated prefix collision. GetTransaction queries the index before reading a supplied block, so getrawtransaction can return -1 despite that block being readable and containing the transaction. Its catch only checks availability flags and rethrows. Without a blockhash, a higher-ranked damaged collision can likewise prevent retrieval of an intact confirmed transaction. Prefer deferring candidate errors while searching for a verified active-chain match. Still throw if nothing verifies, or if only a stale match verifies after an active-chain candidate failed. For explicit-block requests, catch and log the index error and attempt the requested block, retaining its own read-error handling. If failing on any detected corruption is the intended policy instead, document this availability tradeoff in the help and release note. No production occurrence was identified.


Link

[minor] · Block-file fault injection races initial txindex synchronization

The new functional test can request node shutdown by hiding blk00000.dat before node 0 finishes its initial txindex synchronization.

Location: test/functional/rpc_rawtransaction.py:112 (head).

Details and suggested fix

Node 0 starts with -txindex on a cached chain built without it, so initial indexing runs in a background thread. This new test runs before the existing sync_txindex wait, and both requests supply blockhash, bypassing the RPC's index-readiness check. Startup readiness and validation-queue draining do not finish the independent initial sync loop. If that loop opens a historical block while the file is renamed, ProcessBlock fails its disk read and calls FatalErrorf, requesting node shutdown. Renaming the file back does not undo that. Call the already-imported sync_txindex(self, node) before the rename, as the separate I/O test already does through its synced-state wait. The failure depends on scheduling; no intermittent failure was observed.


Optional improvements

Link

[suggestion] · New txindex error classifications lack regression coverage

The tests do not distinguish missing legacy keys from malformed values, or tolerated stale hashed rows from corruption that must throw.

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

Details and suggested fix

The new functional test builds a fresh index and renames a block file, exercising the open-failure branch. The existing collision and reorg tests use readable candidates. txindex_legacy_fallback enables legacy lookup correctly but checks only a well-formed row. Reverting TryRead to Read would therefore leave that assertion satisfied, since Read returns false for both an absent key and a deserialization failure. Extend the legacy fixture by overwriting its value with an undeserializable byte, asserting std::runtime_error, then erasing the key and asserting a miss. Use the existing database helpers to cover hashed classifications too: missing sequence mappings must throw, unknown blocks must be skipped, and known blocks without data must skip only when non-active. These assertions would protect the newly introduced skip-versus-throw policy.


Link

[suggestion] · The release note's “internal error” wording obscures the RPC code

The new RPC failures return -1, although “internal error” also names JSON-RPC error -32603.

Location: doc/release-notes-35728.md:4 (head).

Details and suggested fix

The new read failures throw std::runtime_error, which ExecuteCommand maps to RPC_MISC_ERROR (-1). The new functional test explicitly expects that code. gettxoutproof still returns RPC_INTERNAL_ERROR (-32603) for its direct block-read failure, so unreadable block data can produce either code depending on the lookup path. State the actual -1 code in the RPC release note to avoid suggesting that clients should identify these new failures by -32603. The REST wording is accurate for its HTTP 500 response.


Link

[suggestion] · Lookup declarations omit the read-failure exception contract

The GetTransaction and FindTx declarations describe nullable results but not the exceptions now designated for detected I/O and index failures.

Location: src/node/transaction.cpp:165 (head).

Details and suggested fix

GetTransaction now throws std::runtime_error when it cannot read the requested block and propagates the expanded FindTx/FindLegacyTx exceptions. Their declarations still describe only a transaction or nullptr/nullopt. Database exceptions could already escape before this PR, but the change makes the miss-versus-error distinction central to the API. Add @throws documentation to both declarations separating an ordinary miss from a detected read or corruption failure. Existing RPC and REST exception boundaries handle these failures; the documentation would guide future callers.


Link

[suggestion] · /rest/tx routes expected read failures through the HTTP catch-all

The new REST 500 uses the generic unexpected-error handler, adding another warning and Connection: close instead of the normal REST error format.

Location: doc/release-notes-35728.md:15 (head).

Details and suggested fix

rest_tx lets the new GetTransaction exceptions escape to the HTTP worker. That boundary correctly returns 500, but it also logs an unexpected failure after FindTx has already warned, sets Connection: close, and bypasses RESTERR's text/plain content type and CRLF-terminated message. Other REST block-read I/O failures return 500 explicitly through RESTERR. Catch the lookup's read-failure exception in rest_tx and return RESTERR(req, HTTP_INTERNAL_SERVER_ERROR, e.what()) so this documented error follows the normal REST path. The new test checks only the status and message prefix, so it does not distinguish these responses.


Link

[suggestion] · getrawtransaction's pruned-data error lacks a regression assertion

The new tests do not exercise getrawtransaction's routing from a failed explicit-block lookup to the pruned-data error.

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

Details and suggested fix

The catch now calls CheckBlockDataAvailability, which distinguishes pruned data from a block that was never fully downloaded. The added assertions cover only the header-only and missing-file cases. The existing node-2 pruning step subsequently queries only a mempool transaction, so it cannot protect this new explicit-block path. Reuse that step: before pruning, record a low-height block hash and its coinbase txid and verify retrieval with blockhash; afterward, assert -1 and Block not available (pruned data) for the same request. This uses the existing cached-chain fixture and pruning work without adding nodes or blocks.


Coverage details

Earlier concerns

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