Skip to content

Commit

Permalink
validation: use stronger EXCLUSIVE_LOCKS_REQUIRED()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vasild authored and rebroad committed Feb 15, 2022
1 parent c598534 commit bfda713
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@ class CChainState
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);

/** Import blocks from an external file */
void LoadExternalBlockFile(FILE* fileIn, FlatFilePos* dbp = nullptr);
void LoadExternalBlockFile(FILE* fileIn, FlatFilePos* dbp = nullptr)
EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex);

/**
* Update the on-disk chain state.
Expand Down Expand Up @@ -641,7 +642,9 @@ class CChainState
*/
bool ActivateBestChain(
BlockValidationState& state,
std::shared_ptr<const CBlock> pblock = nullptr) LOCKS_EXCLUDED(m_chainstate_mutex, cs_main);
std::shared_ptr<const CBlock> pblock = nullptr)
EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex)
LOCKS_EXCLUDED(::cs_main);

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);

Expand All @@ -659,9 +662,15 @@ class CChainState
*
* May not be called in a validationinterface callback.
*/
bool PreciousBlock(BlockValidationState& state, CBlockIndex* pindex) LOCKS_EXCLUDED(cs_main);
bool PreciousBlock(BlockValidationState& state, CBlockIndex* pindex)
EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex)
LOCKS_EXCLUDED(::cs_main);

/** Mark a block as invalid. */
bool InvalidateBlock(BlockValidationState& state, CBlockIndex* pindex) LOCKS_EXCLUDED(m_chainstate_mutex, cs_main);
bool InvalidateBlock(BlockValidationState& state, CBlockIndex* pindex)
EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex)
LOCKS_EXCLUDED(::cs_main);

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

Expand Down

0 comments on commit bfda713

Please sign in to comment.