diff --git a/src/rpc/avalanche.cpp b/src/rpc/avalanche.cpp --- a/src/rpc/avalanche.cpp +++ b/src/rpc/avalanche.cpp @@ -125,7 +125,7 @@ CPubKey key = ParsePubKey(request.params[1]); auto proof = RCUPtr::make(); - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); verifyProofOrThrow(node, *proof, request.params[2].get_str()); const avalanche::ProofId &proofid = proof->getId(); @@ -939,7 +939,7 @@ } auto proof = RCUPtr::make(); - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); // Verify the proof. Note that this is redundant with the // verification done when adding the proof to the pool, but we get a @@ -983,7 +983,7 @@ RPCTypeCheck(request.params, {UniValue::VSTR}); avalanche::Proof proof; - verifyProofOrThrow(EnsureNodeContext(request.context), proof, + verifyProofOrThrow(EnsureAnyNodeContext(request.context), proof, request.params[0].get_str()); return true; diff --git a/src/rpc/blockchain.h b/src/rpc/blockchain.h --- a/src/rpc/blockchain.h +++ b/src/rpc/blockchain.h @@ -52,9 +52,11 @@ const CBlockIndex *blockindex) LOCKS_EXCLUDED(cs_main); -NodeContext &EnsureNodeContext(const std::any &context); -CTxMemPool &EnsureMemPool(const std::any &context); -ChainstateManager &EnsureChainman(const std::any &context); +NodeContext &EnsureAnyNodeContext(const std::any &context); +CTxMemPool &EnsureMemPool(const NodeContext &node); +CTxMemPool &EnsureAnyMemPool(const std::any &context); +ChainstateManager &EnsureChainman(const NodeContext &node); +ChainstateManager &EnsureAnyChainman(const std::any &context); /** * Helper to create UTXO snapshots given a chainstate and a file handle. diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -51,7 +51,7 @@ static std::condition_variable cond_blockchange; static CUpdatedBlock latestblock GUARDED_BY(cs_blockchange); -NodeContext &EnsureNodeContext(const std::any &context) { +NodeContext &EnsureAnyNodeContext(const std::any &context) { auto node_context = util::AnyPtr(context); if (!node_context) { throw JSONRPCError(RPC_INTERNAL_ERROR, "Node context not found"); @@ -59,8 +59,7 @@ return *node_context; } -CTxMemPool &EnsureMemPool(const std::any &context) { - const NodeContext &node = EnsureNodeContext(context); +CTxMemPool &EnsureMemPool(const NodeContext &node) { if (!node.mempool) { throw JSONRPCError(RPC_CLIENT_MEMPOOL_DISABLED, "Mempool disabled or instance not found"); @@ -68,14 +67,21 @@ return *node.mempool; } -ChainstateManager &EnsureChainman(const std::any &context) { - const NodeContext &node = EnsureNodeContext(context); +CTxMemPool &EnsureAnyMemPool(const std::any &context) { + return EnsureMemPool(EnsureAnyNodeContext(context)); +} + +ChainstateManager &EnsureChainman(const NodeContext &node) { if (!node.chainman) { throw JSONRPCError(RPC_INTERNAL_ERROR, "Node chainman not found"); } return *node.chainman; } +ChainstateManager &EnsureAnyChainman(const std::any &context) { + return EnsureChainman(EnsureAnyNodeContext(context)); +} + /** * Calculate the difficulty for a given block index. */ @@ -174,7 +180,7 @@ [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { LOCK(cs_main); - return EnsureChainman(request.context).ActiveHeight(); + return EnsureAnyChainman(request.context).ActiveHeight(); }, }; } @@ -191,7 +197,7 @@ [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { LOCK(cs_main); - return EnsureChainman(request.context) + return EnsureAnyChainman(request.context) .ActiveTip() ->GetBlockHash() .GetHex(); @@ -211,7 +217,7 @@ const JSONRPCRequest &request) -> UniValue { LOCK(cs_main); CChainState &active_chainstate = - EnsureChainman(request.context).ActiveChainstate(); + EnsureAnyChainman(request.context).ActiveChainstate(); const CBlockIndex *blockIndexFinalized = active_chainstate.GetFinalizedBlock(); if (blockIndexFinalized) { @@ -441,7 +447,8 @@ [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { LOCK(cs_main); - return GetDifficulty(EnsureChainman(request.context).ActiveTip()); + return GetDifficulty( + EnsureAnyChainman(request.context).ActiveTip()); }, }; } @@ -668,7 +675,7 @@ include_mempool_sequence = request.params[1].get_bool(); } - return MempoolToJSON(EnsureMemPool(request.context), fVerbose, + return MempoolToJSON(EnsureAnyMemPool(request.context), fVerbose, include_mempool_sequence); }, }; @@ -712,7 +719,7 @@ TxId txid(ParseHashV(request.params[0], "parameter 1")); - const CTxMemPool &mempool = EnsureMemPool(request.context); + const CTxMemPool &mempool = EnsureAnyMemPool(request.context); LOCK(mempool.cs); CTxMemPool::txiter it = mempool.mapTx.find(txid); @@ -787,7 +794,7 @@ TxId txid(ParseHashV(request.params[0], "parameter 1")); - const CTxMemPool &mempool = EnsureMemPool(request.context); + const CTxMemPool &mempool = EnsureAnyMemPool(request.context); LOCK(mempool.cs); CTxMemPool::txiter it = mempool.mapTx.find(txid); @@ -838,7 +845,7 @@ const JSONRPCRequest &request) -> UniValue { TxId txid(ParseHashV(request.params[0], "parameter 1")); - const CTxMemPool &mempool = EnsureMemPool(request.context); + const CTxMemPool &mempool = EnsureAnyMemPool(request.context); LOCK(mempool.cs); CTxMemPool::txiter it = mempool.mapTx.find(txid); @@ -870,7 +877,7 @@ const JSONRPCRequest &request) -> UniValue { LOCK(cs_main); const CChain &active_chain = - EnsureChainman(request.context).ActiveChain(); + EnsureAnyChainman(request.context).ActiveChain(); int nHeight = request.params[0].get_int(); if (nHeight < 0 || nHeight > active_chain.Height()) { @@ -957,7 +964,8 @@ const CBlockIndex *tip; { LOCK(cs_main); - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = + EnsureAnyChainman(request.context); pblockindex = chainman.m_blockman.LookupBlockIndex(hash); tip = chainman.ActiveTip(); } @@ -1118,7 +1126,8 @@ const CBlockIndex *tip; { LOCK(cs_main); - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = + EnsureAnyChainman(request.context); pblockindex = chainman.m_blockman.LookupBlockIndex(hash); tip = chainman.ActiveTip(); @@ -1168,7 +1177,7 @@ } LOCK(cs_main); - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); int heightParam = request.params[0].get_int(); if (heightParam < 0) { @@ -1278,7 +1287,7 @@ CCoinsStats stats; CChainState &active_chainstate = - EnsureChainman(request.context).ActiveChainstate(); + EnsureAnyChainman(request.context).ActiveChainstate(); active_chainstate.ForceFlushStateToDisk(); const CoinStatsHashType hash_type{ @@ -1293,7 +1302,7 @@ coins_view = &active_chainstate.CoinsDB(); blockman = &active_chainstate.m_blockman; } - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); if (GetUTXOStats(coins_view, *blockman, stats, hash_type, node.rpc_interruption_point)) { ret.pushKV("height", int64_t(stats.nHeight)); @@ -1385,11 +1394,11 @@ Coin coin; CChainState &active_chainstate = - EnsureChainman(request.context).ActiveChainstate(); + EnsureAnyChainman(request.context).ActiveChainstate(); CCoinsViewCache *coins_view = &active_chainstate.CoinsTip(); if (fMempool) { - const CTxMemPool &mempool = EnsureMemPool(request.context); + const CTxMemPool &mempool = EnsureAnyMemPool(request.context); LOCK(mempool.cs); CCoinsViewMemPool view(coins_view, mempool); if (!view.GetCoin(out, coin) || mempool.isSpent(out)) { @@ -1450,7 +1459,7 @@ LOCK(cs_main); CChainState &active_chainstate = - EnsureChainman(request.context).ActiveChainstate(); + EnsureAnyChainman(request.context).ActiveChainstate(); return CVerifyDB().VerifyDB(active_chainstate, config, active_chainstate.CoinsTip(), check_level, check_depth); @@ -1641,7 +1650,7 @@ const CChainParams &chainparams = config.GetChainParams(); - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); const CBlockIndex *tip = chainman.ActiveTip(); CHECK_NONFATAL(tip); @@ -1747,7 +1756,7 @@ HelpExampleRpc("getchaintips", "")}, [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); LOCK(cs_main); /** @@ -1885,7 +1894,7 @@ HelpExampleRpc("getmempoolinfo", "")}, [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { - return MempoolInfoToJSON(EnsureMemPool(request.context)); + return MempoolInfoToJSON(EnsureAnyMemPool(request.context)); }, }; } @@ -1910,7 +1919,7 @@ BlockHash hash(ParseHashV(request.params[0], "blockhash")); CBlockIndex *pblockindex; - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); { LOCK(cs_main); pblockindex = chainman.m_blockman.LookupBlockIndex(hash); @@ -1953,7 +1962,7 @@ BlockHash hash(uint256S(strHash)); BlockValidationState state; - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); CBlockIndex *pblockindex = nullptr; { LOCK(cs_main); @@ -1997,7 +2006,7 @@ const BlockHash hash(ParseHashV(request.params[0], "blockhash")); BlockValidationState state; - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); CBlockIndex *pblockindex; { LOCK(cs_main); @@ -2040,7 +2049,7 @@ const BlockHash hash(uint256S(strHash)); BlockValidationState state; - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); CBlockIndex *pblockindex = nullptr; { LOCK(cs_main); @@ -2080,7 +2089,7 @@ HelpExampleRpc("reconsiderblock", "\"blockhash\"")}, [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); const BlockHash hash(ParseHashV(request.params[0], "blockhash")); { @@ -2123,7 +2132,7 @@ [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { const std::string strHash = request.params[0].get_str(); - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); const BlockHash hash(uint256S(strHash)); { @@ -2193,7 +2202,7 @@ HelpExampleRpc("getchaintxstats", "2016")}, [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); const CBlockIndex *pindex; // By default: 1 month @@ -2379,7 +2388,7 @@ [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { LOCK(cs_main); - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); CBlockIndex *pindex; if (request.params[0].isNum()) { @@ -2599,7 +2608,7 @@ HelpExampleRpc("savemempool", "")}, [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { - const CTxMemPool &mempool = EnsureMemPool(request.context); + const CTxMemPool &mempool = EnsureAnyMemPool(request.context); if (!mempool.IsLoaded()) { throw JSONRPCError(RPC_MISC_ERROR, @@ -2864,7 +2873,7 @@ { LOCK(cs_main); ChainstateManager &chainman = - EnsureChainman(request.context); + EnsureAnyChainman(request.context); chainman.ActiveChainstate().ForceFlushStateToDisk(); pcursor = std::unique_ptr( chainman.ActiveChainstate().CoinsDB().Cursor()); @@ -2872,7 +2881,7 @@ tip = chainman.ActiveTip(); CHECK_NONFATAL(tip); } - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); bool res = FindScriptPubKey( g_scan_progress, g_should_abort_scan, count, pcursor.get(), needles, coins, node.rpc_interruption_point); @@ -2960,7 +2969,7 @@ bool block_was_connected; { LOCK(cs_main); - block_index = EnsureChainman(request.context) + block_index = EnsureAnyChainman(request.context) .m_blockman.LookupBlockIndex(block_hash); if (!block_index) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, @@ -3051,7 +3060,7 @@ FILE *file{fsbridge::fopen(temppath, "wb")}; CAutoFile afile{file, SER_DISK, CLIENT_VERSION}; - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); UniValue result = CreateUTXOSnapshot( node, node.chainman->ActiveChainstate(), afile); fs::rename(temppath, path); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -114,7 +114,7 @@ const JSONRPCRequest &request) -> UniValue { LOCK(cs_main); const CChain &active_chain = - EnsureChainman(request.context).ActiveChain(); + EnsureAnyChainman(request.context).ActiveChain(); return GetNetworkHashPS( !request.params[0].isNull() ? request.params[0].get_int() : 120, !request.params[1].isNull() ? request.params[1].get_int() : -1, @@ -281,8 +281,8 @@ throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, error); } - const CTxMemPool &mempool = EnsureMemPool(request.context); - ChainstateManager &chainman = EnsureChainman(request.context); + const CTxMemPool &mempool = EnsureAnyMemPool(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); return generateBlocks(config, chainman, mempool, coinbase_script, num_blocks, max_tries); @@ -344,8 +344,8 @@ "Error: Invalid address"); } - const CTxMemPool &mempool = EnsureMemPool(request.context); - ChainstateManager &chainman = EnsureChainman(request.context); + const CTxMemPool &mempool = EnsureAnyMemPool(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); CScript coinbase_script = GetScriptForDestination(destination); @@ -411,7 +411,7 @@ coinbase_script = GetScriptForDestination(destination); } - const CTxMemPool &mempool = EnsureMemPool(request.context); + const CTxMemPool &mempool = EnsureAnyMemPool(request.context); std::vector txs; const auto raw_txs_or_txids = request.params[1].get_array(); @@ -441,7 +441,7 @@ CBlock block; - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); { LOCK(cs_main); @@ -528,9 +528,9 @@ [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { LOCK(cs_main); - const CTxMemPool &mempool = EnsureMemPool(request.context); + const CTxMemPool &mempool = EnsureAnyMemPool(request.context); const CChain &active_chain = - EnsureChainman(request.context).ActiveChain(); + EnsureAnyChainman(request.context).ActiveChain(); UniValue obj(UniValue::VOBJ); obj.pushKV("blocks", int(active_chain.Height())); @@ -593,7 +593,8 @@ "prioritisetransaction must be 0."); } - EnsureMemPool(request.context).PrioritiseTransaction(txid, nAmount); + EnsureAnyMemPool(request.context) + .PrioritiseTransaction(txid, nAmount); return true; }, }; @@ -791,7 +792,7 @@ [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { LOCK(cs_main); - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); const CChainParams &chainparams = config.GetChainParams(); @@ -858,7 +859,7 @@ throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode"); } - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); if (!node.connman) { throw JSONRPCError( RPC_CLIENT_P2P_DISABLED, @@ -877,7 +878,7 @@ } static unsigned int nTransactionsUpdatedLast; - const CTxMemPool &mempool = EnsureMemPool(request.context); + const CTxMemPool &mempool = EnsureAnyMemPool(request.context); if (!lpval.isNull()) { // Wait to respond until either the best block changes, OR a @@ -1125,7 +1126,7 @@ "Block does not start with a coinbase"); } - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); const BlockHash hash = block.GetHash(); { LOCK(cs_main); @@ -1183,7 +1184,7 @@ throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block header decode failed"); } - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); { LOCK(cs_main); if (!chainman.m_blockman.LookupBlockIndex(h.hashPrevBlock)) { @@ -1217,7 +1218,7 @@ RPCExamples{HelpExampleCli("estimatefee", "")}, [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { - const CTxMemPool &mempool = EnsureMemPool(request.context); + const CTxMemPool &mempool = EnsureAnyMemPool(request.context); return mempool.estimateFee().GetFeePerK(); }, }; diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -43,7 +43,7 @@ HelpExampleRpc("getconnectioncount", "")}, [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); if (!node.connman) { throw JSONRPCError( RPC_CLIENT_P2P_DISABLED, @@ -69,7 +69,7 @@ RPCExamples{HelpExampleCli("ping", "") + HelpExampleRpc("ping", "")}, [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); if (!node.peerman) { throw JSONRPCError( RPC_CLIENT_P2P_DISABLED, @@ -225,7 +225,7 @@ HelpExampleRpc("getpeerinfo", "")}, [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); if (!node.connman || !node.peerman) { throw JSONRPCError( RPC_CLIENT_P2P_DISABLED, @@ -385,7 +385,7 @@ throw std::runtime_error(self.ToString()); } - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); if (!node.connman) { throw JSONRPCError( RPC_CLIENT_P2P_DISABLED, @@ -477,7 +477,7 @@ throw JSONRPCError(RPC_INVALID_PARAMETER, self.ToString()); } - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); if (!node.connman) { throw JSONRPCError( RPC_CLIENT_P2P_DISABLED, @@ -524,7 +524,7 @@ HelpExampleRpc("disconnectnode", "\"\", 1")}, [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); if (!node.connman) { throw JSONRPCError( RPC_CLIENT_P2P_DISABLED, @@ -603,7 +603,7 @@ HelpExampleRpc("getaddednodeinfo", "\"192.168.0.201\"")}, [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); if (!node.connman) { throw JSONRPCError( RPC_CLIENT_P2P_DISABLED, @@ -688,7 +688,7 @@ HelpExampleRpc("getnettotals", "")}, [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); if (!node.connman) { throw JSONRPCError( RPC_CLIENT_P2P_DISABLED, @@ -829,7 +829,7 @@ obj.pushKV("version", CLIENT_VERSION); obj.pushKV("subversion", userAgent(config)); obj.pushKV("protocolversion", PROTOCOL_VERSION); - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); if (node.connman) { ServiceFlags services = node.connman->GetLocalServices(); obj.pushKV("localservices", strprintf("%016x", services)); @@ -905,7 +905,7 @@ throw std::runtime_error(help.ToString()); } - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); if (!node.banman) { throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded"); @@ -998,7 +998,7 @@ HelpExampleRpc("listbanned", "")}, [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); if (!node.banman) { throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded"); @@ -1033,7 +1033,7 @@ HelpExampleRpc("clearbanned", "")}, [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); if (!node.banman) { throw JSONRPCError( RPC_CLIENT_P2P_DISABLED, @@ -1059,7 +1059,7 @@ RPCExamples{""}, [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); if (!node.banman) { throw JSONRPCError( RPC_CLIENT_P2P_DISABLED, @@ -1116,7 +1116,7 @@ HelpExampleRpc("getnodeaddresses", "4, \"i2p\"")}, [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); if (!node.banman) { throw JSONRPCError( RPC_CLIENT_P2P_DISABLED, @@ -1184,7 +1184,7 @@ HelpExampleRpc("addpeeraddress", "\"1.2.3.4\", 8333")}, [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); if (!node.connman) { throw JSONRPCError( RPC_CLIENT_P2P_DISABLED, diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -193,8 +193,8 @@ "\"mytxid\" true \"myblockhash\"")}, [&](const RPCHelpMan &self, const Config &config, const JSONRPCRequest &request) -> UniValue { - const NodeContext &node = EnsureNodeContext(request.context); - ChainstateManager &chainman = EnsureChainman(request.context); + const NodeContext &node = EnsureAnyNodeContext(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); bool in_active_chain = true; TxId txid = TxId(ParseHashV(request.params[0], "parameter 1")); @@ -331,7 +331,7 @@ CBlockIndex *pblockindex = nullptr; BlockHash hashBlock; - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); if (!request.params[1].isNull()) { LOCK(cs_main); hashBlock = @@ -448,7 +448,7 @@ LOCK(cs_main); - ChainstateManager &chainman = EnsureChainman(request.context); + ChainstateManager &chainman = EnsureAnyChainman(request.context); const CBlockIndex *pindex = chainman.m_blockman.LookupBlockIndex( merkleBlock.header.GetHash()); @@ -783,10 +783,10 @@ CCoinsView viewDummy; CCoinsViewCache view(&viewDummy); { - const CTxMemPool &mempool = EnsureMemPool(request.context); + const CTxMemPool &mempool = EnsureAnyMemPool(request.context); LOCK(cs_main); LOCK(mempool.cs); - CCoinsViewCache &viewChain = EnsureChainman(request.context) + CCoinsViewCache &viewChain = EnsureAnyChainman(request.context) .ActiveChainstate() .CoinsTip(); CCoinsViewMemPool viewMempool(&viewChain, mempool); @@ -964,7 +964,7 @@ // Create empty map entry keyed by prevout. coins[txin.prevout]; } - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); FindCoins(node, coins); // Parse the prevtxs array @@ -1036,7 +1036,7 @@ std::string err_string; AssertLockNotHeld(cs_main); - NodeContext &node = EnsureNodeContext(request.context); + NodeContext &node = EnsureAnyNodeContext(request.context); const TransactionError err = BroadcastTransaction( node, config, tx, err_string, max_raw_tx_fee, /*relay*/ true, /*wait_callback*/ true); @@ -1145,7 +1145,7 @@ ? DEFAULT_MAX_RAW_TX_FEE_RATE : CFeeRate(AmountFromValue(request.params[1])); - CTxMemPool &mempool = EnsureMemPool(request.context); + CTxMemPool &mempool = EnsureAnyMemPool(request.context); int64_t virtual_size = GetVirtualTransactionSize(*tx); Amount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size); @@ -1159,9 +1159,9 @@ { LOCK(cs_main); test_accept_res = AcceptToMemoryPool( - EnsureChainman(request.context).ActiveChainstate(), config, - mempool, state, std::move(tx), false /* bypass_limits */, - true /* test_accept */, &fee); + EnsureAnyChainman(request.context).ActiveChainstate(), + config, mempool, state, std::move(tx), + false /* bypass_limits */, true /* test_accept */, &fee); } // Check that fee does not exceed maximum fee @@ -1914,9 +1914,9 @@ CCoinsView viewDummy; CCoinsViewCache view(&viewDummy); { - const CTxMemPool &mempool = EnsureMemPool(request.context); + const CTxMemPool &mempool = EnsureAnyMemPool(request.context); LOCK2(cs_main, mempool.cs); - CCoinsViewCache &viewChain = EnsureChainman(request.context) + CCoinsViewCache &viewChain = EnsureAnyChainman(request.context) .ActiveChainstate() .CoinsTip(); CCoinsViewMemPool viewMempool(&viewChain, mempool);