aboutsummaryrefslogtreecommitdiff
path: root/src/rest.cpp
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2021-04-12 18:41:05 -0400
committerCarl Dong <contact@carldong.me>2021-04-14 11:13:09 -0400
commit6a3d1920209cded0dae52fb9070a3530d9a4e5fd (patch)
treee816a3b9369c123cd93cb3145477df6a885a1731 /src/rest.cpp
parent038854f31e3511e8bb6e163305cab0a96783d25b (diff)
downloadbitcoin-6a3d1920209cded0dae52fb9070a3530d9a4e5fd.tar.xz
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.
Diffstat (limited to 'src/rest.cpp')
-rw-r--r--src/rest.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/rest.cpp b/src/rest.cpp
index dd2d649ff4..eea0d67882 100644
--- a/src/rest.cpp
+++ b/src/rest.cpp
@@ -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");
}