mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-26 10:51:11 +02: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:
@@ -180,8 +180,8 @@ static bool rest_headers(const std::any& context,
|
||||
std::vector<const CBlockIndex *> headers;
|
||||
headers.reserve(count);
|
||||
{
|
||||
LOCK(cs_main);
|
||||
ChainstateManager& chainman = EnsureAnyChainman(context);
|
||||
LOCK(cs_main);
|
||||
tip = chainman.ActiveChain().Tip();
|
||||
const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(hash);
|
||||
while (pindex != nullptr && chainman.ActiveChain().Contains(pindex)) {
|
||||
@@ -250,8 +250,8 @@ static bool rest_block(const std::any& context,
|
||||
CBlockIndex* pblockindex = nullptr;
|
||||
CBlockIndex* tip = nullptr;
|
||||
{
|
||||
LOCK(cs_main);
|
||||
ChainstateManager& chainman = EnsureAnyChainman(context);
|
||||
LOCK(cs_main);
|
||||
tip = chainman.ActiveChain().Tip();
|
||||
pblockindex = chainman.m_blockman.LookupBlockIndex(hash);
|
||||
if (!pblockindex) {
|
||||
@@ -641,8 +641,9 @@ static bool rest_blockhash_by_height(const std::any& context, HTTPRequest* req,
|
||||
|
||||
CBlockIndex* pblockindex = nullptr;
|
||||
{
|
||||
ChainstateManager& chainman = EnsureAnyChainman(context);
|
||||
LOCK(cs_main);
|
||||
const CChain& active_chain = EnsureAnyChainman(context).ActiveChain();
|
||||
const CChain& active_chain = chainman.ActiveChain();
|
||||
if (blockheight > active_chain.Height()) {
|
||||
return RESTERR(req, HTTP_NOT_FOUND, "Block height out of range");
|
||||
}
|
||||
|
Reference in New Issue
Block a user