Review report

core: PR #35728

2 minor findings · 4 suggestions

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

Findings

Link

[minor] · The test can rename a block file before txindex sync completes

A scheduling race can abort node 0 before the test checks the intended getrawtransaction error.

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

Details and suggested fix

Node 0 starts with -txindex on a cached chain that was built without the index, so txindex sync continues in the background after startup. This test runs first and renames blk00000.dat without waiting for sync; the existing sync_txindex call runs later. If BaseIndex::Sync reads the block while the file is renamed, ProcessBlock calls FatalErrorf and aborts the node. Renaming the file back does not stop shutdown. The small chain usually finishes indexing first, but the failure depends on thread scheduling. Call sync_txindex(self, node) before renaming the file.


Link

[minor] · An unusable txindex row can prevent an explicit-block lookup

A bad txindex row for another candidate can make getrawtransaction fail even when the requested block contains the transaction.

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

Details and suggested fix

On a -txindex node, getrawtransaction with a blockhash still calls FindTx first. If the txid's prefix bucket contains an unusable row, such as one with an unknown block, missing block data, an unopenable file, or a deserialize error, FindTx throws before GetTransaction reads the requested block. The bad row can belong to another block containing the same txid or to a false-positive prefix match. The requested block may have passed CheckBlockDataAvailability and contain the transaction, yet the RPC returns an error caused by the other candidate. The previous behavior skipped such rows and fell through to reading the requested block. Consider bypassing the txindex when block_index is provided, since that block must be read anyway. This costs a full block read where the index could read only the transaction. The trigger requires a bad row or unreadable file for another candidate; no production occurrence was identified. If the requested block itself cannot be read, ReadBlock still returns its own I/O error.


Optional improvements

Link

[suggestion] · Persistent stale-row errors do not explain how to rebuild the txindex

Affected lookups can keep failing until the index is rebuilt, but the error and release note do not describe that remedy.

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

Details and suggested fix

The collection loop throws on the first row whose block-index entry is missing or lacks BLOCK_HAVE_DATA, before it sorts or reads candidates. A valid active-chain candidate for the same txid therefore cannot prevent the lookup from failing; the previous behavior skipped stale rows. Txindex rows are not deleted, and WriteTxs skips blocks that are already indexed. Because WriteTxs persists rows before FlushStateToDisk writes block-index entries, a crash in that window can leave a stale row. Peers will not re-announce the block, so lookups for transactions from it can continue to fail until the index is rebuilt, including for transactions also confirmed in the winning block. The release note says throwing in an “unclean state” is intended, but neither it nor the error gives a remedy. Consider naming the recovery steps in the error, such as stopping the node, deleting indexes/txindex, and restarting to rebuild it. Alternatively, if a valid candidate should take precedence, record the inconsistency and throw only when no candidate matches. No production occurrence was identified; reaching this state requires a crash in a specific window.


Link

[suggestion] · The release note misstates the RPC error code

Clients checking for -32603 as the note suggests will miss these failures, which return RPC_MISC_ERROR (-1).

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

Details and suggested fix

The release note says getrawtransaction, gettxoutproof, utxoupdatepsbt, and descriptorprocesspsbt now return an “internal error.” These failures are plain std::runtime_error exceptions, which ExecuteCommand maps to RPC_MISC_ERROR (-1), and the functional test asserts -1. In JSON-RPC, “internal error” names -32603 (RPC_INTERNAL_ERROR). Comparable read failures already use -32603, so gettxoutproof can now return different codes for block I/O failures depending on the path. State the actual code, -1 (RPC_MISC_ERROR), in the release note. If -32603 was intended, rethrow these errors as RPC_INTERNAL_ERROR in the RPC callers instead.


Link

[suggestion] · Header documentation omits the new exceptions

The declarations describe only a null result, leaving future callers without the updated error contract.

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

Details and suggested fix

GetTransaction now throws std::runtime_error when the requested block cannot be read and propagates exceptions from FindTx, but its declaration still documents only that it returns the transaction or nullptr. TxIndex::FindTx likewise documents only nullopt for a miss. Add @throws notes to both declarations stating that a null result means a normal miss, while read or index failures arrive as std::runtime_error. Current callers in RPC, REST, and PSBT processing catch std::exception; this documents the contract for future callers.


Link

[suggestion] · The REST error change has no test coverage

Without a test, unreadable confirmed transactions could again produce a misleading REST 404 without failing the test.

Location: test/functional/feature_io_errors.py:36 (head).

Details and suggested fix

The release note says /rest/tx/<TX-HASH> now returns an internal error, rather than not-found, when block files or the txindex are bad. The functional test covers gettxoutproof, getrawtransaction, and utxoupdatepsbt, but not REST. When an exception escapes rest_tx, the HTTP worker returns 500; a genuine miss returns 404. Restart the node with -rest enabled, then, while blk00000.dat is renamed, assert that /rest/tx/<txid>.json for a confirmed transaction returns 500.


Coverage details

Earlier concerns

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