diff --git a/arcanist/linter/CheckNonFatalOverAssertInRpc.php b/arcanist/linter/CheckNonFatalOverAssertInRpc.php --- a/arcanist/linter/CheckNonFatalOverAssertInRpc.php +++ b/arcanist/linter/CheckNonFatalOverAssertInRpc.php @@ -45,7 +45,7 @@ $absPath = Filesystem::resolvePath($path, $this->getProjectRoot()); $fileContent = Filesystem::readFile($absPath); - if (!preg_match_all("/(assert\((.*)\);)/", $fileContent, + if (!preg_match_all("/((A|a)ssert\((.*)\);)/", $fileContent, $matches, PREG_OFFSET_CAPTURE)) { return; } diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -2213,11 +2214,10 @@ GetRand(std::numeric_limits::max())); assert(!node.chainman); node.chainman = &g_chainman; - ChainstateManager &chainman = EnsureChainman(node); + ChainstateManager &chainman = *Assert(node.chainman); - node.peer_logic.reset( - new PeerLogicValidation(node.connman.get(), node.banman.get(), - *node.scheduler, *node.chainman)); + node.peer_logic.reset(new PeerLogicValidation( + node.connman.get(), node.banman.get(), *node.scheduler, chainman)); RegisterValidationInterface(node.peer_logic.get()); // sanitize comments per BIP-0014, format user agent and check total size diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -30,6 +30,7 @@ #include #include #include +#include // For NDEBUG compile time check #include #include #include @@ -37,10 +38,6 @@ #include #include -#if defined(NDEBUG) -#error "Bitcoin cannot be compiled without assertions." -#endif - /** Expiration time for orphan transactions in seconds */ static constexpr int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60; /** Minimum time between orphan transactions expire time checks in seconds */ diff --git a/src/node/context.h b/src/node/context.h --- a/src/node/context.h +++ b/src/node/context.h @@ -49,9 +49,4 @@ ~NodeContext(); }; -inline ChainstateManager &EnsureChainman(const NodeContext &node) { - assert(node.chainman); - return *node.chainman; -} - #endif // BITCOIN_NODE_CONTEXT_H diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -70,7 +70,10 @@ ChainstateManager &EnsureChainman(const util::Ref &context) { NodeContext &node = EnsureNodeContext(context); - return EnsureChainman(node); + if (!node.chainman) { + throw JSONRPCError(RPC_INTERNAL_ERROR, "Node chainman not found"); + } + return *node.chainman; } /** diff --git a/src/test/blockfilter_index_tests.cpp b/src/test/blockfilter_index_tests.cpp --- a/src/test/blockfilter_index_tests.cpp +++ b/src/test/blockfilter_index_tests.cpp @@ -103,8 +103,9 @@ CBlockHeader header = block->GetBlockHeader(); BlockValidationState state; - if (!EnsureChainman(m_node).ProcessNewBlockHeaders( - GetConfig(), {header}, state, &pindex)) { + if (!Assert(m_node.chainman) + ->ProcessNewBlockHeaders(GetConfig(), {header}, state, + &pindex)) { return false; } } @@ -190,8 +191,8 @@ uint256 chainA_last_header = last_header; for (size_t i = 0; i < 2; i++) { const auto &block = chainA[i]; - BOOST_REQUIRE(EnsureChainman(m_node).ProcessNewBlock(GetConfig(), block, - true, nullptr)); + BOOST_REQUIRE(Assert(m_node.chainman) + ->ProcessNewBlock(GetConfig(), block, true, nullptr)); } for (size_t i = 0; i < 2; i++) { const auto &block = chainA[i]; @@ -209,8 +210,8 @@ uint256 chainB_last_header = last_header; for (size_t i = 0; i < 3; i++) { const auto &block = chainB[i]; - BOOST_REQUIRE(EnsureChainman(m_node).ProcessNewBlock(GetConfig(), block, - true, nullptr)); + BOOST_REQUIRE(Assert(m_node.chainman) + ->ProcessNewBlock(GetConfig(), block, true, nullptr)); } for (size_t i = 0; i < 3; i++) { const auto &block = chainB[i]; @@ -241,8 +242,8 @@ // Reorg back to chain A. for (size_t i = 2; i < 4; i++) { const auto &block = chainA[i]; - BOOST_REQUIRE(EnsureChainman(m_node).ProcessNewBlock(GetConfig(), block, - true, nullptr)); + BOOST_REQUIRE(Assert(m_node.chainman) + ->ProcessNewBlock(GetConfig(), block, true, nullptr)); } // Check that chain A and B blocks can be retrieved. diff --git a/src/test/checkpoints_tests.cpp b/src/test/checkpoints_tests.cpp --- a/src/test/checkpoints_tests.cpp +++ b/src/test/checkpoints_tests.cpp @@ -91,8 +91,9 @@ { BlockValidationState state; - BOOST_CHECK(EnsureChainman(m_node).ProcessNewBlockHeaders( - config, {headerG}, state, &pindex)); + BOOST_CHECK( + Assert(m_node.chainman) + ->ProcessNewBlockHeaders(config, {headerG}, state, &pindex)); pindex = nullptr; } @@ -156,8 +157,9 @@ // Headers A and AA should be accepted { BlockValidationState state; - BOOST_CHECK(EnsureChainman(m_node).ProcessNewBlockHeaders( - config, {headerA}, state, &pindex)); + BOOST_CHECK( + Assert(m_node.chainman) + ->ProcessNewBlockHeaders(config, {headerA}, state, &pindex)); BOOST_CHECK(state.IsValid()); BOOST_CHECK(pindex != nullptr); pindex = nullptr; @@ -165,8 +167,9 @@ { BlockValidationState state; - BOOST_CHECK(EnsureChainman(m_node).ProcessNewBlockHeaders( - config, {headerAA}, state, &pindex)); + BOOST_CHECK( + Assert(m_node.chainman) + ->ProcessNewBlockHeaders(config, {headerAA}, state, &pindex)); BOOST_CHECK(state.IsValid()); BOOST_CHECK(pindex != nullptr); pindex = nullptr; @@ -175,8 +178,9 @@ // Header B should be rejected { BlockValidationState state; - BOOST_CHECK(!EnsureChainman(m_node).ProcessNewBlockHeaders( - config, {headerB}, state, &pindex)); + BOOST_CHECK( + !Assert(m_node.chainman) + ->ProcessNewBlockHeaders(config, {headerB}, state, &pindex)); BOOST_CHECK(state.IsInvalid()); BOOST_CHECK(state.GetRejectReason() == "bad-fork-prior-to-checkpoint"); BOOST_CHECK(pindex == nullptr); @@ -191,8 +195,9 @@ // Header AB should be rejected { BlockValidationState state; - BOOST_CHECK(!EnsureChainman(m_node).ProcessNewBlockHeaders( - config, {headerAB}, state, &pindex)); + BOOST_CHECK( + !Assert(m_node.chainman) + ->ProcessNewBlockHeaders(config, {headerAB}, state, &pindex)); BOOST_CHECK(state.IsInvalid()); BOOST_CHECK(state.GetRejectReason() == "checkpoint mismatch"); BOOST_CHECK(pindex == nullptr); diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -321,8 +321,9 @@ } std::shared_ptr shared_pblock = std::make_shared(*pblock); - BOOST_CHECK(EnsureChainman(m_node).ProcessNewBlock( - config, shared_pblock, true, nullptr)); + BOOST_CHECK( + Assert(m_node.chainman) + ->ProcessNewBlock(config, shared_pblock, true, nullptr)); pblock->hashPrevBlock = pblock->GetHash(); } diff --git a/src/test/util/mining.cpp b/src/test/util/mining.cpp --- a/src/test/util/mining.cpp +++ b/src/test/util/mining.cpp @@ -12,6 +12,7 @@ #include #include #include