-
Notifications
You must be signed in to change notification settings - Fork 37.7k
rpc: Use CHECK_NONFATAL over Assert #30429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach ACK. Code fixes fa8b587 LGTM but I think the linter needs some further changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach ACK
Ran lint-assertions.py
against the old rpc/blockchain.cpp
and similarly to what @stickies-v observed the Assert
s did not appear to be caught.
(Debian)$ grep --version | grep GNU
grep (GNU grep) 3.8
Can you add exact steps to reproduce, starting from a fresh install of your operating system? Otherwise there is nothing that can be done. For a fresh install of Ubuntu 24.04 LTS (noble) or Debian GNU/Linux 12 (bookworm) it passes:
|
Same in the CI https://cirrus-ci.com/task/6075434675208192?logs=lint#L755 and when using |
a183627
to
fa62707
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK fa62707
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK fa62707
Can you add exact steps to reproduce, starting from a fresh install of your operating system? Otherwise there is nothing that can be done. For a fresh install of Ubuntu 24.04 LTS (noble) or Debian GNU/Linux 12 (bookworm) it passes:
Was unable to reproduce the original issue.
I had manually changed the CHECK_NONFATAL
s back to Assert
. It's possible it was manual error, but not 100% sure. Either way, it doesn't seem to happen now on a non-fresh/fresh Debian 12 install.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK fa62707
Ran linter without the C++ change:
$ ./test/lint/lint-assertions.py
CHECK_NONFATAL(condition) or NONFATAL_UNREACHABLE should be used instead of assert for RPC code.
src/rpc/blockchain.cpp:804: const auto& first_unpruned{*Assert(blockman.GetFirstBlock(*chain_tip, /*status_mask=*/BLOCK_HAVE_MASK, first_block))};
src/rpc/blockchain.cpp:811: return Assert(first_unpruned.pprev)->nHeight;
Including the C++ change silences the linter. ✅
Concept: Assert()/Assume()
should be possible to use to document/enforce constraints on logic, but such logic should probably live in the code which the RPC code calls out to, not directly in the RPCs themselves. This was already the policy before this PR, just that the previous regexps required that matches end with );
, so it missed the lines in question.
ACK fa62707 |
Summary: From the PR description: > The function GetFirstStoredBlock() helps us find the first block for which we have data. So far this function only looked for a block with BLOCK_HAVE_DATA. However, this doesn't mean that we also have the undo data of that block, and undo data might be required for what a user would like to do with those blocks. One example of how this might happen is if some blocks were fetched using the getblockfrompeer RPC. Blocks fetched from a peer will have data but no undo data. > > In the second commit I am applying the undo check to the RPCs that report pruneheight to the user. I find this much more intuitive because I think the user expects to be able to do all operations on blocks up until the pruneheight but that is not the case if undo data is missing. I personally ran into this once before and now again when testing for assumeutxo when I had used getblockfrompeer. The following commit adds test coverage for this change of behavior. This is a partial backport of [[bitcoin/bitcoin#29668 | core#29668]] and [[bitcoin/bitcoin#30429 | core#30429]] bitcoin/bitcoin@4a19750 bitcoin/bitcoin@8789dc8 bitcoin/bitcoin@fa62707 Depends on D17924 Test Plan: `ninja all check-extended` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D17925
Any RPC method should not abort the whole node when an internal logic error happens.
Fix it by just aborting this single RPC method call when an error happens.
Also, fix the linter to find the fixed cases.