Skip to content

Commit 9b1ff5c

Browse files
committed
Call InvalidateBlock without cs_main held
1 parent 241b2c7 commit 9b1ff5c

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/rpc/blockchain.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,15 +1583,15 @@ static UniValue invalidateblock(const JSONRPCRequest& request)
15831583
uint256 hash(ParseHashV(request.params[0], "blockhash"));
15841584
CValidationState state;
15851585

1586+
CBlockIndex* pblockindex;
15861587
{
15871588
LOCK(cs_main);
1588-
CBlockIndex* pblockindex = LookupBlockIndex(hash);
1589+
pblockindex = LookupBlockIndex(hash);
15891590
if (!pblockindex) {
15901591
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
15911592
}
1592-
1593-
InvalidateBlock(state, Params(), pblockindex);
15941593
}
1594+
InvalidateBlock(state, Params(), pblockindex);
15951595

15961596
if (state.IsValid()) {
15971597
ActivateBestChain(state, Params());

src/validation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class CChainState {
177177

178178
// Manual block validity manipulation:
179179
bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex* pindex) LOCKS_EXCLUDED(cs_main);
180-
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
180+
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex);
181181
void ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
182182

183183
bool ReplayBlocks(const CChainParams& params, CCoinsView* view);
@@ -2789,7 +2789,7 @@ bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIn
27892789

27902790
bool CChainState::InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex *pindex)
27912791
{
2792-
AssertLockHeld(cs_main);
2792+
LOCK(cs_main);
27932793

27942794
// We first disconnect backwards and then mark the blocks as invalid.
27952795
// This prevents a case where pruned nodes may fail to invalidateblock

src/validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& loc
448448
bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main);
449449

450450
/** Mark a block as invalid. */
451-
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
451+
bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex);
452452

453453
/** Remove invalidity status from a block and its descendants. */
454454
void ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);

0 commit comments

Comments
 (0)