Review report

core: PR #35728

2 minor findings · 3 suggestions

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

Findings

Link

[minor] · A damaged txindex candidate aborts lookups that could still succeed

With -txindex, corruption in one candidate can make getrawtransaction fail even when the requested block or another indexed candidate contains the transaction; no production occurrence was identified.

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

Details and suggested fix

FindTx now throws when it cannot open a candidate's block file or deserialize its transaction, and also throws for an active-chain candidate without BLOCK_HAVE_DATA. Because candidates share only a 5-byte hash prefix, a failing row can belong to an unrelated txid or another block containing the same txid, and can sort before a valid match. The previous code logged and skipped such rows. This makes a txid-only lookup fail when its readable match follows the bad candidate. It also makes getrawtransaction with blockhash fail: GetTransaction calls FindTx before reading the requested block, even though that block has passed CheckBlockDataAvailability and could be read. The RPC help documents blockhash as a way to fetch a transaction from a specific block. Once FindTx throws, the caller cannot retrieve the match, despite the commit message's stated intent to leave I/O-error handling to callers. Record candidate failures, continue scanning, return a verified match if found, and throw only if none matches. Alternatively, when block_index is set, GetTransaction could catch the FindTx error and fall through to ReadBlock, while still throwing if that read fails. If failing on any corruption is intended, document that policy. The behavior requires corruption in candidate block or index data; no production occurrence was identified, so practical impact is unconfirmed.


Link

[minor] · The test can rename a block file while txindex is syncing

If background index sync reads a block during the rename, node 0 aborts and the test fails before checking the expected error.

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

Details and suggested fix

Node 0 starts with -txindex on the cached chain, so index sync runs in a background thread after startup. test_getrawtransaction_block_data_errors runs first in run_test and renames blk00000.dat without waiting for sync; the existing sync_txindex call happens later, in getrawtransaction_tests. If BaseIndex::Sync reaches ProcessBlock while the file is renamed, ReadBlock fails and FatalErrorf calls AbortNode. Renaming the file back does not cancel shutdown, so the test fails with a lost RPC connection. Call sync_txindex(self, node) before the rename, as feature_io_errors.py does with its synced wait. The race depends on thread scheduling, and the small cached chain usually finishes indexing first.


Optional improvements

Link

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

Clients that interpret “internal error” as JSON-RPC code -32603 will not match these failures, which return -1.

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

Details and suggested fix

The note says getrawtransaction, gettxoutproof, utxoupdatepsbt, and descriptorprocesspsbt now return an internal error. The new failures throw std::runtime_error, which ExecuteCommand maps to RPC_MISC_ERROR (-1); feature_io_errors.py also asserts -1. RPC_INTERNAL_ERROR (-32603) is a different code. gettxoutproof already returns -32603 for its own “Can't read block from disk” failure, which the same test asserts. Thus, gettxoutproof reports block-read failures as -1 or -32603 depending on the path. State the actual code (-1) in the release note. If -32603 is intended, rethrow these errors as RPC_INTERNAL_ERROR in the RPC callers. The note correctly describes the REST endpoint's HTTP 500 response.


Link

[suggestion] · GetTransaction and FindTx declarations omit their new exceptions

Both declarations describe only a null result, although throwing is now how this change reports read failures.

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 the new FindTx exceptions. Its declaration describes only “The tx if found, otherwise nullptr.” TxIndex::FindTx likewise documents only nullopt for a miss. The base FindTx could already throw dbwrapper_error from Read, but this change adds more throw paths and relies on nullptr or nullopt meaning a genuine miss. Add @throws notes to both declarations stating that a null result is an ordinary miss and read or index failures throw. Current callers are RPC or REST handlers that catch std::exception; documenting the contract will clarify it for future callers.


Link

[suggestion] · Tests do not cover the legacy-entry deserialization error

If TryRead regressed to Read, a malformed legacy entry would again appear missing, and the current tests would still pass.

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

Details and suggested fix

FindLegacyTx now uses TryRead, so a legacy value that fails deserialization throws instead of being treated as absent; Read returns false in that case. The new functional tests use a freshly created hashed index and remove a block file, so they do not cover this branch. txindex_legacy_fallback already seeds a legacy row, erases hashed entries, and checks a successful lookup. Extend it by first overwriting the legacy value with bytes that cannot deserialize as CDiskTxPos, such as uint8_t{0}, and checking that FindTx throws std::runtime_error. Then erase the key and check that FindTx returns nullopt. This test-only change protects the distinction between a read error and a genuine miss for upgraded indexes.


Coverage details

Earlier concerns

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