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] · A corrupt txindex row can block an explicit-blockhash lookup

With -txindex, a bad row for another block can make getrawtransaction return -1 even when the requested block is readable and contains the transaction; no production occurrence was identified.

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

Details and suggested fix

On a -txindex node, getrawtransaction with a blockhash checks that the requested block data is available, then calls GetTransaction. FindTx can throw on the first unusable row in the txid's prefix bucket before the code reads the requested block. The row may belong to another block containing the same txid or to an unrelated txid with the same prefix. The exception therefore makes the RPC return -1 even though the requested block is on disk and contains the transaction. The previous code skipped unusable rows and read the requested block, matching the RPC help. When block_index is non-null, skip the txindex or catch its exception and fall through to the block read. Keep throwing if reading the requested block itself fails. This can require reading the full block instead of one transaction. The behavior is established, but no production trigger or affected caller was identified; production impact is conditional on an unusable alternate row.


Link

[minor] · The test can rename a block file before txindex finishes syncing

If txindex is still syncing when the test renames the block file, node 0 can shut down before the test reaches its expected getrawtransaction error.

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

Details and suggested fix

Node 0 starts with -txindex on a cached chain built without the index, so indexing continues in the background after startup. The test framework does not wait for the index to sync, and test_getrawtransaction_block_data_errors runs before the later sync_txindex call. If BaseIndex::Sync reads a block while the test has renamed blk00000.dat, ProcessBlock calls FatalErrorf and shuts down the node. Renaming the file back does not cancel the shutdown, so the test fails before checking the expected RPC error. Call sync_txindex(self, node) before renaming the file. The race depends on thread scheduling, and the small cached chain usually finishes indexing first.


Optional improvements

Link

[suggestion] · A stale txindex row can make lookups fail until the index is rebuilt

A crash in a specific window can leave a stale row that makes affected lookups fail until the index is rebuilt; no production occurrence was identified.

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

Details and suggested fix

The new checks throw on the first row in a prefix bucket whose block-index entry is missing or lacks BLOCK_HAVE_DATA, before sorting candidates or verifying a txid. A lookup can therefore fail despite a valid active-chain candidate, or because a bad row belongs to an unrelated txid with the same prefix. The previous code skipped such rows. A crash could leave a stale row if WriteTxs persists it before the block index is flushed and the block is later reorged out. Because TxIndex has no CustomRemove and WriteTxs skips already indexed blocks, lookups for affected txids can then keep returning RPC -1 or HTTP 500 until the index is rebuilt, including for transactions also confirmed in the winning block. The release note mentions an unclean state but gives no remedy. State in the error and release note that the operator can stop the node, delete indexes/txindex or use -reindex, and restart to rebuild the index. Alternatively, record the inconsistency and throw only if no candidate yields a verified match. The behavior is established, but no production trigger or affected caller was identified; reaching this state requires a crash in a specific window.


Link

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

Clients that interpret “internal error” as -32603 may 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 return an “internal error.” The new failures throw std::runtime_error, which ExecuteCommand maps to RPC_MISC_ERROR (-1), as the functional test asserts. But “internal error” is also the name of RPC_INTERNAL_ERROR (-32603), and gettxoutproof uses that code for a direct block-read failure. Thus the same RPC can report block I/O failures with different codes depending on the path. State the actual code, -1 (RPC_MISC_ERROR), in the note. If -32603 was intended, rethrow these errors as RPC_INTERNAL_ERROR in the RPC callers.


Link

[suggestion] · The documented REST error change has no functional test

If /rest/tx/<TX-HASH> reverted to returning 404 for a confirmed but unreadable transaction, the current tests would not catch it.

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. rest_tx returns 404 only when GetTransaction returns null; an escaping exception reaches the HTTP worker and produces a 500 response. The new test covers JSON-RPC calls but does not enable -rest or send a REST request. Restart the node with -txindex and -rest, rename blk00000.dat, and assert that /rest/tx/<txid>.json for the confirmed transaction returns 500.


Link

[suggestion] · WarnAndThrowErr has external linkage despite being used only in this file

The globally visible helper has external linkage even though only txindex.cpp uses it, creating a potential name collision with another translation unit.

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

Details and suggested fix

WarnAndThrowErr is defined outside the anonymous namespace and is not static, so it has external linkage in the global namespace. Move it into the file's anonymous namespace or mark it static.


Coverage details

Earlier concerns

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