mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
rpc: Properly throw on internal I/O errors in GetTransaction #35728
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!35728
Loading…
Reference in a new issue
No description provided.
Delete branch "2607-io-error-tx"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, 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.
🚧 At least one of the CI tasks failed.
Task
lint: https://github.com/bitcoin/bitcoin/actions/runs/29414186507/job/87348122506LLM reason (✨ experimental): CI failed due to a Python lint error from
ruff(F401unused import intest/functional/feature_io_errors.py).Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
Concept ACK
Distinguishing “transaction not found” from internal read failures in
TxIndex::FindTx/GetTransactionmakes sense.Do we ever reach here? In pruned mode when user calls
getrawtransaction <txid> <blockhash>for the block that is pruned we return"I/O error reading block data"instead we should return"Block not available"which was done previously?functional test to check this behavior
Concept ACK on separating expected outcomes ("transaction not found") from unexpected failures (I/O errors).
Some small suggestions:
Will it be worth it to add a brief comment before renaming
blk00000.datto clarify that the rename is intentionally simulating a block file I/O failure?Since the test temporarily renames
blk00000.datto simulate an I/O failure, would it be safer to wrap the assertions in atry...finallyblock so that the block file is always restored, even if an assertion or unexpected exception causes the test to exit early.Why would it be safer to rename a file that will be deleted a tick later?
Apologies not sure if I understand the question, but what I mean by wrapping in
try...finallyis:If
node.getrawtransaction(txid)does not return the expected RPC error (for example, due to a regression).Now the code is left with
blk00000.dat.moved.So my thought is with
try...finallyeven if the assertion fails, thefinallyblock executes first, and the node is restored to its original state.So my initial comment is more of a question; would it be safer if we wrap the assertations in a
try...finally.🐙 This pull request conflicts with the target branch and needs rebase.
Hmm, I think the
"I/O error reading block data"is correct, even when pruning.The correct way to handle this is to call
CheckBlockDataAvailabilityearly, and then throw the"I/O error reading block data"inGetTransaction.Waiting for the txindex and the blockindex to "fall through" to return a nullptr makes it impossible to uncover IO errors and makes it impossible to distinguish IO errors with normal missing data.
The goal of this pull is to fix exactly that.
(Edit: I've pushed your test draft and my fix)
It was just a rhetorical question with the answer: "I don’t think a finally block is needed here: if an assertion fails, the functional test’s temporary datadir is deleted during teardown, so restoring the renamed file provides no practical benefit."
Force pushed to re-create the patch from scratch (addressing all feedback + "rebase")
🐙 This pull request conflicts with the target branch and needs rebase.
2 additional verified findings in the full report.
🟠 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).🟠 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).🟠 Minor · Txindex key decode failures can appear as transaction misses
txindex.cpp:186: the prefix-scan condition matches base. An iterator failure or an undecodable key (GetKey swallows exceptions) silently ends the scan and can still produce nullopt. This predates the PR, which does not make it worse.
Location:
src/index/txindex.cpp:186(head).🔵 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).🔵 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).🔵 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).Review coverage was incomplete.
Reviewed:
fad49fd81fcf· Full review report · Previous reportspermalink
🚧 At least one of the CI tasks failed.
Task
iwyu: https://github.com/bitcoin/bitcoin/actions/runs/38228957902/job/114743378818LLM reason (✨ experimental): CI failed because IWYU removed the unused
<atomic>include fromsrc/index/txindex.cpp, leaving an uncommitted diff that the check rejects.Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
rebased
Concept ACK
fa5ad60c32introducedtest_getrawtransaction_block_data_errorsshowing default errors when the block is not available and when the block cannot be readfa5b2f13dagetrawtransactionno longer checks the block availability inline, task delegated toCheckBlockDataAvailability, now I/O errors can be detected inGetTransactionand thrownfa8a5b033bintroducedfeature_io_errors.pyto test I/O errors, creates a psbt and makes the block file unavailable, showing default behavior when rpc commands try to read this file3333a91dbfFindTxstill returns nullopt for a missing tx, but on the I/O and index, errors are handled here, we now log the warning and throw instead of continuing (updated test to use the change)faa4bb35aeInProcessPSBTnow usingGetTransactioninstead of a more verbose tx lookupChanges look good to me, left a few nits, I do have a question though;
I wonder if throwing immediately here could prevent callers from trying other lookups that might still succeed for example in
ProcessPSBT, we first callGetTransactionwhich checks the mempool and txindex, if the tx isnt found we useFindCoinsto look in the utxo setBut if
FindTxthrows, we never reach that last check, even though the utxo set might still have the input information.In commit https://github.com/bitcoin/bitcoin/pull/35728/changes/3333a91dbf1eac659cd7d027bc891a80241e8f66#r4265873624: rpc: Properly throw on internal FindTx IO errors in ProcessPSBT and GetTransaction
nit: the header documentation for this method should be updated to mention it can now throw
In commit https://github.com/bitcoin/bitcoin/pull/35728/changes/3333a91dbf1eac659cd7d027bc891a80241e8f66: rpc: Properly throw on internal FindTx IO errors in ProcessPSBT and GetTransaction
nit: Here I think what is missing is the block data and not the index
In commit https://github.com/bitcoin/bitcoin/pull/35728/changes/fa5b2f13da03d295ab624190f0d393b13da5b929: rpc: Return proper error messages from getrawtransaction
nit: the header file should be updated to mention that this can throw now
Correct. But this is intentional: I'd say if someone is running with a corrupt index (or an index with stale data from an unclean shutdown, it would be good to notify them about it as early as possible. This way, they can either disable the index, or recreate it by deleting the index folder. Somehow adding extra fallback code means they'll still run into the issue, just later.
This is already true on current master: It calls
m_db->Read(...), which can throwdbwrapper_error, which is also a runtime_error. So my preference would be to leave this as-is for now. If you really want, I can add a unrelated first commit to document this, but I think it is fine.thx, done
This is already true on current master: It calls
m_db->Read(...), which can throwdbwrapper_error, which is also a runtime_error. So my preference would be to leave this as-is for now. If you really want, I can add a unrelated first commit to document this, but I think it is fine.Sounds good, letting the user know early on that the index is corrupted is a good idea, Would a short release note make sense for this, since some rpcs now report index or read errors where they previously continued with other lookups or reported a missing tx?
thx, added release note
ACK https://github.com/bitcoin/bitcoin/pull/35728/changes/fa87067c397814f79566f8e1b4f407745e3e1f8c
Thanks for applying the changes. LGTM
lgmt! ACK
fa87067c39My earlier concern has been addressed.
While testing this, I think I might have found another case where
FindTx()returnsnulloptinstead of throwing.I first confirmed that a transaction could be retrieved, then deliberately damaged part of the test’s temporary transaction-index database. LevelDB detected the corruption, but
FindTx()still returnednulloptwithout throwing. Restoring the original data made the lookup work again.It looks like the candidate scan checks whether the iterator has a valid entry, but does not check whether a database error occurred. That means a failed lookup can be treated as an ordinary missing transaction.
Could we add this to the public methods of
CDBIteratorindbwrapper.h?Then implement it in
dbwrapper.cpp, using the existing error handler to throw when LevelDB reports an error:Finally, call it immediately after the candidate-collection loop in
FindTx(), before the iterator goes out of scope:This would let an ordinary missing transaction still return
nullopt, while reporting a database error instead of silently treating it as missing.Yes, this seems plausible. I think Ralph LLM Review also says this. IIRC, I had a LLM say
- [P2] src/index/txindex.cpp:187: iterator failures still become nullopt. A LevelDB iterator I/O error makes Valid() false, while malformed key data makes GetKey() false. Both terminate the loop and can still produce “transaction not found.”at one point.However, the goal here is to primarily map the existing errors from a warning log to an actual real error. Happy to look into the dbwrapper itself later, but I think there are a bunch of other pulls open (or in the plans), so I don't want to create merge conflicts there.
Also, I think this is a pre-existing issue, which is true before and after this pull request, so a separate pull for this could make sense?
Yes I think a separate PR makes sense. I will open one as a follow-up to this.
Tested ACK fa87067
cc @furszy I created this in reply to #35003, and to unblock the index-pessimisation from 35003: 35003 turns a correct
rpc_error(-1, "filesystem error", node.getrawtransactioninto a buggyrpc_error(-5, "No such mempool or blockchain transaction", node.getrawtransaction. So you may be qualified and interested to review/nack/ack this?Concept ACK, thanks for the ping @maflcko. Currently in vacation but will check it next week.
ACK
fa87067c39ACK
fa87067c39It would be good to improve the "OpenBlockFile" mention in the err msg (see comment below). Happy to quickly re-ack if you do it.
Not for this PR, but instead of having to hardcode the error msg at this layer again, we could make
ReadBlockreturn aResult<CBlock, ErrCase>withErrCasecontaining an enum for the error type and a error msg string.Mentioning "OpenBlockFile" in the error message doesn't seem the best for the user, it shares internals. May be better to change it to something like "Failed to open file for block hash %s".
I guess I agree, but this was taken from the prior debug log warning message.
This has 5 acks, so maybe a trivial (unrelated) commit can be added to https://github.com/bitcoin/bitcoin/pull/35003 , or some of the other follow-ups?
np for me. Happy to move forward in any direction.
I pushed
github.com/maflcko/DrahtBot@e2ba727520, for the DrahtBot LLM which prints:src/index/txindex.cpp:WarnAndThrowErr(strprintf("%s: OpenBlockFile failed for txid %s at %s", ...))→ ReplaceOpenBlockFile failedwith plain-language wording such as “Unable to open block file”; it exposes an internal function name in the warning.Should avoid this wording in the future, maybe.
Yeah, seems fine. Personally I think it would be fine to also return
std::optional<CBlock>and just log the error. After all, this should be relatively rare, so UX doesn't need to be too fine. But no strong opinion.nice!
rfm with 5 acks, or should I address the log msg nit, or does it need more review?
Code review ACK
fa87067c39. Good change: a confirmed transaction reported as missing is the wrong answer, and each path that turned an I/O or index error into "not found" now throws instead.Agree this looks ready for merge, since the remaining suggestions are agreed to be follow-ups: the "OpenBlockFile" wording https://github.com/bitcoin/bitcoin/pull/35728#discussion_r4389790136 and checking the LevelDB iterator status after the
FindTxscan https://github.com/bitcoin/bitcoin/pull/35728#pullrequestreview-5546709537. The latter fixes similar bugs that happen one level lower at the database layer.One question before merging: would you want to include the change suggested in the comment about leftover txindex entries after an unclean shutdown? If a node crashes shortly after connecting a block that later goes stale, the txindex keeps leftover entries for that block. Before this PR,
getrawtransaction,gettxoutproofandutxoupdatepsbtskipped those entries and returned the correct result. With this PR, calls that run into them fail with an internal error, and keep failing until the txindex is rebuilt.In commit "Add doc/release-notes-35728.md" (
fa87067c39)Note for reviewers:
rest_txdoesn't catch the new exception itself, buthttpserver.cppwraps every handler in acatch (const std::exception&)that replies HTTP 500 with the message, so this REST behavior is right. It isn't covered byfeature_io_errors.py, which only exercises RPC; a/rest/tx/<txid>check there would be a small follow-up.Update: the Ralph review also flags this.
In commit "rpc: Properly throw on internal FindTx IO errors in ProcessPSBT and GetTransaction" (
fa5c96a112)Nit for a follow-up: this could be
static(or live in the anonymous namespace above), since it is only used in this file and has no declaration in the header.Update: the Ralph review also flags this.
In commit "rpc: Properly throw on internal FindTx IO errors in ProcessPSBT and GetTransaction" (
fa5c96a112)Suggestion for a follow-up: skip index entries left behind by an unclean shutdown instead of throwing here and in the
BLOCK_HAVE_DATAcheck below. Otherwise a crash at the wrong moment leaves some transactions permanently failing to look up with this error, even though nothing is corrupt, and the only way out is rebuilding the whole txindex.The leftovers happen because
WriteTxswrites entries as soon as a block is connected, while the block index is only flushed every 50–70 minutes. After a crash, the txindex can have entries for a block the node no longer knows about, or knows only as a header. If that block is connected again, everything lines up, but if it went stale in the meantime, its entries stay forever.Such a block can't be in the active chain, so skipping its entries gives the same result as if it had never been indexed, which is what the code did before this PR. Missing data for a block that is in the active chain does mean corruption, and the change below still throws for that:
Unit test
Update: the Ralph review also flags this.
In commit "rpc: Return proper error messages from getrawtransaction" (
fa5b2f13da)Nit, only if you push again: the commit message opens by describing the previous error messages and saying it is fixing them, but those messages are actually correct and make sense. The actual bug is described later in the second paragraph: a block that fails to read is reported as "No such transaction found in the provided block". Suggested rewrite:
In commit "refactor: Use GetTransaction in ProcessPSBT" (
fa6a70716a)Nit, only if you push again: it would help to say why this commit is here, since nothing else in the PR depends on it. As far as I can tell it's an independent cleanup.
ProcessPSBTrepeated the txindex and mempool lookups thatGetTransactionalready does, and it picks up the new errors in the previous commit by callingFindTxdirectly. It is also not a strict refactor, though the difference only shows up on errors:GetTransactionchecks the mempool first, so a prevout in the mempool is now found without reading the txindex, and an index error no longer fails the RPC for it. Maybe something like:In commit "rpc: Return proper error messages from getrawtransaction" (
fa5b2f13da)Not blocking, but the race this comment describes could be closed by checking again after the read fails. The old order had no race: it checked
BLOCK_HAVE_DATAonly after the read had failed, so a block pruned in between was reported as "Block not available". With the check moved before the read, the same race now produces "I/O error reading block data". Keeping this up-front check for the better messages and re-running it whenGetTransactionthrows would report pruned data correctly in both cases. For example:Alternatively,
GetTransactioncould checkBLOCK_HAVE_DATAitself after a failedReadBlockand only throw the I/O error if the flag is still set. Either would fit in a follow-up.Update: the Ralph review also flags this.
Notes on the Ralph review which mostly covers the same ground as mine: (unclean shutdown leftovers, pruning race, REST test,
WarnAndThrowErrlinkage), and has two findings that are new to me:rpc_rawtransaction.pycould fail intermittently. The new test renamesblk00000.datbefore waiting for the txindex to finish syncing, and if the sync reads a block while the file is missing, the node shuts down. Callingsync_txindex(self, node)before the rename avoids this.getrawtransaction txid blockhash. With-txindex, the RPC looks in the txindex before reading the requested block, so a bad index row for a different block now fails the call even when the requested block is readable and contains the transaction. Catching theFindTxerror when a block hash is given and falling through to the block read would avoid this.It also points out that the release note's "internal error" could be read as
RPC_INTERNAL_ERROR(-32603), while these errors returnRPC_MISC_ERROR(-1).thx, used your commit msg
Right. When I wrote this back in July, this was intentional, because I assumed that unclean shutdowns are rare enough to just let the user quickly create a fresh txindex. However, I think the picture has changed in the meantime:
I didn't take your comment, because the code paths are also reachable when doing something fancy such as:
There is probably no need to enumerate all of them in the code. Modern LLMs should be capable to enumerate them for anyone who needs them.
I think a unit test is not needed, so I'll skip it for now.
thx, used your commit msg
Hmm, I think this is true for all places that call
CheckBlockDataAvailability, so I think I'll leave as-is for now. Maybe someone can fix this later for all places? Maybe like furszy suggested in https://github.com/bitcoin/bitcoin/pull/35728#discussion_r4389671104 to return the error message (and possibly type) from the blockstorage module?thx, added REST test
thx, added
staticthx, reworded debug log msg.
Edit: Dropped the DrahtBot LLM linter again, because it would print stuff like:
(resolving for now)
Sure, but I don't think we have the review resources to review fixes here (and in all other tests) that are missing the sync. This is already fixed in https://github.com/bitcoin/bitcoin/pull/36618
Yes, this is intentional. I think a known corruption should be surfaced to the user, so that they can test/migrate their hardware. Silently ignoring this seems a bit rude toward the user.
Sure, but this is a bug in the server to not throw
RPC_INTERNAL_ERRORon all the internal errors like exceptions fromstd::vector::at,CHECK_NONFATAL, or the i/o errors, ...Code review ACK
fab96992ac. Since my last review,FindTxskips leftover entries for blocks outside the active chain instead of throwing, the REST endpoint is tested, and the error message and two commit messages are clearer. Thanks for taking the suggestions!The "test ancestor commits" CI failure is the
p2p_segwit.pytest_uncompressed_pubkeyintermittent failure in #36700, unrelated to this PR.re: https://github.com/bitcoin/bitcoin/pull/35728#issuecomment-6519330596
In commit "Add doc/release-notes-35728.md" (
fab96992ac)Agree, these are logically internal errors, and the server's catch-all mislabels them as
RPC_MISC_ERROR. Until that's fixed, the release note could mention the code, so clients don't look for -32603.Separately, "or in an unclean state" no longer fits, since entries left behind by an unclean shutdown are now skipped. Maybe:
The REST entry below has the same "unclean state" wording.
re: https://github.com/bitcoin/bitcoin/pull/35728#issuecomment-6519330596
In commit "rpc: Return proper error messages from getrawtransaction" (
faed3d2b3f)Agree. Now that entries left behind by an unclean shutdown are skipped, an error from the txindex here means real corruption, and reporting it is better than quietly falling through to this block read.
re: https://github.com/bitcoin/bitcoin/pull/35728#discussion_r4421983063
Not blocking, but I'm not sure the other callers are a good reason to add the race here.
getrawtransactiondidn't have it before this PR, because it only checkedBLOCK_HAVE_DATAafter the read failed. Since this call is new, it seems better to add it in a form that doesn't race, for example by re-checking whenGetTransactionthrows, as in the snippet above. That is also the direction of furszy's suggestion to haveReadBlockreport the kind of failure.The race case also matters a bit more here, because it reports "I/O error reading block data" for a block that was just pruned, the kind of misreport this PR is fixing.
GetBlockCheckedhas the same pattern but reports a neutral "Block not found on disk".re: https://github.com/bitcoin/bitcoin/pull/35728#issuecomment-6519330596
In commit "test: Add test for getrawtransaction block read errors" (
fa5ad60c32)Makes sense, thanks. Waiting for index sync whenever a node starts covers this rename too.
ok, pushed. I didn't like how the code looks, but I guess this may fix itself when
ReadBlock's return value is refactored.heh, I still disagree. We shouldn't use release notes to cement bugs. If this is fixed, the release note will incorrectly describe the buggy behavior.
Maybe the RPC docs should describe which exceptions can be thrown, but C++ doesn't have a way to do that at compile-time ...
thx, removed unclean
addressed all nits (including the iwyu ci)
Code review ACK
faa532fd36.Since last review,
getrawtransactionpossible race is avoided, and release note is updated to match latest state. Thanks!re: https://github.com/bitcoin/bitcoin/pull/35728#discussion_r4425471566
Makes sense, agree it's better not to document a code we think is wrong. Thanks for removing "unclean".
re: https://github.com/bitcoin/bitcoin/pull/35728#discussion_r4421981396
Thanks, the new version looks good, and the other ways to reach these paths are a good point. Fine without the unit test.
re: https://github.com/bitcoin/bitcoin/pull/35728#discussion_r4425438843
Thanks! Agree, it should get simpler once
ReadBlockreports why it failed.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.
Is it accurate to say block corruption is detected here?
As far as I can tell Merkle root isn't checked, so wouldn’t it be simpler to say the block files couldn’t be read?
We could probably let
WarnAndThrowErrtake the format string and its arguments directly to get rid of the repeatedstrprintfwrappers (while keeping compile-time checks).Format warnings in the helper
This is just the release notes, so they should roughly be correct on a conceptual level, but I don't think we need to enumerate the exact behavior here. If we wanted to do that, the RPC docs should be used.
Still, I pushed something.
sure, pushed.
Also:
I think it should be trivial to change
WarnAndThrowErrtoWarnAndAbortorWarnAndTriggerShutdown. Also, it should be trivial to rebase 34132 on top of this one.I won't comment on the db error here, to keep the thread here focussed (let's do that in the respective threads). Also, I am not fixing all db errors here (ref: https://github.com/bitcoin/bitcoin/pull/35728#issuecomment-6214014188). So my hope is that this pull is a minimal change in the right direction. The benefits are:
ACK
fad49fd81fnit
thx, but I'll leave further nits for now, to limit the review churn :)
ACK
fad49fd81fOnly left some simplification nits, happy to re-ACK if you pick any of them up, but I’m also fine with merging as-is.
Nit: another one that is slightly unrelated: we could avoid the negation by checking the complement instead:
nit: I’ve bumped into these lookup paths a few times and find them easier to follow with the whole happy paths inside the
tryblocks. Just resolve without comment if you think it's completely unrelated, but I find this more consistent.Keep the happy paths together
Nit: was searching for where this is used - it's not, we could name it
dummy_hashto make that clear.I also noticed that it's not strictly a refactor (the order reversal potentially changes the error), but now that I reviewed it, I don't mind either way.
nit: the commit message still says “check block availability up front”, but the check is in the catch now.
Any reason for the restart?
nit:
nit: similarly,
send_self_transfer_chain(..., chain_length=2)seems simpler hereReuse the existing transaction-chain helper
We could probably avoid the startup txindex race here and simplify a bit:
Share one block-file failure window
nit:
generateblock(..., submit=False)could be used here:Reuse the block-generation helper
nit: to help the reviewers distinguish desired behavior from assertions that will be changed later, we could add TODOs to expectations that will change in follow-up commits.
Mark the expectations changed by the fix
I wanted to show the different outcomes of
getrawtransactionon a header vs missing block file next to each other. So I think I'll leave as-isthx, will remove
up frontif I have to re-touchI don't like
TODOs. I think an issue or a pull request is better (and this is already a pull request 😅 )thx, could rename to
dummy_block_hashif I have to re-touch, but I think it is fine, the scope ends in 4 lines anyway.leaving as-is to keep this easier to review and consistent:
leaving as-is to keep it easier to review
thx, will do if I have to re-touch
thx, will do if I have to re-touch
I think this depend on how this test evolves in the future. I can see it go either way (or another).
Pretty sure
sync_txindexhas been removed by now. The line can just be removed(I'll leave the test nits for the future)
Ah, no, I mean for code that is added in one commit and changed in the next one (to guide the reviewer through the effects of the change) - i.e. forward pointers. It can help reviewers know that the currently documented state is not final or desired, the assertions are just meant to make the current state clear.
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
GetTransactionfails 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.
Code review ACK
fad49fd81f. Since last review,WarnAndThrowErrtakes the format string and arguments directly, and the release note wording is updated. Thanks!re: https://github.com/bitcoin/bitcoin/pull/35728#discussion_r4451902741
Yeah FWIW I prefer current version because it makes it intent clearer. If
file.seekis only thing insidetryblock it makes it obvious code is trying and expecting to catch exceptions fromfile.seek. Iftx->GetHash()and other code is moved in to the block it makes it look misleadingly like the we are expectingtx->GetHash()or that other code to throw when we aren't.re: https://github.com/bitcoin/bitcoin/pull/35728#discussion_r4451904453
Note: this is referring to #36618, which removed
sync_txindexand made every node start and restart wait for index sync. After a rebase, therestart_nodecall above already waits, so thiswait_untilline is redundant but harmless. (This PR would need to be rebased to remove here.)I rolled the test fixups into https://github.com/bitcoin/bitcoin/pull/36748 (along with other sync fixups I carried around). The other two remaining follow-ups would be:
Tried to fix this in https://github.com/bitcoin/bitcoin/pull/36826, but a complete fix is impossible to review, so I think we can give up on this for now.