Skip to content

Commit 4d92b5a

Browse files
committed
rpc: reduce LOCK(cs_main) scope in GetUndoChecked and getblockstats
1 parent efd82ae commit 4d92b5a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/rpc/blockchain.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -600,16 +600,18 @@ static CBlock GetBlockChecked(BlockManager& blockman, const CBlockIndex* pblocki
600600
return block;
601601
}
602602

603-
static CBlockUndo GetUndoChecked(BlockManager& blockman, const CBlockIndex* pblockindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
603+
static CBlockUndo GetUndoChecked(BlockManager& blockman, const CBlockIndex* pblockindex)
604604
{
605-
AssertLockHeld(::cs_main);
606605
CBlockUndo blockUndo;
607606

608607
// The Genesis block does not have undo data
609608
if (pblockindex->nHeight == 0) return blockUndo;
610609

611-
if (blockman.IsBlockPruned(pblockindex)) {
612-
throw JSONRPCError(RPC_MISC_ERROR, "Undo data not available (pruned data)");
610+
{
611+
LOCK(cs_main);
612+
if (blockman.IsBlockPruned(pblockindex)) {
613+
throw JSONRPCError(RPC_MISC_ERROR, "Undo data not available (pruned data)");
614+
}
613615
}
614616

615617
if (!UndoReadFromDisk(blockUndo, pblockindex)) {
@@ -1799,7 +1801,6 @@ static RPCHelpMan getblockstats()
17991801
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
18001802
{
18011803
ChainstateManager& chainman = EnsureAnyChainman(request.context);
1802-
LOCK(cs_main);
18031804
const CBlockIndex& pindex{*CHECK_NONFATAL(ParseHashOrHeight(request.params[0], chainman))};
18041805

18051806
std::set<std::string> stats;

0 commit comments

Comments
 (0)