mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-21 14:34:49 +01:00
rpc: Use mempool from node context instead of global
Currently they are identical, but in the future we might want to turn the mempool into a unique_ptr. Replacing the global with the mempool pointer from the node context simplifies this step.
This commit is contained in:
parent
b983e7e172
commit
facbaf092f
3 changed files with 20 additions and 9 deletions
|
@ -528,7 +528,7 @@ static UniValue getrawmempool(const JSONRPCRequest& request)
|
|||
if (!request.params[0].isNull())
|
||||
fVerbose = request.params[0].get_bool();
|
||||
|
||||
return MempoolToJSON(::mempool, fVerbose);
|
||||
return MempoolToJSON(EnsureMemPool(), fVerbose);
|
||||
}
|
||||
|
||||
static UniValue getmempoolancestors(const JSONRPCRequest& request)
|
||||
|
@ -566,6 +566,7 @@ static UniValue getmempoolancestors(const JSONRPCRequest& request)
|
|||
|
||||
uint256 hash = ParseHashV(request.params[0], "parameter 1");
|
||||
|
||||
const CTxMemPool& mempool = EnsureMemPool();
|
||||
LOCK(mempool.cs);
|
||||
|
||||
CTxMemPool::txiter it = mempool.mapTx.find(hash);
|
||||
|
@ -591,7 +592,7 @@ static UniValue getmempoolancestors(const JSONRPCRequest& request)
|
|||
const CTxMemPoolEntry &e = *ancestorIt;
|
||||
const uint256& _hash = e.GetTx().GetHash();
|
||||
UniValue info(UniValue::VOBJ);
|
||||
entryToJSON(::mempool, info, e);
|
||||
entryToJSON(mempool, info, e);
|
||||
o.pushKV(_hash.ToString(), info);
|
||||
}
|
||||
return o;
|
||||
|
@ -633,6 +634,7 @@ static UniValue getmempooldescendants(const JSONRPCRequest& request)
|
|||
|
||||
uint256 hash = ParseHashV(request.params[0], "parameter 1");
|
||||
|
||||
const CTxMemPool& mempool = EnsureMemPool();
|
||||
LOCK(mempool.cs);
|
||||
|
||||
CTxMemPool::txiter it = mempool.mapTx.find(hash);
|
||||
|
@ -658,7 +660,7 @@ static UniValue getmempooldescendants(const JSONRPCRequest& request)
|
|||
const CTxMemPoolEntry &e = *descendantIt;
|
||||
const uint256& _hash = e.GetTx().GetHash();
|
||||
UniValue info(UniValue::VOBJ);
|
||||
entryToJSON(::mempool, info, e);
|
||||
entryToJSON(mempool, info, e);
|
||||
o.pushKV(_hash.ToString(), info);
|
||||
}
|
||||
return o;
|
||||
|
@ -685,6 +687,7 @@ static UniValue getmempoolentry(const JSONRPCRequest& request)
|
|||
|
||||
uint256 hash = ParseHashV(request.params[0], "parameter 1");
|
||||
|
||||
const CTxMemPool& mempool = EnsureMemPool();
|
||||
LOCK(mempool.cs);
|
||||
|
||||
CTxMemPool::txiter it = mempool.mapTx.find(hash);
|
||||
|
@ -694,7 +697,7 @@ static UniValue getmempoolentry(const JSONRPCRequest& request)
|
|||
|
||||
const CTxMemPoolEntry &e = *it;
|
||||
UniValue info(UniValue::VOBJ);
|
||||
entryToJSON(::mempool, info, e);
|
||||
entryToJSON(mempool, info, e);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
@ -1070,6 +1073,7 @@ UniValue gettxout(const JSONRPCRequest& request)
|
|||
CCoinsViewCache* coins_view = &::ChainstateActive().CoinsTip();
|
||||
|
||||
if (fMempool) {
|
||||
const CTxMemPool& mempool = EnsureMemPool();
|
||||
LOCK(mempool.cs);
|
||||
CCoinsViewMemPool view(coins_view, mempool);
|
||||
if (!view.GetCoin(out, coin) || mempool.isSpent(out)) {
|
||||
|
@ -1448,7 +1452,7 @@ static UniValue getmempoolinfo(const JSONRPCRequest& request)
|
|||
},
|
||||
}.Check(request);
|
||||
|
||||
return MempoolInfoToJSON(::mempool);
|
||||
return MempoolInfoToJSON(EnsureMemPool());
|
||||
}
|
||||
|
||||
static UniValue preciousblock(const JSONRPCRequest& request)
|
||||
|
@ -1964,11 +1968,13 @@ static UniValue savemempool(const JSONRPCRequest& request)
|
|||
},
|
||||
}.Check(request);
|
||||
|
||||
if (!::mempool.IsLoaded()) {
|
||||
const CTxMemPool& mempool = EnsureMemPool();
|
||||
|
||||
if (!mempool.IsLoaded()) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "The mempool was not loaded yet");
|
||||
}
|
||||
|
||||
if (!DumpMempool(::mempool)) {
|
||||
if (!DumpMempool(mempool)) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Unable to dump mempool to disk");
|
||||
}
|
||||
|
||||
|
|
|
@ -244,6 +244,7 @@ static UniValue getmininginfo(const JSONRPCRequest& request)
|
|||
}.Check(request);
|
||||
|
||||
LOCK(cs_main);
|
||||
const CTxMemPool& mempool = EnsureMemPool();
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.pushKV("blocks", (int)::ChainActive().Height());
|
||||
|
@ -290,7 +291,7 @@ static UniValue prioritisetransaction(const JSONRPCRequest& request)
|
|||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Priority is no longer supported, dummy argument to prioritisetransaction must be 0.");
|
||||
}
|
||||
|
||||
mempool.PrioritiseTransaction(hash, nAmount);
|
||||
EnsureMemPool().PrioritiseTransaction(hash, nAmount);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -476,6 +477,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
|
|||
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, PACKAGE_NAME " is in initial sync and waiting for blocks...");
|
||||
|
||||
static unsigned int nTransactionsUpdatedLast;
|
||||
const CTxMemPool& mempool = EnsureMemPool();
|
||||
|
||||
if (!lpval.isNull())
|
||||
{
|
||||
|
@ -510,7 +512,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
|
|||
if (g_best_block_cv.wait_until(lock, checktxtime) == std::cv_status::timeout)
|
||||
{
|
||||
// Timeout: Check transactions for update
|
||||
// without holding ::mempool.cs to avoid deadlocks
|
||||
// without holding the mempool lock to avoid deadlocks
|
||||
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLastLP)
|
||||
break;
|
||||
checktxtime += std::chrono::seconds(10);
|
||||
|
|
|
@ -636,6 +636,7 @@ static UniValue combinerawtransaction(const JSONRPCRequest& request)
|
|||
CCoinsView viewDummy;
|
||||
CCoinsViewCache view(&viewDummy);
|
||||
{
|
||||
const CTxMemPool& mempool = EnsureMemPool();
|
||||
LOCK(cs_main);
|
||||
LOCK(mempool.cs);
|
||||
CCoinsViewCache &viewChain = ::ChainstateActive().CoinsTip();
|
||||
|
@ -888,6 +889,7 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request)
|
|||
max_raw_tx_fee_rate = CFeeRate(AmountFromValue(request.params[1]));
|
||||
}
|
||||
|
||||
CTxMemPool& mempool = EnsureMemPool();
|
||||
int64_t virtual_size = GetVirtualTransactionSize(*tx);
|
||||
CAmount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size);
|
||||
|
||||
|
@ -1506,6 +1508,7 @@ UniValue utxoupdatepsbt(const JSONRPCRequest& request)
|
|||
CCoinsView viewDummy;
|
||||
CCoinsViewCache view(&viewDummy);
|
||||
{
|
||||
const CTxMemPool& mempool = EnsureMemPool();
|
||||
LOCK2(cs_main, mempool.cs);
|
||||
CCoinsViewCache &viewChain = ::ChainstateActive().CoinsTip();
|
||||
CCoinsViewMemPool viewMempool(&viewChain, mempool);
|
||||
|
|
Loading…
Add table
Reference in a new issue