Skip to content

Commit 99de806

Browse files
committed
validation: use stronger EXCLUSIVE_LOCKS_REQUIRED()
bitcoin/bitcoin#24103 added annotations to denote that the callers of `CChainState::ActivateBestChain()` and `CChainState::InvalidateBlock()` must not own `m_chainstate_mutex` at the time of the call. Replace the added `LOCKS_EXCLUDED()` with a stronger `EXCLUSIVE_LOCKS_REQUIRED()`, see https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#negative for the difference between both.
1 parent 02e1d8d commit 99de806

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/validation.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,8 @@ class CChainState
597597
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
598598

599599
/** Import blocks from an external file */
600-
void LoadExternalBlockFile(FILE* fileIn, FlatFilePos* dbp = nullptr);
600+
void LoadExternalBlockFile(FILE* fileIn, FlatFilePos* dbp = nullptr)
601+
EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex);
601602

602603
/**
603604
* Update the on-disk chain state.
@@ -639,7 +640,9 @@ class CChainState
639640
*/
640641
bool ActivateBestChain(
641642
BlockValidationState& state,
642-
std::shared_ptr<const CBlock> pblock = nullptr) LOCKS_EXCLUDED(m_chainstate_mutex, cs_main);
643+
std::shared_ptr<const CBlock> pblock = nullptr)
644+
EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex)
645+
LOCKS_EXCLUDED(::cs_main);
643646

644647
bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, BlockValidationState& state, CBlockIndex** ppindex, bool fRequested, const FlatFilePos* dbp, bool* fNewBlock) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
645648

@@ -657,9 +660,15 @@ class CChainState
657660
*
658661
* May not be called in a validationinterface callback.
659662
*/
660-
bool PreciousBlock(BlockValidationState& state, CBlockIndex* pindex) LOCKS_EXCLUDED(cs_main);
663+
bool PreciousBlock(BlockValidationState& state, CBlockIndex* pindex)
664+
EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex)
665+
LOCKS_EXCLUDED(::cs_main);
666+
661667
/** Mark a block as invalid. */
662-
bool InvalidateBlock(BlockValidationState& state, CBlockIndex* pindex) LOCKS_EXCLUDED(m_chainstate_mutex, cs_main);
668+
bool InvalidateBlock(BlockValidationState& state, CBlockIndex* pindex)
669+
EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex)
670+
LOCKS_EXCLUDED(::cs_main);
671+
663672
/** Remove invalidity status from a block and its descendants. */
664673
void ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
665674

0 commit comments

Comments
 (0)