Merge bitcoin/bitcoin#24235: validation: use stronger EXCLUSIVE_LOCKS_REQUIRED()

99de8068cd validation: use stronger EXCLUSIVE_LOCKS_REQUIRED() (Vasil Dimov)

Pull request description:

  https://github.com/bitcoin/bitcoin/pull/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.

ACKs for top commit:
  hebasto:
    ACK 99de8068cd.
  jonatack:
    ACK 99de8068cd. Tested with Debian clang version 13.0.1.  Reproduced hebasto's results. Verified that  `LoadExternalBlockFile()` needs the annotation added here.

Tree-SHA512: 59640d9ad472cdb5066ecde89cc0aff8632a351fc030f39bb43800d2c856fb1aed3576e4134212d32be161b18780f06dc5066ac71df7f7cd69e3f21f886e1542
This commit is contained in:
MarcoFalke 2022-02-08 15:53:45 +01:00
commit 280a7777d3
No known key found for this signature in database
GPG key ID: CE2B75697E69A548

View file

@ -597,7 +597,8 @@ public:
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.
@ -639,7 +640,9 @@ public:
*/
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);
@ -657,9 +660,15 @@ public:
*
* 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);