mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
rpc: Tidy up local references (see commit message)
Organize local variables/references such that: 1. There is always a `ChainstateManager` reference before any `LOCK(cs_main)`. 2. NodeContext references are used with Ensure*() functions introduced in previous commit where appropriate to avoid duplicate assertions.
This commit is contained in:
@@ -158,7 +158,7 @@ static RPCHelpMan getrawtransaction()
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
const NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
||||
ChainstateManager& chainman = EnsureChainman(node);
|
||||
|
||||
bool in_active_chain = true;
|
||||
uint256 hash = ParseHashV(request.params[0], "parameter 1");
|
||||
@@ -350,9 +350,9 @@ static RPCHelpMan verifytxoutproof()
|
||||
if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) != merkleBlock.header.hashMerkleRoot)
|
||||
return res;
|
||||
|
||||
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
||||
LOCK(cs_main);
|
||||
|
||||
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
||||
const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(merkleBlock.header.GetHash());
|
||||
if (!pindex || !chainman.ActiveChain().Contains(pindex) || pindex->nTx == 0) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found in chain");
|
||||
@@ -678,10 +678,11 @@ static RPCHelpMan combinerawtransaction()
|
||||
CCoinsView viewDummy;
|
||||
CCoinsViewCache view(&viewDummy);
|
||||
{
|
||||
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
|
||||
LOCK(cs_main);
|
||||
LOCK(mempool.cs);
|
||||
CCoinsViewCache &viewChain = EnsureAnyChainman(request.context).ActiveChainstate().CoinsTip();
|
||||
NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
const CTxMemPool& mempool = EnsureMemPool(node);
|
||||
ChainstateManager& chainman = EnsureChainman(node);
|
||||
LOCK2(cs_main, mempool.cs);
|
||||
CCoinsViewCache &viewChain = chainman.ActiveChainstate().CoinsTip();
|
||||
CCoinsViewMemPool viewMempool(&viewChain, mempool);
|
||||
view.SetBackend(viewMempool); // temporarily switch cache backend to db+mempool view
|
||||
|
||||
@@ -943,7 +944,9 @@ static RPCHelpMan testmempoolaccept()
|
||||
DEFAULT_MAX_RAW_TX_FEE_RATE :
|
||||
CFeeRate(AmountFromValue(request.params[1]));
|
||||
|
||||
CTxMemPool& mempool = EnsureAnyMemPool(request.context);
|
||||
NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
|
||||
CTxMemPool& mempool = EnsureMemPool(node);
|
||||
int64_t virtual_size = GetVirtualTransactionSize(*tx);
|
||||
CAmount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size);
|
||||
|
||||
@@ -952,7 +955,8 @@ static RPCHelpMan testmempoolaccept()
|
||||
result_0.pushKV("txid", tx->GetHash().GetHex());
|
||||
result_0.pushKV("wtxid", tx->GetWitnessHash().GetHex());
|
||||
|
||||
const MempoolAcceptResult accept_result = WITH_LOCK(cs_main, return AcceptToMemoryPool(EnsureAnyChainman(request.context).ActiveChainstate(), mempool, std::move(tx),
|
||||
ChainstateManager& chainman = EnsureChainman(node);
|
||||
const MempoolAcceptResult accept_result = WITH_LOCK(cs_main, return AcceptToMemoryPool(chainman.ActiveChainstate(), mempool, std::move(tx),
|
||||
false /* bypass_limits */, /* test_accept */ true));
|
||||
|
||||
// Only return the fee and vsize if the transaction would pass ATMP.
|
||||
@@ -1601,9 +1605,11 @@ static RPCHelpMan utxoupdatepsbt()
|
||||
CCoinsView viewDummy;
|
||||
CCoinsViewCache view(&viewDummy);
|
||||
{
|
||||
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
|
||||
NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
const CTxMemPool& mempool = EnsureMemPool(node);
|
||||
ChainstateManager& chainman = EnsureChainman(node);
|
||||
LOCK2(cs_main, mempool.cs);
|
||||
CCoinsViewCache &viewChain = EnsureAnyChainman(request.context).ActiveChainstate().CoinsTip();
|
||||
CCoinsViewCache &viewChain = chainman.ActiveChainstate().CoinsTip();
|
||||
CCoinsViewMemPool viewMempool(&viewChain, mempool);
|
||||
view.SetBackend(viewMempool); // temporarily switch cache backend to db+mempool view
|
||||
|
||||
|
||||
Reference in New Issue
Block a user