Repository navigation
rpc: Properly throw on internal I/O errors in GetTransaction - #35728
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
fa1ee01 to
faa74d2
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
fa1ce3d to
fac83ef
Compare
|
Concept ACK |
musaHaruna
left a comment
There was a problem hiding this comment.
Concept ACK on separating expected outcomes ("transaction not found") from unexpected failures (I/O errors).
fa18e51 to
fa52cc1
Compare
l0rinc
left a comment
There was a problem hiding this comment.
I’ve just started reviewing this and wanted to clarify the overlap with #34132 before continuing.
The error handling here complements it, but there’s overlap in the index database reads: this PR throws on undecodable entries, while #34132 makes those failures fatal in CDBWrapper. It also removes TryRead(), which the legacy lookup here uses.
I don’t mind rebasing again if this lands first, but I’d like to clarify how we want these database-read failures handled so the two changes fit together.
…etTransaction Currently, the FindTx return value is an optional, where nullopt represents two different outcomes: I/O error and missing tx. One may argue that this is fine in ProcessPSBT, because a -txindex lookup error is rare, and an error where the fallbacks to lookup the tx are also failing is even rarer. However, a -txindex corruption may also point to a larger system corruption and it seems better to notify the user properly by throwing an exception. If I/O errors should be ignored in the future, it would be trivial to catch them here. However, that decision should be up to the caller, and not enforced by the low-level function. Do the same for GetTransaction: Currently the GetTransaction return value is a nullable transaction pointer, where nullptr represents two different outcomes: I/O error and missing tx. Reporting a confirmed transaction as missing is wrong, so properly return an error instead.
ProcessPSBT repeats the txindex and mempool lookups in GetTransaction. Call GetTransaction instead, so the lookup and its error handling are in one place. GetTransaction checks the mempool before the txindex, so a prevout in the mempool is now found without reading the index.
faa532f to
fad49fd
Compare
| try { | ||
| tx = GetTransaction(blockindex, node.mempool.get(), txid, chainman.m_blockman, hash_block); | ||
| } catch (const std::runtime_error&) { | ||
| if (blockindex) WITH_LOCK(::cs_main, CheckBlockDataAvailability(chainman.m_blockman, *blockindex, /*check_for_undo=*/false)); |
There was a problem hiding this comment.
nit
| if (blockindex) WITH_LOCK(::cs_main, CheckBlockDataAvailability(chainman.m_blockman, *blockindex, /*check_for_undo=*/false)); | |
| if (blockindex) WITH_LOCK(chainman.GetMutext(), CheckBlockDataAvailability(chainman.m_blockman, *blockindex, /*check_for_undo=*/false)); |
There was a problem hiding this comment.
thx, but I'll leave further nits for now, to limit the review churn :)
| def test_blk_dat_io_error(self): | ||
| node = self.nodes[0] | ||
| self.restart_node(0, ["-txindex", "-rest"]) | ||
| self.wait_until(lambda: node.getindexinfo()["txindex"]["synced"]) |
There was a problem hiding this comment.
faaf4a7 test: Add test to check RPCs throw on IO errors:
nit:
| self.wait_until(lambda: node.getindexinfo()["txindex"]["synced"]) | |
| sync_txindex(self, node) |
There was a problem hiding this comment.
Pretty sure sync_txindex has been removed by now. The line can just be removed
There was a problem hiding this comment.
re: #35728 (comment)
Pretty sure
sync_txindexhas been removed by now. The line can just be removed
Note: this is referring to #36618, which removed sync_txindex and made every node start and restart wait for index sync. After a rebase, the restart_node call above already waits, so this wait_until line is redundant but harmless. (This PR would need to be rebased to remove here.)
| def test_getrawtransaction_block_data_errors(self): | ||
| node = self.nodes[0] | ||
| self.log.info("Test getrawtransaction with a header-only block") | ||
| block = create_block(tmpl=node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)) |
There was a problem hiding this comment.
fa5ad60 test: Add test for getrawtransaction block read errors:
nit: generateblock(..., submit=False) could be used here:
Reuse the block-generation helper
diff --git a/test/functional/rpc_rawtransaction.py b/test/functional/rpc_rawtransaction.py
index 56492c660b..998114642a 100755
--- a/test/functional/rpc_rawtransaction.py
+++ b/test/functional/rpc_rawtransaction.py
@@ -18,6 +18,2 @@ from itertools import product
-from test_framework.blocktools import (
- NORMAL_GBT_REQUEST_PARAMS,
- create_block,
-)
from test_framework.messages import (
@@ -101,7 +97,6 @@ class RawTransactionsTest(BitcoinTestFramework):
self.log.info("Test getrawtransaction with a header-only block")
- block = create_block(tmpl=node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS))
- block.solve()
- node.submitheader(block.serialize()[:80].hex())
+ block = self.generateblock(node, output="raw(55)", transactions=[], submit=False)
+ node.submitheader(block["hex"])
- assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", node.getrawtransaction, txid="a" * 64, blockhash=block.hash_hex)
+ assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", node.getrawtransaction, txid="a" * 64, blockhash=block["hash"])
There was a problem hiding this comment.
thx, will do if I have to re-touch
| self.wait_until(lambda: node.getindexinfo()["txindex"]["synced"]) | ||
| wallet = MiniWallet(node) | ||
|
|
||
| tx = wallet.send_self_transfer(from_node=node) |
There was a problem hiding this comment.
faaf4a7 test: Add test to check RPCs throw on IO errors:
nit: similarly, send_self_transfer_chain(..., chain_length=2) seems simpler here
Reuse the existing transaction-chain helper
diff --git a/test/functional/feature_io_errors.py b/test/functional/feature_io_errors.py
index 3fff0ad44b..fff7345729 100755
--- a/test/functional/feature_io_errors.py
+++ b/test/functional/feature_io_errors.py
@@ -27,9 +27,8 @@ class IOErrorTest(BitcoinTestFramework):
self.wait_until(lambda: node.getindexinfo()["txindex"]["synced"])
wallet = MiniWallet(node)
- tx = wallet.send_self_transfer(from_node=node)
+ tx, tx2 = wallet.send_self_transfer_chain(from_node=node, chain_length=2)
txid = tx["txid"]
- tx2 = wallet.send_self_transfer(from_node=node, utxo_to_spend=tx["new_utxo"])
self.generate(node, 1)
psbt = node.createpsbt(inputs=[{"txid": txid, "vout": 0}], outputs=[])
There was a problem hiding this comment.
thx, will do if I have to re-touch
| if (!tx) { | ||
| tx = node.mempool->get(psbt_input.prev_txid); | ||
| } | ||
| uint256 block_hash; |
There was a problem hiding this comment.
fa7d278 refactor: Use GetTransaction in ProcessPSBT:
Nit: was searching for where this is used - it's not, we could name it dummy_hash to make that clear.
There was a problem hiding this comment.
thx, could rename to dummy_block_hash if I have to re-touch, but I think it is fine, the scope ends in 4 lines anyway.
commented
Nov 3, 2026
|
(I'll leave the test nits for the future) |
left a comment
There was a problem hiding this comment.
re-ACK fad49fd
Reviewed the range-diff since my previous ACK at fa87067. The updated lookup skips leftover txindex entries referring to unknown blocks or non-active blocks without data. Missing active-chain data and failures to open or read a file still produce errors.
Checking block availability after GetTransaction fails also handles the pruning race: if the block was pruned before it could be read, the RPC reports that it was pruned instead of returning a generic I/O error.
The added REST error coverage, clearer diagnostics, formatting-helper cleanup, and release-note changes look good.
Happy to re-ACK if this is retouched, or to open a follow-up PR right after merge to address some of the remaining review comments.
left a comment
There was a problem hiding this comment.
Code review ACK fad49fd. Since last review, WarnAndThrowErr takes the format string and arguments directly, and the release note wording is updated. Thanks!
| def test_blk_dat_io_error(self): | ||
| node = self.nodes[0] | ||
| self.restart_node(0, ["-txindex", "-rest"]) | ||
| self.wait_until(lambda: node.getindexinfo()["txindex"]["synced"]) |
There was a problem hiding this comment.
re: #35728 (comment)
Pretty sure
sync_txindexhas been removed by now. The line can just be removed
Note: this is referring to #36618, which removed sync_txindex and made every node start and restart wait for index sync. After a rebase, the restart_node call above already waits, so this wait_until line is redundant but harmless. (This PR would need to be rebased to remove here.)
commented
Nov 3, 2026
|
I rolled the test fixups into #36748 (along with other sync fixups I carried around). The other two remaining follow-ups would be:
|

Currently the GetTransaction return value is a nullable transaction
pointer, where nullptr represents two different outcomes: I/O error and
missing tx.
Reporting a confirmed transaction as missing is wrong, so properly
return an error instead.