mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-16 13:01:19 +02: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())
|
if (!request.params[0].isNull())
|
||||||
fVerbose = request.params[0].get_bool();
|
fVerbose = request.params[0].get_bool();
|
||||||
|
|
||||||
return MempoolToJSON(::mempool, fVerbose);
|
return MempoolToJSON(EnsureMemPool(), fVerbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniValue getmempoolancestors(const JSONRPCRequest& request)
|
static UniValue getmempoolancestors(const JSONRPCRequest& request)
|
||||||
|
|
@ -566,6 +566,7 @@ static UniValue getmempoolancestors(const JSONRPCRequest& request)
|
||||||
|
|
||||||
uint256 hash = ParseHashV(request.params[0], "parameter 1");
|
uint256 hash = ParseHashV(request.params[0], "parameter 1");
|
||||||
|
|
||||||
|
const CTxMemPool& mempool = EnsureMemPool();
|
||||||
LOCK(mempool.cs);
|
LOCK(mempool.cs);
|
||||||
|
|
||||||
CTxMemPool::txiter it = mempool.mapTx.find(hash);
|
CTxMemPool::txiter it = mempool.mapTx.find(hash);
|
||||||
|
|
@ -591,7 +592,7 @@ static UniValue getmempoolancestors(const JSONRPCRequest& request)
|
||||||
const CTxMemPoolEntry &e = *ancestorIt;
|
const CTxMemPoolEntry &e = *ancestorIt;
|
||||||
const uint256& _hash = e.GetTx().GetHash();
|
const uint256& _hash = e.GetTx().GetHash();
|
||||||
UniValue info(UniValue::VOBJ);
|
UniValue info(UniValue::VOBJ);
|
||||||
entryToJSON(::mempool, info, e);
|
entryToJSON(mempool, info, e);
|
||||||
o.pushKV(_hash.ToString(), info);
|
o.pushKV(_hash.ToString(), info);
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
|
|
@ -633,6 +634,7 @@ static UniValue getmempooldescendants(const JSONRPCRequest& request)
|
||||||
|
|
||||||
uint256 hash = ParseHashV(request.params[0], "parameter 1");
|
uint256 hash = ParseHashV(request.params[0], "parameter 1");
|
||||||
|
|
||||||
|
const CTxMemPool& mempool = EnsureMemPool();
|
||||||
LOCK(mempool.cs);
|
LOCK(mempool.cs);
|
||||||
|
|
||||||
CTxMemPool::txiter it = mempool.mapTx.find(hash);
|
CTxMemPool::txiter it = mempool.mapTx.find(hash);
|
||||||
|
|
@ -658,7 +660,7 @@ static UniValue getmempooldescendants(const JSONRPCRequest& request)
|
||||||
const CTxMemPoolEntry &e = *descendantIt;
|
const CTxMemPoolEntry &e = *descendantIt;
|
||||||
const uint256& _hash = e.GetTx().GetHash();
|
const uint256& _hash = e.GetTx().GetHash();
|
||||||
UniValue info(UniValue::VOBJ);
|
UniValue info(UniValue::VOBJ);
|
||||||
entryToJSON(::mempool, info, e);
|
entryToJSON(mempool, info, e);
|
||||||
o.pushKV(_hash.ToString(), info);
|
o.pushKV(_hash.ToString(), info);
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
|
|
@ -685,6 +687,7 @@ static UniValue getmempoolentry(const JSONRPCRequest& request)
|
||||||
|
|
||||||
uint256 hash = ParseHashV(request.params[0], "parameter 1");
|
uint256 hash = ParseHashV(request.params[0], "parameter 1");
|
||||||
|
|
||||||
|
const CTxMemPool& mempool = EnsureMemPool();
|
||||||
LOCK(mempool.cs);
|
LOCK(mempool.cs);
|
||||||
|
|
||||||
CTxMemPool::txiter it = mempool.mapTx.find(hash);
|
CTxMemPool::txiter it = mempool.mapTx.find(hash);
|
||||||
|
|
@ -694,7 +697,7 @@ static UniValue getmempoolentry(const JSONRPCRequest& request)
|
||||||
|
|
||||||
const CTxMemPoolEntry &e = *it;
|
const CTxMemPoolEntry &e = *it;
|
||||||
UniValue info(UniValue::VOBJ);
|
UniValue info(UniValue::VOBJ);
|
||||||
entryToJSON(::mempool, info, e);
|
entryToJSON(mempool, info, e);
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1070,6 +1073,7 @@ UniValue gettxout(const JSONRPCRequest& request)
|
||||||
CCoinsViewCache* coins_view = &::ChainstateActive().CoinsTip();
|
CCoinsViewCache* coins_view = &::ChainstateActive().CoinsTip();
|
||||||
|
|
||||||
if (fMempool) {
|
if (fMempool) {
|
||||||
|
const CTxMemPool& mempool = EnsureMemPool();
|
||||||
LOCK(mempool.cs);
|
LOCK(mempool.cs);
|
||||||
CCoinsViewMemPool view(coins_view, mempool);
|
CCoinsViewMemPool view(coins_view, mempool);
|
||||||
if (!view.GetCoin(out, coin) || mempool.isSpent(out)) {
|
if (!view.GetCoin(out, coin) || mempool.isSpent(out)) {
|
||||||
|
|
@ -1448,7 +1452,7 @@ static UniValue getmempoolinfo(const JSONRPCRequest& request)
|
||||||
},
|
},
|
||||||
}.Check(request);
|
}.Check(request);
|
||||||
|
|
||||||
return MempoolInfoToJSON(::mempool);
|
return MempoolInfoToJSON(EnsureMemPool());
|
||||||
}
|
}
|
||||||
|
|
||||||
static UniValue preciousblock(const JSONRPCRequest& request)
|
static UniValue preciousblock(const JSONRPCRequest& request)
|
||||||
|
|
@ -1964,11 +1968,13 @@ static UniValue savemempool(const JSONRPCRequest& request)
|
||||||
},
|
},
|
||||||
}.Check(request);
|
}.Check(request);
|
||||||
|
|
||||||
if (!::mempool.IsLoaded()) {
|
const CTxMemPool& mempool = EnsureMemPool();
|
||||||
|
|
||||||
|
if (!mempool.IsLoaded()) {
|
||||||
throw JSONRPCError(RPC_MISC_ERROR, "The mempool was not loaded yet");
|
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");
|
throw JSONRPCError(RPC_MISC_ERROR, "Unable to dump mempool to disk");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -244,6 +244,7 @@ static UniValue getmininginfo(const JSONRPCRequest& request)
|
||||||
}.Check(request);
|
}.Check(request);
|
||||||
|
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
const CTxMemPool& mempool = EnsureMemPool();
|
||||||
|
|
||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
obj.pushKV("blocks", (int)::ChainActive().Height());
|
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.");
|
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;
|
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...");
|
throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, PACKAGE_NAME " is in initial sync and waiting for blocks...");
|
||||||
|
|
||||||
static unsigned int nTransactionsUpdatedLast;
|
static unsigned int nTransactionsUpdatedLast;
|
||||||
|
const CTxMemPool& mempool = EnsureMemPool();
|
||||||
|
|
||||||
if (!lpval.isNull())
|
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)
|
if (g_best_block_cv.wait_until(lock, checktxtime) == std::cv_status::timeout)
|
||||||
{
|
{
|
||||||
// Timeout: Check transactions for update
|
// Timeout: Check transactions for update
|
||||||
// without holding ::mempool.cs to avoid deadlocks
|
// without holding the mempool lock to avoid deadlocks
|
||||||
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLastLP)
|
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLastLP)
|
||||||
break;
|
break;
|
||||||
checktxtime += std::chrono::seconds(10);
|
checktxtime += std::chrono::seconds(10);
|
||||||
|
|
|
||||||
|
|
@ -636,6 +636,7 @@ static UniValue combinerawtransaction(const JSONRPCRequest& request)
|
||||||
CCoinsView viewDummy;
|
CCoinsView viewDummy;
|
||||||
CCoinsViewCache view(&viewDummy);
|
CCoinsViewCache view(&viewDummy);
|
||||||
{
|
{
|
||||||
|
const CTxMemPool& mempool = EnsureMemPool();
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
LOCK(mempool.cs);
|
LOCK(mempool.cs);
|
||||||
CCoinsViewCache &viewChain = ::ChainstateActive().CoinsTip();
|
CCoinsViewCache &viewChain = ::ChainstateActive().CoinsTip();
|
||||||
|
|
@ -888,6 +889,7 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request)
|
||||||
max_raw_tx_fee_rate = CFeeRate(AmountFromValue(request.params[1]));
|
max_raw_tx_fee_rate = CFeeRate(AmountFromValue(request.params[1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CTxMemPool& mempool = EnsureMemPool();
|
||||||
int64_t virtual_size = GetVirtualTransactionSize(*tx);
|
int64_t virtual_size = GetVirtualTransactionSize(*tx);
|
||||||
CAmount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size);
|
CAmount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size);
|
||||||
|
|
||||||
|
|
@ -1506,6 +1508,7 @@ UniValue utxoupdatepsbt(const JSONRPCRequest& request)
|
||||||
CCoinsView viewDummy;
|
CCoinsView viewDummy;
|
||||||
CCoinsViewCache view(&viewDummy);
|
CCoinsViewCache view(&viewDummy);
|
||||||
{
|
{
|
||||||
|
const CTxMemPool& mempool = EnsureMemPool();
|
||||||
LOCK2(cs_main, mempool.cs);
|
LOCK2(cs_main, mempool.cs);
|
||||||
CCoinsViewCache &viewChain = ::ChainstateActive().CoinsTip();
|
CCoinsViewCache &viewChain = ::ChainstateActive().CoinsTip();
|
||||||
CCoinsViewMemPool viewMempool(&viewChain, mempool);
|
CCoinsViewMemPool viewMempool(&viewChain, mempool);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue