Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Jul 11, 2024

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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 11, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK stickies-v, tdb3, hodlinator, achow101

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #29770 (index: Check all necessary block data is available before starting to sync by fjahr)

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.

Copy link
Contributor

@stickies-v stickies-v left a 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.

Copy link
Contributor

@tdb3 tdb3 left a 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 Asserts did not appear to be caught.

(Debian)$ grep --version | grep GNU
grep (GNU grep) 3.8

@maflcko
Copy link
Member Author

maflcko commented Jul 12, 2024

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:

git switch --detach fa8b587b91dfa8df28fc13589c511b871902670b && ( git show src | git apply --reverse ) && ./test/lint/lint-assertions.py 
HEAD is now at fa8b587 rpc: Use CHECK_NONFATAL over Assert
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;

@maflcko
Copy link
Member Author

maflcko commented Jul 12, 2024

Same in the CI https://cirrus-ci.com/task/6075434675208192?logs=lint#L755 and when using ( cd ./test/lint/test_runner/ && RUST_BACKTRACE=1 cargo run -- --lint=all_python_linters ) locally. Again, I'll need exact steps to reproduce, otherwise there is little that can be done.

@maflcko maflcko force-pushed the 2407-rpc-no-assert branch from a183627 to fa62707 Compare July 12, 2024 07:35
Copy link
Contributor

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK fa62707

@DrahtBot DrahtBot requested a review from tdb3 July 12, 2024 11:33
Copy link
Contributor

@tdb3 tdb3 left a 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_NONFATALs 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.

Copy link
Contributor

@hodlinator hodlinator left a 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.

@achow101
Copy link
Member

ACK fa62707

@achow101 achow101 merged commit ad5579e into bitcoin:master Jul 16, 2024
@maflcko maflcko deleted the 2407-rpc-no-assert branch July 16, 2024 20:13
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Apr 14, 2025
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
@bitcoin bitcoin locked and limited conversation to collaborators Jul 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants