aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
authorAndrew Toth <andrewstoth@gmail.com>2022-10-17 09:12:10 -0400
committerAndrew Toth <andrewstoth@gmail.com>2022-12-06 15:07:04 -0500
commit4d92b5aabaf371225cdc37a7b114adc040bf4da5 (patch)
treeb818199845d343c26859d19f3481dbd5505f32dc /src/rpc
parentefd82aec8a2dd0fca8f2597c3f84cefe057d1243 (diff)
downloadbitcoin-4d92b5aabaf371225cdc37a7b114adc040bf4da5.tar.xz
rpc: reduce LOCK(cs_main) scope in GetUndoChecked and getblockstats
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/blockchain.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index 39242ce374..784fb64d36 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -600,16 +600,18 @@ static CBlock GetBlockChecked(BlockManager& blockman, const CBlockIndex* pblocki
return block;
}
-static CBlockUndo GetUndoChecked(BlockManager& blockman, const CBlockIndex* pblockindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
+static CBlockUndo GetUndoChecked(BlockManager& blockman, const CBlockIndex* pblockindex)
{
- AssertLockHeld(::cs_main);
CBlockUndo blockUndo;
// The Genesis block does not have undo data
if (pblockindex->nHeight == 0) return blockUndo;
- if (blockman.IsBlockPruned(pblockindex)) {
- throw JSONRPCError(RPC_MISC_ERROR, "Undo data not available (pruned data)");
+ {
+ LOCK(cs_main);
+ if (blockman.IsBlockPruned(pblockindex)) {
+ throw JSONRPCError(RPC_MISC_ERROR, "Undo data not available (pruned data)");
+ }
}
if (!UndoReadFromDisk(blockUndo, pblockindex)) {
@@ -1799,7 +1801,6 @@ static RPCHelpMan getblockstats()
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
ChainstateManager& chainman = EnsureAnyChainman(request.context);
- LOCK(cs_main);
const CBlockIndex& pindex{*CHECK_NONFATAL(ParseHashOrHeight(request.params[0], chainman))};
std::set<std::string> stats;