diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1638,15 +1638,15 @@ const BlockHash hash(uint256S(strHash)); CValidationState state; + CBlockIndex *pblockindex; { LOCK(cs_main); - CBlockIndex *pblockindex = LookupBlockIndex(hash); + pblockindex = LookupBlockIndex(hash); if (!pblockindex) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); } - - InvalidateBlock(config, state, pblockindex); } + InvalidateBlock(config, state, pblockindex); if (state.IsValid()) { ActivateBestChain(config, state); @@ -1676,15 +1676,16 @@ const BlockHash hash(uint256S(strHash)); CValidationState state; + CBlockIndex *pblockindex; { LOCK(cs_main); if (mapBlockIndex.count(hash) == 0) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); } - CBlockIndex *pblockindex = mapBlockIndex[hash]; - ParkBlock(config, state, pblockindex); + pblockindex = mapBlockIndex[hash]; } + ParkBlock(config, state, pblockindex); if (state.IsValid()) { ActivateBestChain(config, state); diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -644,11 +644,11 @@ /** Mark a block as invalid. */ bool InvalidateBlock(const Config &config, CValidationState &state, - CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main); + CBlockIndex *pindex); /** Park a block. */ bool ParkBlock(const Config &config, CValidationState &state, - CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main); + CBlockIndex *pindex); /** Remove invalidity status from a block and its descendants. */ void ResetBlockFailureFlags(CBlockIndex *pindex) diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -169,8 +169,7 @@ bool PreciousBlock(const Config &config, CValidationState &state, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main); bool UnwindBlock(const Config &config, CValidationState &state, - CBlockIndex *pindex, bool invalidate) - EXCLUSIVE_LOCKS_REQUIRED(cs_main); + CBlockIndex *pindex, bool invalidate); void ResetBlockFailureFlags(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main); template @@ -3026,7 +3025,7 @@ bool CChainState::UnwindBlock(const Config &config, CValidationState &state, CBlockIndex *pindex, bool invalidate) { - AssertLockHeld(cs_main); + LOCK(cs_main); // We first disconnect backwards and then mark the blocks as invalid. // This prevents a case where pruned nodes may fail to invalidateblock