rpc: Avoid permanent cs_main lock in getblockheader
This commit is contained in:
parent
f7e182a973
commit
f12e1d0b51
1 changed files with 9 additions and 4 deletions
|
@ -747,15 +747,20 @@ static UniValue getblockheader(const JSONRPCRequest& request)
|
|||
+ HelpExampleRpc("getblockheader", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
uint256 hash(ParseHashV(request.params[0], "hash"));
|
||||
|
||||
bool fVerbose = true;
|
||||
if (!request.params[1].isNull())
|
||||
fVerbose = request.params[1].get_bool();
|
||||
|
||||
const CBlockIndex* pblockindex = LookupBlockIndex(hash);
|
||||
const CBlockIndex* pblockindex;
|
||||
const CBlockIndex* tip;
|
||||
{
|
||||
LOCK(cs_main);
|
||||
pblockindex = LookupBlockIndex(hash);
|
||||
tip = chainActive.Tip();
|
||||
}
|
||||
|
||||
if (!pblockindex) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
||||
}
|
||||
|
@ -768,7 +773,7 @@ static UniValue getblockheader(const JSONRPCRequest& request)
|
|||
return strHex;
|
||||
}
|
||||
|
||||
return blockheaderToJSON(chainActive.Tip(), pblockindex);
|
||||
return blockheaderToJSON(tip, pblockindex);
|
||||
}
|
||||
|
||||
static CBlock GetBlockChecked(const CBlockIndex* pblockindex)
|
||||
|
|
Loading…
Reference in a new issue