mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-09 01:40:27 +02:00
validation: Guard the active_chainstate with cs_main
This avoids a potential race-condition where a thread is reading the ChainstateManager::m_active_chainstate pointer while another one is writing to it. There is no portable guarantee that reading/writing the pointer is thread-safe. This is also done in way that mimics ::ChainstateActive(), so the transition from that function to this method is easy. More discussion: 1. https://github.com/bitcoin/bitcoin/pull/20749#discussion_r559544027 2. https://github.com/bitcoin/bitcoin/pull/19806#discussion_r561023961 3. https://github.com/bitcoin/bitcoin/pull/19806#issuecomment-768946522 4. https://github.com/bitcoin/bitcoin/pull/19806#issuecomment-768955695
This commit is contained in:
@ -817,7 +817,7 @@ private:
|
||||
//! 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.
|
||||
CChainState* m_active_chainstate{nullptr};
|
||||
CChainState* m_active_chainstate GUARDED_BY(::cs_main) {nullptr};
|
||||
|
||||
//! If true, the assumed-valid chainstate has been fully validated
|
||||
//! by the background validation chainstate.
|
||||
|
Reference in New Issue
Block a user