mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
rpc/rest: Take and reuse local Chain/ChainState obj
In all rest/rpc-related modules, if there are multiple calls to
ActiveChain{,State}(), and the calls fall under the same ::cs_main lock,
we can simply take a local reference and use/reuse it instead of calling
ActiveChain{,State}() again and again.
This commit is contained in:
@@ -268,12 +268,13 @@ static RPCHelpMan gettxoutproof()
|
||||
}
|
||||
} else {
|
||||
LOCK(cs_main);
|
||||
CChainState& active_chainstate = chainman.ActiveChainstate();
|
||||
|
||||
// Loop through txids and try to find which block they're in. Exit loop once a block is found.
|
||||
for (const auto& tx : setTxids) {
|
||||
const Coin& coin = AccessByTxid(chainman.ActiveChainstate().CoinsTip(), tx);
|
||||
const Coin& coin = AccessByTxid(active_chainstate.CoinsTip(), tx);
|
||||
if (!coin.IsSpent()) {
|
||||
pblockindex = chainman.ActiveChain()[coin.nHeight];
|
||||
pblockindex = active_chainstate.m_chain[coin.nHeight];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user