Page MenuHomePhabricator

D7990.diff
No OneTemporary

D7990.diff

diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp
--- a/src/bitcoind.cpp
+++ b/src/bitcoind.cpp
@@ -18,6 +18,7 @@
#include <noui.h>
#include <shutdown.h>
#include <ui_interface.h>
+#include <util/ref.h>
#include <util/strencodings.h>
#include <util/system.h>
#include <util/threadnames.h>
@@ -64,10 +65,14 @@
// not possible as the whole application has too many global state. However,
// this is a first step.
auto &config = const_cast<Config &>(GetConfig());
+
RPCServer rpcServer;
- HTTPRPCRequestProcessor httpRPCRequestProcessor(config, rpcServer);
NodeContext node;
+ util::Ref context{node};
+
+ HTTPRPCRequestProcessor httpRPCRequestProcessor(config, rpcServer, context);
+
bool fRet = false;
util::ThreadSetInternalName("init");
diff --git a/src/httprpc.h b/src/httprpc.h
--- a/src/httprpc.h
+++ b/src/httprpc.h
@@ -10,6 +10,10 @@
class Config;
+namespace util {
+class Ref;
+} // namespace util
+
class HTTPRPCRequestProcessor {
private:
Config &config;
@@ -18,8 +22,11 @@
bool ProcessHTTPRequest(HTTPRequest *request);
public:
- HTTPRPCRequestProcessor(Config &configIn, RPCServer &rpcServerIn)
- : config(configIn), rpcServer(rpcServerIn) {}
+ const util::Ref &context;
+
+ HTTPRPCRequestProcessor(Config &configIn, RPCServer &rpcServerIn,
+ const util::Ref &contextIn)
+ : config(configIn), rpcServer(rpcServerIn), context(contextIn) {}
static bool DelegateHTTPRequest(HTTPRPCRequestProcessor *requestProcessor,
HTTPRequest *request) {
@@ -46,7 +53,7 @@
* Start HTTP REST subsystem.
* Precondition; HTTP and RPC has been started.
*/
-void StartREST();
+void StartREST(const util::Ref &context);
/** Interrupt RPC REST subsystem */
void InterruptREST();
diff --git a/src/httprpc.cpp b/src/httprpc.cpp
--- a/src/httprpc.cpp
+++ b/src/httprpc.cpp
@@ -9,6 +9,7 @@
#include <crypto/hmac_sha256.h>
#include <rpc/protocol.h>
#include <ui_interface.h>
+#include <util/ref.h>
#include <util/strencodings.h>
#include <util/system.h>
#include <util/translation.h>
@@ -305,7 +306,7 @@
return false;
}
- JSONRPCRequest jreq;
+ JSONRPCRequest jreq(context);
jreq.peerAddr = req->GetPeer().ToString();
if (!RPCAuthorized(authHeader.second, jreq.authUser)) {
LogPrintf("ThreadRPCServer incorrect password attempt from %s\n",
diff --git a/src/init.h b/src/init.h
--- a/src/init.h
+++ b/src/init.h
@@ -22,6 +22,9 @@
namespace boost {
class thread_group;
} // namespace boost
+namespace util {
+class Ref;
+} // namespace util
/** Interrupt threads */
void Interrupt(NodeContext &node);
diff --git a/src/init.cpp b/src/init.cpp
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1413,7 +1413,7 @@
return false;
}
if (gArgs.GetBoolArg("-rest", DEFAULT_REST_ENABLE)) {
- StartREST();
+ StartREST(httpRPCRequestProcessor.context);
}
StartHTTPServer();
diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp
--- a/src/interfaces/node.cpp
+++ b/src/interfaces/node.cpp
@@ -27,6 +27,7 @@
#include <sync.h>
#include <txmempool.h>
#include <ui_interface.h>
+#include <util/ref.h>
#include <util/system.h>
#include <util/translation.h>
#include <validation.h>
@@ -257,7 +258,7 @@
UniValue executeRpc(Config &config, const std::string &command,
const UniValue &params,
const std::string &uri) override {
- JSONRPCRequest req;
+ JSONRPCRequest req(m_context_ref);
req.params = params;
req.strMethod = command;
req.URI = uri;
@@ -364,6 +365,7 @@
}
NodeContext *context() override { return &m_context; }
NodeContext m_context;
+ util::Ref m_context_ref{m_context};
};
} // namespace
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -23,6 +23,7 @@
#include <qt/winshutdownmonitor.h>
#include <ui_interface.h>
#include <uint256.h>
+#include <util/ref.h>
#include <util/system.h>
#include <util/threadnames.h>
@@ -728,7 +729,8 @@
}
RPCServer rpcServer;
- HTTPRPCRequestProcessor httpRPCRequestProcessor(config, rpcServer);
+ util::Ref context{node};
+ HTTPRPCRequestProcessor httpRPCRequestProcessor(config, rpcServer, context);
try {
app.createWindow(&config, networkStyle.data());
diff --git a/src/qt/test/apptests.cpp b/src/qt/test/apptests.cpp
--- a/src/qt/test/apptests.cpp
+++ b/src/qt/test/apptests.cpp
@@ -14,6 +14,7 @@
#include <qt/rpcconsole.h>
#include <rpc/server.h>
#include <shutdown.h>
+#include <util/ref.h>
#include <validation.h>
#if defined(HAVE_CONFIG_H)
@@ -93,7 +94,8 @@
m_app.baseInitialize(config);
RPCServer rpcServer;
- HTTPRPCRequestProcessor httpRPCRequestProcessor(config, rpcServer);
+ util::Ref context{test.m_node};
+ HTTPRPCRequestProcessor httpRPCRequestProcessor(config, rpcServer, context);
m_app.requestInitialize(config, rpcServer, httpRPCRequestProcessor);
m_app.exec();
m_app.requestShutdown(config);
diff --git a/src/rest.cpp b/src/rest.cpp
--- a/src/rest.cpp
+++ b/src/rest.cpp
@@ -19,6 +19,7 @@
#include <streams.h>
#include <sync.h>
#include <txmempool.h>
+#include <util/ref.h>
#include <util/strencodings.h>
#include <validation.h>
#include <version.h>
@@ -82,12 +83,14 @@
* @param[in] req the HTTP request
* return pointer to the mempool or nullptr if no mempool found
*/
-static CTxMemPool *GetMemPool(HTTPRequest *req) {
- if (!g_rpc_node || !g_rpc_node->mempool) {
+static CTxMemPool *GetMemPool(const util::Ref &context, HTTPRequest *req) {
+ NodeContext *node =
+ context.Has<NodeContext>() ? &context.Get<NodeContext>() : nullptr;
+ if (!node || !node->mempool) {
RESTERR(req, HTTP_NOT_FOUND, "Mempool disabled or instance not found");
return nullptr;
}
- return g_rpc_node->mempool;
+ return node->mempool;
}
static RetFormat ParseDataFormat(std::string &param,
@@ -139,8 +142,8 @@
return true;
}
-static bool rest_headers(Config &config, HTTPRequest *req,
- const std::string &strURIPart) {
+static bool rest_headers(Config &config, const util::Ref &context,
+ HTTPRequest *req, const std::string &strURIPart) {
if (!CheckWarmup(req)) {
return false;
}
@@ -304,18 +307,20 @@
}
}
-static bool rest_block_extended(Config &config, HTTPRequest *req,
+static bool rest_block_extended(Config &config, const util::Ref &context,
+ HTTPRequest *req,
const std::string &strURIPart) {
return rest_block(config, req, strURIPart, true);
}
-static bool rest_block_notxdetails(Config &config, HTTPRequest *req,
+static bool rest_block_notxdetails(Config &config, const util::Ref &context,
+ HTTPRequest *req,
const std::string &strURIPart) {
return rest_block(config, req, strURIPart, false);
}
-static bool rest_chaininfo(Config &config, HTTPRequest *req,
- const std::string &strURIPart) {
+static bool rest_chaininfo(Config &config, const util::Ref &context,
+ HTTPRequest *req, const std::string &strURIPart) {
if (!CheckWarmup(req)) {
return false;
}
@@ -325,7 +330,7 @@
switch (rf) {
case RetFormat::JSON: {
- JSONRPCRequest jsonRequest;
+ JSONRPCRequest jsonRequest(context);
jsonRequest.params = UniValue(UniValue::VARR);
UniValue chainInfoObject = getblockchaininfo(config, jsonRequest);
std::string strJSON = chainInfoObject.write() + "\n";
@@ -340,13 +345,13 @@
}
}
-static bool rest_mempool_info(Config &config, HTTPRequest *req,
- const std::string &strURIPart) {
+static bool rest_mempool_info(Config &config, const util::Ref &context,
+ HTTPRequest *req, const std::string &strURIPart) {
if (!CheckWarmup(req)) {
return false;
}
- const CTxMemPool *mempool = GetMemPool(req);
+ const CTxMemPool *mempool = GetMemPool(context, req);
if (!mempool) {
return false;
}
@@ -370,13 +375,14 @@
}
}
-static bool rest_mempool_contents(Config &config, HTTPRequest *req,
+static bool rest_mempool_contents(Config &config, const util::Ref &context,
+ HTTPRequest *req,
const std::string &strURIPart) {
if (!CheckWarmup(req)) {
return false;
}
- const CTxMemPool *mempool = GetMemPool(req);
+ const CTxMemPool *mempool = GetMemPool(context, req);
if (!mempool) {
return false;
}
@@ -400,7 +406,7 @@
}
}
-static bool rest_tx(Config &config, HTTPRequest *req,
+static bool rest_tx(Config &config, const util::Ref &context, HTTPRequest *req,
const std::string &strURIPart) {
if (!CheckWarmup(req)) {
return false;
@@ -467,8 +473,8 @@
}
}
-static bool rest_getutxos(Config &config, HTTPRequest *req,
- const std::string &strURIPart) {
+static bool rest_getutxos(Config &config, const util::Ref &context,
+ HTTPRequest *req, const std::string &strURIPart) {
if (!CheckWarmup(req)) {
return false;
}
@@ -599,7 +605,7 @@
};
if (fCheckMemPool) {
- const CTxMemPool *mempool = GetMemPool(req);
+ const CTxMemPool *mempool = GetMemPool(context, req);
if (!mempool) {
return false;
}
@@ -692,7 +698,8 @@
}
}
-static bool rest_blockhash_by_height(Config &config, HTTPRequest *req,
+static bool rest_blockhash_by_height(Config &config, const util::Ref &context,
+ HTTPRequest *req,
const std::string &str_uri_part) {
if (!CheckWarmup(req)) {
return false;
@@ -745,7 +752,7 @@
static const struct {
const char *prefix;
- bool (*handler)(Config &config, HTTPRequest *req,
+ bool (*handler)(Config &config, const util::Ref &context, HTTPRequest *req,
const std::string &strReq);
} uri_prefixes[] = {
{"/rest/tx/", rest_tx},
@@ -759,10 +766,13 @@
{"/rest/blockhashbyheight/", rest_blockhash_by_height},
};
-void StartREST() {
- for (size_t i = 0; i < ARRAYLEN(uri_prefixes); i++) {
- RegisterHTTPHandler(uri_prefixes[i].prefix, false,
- uri_prefixes[i].handler);
+void StartREST(const util::Ref &context) {
+ for (const auto &up : uri_prefixes) {
+ auto handler = [&context, up](Config &config, HTTPRequest *req,
+ const std::string &prefix) {
+ return up.handler(config, context, req, prefix);
+ };
+ RegisterHTTPHandler(up.prefix, false, handler);
}
}
diff --git a/src/rpc/blockchain.h b/src/rpc/blockchain.h
--- a/src/rpc/blockchain.h
+++ b/src/rpc/blockchain.h
@@ -15,6 +15,9 @@
class CTxMemPool;
class JSONRPCRequest;
struct NodeContext;
+namespace util {
+class Ref;
+} // namespace util
extern RecursiveMutex cs_main;
@@ -52,6 +55,7 @@
//! direct way to pass in state to RPC methods without globals.
extern NodeContext *g_rpc_node;
-CTxMemPool &EnsureMemPool();
+NodeContext &EnsureNodeContext(const util::Ref &context);
+CTxMemPool &EnsureMemPool(const util::Ref &context);
#endif // BITCOIN_RPC_BLOCKCHAIN_H
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -29,6 +29,7 @@
#include <txdb.h>
#include <txmempool.h>
#include <undo.h>
+#include <util/ref.h>
#include <util/strencodings.h>
#include <util/system.h>
#include <util/validation.h>
@@ -53,13 +54,20 @@
static std::condition_variable cond_blockchange;
static CUpdatedBlock latestblock GUARDED_BY(cs_blockchange);
-CTxMemPool &EnsureMemPool() {
- CHECK_NONFATAL(g_rpc_node);
- if (!g_rpc_node->mempool) {
+NodeContext &EnsureNodeContext(const util::Ref &context) {
+ if (!context.Has<NodeContext>()) {
+ throw JSONRPCError(RPC_INTERNAL_ERROR, "Node context not found");
+ }
+ return context.Get<NodeContext>();
+}
+
+CTxMemPool &EnsureMemPool(const util::Ref &context) {
+ NodeContext &node = EnsureNodeContext(context);
+ if (!node.mempool) {
throw JSONRPCError(RPC_CLIENT_MEMPOOL_DISABLED,
"Mempool disabled or instance not found");
}
- return *g_rpc_node->mempool;
+ return *node.mempool;
}
/**
@@ -595,7 +603,7 @@
fVerbose = request.params[0].get_bool();
}
- return MempoolToJSON(EnsureMemPool(), fVerbose);
+ return MempoolToJSON(EnsureMemPool(request.context), fVerbose);
}
static UniValue getmempoolancestors(const Config &config,
@@ -635,7 +643,7 @@
TxId txid(ParseHashV(request.params[0], "parameter 1"));
- const CTxMemPool &mempool = EnsureMemPool();
+ const CTxMemPool &mempool = EnsureMemPool(request.context);
LOCK(mempool.cs);
CTxMemPool::txiter it = mempool.mapTx.find(txid);
@@ -707,7 +715,7 @@
TxId txid(ParseHashV(request.params[0], "parameter 1"));
- const CTxMemPool &mempool = EnsureMemPool();
+ const CTxMemPool &mempool = EnsureMemPool(request.context);
LOCK(mempool.cs);
CTxMemPool::txiter it = mempool.mapTx.find(txid);
@@ -759,7 +767,7 @@
TxId txid(ParseHashV(request.params[0], "parameter 1"));
- const CTxMemPool &mempool = EnsureMemPool();
+ const CTxMemPool &mempool = EnsureMemPool(request.context);
LOCK(mempool.cs);
CTxMemPool::txiter it = mempool.mapTx.find(txid);
@@ -1219,7 +1227,7 @@
CCoinsViewCache *coins_view = &::ChainstateActive().CoinsTip();
if (fMempool) {
- const CTxMemPool &mempool = EnsureMemPool();
+ const CTxMemPool &mempool = EnsureMemPool(request.context);
LOCK(mempool.cs);
CCoinsViewMemPool view(coins_view, mempool);
if (!view.GetCoin(out, coin) || mempool.isSpent(out)) {
@@ -1657,7 +1665,7 @@
}
.Check(request);
- return MempoolInfoToJSON(EnsureMemPool());
+ return MempoolInfoToJSON(EnsureMemPool(request.context));
}
static UniValue preciousblock(const Config &config,
@@ -2323,7 +2331,7 @@
}
.Check(request);
- const CTxMemPool &mempool = EnsureMemPool();
+ const CTxMemPool &mempool = EnsureMemPool(request.context);
if (!mempool.IsLoaded()) {
throw JSONRPCError(RPC_MISC_ERROR, "The mempool was not loaded yet");
diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp
--- a/src/rpc/mining.cpp
+++ b/src/rpc/mining.cpp
@@ -225,7 +225,7 @@
strprintf("Cannot derive script without private keys"));
}
- const CTxMemPool &mempool = EnsureMemPool();
+ const CTxMemPool &mempool = EnsureMemPool(request.context);
CHECK_NONFATAL(coinbase_script.size() == 1);
@@ -270,7 +270,7 @@
"Error: Invalid address");
}
- const CTxMemPool &mempool = EnsureMemPool();
+ const CTxMemPool &mempool = EnsureMemPool(request.context);
CScript coinbase_script = GetScriptForDestination(destination);
@@ -309,7 +309,7 @@
.Check(request);
LOCK(cs_main);
- const CTxMemPool &mempool = EnsureMemPool();
+ const CTxMemPool &mempool = EnsureMemPool(request.context);
UniValue obj(UniValue::VOBJ);
obj.pushKV("blocks", int(::ChainActive().Height()));
@@ -368,7 +368,7 @@
"prioritisetransaction must be 0.");
}
- EnsureMemPool().PrioritiseTransaction(txid, nAmount);
+ EnsureMemPool(request.context).PrioritiseTransaction(txid, nAmount);
return true;
}
@@ -589,13 +589,14 @@
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
}
- if (!g_rpc_node->connman) {
+ NodeContext &node = EnsureNodeContext(request.context);
+ if (!node.connman) {
throw JSONRPCError(
RPC_CLIENT_P2P_DISABLED,
"Error: Peer-to-peer functionality missing or disabled");
}
- if (g_rpc_node->connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0) {
+ if (node.connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0) {
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED,
"Bitcoin is not connected!");
}
@@ -606,7 +607,7 @@
}
static unsigned int nTransactionsUpdatedLast;
- const CTxMemPool &mempool = EnsureMemPool();
+ const CTxMemPool &mempool = EnsureMemPool(request.context);
if (!lpval.isNull()) {
// Wait to respond until either the best block changes, OR a minute has
@@ -929,7 +930,7 @@
}
.Check(request);
- const CTxMemPool &mempool = EnsureMemPool();
+ const CTxMemPool &mempool = EnsureMemPool(request.context);
return ValueFromAmount(mempool.estimateFee().GetFeePerK());
}
diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp
--- a/src/rpc/misc.cpp
+++ b/src/rpc/misc.cpp
@@ -17,6 +17,7 @@
#include <scheduler.h>
#include <script/descriptor.h>
#include <util/check.h>
+#include <util/ref.h>
#include <util/strencodings.h>
#include <util/system.h>
#include <util/validation.h>
@@ -453,8 +454,9 @@
"Timestamp must be 0 or greater");
}
SetMockTime(time);
- if (g_rpc_node) {
- for (const auto &chain_client : g_rpc_node->chain_clients) {
+ if (request.context.Has<NodeContext>()) {
+ for (const auto &chain_client :
+ request.context.Get<NodeContext>().chain_clients) {
chain_client->setMockTime(time);
}
}
@@ -490,9 +492,10 @@
}
// protect against null pointer dereference
- CHECK_NONFATAL(g_rpc_node);
- CHECK_NONFATAL(g_rpc_node->scheduler);
- g_rpc_node->scheduler->MockForward(std::chrono::seconds(delta_seconds));
+ CHECK_NONFATAL(request.context.Has<NodeContext>());
+ NodeContext &node = request.context.Get<NodeContext>();
+ CHECK_NONFATAL(node.scheduler);
+ node.scheduler->MockForward(std::chrono::seconds(delta_seconds));
return NullUniValue;
}
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -40,7 +40,8 @@
}
.Check(request);
- if (!g_rpc_node->connman) {
+ NodeContext &node = EnsureNodeContext(request.context);
+ if (!node.connman) {
throw JSONRPCError(
RPC_CLIENT_P2P_DISABLED,
"Error: Peer-to-peer functionality missing or disabled");
@@ -64,7 +65,8 @@
}
.Check(request);
- if (!g_rpc_node->connman) {
+ NodeContext &node = EnsureNodeContext(request.context);
+ if (!node.connman) {
throw JSONRPCError(
RPC_CLIENT_P2P_DISABLED,
"Error: Peer-to-peer functionality missing or disabled");
@@ -177,7 +179,8 @@
}
.Check(request);
- if (!g_rpc_node->connman) {
+ NodeContext &node = EnsureNodeContext(request.context);
+ if (!node.connman) {
throw JSONRPCError(
RPC_CLIENT_P2P_DISABLED,
"Error: Peer-to-peer functionality missing or disabled");
@@ -300,7 +303,8 @@
.ToString());
}
- if (!g_rpc_node->connman) {
+ NodeContext &node = EnsureNodeContext(request.context);
+ if (!node.connman) {
throw JSONRPCError(
RPC_CLIENT_P2P_DISABLED,
"Error: Peer-to-peer functionality missing or disabled");
@@ -352,7 +356,8 @@
}
.Check(request);
- if (!g_rpc_node->connman) {
+ NodeContext &node = EnsureNodeContext(request.context);
+ if (!node.connman) {
throw JSONRPCError(
RPC_CLIENT_P2P_DISABLED,
"Error: Peer-to-peer functionality missing or disabled");
@@ -419,7 +424,8 @@
}
.Check(request);
- if (!g_rpc_node->connman) {
+ NodeContext &node = EnsureNodeContext(request.context);
+ if (!node.connman) {
throw JSONRPCError(
RPC_CLIENT_P2P_DISABLED,
"Error: Peer-to-peer functionality missing or disabled");
@@ -496,7 +502,8 @@
}
.Check(request);
- if (!g_rpc_node->connman) {
+ NodeContext &node = EnsureNodeContext(request.context);
+ if (!node.connman) {
throw JSONRPCError(
RPC_CLIENT_P2P_DISABLED,
"Error: Peer-to-peer functionality missing or disabled");
@@ -623,7 +630,8 @@
obj.pushKV("version", CLIENT_VERSION);
obj.pushKV("subversion", userAgent(config));
obj.pushKV("protocolversion", PROTOCOL_VERSION);
- if (g_rpc_node->connman) {
+ NodeContext &node = EnsureNodeContext(request.context);
+ if (node.connman) {
ServiceFlags services = g_rpc_node->connman->GetLocalServices();
obj.pushKV("localservices", strprintf("%016x", services));
obj.pushKV("localservicesnames", GetServicesNames(services));
@@ -692,7 +700,8 @@
throw std::runtime_error(help.ToString());
}
- if (!g_rpc_node->banman) {
+ NodeContext &node = EnsureNodeContext(request.context);
+ if (!node.banman) {
throw JSONRPCError(RPC_DATABASE_ERROR,
"Error: Ban database not loaded");
}
@@ -770,7 +779,8 @@
}
.Check(request);
- if (!g_rpc_node->banman) {
+ NodeContext &node = EnsureNodeContext(request.context);
+ if (!node.banman) {
throw JSONRPCError(RPC_DATABASE_ERROR,
"Error: Ban database not loaded");
}
@@ -804,7 +814,8 @@
}
.Check(request);
- if (!g_rpc_node->banman) {
+ NodeContext &node = EnsureNodeContext(request.context);
+ if (!node.banman) {
throw JSONRPCError(
RPC_CLIENT_P2P_DISABLED,
"Error: Peer-to-peer functionality missing or disabled");
@@ -829,7 +840,8 @@
}
.Check(request);
- if (!g_rpc_node->connman) {
+ NodeContext &node = EnsureNodeContext(request.context);
+ if (!node.banman) {
throw JSONRPCError(
RPC_CLIENT_P2P_DISABLED,
"Error: Peer-to-peer functionality missing or disabled");
@@ -871,7 +883,8 @@
}
.Check(request);
- if (!g_rpc_node->connman) {
+ NodeContext &node = EnsureNodeContext(request.context);
+ if (!node.banman) {
throw JSONRPCError(
RPC_CLIENT_P2P_DISABLED,
"Error: Peer-to-peer functionality missing or disabled");
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp
--- a/src/rpc/rawtransaction.cpp
+++ b/src/rpc/rawtransaction.cpp
@@ -709,7 +709,7 @@
CCoinsView viewDummy;
CCoinsViewCache view(&viewDummy);
{
- const CTxMemPool &mempool = EnsureMemPool();
+ const CTxMemPool &mempool = EnsureMemPool(request.context);
LOCK(cs_main);
LOCK(mempool.cs);
CCoinsViewCache &viewChain = ::ChainstateActive().CoinsTip();
@@ -874,7 +874,8 @@
// Create empty map entry keyed by prevout.
coins[txin.prevout];
}
- FindCoins(*g_rpc_node, coins);
+ NodeContext &node = EnsureNodeContext(request.context);
+ FindCoins(node, coins);
// Parse the prevtxs array
ParsePrevouts(request.params[2], &keystore, coins);
@@ -945,8 +946,9 @@
}
std::string err_string;
AssertLockNotHeld(cs_main);
+ NodeContext &node = EnsureNodeContext(request.context);
const TransactionError err = BroadcastTransaction(
- *g_rpc_node, config, tx, err_string, max_raw_tx_fee, /*relay*/ true,
+ node, config, tx, err_string, max_raw_tx_fee, /*relay*/ true,
/*wait_callback*/ true);
if (err != TransactionError::OK) {
throw JSONRPCTransactionError(err, err_string);
@@ -1041,7 +1043,7 @@
max_raw_tx_fee = fr.GetFee(sz);
}
- CTxMemPool &mempool = EnsureMemPool();
+ CTxMemPool &mempool = EnsureMemPool(request.context);
UniValue result(UniValue::VARR);
UniValue result_0(UniValue::VOBJ);
@@ -1728,7 +1730,7 @@
CCoinsView viewDummy;
CCoinsViewCache view(&viewDummy);
{
- const CTxMemPool &mempool = EnsureMemPool();
+ const CTxMemPool &mempool = EnsureMemPool(request.context);
LOCK2(cs_main, mempool.cs);
CCoinsViewCache &viewChain = ::ChainstateActive().CoinsTip();
CCoinsViewMemPool viewMempool(&viewChain, mempool);
diff --git a/src/rpc/request.h b/src/rpc/request.h
--- a/src/rpc/request.h
+++ b/src/rpc/request.h
@@ -9,6 +9,10 @@
#include <univalue.h>
+namespace util {
+class Ref;
+} // namespace util
+
UniValue JSONRPCRequestObj(const std::string &strMethod, const UniValue &params,
const UniValue &id);
UniValue JSONRPCReplyObj(const UniValue &result, const UniValue &error,
@@ -35,8 +39,11 @@
std::string URI;
std::string authUser;
std::string peerAddr;
+ const util::Ref &context;
- JSONRPCRequest() : id(NullUniValue), params(NullUniValue), fHelp(false) {}
+ JSONRPCRequest(const util::Ref &contextIn)
+ : id(NullUniValue), params(NullUniValue), fHelp(false),
+ context(contextIn) {}
void parse(const UniValue &valRequest);
};
diff --git a/src/test/excessiveblock_tests.cpp b/src/test/excessiveblock_tests.cpp
--- a/src/test/excessiveblock_tests.cpp
+++ b/src/test/excessiveblock_tests.cpp
@@ -4,6 +4,7 @@
#include <consensus/consensus.h>
#include <rpc/server.h>
+#include <util/ref.h>
#include <test/util/setup_common.h>
@@ -13,9 +14,17 @@
#include <limits>
#include <string>
-extern UniValue CallRPC(std::string strMethod);
+extern UniValue CallRPC(const std::string &args, const util::Ref &context);
-BOOST_FIXTURE_TEST_SUITE(excessiveblock_tests, TestingSetup)
+class ExcessiveBlockTestingSetup : public TestingSetup {
+public:
+ UniValue CallRPC(const std::string &args) {
+ const util::Ref context{m_node};
+ return ::CallRPC(args, context);
+ }
+};
+
+BOOST_FIXTURE_TEST_SUITE(excessiveblock_tests, ExcessiveBlockTestingSetup)
BOOST_AUTO_TEST_CASE(excessiveblock_rpc) {
BOOST_CHECK_NO_THROW(CallRPC("getexcessiveblock"));
diff --git a/src/test/rpc_server_tests.cpp b/src/test/rpc_server_tests.cpp
--- a/src/test/rpc_server_tests.cpp
+++ b/src/test/rpc_server_tests.cpp
@@ -8,6 +8,7 @@
#include <chainparams.h>
#include <config.h>
+#include <util/ref.h>
#include <util/system.h>
#include <test/util/setup_common.h>
@@ -44,14 +45,15 @@
args.pushKV("arg1", "value1");
// Registered commands execute and return values correctly
- JSONRPCRequest request;
+ util::Ref context{m_node};
+ JSONRPCRequest request(context);
request.strMethod = commandName;
request.params = args;
UniValue output = rpcServer.ExecuteCommand(config, request);
BOOST_CHECK_EQUAL(output.get_str(), "testing1");
// Not-registered commands throw an exception as expected
- JSONRPCRequest badCommandRequest;
+ JSONRPCRequest badCommandRequest(context);
badCommandRequest.strMethod = "this-command-does-not-exist";
BOOST_CHECK_EXCEPTION(rpcServer.ExecuteCommand(config, badCommandRequest),
UniValue, isRpcMethodNotFound);
@@ -83,7 +85,8 @@
args.pushKV("arg2", "value2");
// Registered commands execute and return values correctly
- JSONRPCRequest request;
+ util::Ref context{m_node};
+ JSONRPCRequest request(context);
request.strMethod = commandName;
request.params = args;
UniValue output = rpcServer.ExecuteCommand(config, request);
diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp
--- a/src/test/rpc_tests.cpp
+++ b/src/test/rpc_tests.cpp
@@ -11,6 +11,7 @@
#include <core_io.h>
#include <interfaces/chain.h>
#include <node/context.h>
+#include <util/ref.h>
#include <util/time.h>
#include <test/util/setup_common.h>
@@ -20,13 +21,13 @@
#include <univalue.h>
-UniValue CallRPC(std::string args) {
+UniValue CallRPC(const std::string &args, const util::Ref &context) {
std::vector<std::string> vArgs;
boost::split(vArgs, args, boost::is_any_of(" \t"));
std::string strMethod = vArgs[0];
vArgs.erase(vArgs.begin());
GlobalConfig config;
- JSONRPCRequest request;
+ JSONRPCRequest request(context);
request.strMethod = strMethod;
request.params = RPCConvertValues(strMethod, vArgs);
request.fHelp = false;
@@ -41,7 +42,15 @@
}
}
-BOOST_FIXTURE_TEST_SUITE(rpc_tests, TestingSetup)
+class RPCTestingSetup : public TestingSetup {
+public:
+ UniValue CallRPC(const std::string &args) {
+ const util::Ref context{m_node};
+ return ::CallRPC(args, context);
+ }
+};
+
+BOOST_FIXTURE_TEST_SUITE(rpc_tests, RPCTestingSetup)
BOOST_AUTO_TEST_CASE(rpc_rawparams) {
// Test raw transaction API argument handling
diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp
--- a/src/test/util/setup_common.cpp
+++ b/src/test/util/setup_common.cpp
@@ -141,7 +141,7 @@
// We have to run a scheduler thread to prevent ActivateBestChain
// from blocking due to queue overrun.
threadGroup.create_thread([&] { m_node.scheduler->serviceQueue(); });
- GetMainSignals().RegisterBackgroundSignalScheduler(*g_rpc_node->scheduler);
+ GetMainSignals().RegisterBackgroundSignalScheduler(*m_node.scheduler);
pblocktree.reset(new CBlockTreeDB(1 << 20, true));
g_chainstate = std::make_unique<CChainState>();
diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp
--- a/src/wallet/test/wallet_tests.cpp
+++ b/src/wallet/test/wallet_tests.cpp
@@ -9,6 +9,7 @@
#include <node/context.h>
#include <policy/policy.h>
#include <rpc/server.h>
+#include <util/ref.h>
#include <util/translation.h>
#include <validation.h>
#include <wallet/coincontrol.h>
@@ -197,7 +198,8 @@
newTip->GetBlockTimeMax() + TIMESTAMP_WINDOW + 1);
key.pushKV("internal", UniValue(true));
keys.push_back(key);
- JSONRPCRequest request;
+ util::Ref context;
+ JSONRPCRequest request(context);
request.params.setArray();
request.params.push_back(keys);
@@ -269,7 +271,8 @@
::ChainActive().Height(),
::ChainActive().Tip()->GetBlockHash());
}
- JSONRPCRequest request;
+ util::Ref context;
+ JSONRPCRequest request(context);
request.params.setArray();
request.params.push_back(backup_file);
::dumpwallet(GetConfig(), request);
@@ -285,7 +288,8 @@
LOCK(wallet->cs_wallet);
wallet->SetupLegacyScriptPubKeyMan();
- JSONRPCRequest request;
+ util::Ref context;
+ JSONRPCRequest request(context);
request.params.setArray();
request.params.push_back(backup_file);
AddWallet(wallet);

File Metadata

Mime Type
text/plain
Expires
Sat, Mar 1, 11:03 (11 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5187468
Default Alt Text
D7990.diff (30 KB)

Event Timeline