mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-23 07:52:46 +02: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:
@@ -182,13 +182,14 @@ static bool rest_headers(const std::any& context,
|
||||
{
|
||||
ChainstateManager& chainman = EnsureAnyChainman(context);
|
||||
LOCK(cs_main);
|
||||
tip = chainman.ActiveChain().Tip();
|
||||
CChain& active_chain = chainman.ActiveChain();
|
||||
tip = active_chain.Tip();
|
||||
const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(hash);
|
||||
while (pindex != nullptr && chainman.ActiveChain().Contains(pindex)) {
|
||||
while (pindex != nullptr && active_chain.Contains(pindex)) {
|
||||
headers.push_back(pindex);
|
||||
if (headers.size() == (unsigned long)count)
|
||||
break;
|
||||
pindex = chainman.ActiveChain().Next(pindex);
|
||||
pindex = active_chain.Next(pindex);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user