diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 6bf41d7ba8..94426f7da4 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -1359,8 +1360,7 @@ static RPCHelpMan pruneblockchain() } PruneBlockFilesManual(active_chainstate, height); - const CBlockIndex* block = active_chain.Tip(); - CHECK_NONFATAL(block); + const CBlockIndex* block = CHECK_NONFATAL(active_chain.Tip()); while (block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) { block = block->pprev; } @@ -1635,14 +1635,13 @@ static RPCHelpMan verifychain() const int check_depth{request.params[1].isNull() ? DEFAULT_CHECKBLOCKS : request.params[1].get_int()}; const NodeContext& node = EnsureAnyNodeContext(request.context); - CHECK_NONFATAL(node.evodb); ChainstateManager& chainman = EnsureChainman(node); LOCK(cs_main); CChainState& active_chainstate = chainman.ActiveChainstate(); return CVerifyDB().VerifyDB( - active_chainstate, Params(), active_chainstate.CoinsTip(), *node.evodb, check_level, check_depth); + active_chainstate, Params(), active_chainstate.CoinsTip(), *CHECK_NONFATAL(node.evodb), check_level, check_depth); }, }; } @@ -1782,13 +1781,11 @@ RPCHelpMan getblockchaininfo() LOCK(cs_main); CChainState& active_chainstate = chainman.ActiveChainstate(); - const CBlockIndex* tip = active_chainstate.m_chain.Tip(); - CHECK_NONFATAL(tip); + const CBlockIndex* tip = CHECK_NONFATAL(active_chainstate.m_chain.Tip()); const int height = tip->nHeight; - CHECK_NONFATAL(node.mnhf_manager); - const auto ehfSignals = node.mnhf_manager->GetSignalsStage(tip); + const auto ehfSignals = CHECK_NONFATAL(node.mnhf_manager)->GetSignalsStage(tip); UniValue obj(UniValue::VOBJ); if (args.IsArgSet("-devnet")) { @@ -1808,8 +1805,7 @@ RPCHelpMan getblockchaininfo() obj.pushKV("size_on_disk", chainman.m_blockman.CalculateCurrentUsage()); obj.pushKV("pruned", fPruneMode); if (fPruneMode) { - const CBlockIndex* block = tip; - CHECK_NONFATAL(block); + const CBlockIndex* block = CHECK_NONFATAL(tip); while (block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) { block = block->pprev; } @@ -2863,10 +2859,8 @@ static RPCHelpMan scantxoutset() LOCK(cs_main); CChainState& active_chainstate = chainman.ActiveChainstate(); active_chainstate.ForceFlushStateToDisk(); - pcursor = active_chainstate.CoinsDB().Cursor(); - CHECK_NONFATAL(pcursor); - tip = active_chainstate.m_chain.Tip(); - CHECK_NONFATAL(tip); + pcursor = CHECK_NONFATAL(active_chainstate.CoinsDB().Cursor()); + tip = CHECK_NONFATAL(active_chainstate.m_chain.Tip()); } bool res = FindScriptPubKey(g_scan_progress, g_should_abort_scan, count, pcursor.get(), needles, coins, node.rpc_interruption_point); result.pushKV("success", res); @@ -3061,8 +3055,7 @@ UniValue CreateUTXOSnapshot(NodeContext& node, CChainState& chainstate, CAutoFil } pcursor = chainstate.CoinsDB().Cursor(); - tip = chainstate.m_blockman.LookupBlockIndex(stats.hashBlock); - CHECK_NONFATAL(tip); + tip = CHECK_NONFATAL(chainstate.m_blockman.LookupBlockIndex(stats.hashBlock)); } SnapshotMetadata metadata{tip->GetBlockHash(), stats.coins_count, tip->nChainTx}; diff --git a/src/rpc/coinjoin.cpp b/src/rpc/coinjoin.cpp index 0ce1bffff9..8e477ce8ce 100644 --- a/src/rpc/coinjoin.cpp +++ b/src/rpc/coinjoin.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -83,11 +84,8 @@ static RPCHelpMan coinjoin_reset() ValidateCoinJoinArguments(); - CHECK_NONFATAL(node.coinjoin_loader); - auto cj_clientman = node.coinjoin_loader->walletman().Get(wallet->GetName()); - - CHECK_NONFATAL(cj_clientman); - cj_clientman->ResetPool(); + auto cj_clientman = CHECK_NONFATAL(node.coinjoin_loader)->walletman().Get(wallet->GetName()); + CHECK_NONFATAL(cj_clientman)->ResetPool(); return "Mixing was reset"; }, @@ -126,10 +124,7 @@ static RPCHelpMan coinjoin_start() throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please unlock wallet for mixing with walletpassphrase first."); } - CHECK_NONFATAL(node.coinjoin_loader); - auto cj_clientman = node.coinjoin_loader->walletman().Get(wallet->GetName()); - - CHECK_NONFATAL(cj_clientman); + auto cj_clientman = CHECK_NONFATAL(CHECK_NONFATAL(node.coinjoin_loader)->walletman().Get(wallet->GetName())); if (!cj_clientman->StartMixing()) { throw JSONRPCError(RPC_INTERNAL_ERROR, "Mixing has been started already."); } @@ -450,8 +445,7 @@ static RPCHelpMan getcoinjoininfo() return obj; } - auto manager = node.coinjoin_loader->walletman().Get(wallet->GetName()); - CHECK_NONFATAL(manager != nullptr); + auto* manager = CHECK_NONFATAL(node.coinjoin_loader->walletman().Get(wallet->GetName())); manager->GetJsonInfo(obj); std::string warning_msg{""}; diff --git a/src/rpc/evo.cpp b/src/rpc/evo.cpp index 30fdab04b7..b584f888ab 100644 --- a/src/rpc/evo.cpp +++ b/src/rpc/evo.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -628,8 +629,7 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request, const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); - CHECK_NONFATAL(node.chain_helper); - CChainstateHelper& chain_helper = *node.chain_helper; + CChainstateHelper& chain_helper = *CHECK_NONFATAL(node.chain_helper); const bool isEvoRequested = mnType == MnType::Evo; @@ -855,8 +855,7 @@ static RPCHelpMan protx_register_submit() const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); - CHECK_NONFATAL(node.chain_helper); - CChainstateHelper& chain_helper = *node.chain_helper; + CChainstateHelper& chain_helper = *CHECK_NONFATAL(node.chain_helper); std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); if (!wallet) return NullUniValue; @@ -954,11 +953,8 @@ static UniValue protx_update_service_common_wrapper(const JSONRPCRequest& reques const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); - CHECK_NONFATAL(node.dmnman); - CDeterministicMNManager& dmnman = *node.dmnman; - - CHECK_NONFATAL(node.chain_helper); - CChainstateHelper& chain_helper = *node.chain_helper; + CDeterministicMNManager& dmnman = *CHECK_NONFATAL(node.dmnman); + CChainstateHelper& chain_helper = *CHECK_NONFATAL(node.chain_helper); const bool isEvoRequested = mnType == MnType::Evo; std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); @@ -1092,11 +1088,8 @@ static RPCHelpMan protx_update_registrar_wrapper(bool specific_legacy_bls_scheme const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); - CHECK_NONFATAL(node.dmnman); - CDeterministicMNManager& dmnman = *node.dmnman; - - CHECK_NONFATAL(node.chain_helper); - CChainstateHelper& chain_helper = *node.chain_helper; + CDeterministicMNManager& dmnman = *CHECK_NONFATAL(node.dmnman); + CChainstateHelper& chain_helper = *CHECK_NONFATAL(node.chain_helper); std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); if (!wallet) return NullUniValue; @@ -1207,12 +1200,8 @@ static RPCHelpMan protx_revoke() const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); - CHECK_NONFATAL(node.dmnman); - CDeterministicMNManager& dmnman = *node.dmnman; - - CHECK_NONFATAL(node.chain_helper); - CChainstateHelper& chain_helper = *node.chain_helper; - + CDeterministicMNManager& dmnman = *CHECK_NONFATAL(node.dmnman); + CChainstateHelper& chain_helper = *CHECK_NONFATAL(node.chain_helper); std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); if (!pwallet) return NullUniValue; @@ -1370,11 +1359,8 @@ static RPCHelpMan protx_list() const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); - CHECK_NONFATAL(node.dmnman); - CDeterministicMNManager& dmnman = *node.dmnman; - - CHECK_NONFATAL(node.mn_metaman); - CMasternodeMetaMan& mn_metaman = *node.mn_metaman; + CDeterministicMNManager& dmnman = *CHECK_NONFATAL(node.dmnman); + CMasternodeMetaMan& mn_metaman = *CHECK_NONFATAL(node.mn_metaman); std::shared_ptr wallet{nullptr}; #ifdef ENABLE_WALLET @@ -1486,11 +1472,8 @@ static RPCHelpMan protx_info() const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); - CHECK_NONFATAL(node.dmnman); - CDeterministicMNManager& dmnman = *node.dmnman; - - CHECK_NONFATAL(node.mn_metaman); - CMasternodeMetaMan& mn_metaman = *node.mn_metaman; + CDeterministicMNManager& dmnman = *CHECK_NONFATAL(node.dmnman); + CMasternodeMetaMan& mn_metaman = *CHECK_NONFATAL(node.mn_metaman); std::shared_ptr wallet{nullptr}; #ifdef ENABLE_WALLET @@ -1560,11 +1543,8 @@ static RPCHelpMan protx_diff() const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); - CHECK_NONFATAL(node.dmnman); - CDeterministicMNManager& dmnman = *node.dmnman; - - CHECK_NONFATAL(node.llmq_ctx); - const LLMQContext& llmq_ctx = *node.llmq_ctx; + CDeterministicMNManager& dmnman = *CHECK_NONFATAL(node.dmnman); + const LLMQContext& llmq_ctx = *CHECK_NONFATAL(node.llmq_ctx); LOCK(cs_main); uint256 baseBlockHash = ParseBlock(request.params[0], chainman, "baseBlock"); @@ -1621,8 +1601,7 @@ static RPCHelpMan protx_listdiff() const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); - CHECK_NONFATAL(node.dmnman); - CDeterministicMNManager& dmnman = *node.dmnman; + CDeterministicMNManager& dmnman = *CHECK_NONFATAL(node.dmnman); LOCK(cs_main); UniValue ret(UniValue::VOBJ); diff --git a/src/rpc/governance.cpp b/src/rpc/governance.cpp index 2137e91a7b..5123945c3f 100644 --- a/src/rpc/governance.cpp +++ b/src/rpc/governance.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -194,12 +195,11 @@ static RPCHelpMan gobject_prepare() const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); - CHECK_NONFATAL(node.dmnman); { LOCK(cs_main); std::string strError = ""; - if (!govobj.IsValidLocally(node.dmnman->GetListAtChainTip(), chainman, strError, false)) + if (!govobj.IsValidLocally(CHECK_NONFATAL(node.dmnman)->GetListAtChainTip(), chainman, strError, false)) throw JSONRPCError(RPC_INTERNAL_ERROR, "Governance object is not valid - " + govobj.GetHash().ToString() + " - " + strError); } @@ -303,14 +303,12 @@ static RPCHelpMan gobject_submit() { const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); - CHECK_NONFATAL(node.dmnman); - CHECK_NONFATAL(node.govman); if(!node.mn_sync->IsBlockchainSynced()) { throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Must wait for client to sync with masternode network. Try again in a minute or so."); } - auto mnList = node.dmnman->GetListAtChainTip(); + auto mnList = CHECK_NONFATAL(node.dmnman)->GetListAtChainTip(); if (node.mn_activeman) { const bool fMnFound = mnList.HasValidMNByCollateral(node.mn_activeman->GetOutPoint()); @@ -373,7 +371,6 @@ static RPCHelpMan gobject_submit() } LOCK2(cs_main, mempool.cs); - CHECK_NONFATAL(node.dmnman); std::string strError; if (!govobj.IsValidLocally(node.dmnman->GetListAtChainTip(), chainman, strError, fMissingConfirmations, true) && !fMissingConfirmations) { @@ -384,7 +381,7 @@ static RPCHelpMan gobject_submit() // RELAY THIS OBJECT // Reject if rate check fails but don't update buffer - if (!node.govman->MasternodeRateCheck(govobj)) { + if (!CHECK_NONFATAL(node.govman)->MasternodeRateCheck(govobj)) { LogPrintf("gobject(submit) -- Object submission rejected because of rate check failure - hash = %s\n", strHash); throw JSONRPCError(RPC_INVALID_PARAMETER, "Object creation rate limit exceeded"); } @@ -393,9 +390,8 @@ static RPCHelpMan gobject_submit() PeerManager& peerman = EnsurePeerman(node); if (fMissingConfirmations) { - CHECK_NONFATAL(node.mn_sync); node.govman->AddPostponedObject(govobj); - govobj.Relay(peerman, *node.mn_sync); + govobj.Relay(peerman, *CHECK_NONFATAL(node.mn_sync)); } else { node.govman->AddGovernanceObject(govobj, peerman); } @@ -452,7 +448,7 @@ static UniValue VoteWithMasternodes(const JSONRPCRequest& request, const CWallet int nSuccessful = 0; int nFailed = 0; - auto mnList = node.dmnman->GetListAtChainTip(); + auto mnList = CHECK_NONFATAL(node.dmnman)->GetListAtChainTip(); UniValue resultsObj(UniValue::VOBJ); @@ -529,7 +525,6 @@ static RPCHelpMan gobject_vote_many() if (!wallet) return NullUniValue; const NodeContext& node = EnsureAnyNodeContext(request.context); - CHECK_NONFATAL(node.dmnman); uint256 hash(ParseHashV(request.params[0], "Object hash")); std::string strVoteSignal = request.params[1].get_str(); @@ -551,7 +546,7 @@ static RPCHelpMan gobject_vote_many() std::map votingKeys; - auto mnList = node.dmnman->GetListAtChainTip(); + auto mnList = CHECK_NONFATAL(node.dmnman)->GetListAtChainTip(); mnList.ForEachMN(true, [&](auto& dmn) { const bool is_mine = CheckWalletOwnsKey(*wallet, dmn.pdmnState->keyIDVoting); if (is_mine) { @@ -583,7 +578,6 @@ static RPCHelpMan gobject_vote_alias() if (!wallet) return NullUniValue; const NodeContext& node = EnsureAnyNodeContext(request.context); - CHECK_NONFATAL(node.dmnman); uint256 hash(ParseHashV(request.params[0], "Object hash")); std::string strVoteSignal = request.params[1].get_str(); @@ -604,7 +598,7 @@ static RPCHelpMan gobject_vote_alias() EnsureWalletIsUnlocked(*wallet); uint256 proTxHash(ParseHashV(request.params[3], "protx-hash")); - auto dmn = node.dmnman->GetListAtChainTip().GetValidMN(proTxHash); + auto dmn = CHECK_NONFATAL(node.dmnman)->GetListAtChainTip().GetValidMN(proTxHash); if (!dmn) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid or unknown proTxHash"); } @@ -718,11 +712,10 @@ static RPCHelpMan gobject_list_helper(const bool make_a_diff) const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); - CHECK_NONFATAL(node.dmnman); - CHECK_NONFATAL(node.govman); const int64_t last_time = make_a_diff ? node.govman->GetLastDiffTime() : 0; - return ListObjects(*node.govman, node.dmnman->GetListAtChainTip(), chainman, strCachedSignal, strType, last_time); + return ListObjects(*CHECK_NONFATAL(node.govman), CHECK_NONFATAL(node.dmnman)->GetListAtChainTip(), chainman, + strCachedSignal, strType, last_time); }, }; } @@ -759,8 +752,8 @@ static RPCHelpMan gobject_get() // FIND THE GOVERNANCE OBJECT THE USER IS LOOKING FOR const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); - CHECK_NONFATAL(node.dmnman && node.govman); + CHECK_NONFATAL(node.govman); LOCK2(cs_main, node.govman->cs); const CGovernanceObject* pGovObj = node.govman->FindConstGovernanceObject(hash); @@ -785,7 +778,7 @@ static RPCHelpMan gobject_get() // SHOW (MUCH MORE) INFORMATION ABOUT VOTES FOR GOVERNANCE OBJECT (THAN LIST/DIFF ABOVE) // -- FUNDING VOTING RESULTS - auto tip_mn_list = node.dmnman->GetListAtChainTip(); + auto tip_mn_list = CHECK_NONFATAL(node.dmnman)->GetListAtChainTip(); UniValue objFundingResult(UniValue::VOBJ); objFundingResult.pushKV("AbsoluteYesCount", pGovObj->GetAbsoluteYesCount(tip_mn_list, VOTE_SIGNAL_FUNDING)); @@ -858,8 +851,8 @@ static RPCHelpMan gobject_getcurrentvotes() // FIND OBJECT USER IS LOOKING FOR const NodeContext& node = EnsureAnyNodeContext(request.context); - CHECK_NONFATAL(node.govman); + CHECK_NONFATAL(node.govman); LOCK(node.govman->cs); const CGovernanceObject* pGovObj = node.govman->FindConstGovernanceObject(hash); @@ -872,10 +865,9 @@ static RPCHelpMan gobject_getcurrentvotes() UniValue bResult(UniValue::VOBJ); // GET MATCHING VOTES BY HASH, THEN SHOW USERS VOTE INFORMATION - CHECK_NONFATAL(node.dmnman); std::vector vecVotes = node.govman->GetCurrentVotes(hash, mnCollateralOutpoint); for (const auto& vote : vecVotes) { - bResult.pushKV(vote.GetHash().ToString(), vote.ToString(node.dmnman->GetListAtChainTip())); + bResult.pushKV(vote.GetHash().ToString(), vote.ToString(CHECK_NONFATAL(node.dmnman)->GetListAtChainTip())); } return bResult; @@ -975,8 +967,7 @@ static RPCHelpMan voteraw() throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding"); } - CHECK_NONFATAL(node.dmnman); - const auto tip_mn_list = node.dmnman->GetListAtChainTip(); + const auto tip_mn_list = CHECK_NONFATAL(node.dmnman)->GetListAtChainTip(); auto dmn = tip_mn_list.GetValidMNByCollateral(outpoint); if (!dmn) { @@ -1034,7 +1025,6 @@ static RPCHelpMan getgovernanceinfo() const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureAnyChainman(request.context); - CHECK_NONFATAL(node.dmnman); const auto* pindex = WITH_LOCK(cs_main, return chainman.ActiveChain().Tip()); int nBlockHeight = pindex->nHeight; @@ -1048,7 +1038,7 @@ static RPCHelpMan getgovernanceinfo() obj.pushKV("superblockmaturitywindow", Params().GetConsensus().nSuperblockMaturityWindow); obj.pushKV("lastsuperblock", nLastSuperblock); obj.pushKV("nextsuperblock", nNextSuperblock); - obj.pushKV("fundingthreshold", int(node.dmnman->GetListAtChainTip().GetValidWeightedMNsCount() / 10)); + obj.pushKV("fundingthreshold", int(CHECK_NONFATAL(node.dmnman)->GetListAtChainTip().GetValidWeightedMNsCount() / 10)); obj.pushKV("governancebudget", ValueFromAmount(CSuperblock::GetPaymentsLimit(chainman.ActiveChain(), nNextSuperblock))); return obj; diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index 5b30f0944b..ee5fcbdea0 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -138,8 +139,7 @@ static RPCHelpMan masternode_winner() const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); - CHECK_NONFATAL(node.dmnman); - return GetNextMasternodeForPayment(chainman.ActiveChain(), *node.dmnman, 10); + return GetNextMasternodeForPayment(chainman.ActiveChain(), *CHECK_NONFATAL(node.dmnman), 10); }, }; } @@ -159,8 +159,7 @@ static RPCHelpMan masternode_current() const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); - CHECK_NONFATAL(node.dmnman); - return GetNextMasternodeForPayment(chainman.ActiveChain(), *node.dmnman, 1); + return GetNextMasternodeForPayment(chainman.ActiveChain(), *CHECK_NONFATAL(node.dmnman), 1); }, }; } @@ -212,7 +211,7 @@ static RPCHelpMan masternode_status() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const NodeContext& node = EnsureAnyNodeContext(request.context); - CHECK_NONFATAL(node.dmnman); + if (!node.mn_activeman) { throw JSONRPCError(RPC_INTERNAL_ERROR, "This node does not run an active masternode."); } @@ -221,7 +220,7 @@ static RPCHelpMan masternode_status() // keep compatibility with legacy status for now (might get deprecated/removed later) mnObj.pushKV("outpoint", node.mn_activeman->GetOutPoint().ToStringShort()); mnObj.pushKV("service", node.mn_activeman->GetService().ToStringAddrPort()); - CDeterministicMNCPtr dmn = node.dmnman->GetListAtChainTip().GetMN(node.mn_activeman->GetProTxHash()); + CDeterministicMNCPtr dmn = CHECK_NONFATAL(node.dmnman)->GetListAtChainTip().GetMN(node.mn_activeman->GetProTxHash()); if (dmn) { mnObj.pushKV("proTxHash", dmn->proTxHash.ToString()); mnObj.pushKV("type", std::string(GetMnType(dmn->nType).description)); @@ -243,12 +242,12 @@ static std::string GetRequiredPaymentsString(CGovernanceManager& govman, const C if (payee) { CTxDestination dest; if (!ExtractDestination(payee->pdmnState->scriptPayout, dest)) { - CHECK_NONFATAL(false); + NONFATAL_UNREACHABLE(); } strPayments = EncodeDestination(dest); if (payee->nOperatorReward != 0 && payee->pdmnState->scriptOperatorPayout != CScript()) { if (!ExtractDestination(payee->pdmnState->scriptOperatorPayout, dest)) { - CHECK_NONFATAL(false); + NONFATAL_UNREACHABLE(); } strPayments += ", " + EncodeDestination(dest); } @@ -310,14 +309,11 @@ static RPCHelpMan masternode_winners() int nChainTipHeight = pindexTip->nHeight; int nStartHeight = std::max(nChainTipHeight - nCount, 1); - CHECK_NONFATAL(node.dmnman); - CHECK_NONFATAL(node.govman); - - const auto tip_mn_list = node.dmnman->GetListAtChainTip(); + const auto tip_mn_list = CHECK_NONFATAL(node.dmnman)->GetListAtChainTip(); for (int h = nStartHeight; h <= nChainTipHeight; h++) { const CBlockIndex* pIndex = pindexTip->GetAncestor(h - 1); auto payee = node.dmnman->GetListForBlock(pIndex).GetMNPayee(pIndex); - std::string strPayments = GetRequiredPaymentsString(*node.govman, tip_mn_list, h, payee); + std::string strPayments = GetRequiredPaymentsString(*CHECK_NONFATAL(node.govman), tip_mn_list, h, payee); if (strFilter != "" && strPayments.find(strFilter) == std::string::npos) continue; obj.pushKV(strprintf("%d", h), strPayments); } @@ -558,11 +554,10 @@ static RPCHelpMan masternodelist_helper(bool is_composite) const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); - CHECK_NONFATAL(node.dmnman); UniValue obj(UniValue::VOBJ); - const auto mnList = node.dmnman->GetListAtChainTip(); + const auto mnList = CHECK_NONFATAL(node.dmnman)->GetListAtChainTip(); const auto dmnToStatus = [&](const auto& dmn) { if (mnList.IsMNValid(dmn)) { return "ENABLED"; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index af51ecc9f8..0444fc5a91 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -391,12 +392,11 @@ static RPCHelpMan generateblock() block.vtx.insert(block.vtx.end(), txs.begin(), txs.end()); { - CHECK_NONFATAL(node.evodb); - LOCK(cs_main); BlockValidationState state; - if (!TestBlockValidity(state, *llmq_ctx.clhandler, *node.evodb, chainparams, active_chainstate, block, chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock), false, false)) { + if (!TestBlockValidity(state, *llmq_ctx.clhandler, *CHECK_NONFATAL(node.evodb), chainparams, active_chainstate, + block, chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock), false, false)) { throw JSONRPCError(RPC_VERIFY_ERROR, strprintf("TestBlockValidity failed: %s", state.GetRejectReason())); } } @@ -710,14 +710,14 @@ static RPCHelpMan getblocktemplate() } LLMQContext& llmq_ctx = EnsureLLMQContext(node); - CHECK_NONFATAL(node.evodb); CBlockIndex* const pindexPrev = active_chain.Tip(); // TestBlockValidity only supports blocks built on the current Tip if (block.hashPrevBlock != pindexPrev->GetBlockHash()) return "inconclusive-not-best-prevblk"; BlockValidationState state; - TestBlockValidity(state, *llmq_ctx.clhandler, *node.evodb, Params(), active_chainstate, block, pindexPrev, false, true); + TestBlockValidity(state, *llmq_ctx.clhandler, *CHECK_NONFATAL(node.evodb), Params(), active_chainstate, + block, pindexPrev, false, true); return BIP22ValidationResult(state); } diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 0250036d04..40ed64f821 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -1194,9 +1194,8 @@ static RPCHelpMan mockscheduler() throw std::runtime_error("delta_time must be between 1 and 3600 seconds (1 hr)"); } - auto* node_context = GetContext(request.context); + auto* node_context = CHECK_NONFATAL(GetContext(request.context)); // protect against null pointer dereference - CHECK_NONFATAL(node_context); CHECK_NONFATAL(node_context->scheduler); node_context->scheduler->MockForward(std::chrono::seconds(delta_seconds)); diff --git a/src/rpc/quorums.cpp b/src/rpc/quorums.cpp index f6c27f4c73..3aa5de1a5a 100644 --- a/src/rpc/quorums.cpp +++ b/src/rpc/quorums.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -282,7 +283,6 @@ static RPCHelpMan quorum_dkgstatus() const ChainstateManager& chainman = EnsureChainman(node); const LLMQContext& llmq_ctx = EnsureLLMQContext(node); const CConnman& connman = EnsureConnman(node); - CHECK_NONFATAL(node.dmnman); CHECK_NONFATAL(node.sporkman); int detailLevel = 0; @@ -296,7 +296,7 @@ static RPCHelpMan quorum_dkgstatus() llmq::CDKGDebugStatus status; llmq_ctx.dkg_debugman->GetLocalDebugStatus(status); - auto ret = status.ToJson(*node.dmnman, chainman, detailLevel); + auto ret = status.ToJson(*CHECK_NONFATAL(node.dmnman), chainman, detailLevel); CBlockIndex* pindexTip = WITH_LOCK(cs_main, return chainman.ActiveChain().Tip()); int tipHeight = pindexTip->nHeight; @@ -385,7 +385,6 @@ static RPCHelpMan quorum_memberof() const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); const LLMQContext& llmq_ctx = EnsureLLMQContext(node); - CHECK_NONFATAL(node.dmnman); uint256 protxHash(ParseHashV(request.params[0], "proTxHash")); int scanQuorumsCount = -1; @@ -397,7 +396,7 @@ static RPCHelpMan quorum_memberof() } const CBlockIndex* pindexTip = WITH_LOCK(cs_main, return chainman.ActiveChain().Tip()); - auto mnList = node.dmnman->GetListForBlock(pindexTip); + auto mnList = CHECK_NONFATAL(node.dmnman)->GetListForBlock(pindexTip); auto dmn = mnList.GetMN(protxHash); if (!dmn) { throw JSONRPCError(RPC_INVALID_PARAMETER, "masternode not found"); @@ -842,7 +841,7 @@ static RPCHelpMan quorum_rotationinfo() const NodeContext& node = EnsureAnyNodeContext(request.context); const ChainstateManager& chainman = EnsureChainman(node); const LLMQContext& llmq_ctx = EnsureLLMQContext(node); - CHECK_NONFATAL(node.dmnman); + ; llmq::CGetQuorumRotationInfo cmd; llmq::CQuorumRotationInfo quorumRotationInfoRet; @@ -859,7 +858,8 @@ static RPCHelpMan quorum_rotationinfo() LOCK(cs_main); - if (!BuildQuorumRotationInfo(*node.dmnman, chainman, *llmq_ctx.qman, *llmq_ctx.quorum_block_processor, cmd, quorumRotationInfoRet, strError)) { + if (!BuildQuorumRotationInfo(*CHECK_NONFATAL(node.dmnman), chainman, *llmq_ctx.qman, *llmq_ctx.quorum_block_processor, + cmd, quorumRotationInfoRet, strError)) { throw JSONRPCError(RPC_INVALID_REQUEST, strError); } @@ -1073,7 +1073,8 @@ static RPCHelpMan verifyislock() auto llmqType = Params().GetConsensus().llmqTypeDIP0024InstantSend; const auto llmq_params_opt = Params().GetLLMQ(llmqType); CHECK_NONFATAL(llmq_params_opt.has_value()); - return VerifyRecoveredSigLatestQuorums(*llmq_params_opt, chainman.ActiveChain(), *llmq_ctx.qman, signHeight, id, txid, sig); + return VerifyRecoveredSigLatestQuorums(*llmq_params_opt, chainman.ActiveChain(), *CHECK_NONFATAL(llmq_ctx.qman), + signHeight, id, txid, sig); }, }; } diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 1b01eb3195..e06382711e 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -495,8 +496,6 @@ static RPCHelpMan getassetunlockstatuses() throw JSONRPCError(RPC_INTERNAL_ERROR, "No blocks in chain"); } - CHECK_NONFATAL(node.cpoolman); - std::optional poolCL{std::nullopt}; std::optional poolOnTip{std::nullopt}; std::optional nSpecificCoreHeight{std::nullopt}; @@ -506,7 +505,7 @@ static RPCHelpMan getassetunlockstatuses() if (nSpecificCoreHeight.value() < 0 || nSpecificCoreHeight.value() > chainman.ActiveChain().Height()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); } - poolCL = std::make_optional(node.cpoolman->GetCreditPool(chainman.ActiveChain()[nSpecificCoreHeight.value()], Params().GetConsensus())); + poolCL = std::make_optional(CHECK_NONFATAL(node.cpoolman)->GetCreditPool(chainman.ActiveChain()[nSpecificCoreHeight.value()], Params().GetConsensus())); } else { const auto pBlockIndexBestCL = [&]() -> const CBlockIndex* { diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 727fa5e694..4a63378b84 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -10,6 +10,7 @@ #include