@@ -579,18 +579,20 @@ static RPCHelpMan getblockheader()
579
579
};
580
580
}
581
581
582
- static CBlock GetBlockChecked (BlockManager& blockman, const CBlockIndex* pblockindex) EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
582
+ static CBlock GetBlockChecked (BlockManager& blockman, const CBlockIndex* pblockindex)
583
583
{
584
- AssertLockHeld (::cs_main);
585
584
CBlock block;
586
- if (blockman.IsBlockPruned (pblockindex)) {
587
- throw JSONRPCError (RPC_MISC_ERROR, " Block not available (pruned data)" );
585
+ {
586
+ LOCK (cs_main);
587
+ if (blockman.IsBlockPruned (pblockindex)) {
588
+ throw JSONRPCError (RPC_MISC_ERROR, " Block not available (pruned data)" );
589
+ }
588
590
}
589
591
590
592
if (!ReadBlockFromDisk (block, pblockindex, Params ().GetConsensus ())) {
591
593
// Block not found on disk. This could be because we have the block
592
594
// header in our index but not yet have the block or did not accept the
593
- // block.
595
+ // block. Or if the block was pruned right after we released the lock above.
594
596
throw JSONRPCError (RPC_MISC_ERROR, " Block not found on disk" );
595
597
}
596
598
@@ -721,7 +723,6 @@ static RPCHelpMan getblock()
721
723
}
722
724
}
723
725
724
- CBlock block;
725
726
const CBlockIndex* pblockindex;
726
727
const CBlockIndex* tip;
727
728
ChainstateManager& chainman = EnsureAnyChainman (request.context );
@@ -733,10 +734,10 @@ static RPCHelpMan getblock()
733
734
if (!pblockindex) {
734
735
throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Block not found" );
735
736
}
736
-
737
- block = GetBlockChecked (chainman.m_blockman , pblockindex);
738
737
}
739
738
739
+ const CBlock block{GetBlockChecked (chainman.m_blockman , pblockindex)};
740
+
740
741
if (verbosity <= 0 )
741
742
{
742
743
CDataStream ssBlock (SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags ());
0 commit comments