Skip to content

Commit ad5579e

Browse files
committed
Merge bitcoin/bitcoin#30429: rpc: Use CHECK_NONFATAL over Assert
fa62707 rpc: Use CHECK_NONFATAL over Assert (MarcoFalke) Pull request description: 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. ACKs for top commit: achow101: ACK fa62707 stickies-v: ACK fa62707 tdb3: ACK fa62707 hodlinator: ACK fa62707 Tree-SHA512: dad2f31b01a66578949009499e4385fb4d72f0f897419f2a6e0ea02e799b9a31e6ecb5a67fa5d27fcbc7939fe8acd62dc04e877b35831493b7f2c604dec7dc64
2 parents 1d24d38 + fa62707 commit ad5579e

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/rpc/blockchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,14 +801,14 @@ std::optional<int> GetPruneHeight(const BlockManager& blockman, const CChain& ch
801801
// If the chain tip is pruned, everything is pruned.
802802
if (!((chain_tip->nStatus & BLOCK_HAVE_MASK) == BLOCK_HAVE_MASK)) return chain_tip->nHeight;
803803

804-
const auto& first_unpruned{*Assert(blockman.GetFirstBlock(*chain_tip, /*status_mask=*/BLOCK_HAVE_MASK, first_block))};
804+
const auto& first_unpruned{*CHECK_NONFATAL(blockman.GetFirstBlock(*chain_tip, /*status_mask=*/BLOCK_HAVE_MASK, first_block))};
805805
if (&first_unpruned == first_block) {
806806
// All blocks between first_block and chain_tip have data, so nothing is pruned.
807807
return std::nullopt;
808808
}
809809

810810
// Block before the first unpruned block is the last pruned block.
811-
return Assert(first_unpruned.pprev)->nHeight;
811+
return CHECK_NONFATAL(first_unpruned.pprev)->nHeight;
812812
}
813813

814814
static RPCHelpMan pruneblockchain()

test/lint/lint-assertions.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ def main():
2727
# checks should be used over assert. See: src/util/check.h
2828
# src/rpc/server.cpp is excluded from this check since it's mostly meta-code.
2929
exit_code = git_grep([
30-
"-nE",
31-
r"\<(A|a)ss(ume|ert) *\(.*\);",
30+
"--line-number",
31+
"--extended-regexp",
32+
r"\<(A|a)ss(ume|ert)\(",
3233
"--",
3334
"src/rpc/",
3435
"src/wallet/rpc*",
@@ -38,8 +39,9 @@ def main():
3839
# The `BOOST_ASSERT` macro requires to `#include boost/assert.hpp`,
3940
# which is an unnecessary Boost dependency.
4041
exit_code |= git_grep([
41-
"-E",
42-
r"BOOST_ASSERT *\(.*\);",
42+
"--line-number",
43+
"--extended-regexp",
44+
r"BOOST_ASSERT\(",
4345
"--",
4446
"*.cpp",
4547
"*.h",

0 commit comments

Comments
 (0)