diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -1107,7 +1107,7 @@ //! This is especially important when, e.g., calling ActivateBestChain() //! on all chainstates because we are not able to hold ::cs_main going into //! that call. - std::unique_ptr m_ibd_chainstate; + std::unique_ptr m_ibd_chainstate GUARDED_BY(::cs_main); //! A chainstate initialized on the basis of a UTXO snapshot. If this is //! non-null, it is always our active chainstate. @@ -1118,7 +1118,7 @@ //! This is especially important when, e.g., calling ActivateBestChain() //! on all chainstates because we are not able to hold ::cs_main going into //! that call. - std::unique_ptr m_snapshot_chainstate; + std::unique_ptr m_snapshot_chainstate GUARDED_BY(::cs_main); //! Points to either the ibd or snapshot chainstate; indicates our //! most-work chain. diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -5912,7 +5912,6 @@ } std::optional ChainstateManager::SnapshotBlockhash() const { - // for m_active_chainstate access LOCK(::cs_main); if (m_active_chainstate && m_active_chainstate->m_from_snapshot_blockhash) { // If a snapshot chainstate exists, it will always be our active. @@ -5922,6 +5921,7 @@ } std::vector ChainstateManager::GetAll() { + LOCK(::cs_main); std::vector out; if (!IsSnapshotValidated() && m_ibd_chainstate) { @@ -6253,12 +6253,13 @@ } bool ChainstateManager::IsSnapshotActive() const { + LOCK(::cs_main); return m_snapshot_chainstate && - WITH_LOCK(::cs_main, return m_active_chainstate) == - m_snapshot_chainstate.get(); + m_active_chainstate == m_snapshot_chainstate.get(); } CChainState &ChainstateManager::ValidatedChainstate() const { + LOCK(::cs_main); if (m_snapshot_chainstate && IsSnapshotValidated()) { return *m_snapshot_chainstate.get(); } @@ -6267,6 +6268,7 @@ } bool ChainstateManager::IsBackgroundIBD(CChainState *chainstate) const { + LOCK(::cs_main); return (m_snapshot_chainstate && chainstate == m_ibd_chainstate.get()); } @@ -6280,12 +6282,10 @@ } void ChainstateManager::Reset() { + LOCK(::cs_main); m_ibd_chainstate.reset(); m_snapshot_chainstate.reset(); - { - LOCK(::cs_main); - m_active_chainstate = nullptr; - } + m_active_chainstate = nullptr; m_snapshot_validated = false; }