diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2019-01-08 13:53:20 +0100 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2019-01-08 13:53:35 +0100 |
commit | 29a9f07743500322498592b62134d6fa3d0b1a99 (patch) | |
tree | 132684321e827a3d0b6fc06e54e8885bcf13a1dd /src/rpc/blockchain.cpp | |
parent | 1973257da0501169f9d1e1eb5c0896ac25b471f9 (diff) | |
parent | f12e1d0b5117e3688f52a25ed0170d76ecdbf233 (diff) |
Merge #12153: Avoid permanent cs_main lock in getblockheader
f12e1d0b5117e3688f52a25ed0170d76ecdbf233 rpc: Avoid permanent cs_main lock in getblockheader (João Barbosa)
Pull request description:
This PR reduces the `cs_main` lock scope in `getblockheader` RPC.
Tree-SHA512: bc51f80e15d1b32d3c7886836457f9929706b6aad9841dafce31ffca444281471b21b56192bb50de774184b9377412f815ad8d3d2439049a7e64d2e59c415767
Diffstat (limited to 'src/rpc/blockchain.cpp')
-rw-r--r-- | src/rpc/blockchain.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 4846d7cc95..315f69d46b 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -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) |