Repository: bitcoin/bitcoin
File: src/validation.h (C/C++)

Code before:
    Mutex m_chainstate_mutex;

    //! Optional mempool that is kept in sync with the chain.
    //! Only the active chainstate has a mempool.
    CTxMemPool* m_mempool;

    //! Manages the UTXO set, which is a reflection of the contents of `m_chain`.
    std::unique_ptr<CoinsViews> m_coins_views;

    //! This toggle exists for use when doing background validation for UTXO
    //! snapshots.
    //!
    //! In the expected case, it is set once the background validation chain reaches the
    //! same height as the base of the snapshot and its UTXO set is found to hash to
    //! the expected assumeutxo value. It signals that we should no longer connect
    //! blocks to the background chainstate. When set on the background validation
    //! chainstate, it signifies that we have fully validated the snapshot chainstate.
    //!
    //! In the unlikely case that the snapshot chainstate is found to be invalid, this
    //! is set to true on the snapshot chainstate.
    bool m_disabled GUARDED_BY(::cs_main) {false};

    //! Cached result of LookupBlockIndex(*m_from_snapshot_blockhash)
    mutable const CBlockIndex* m_cached_snapshot_base GUARDED_BY(::cs_main){nullptr};

    std::atomic_bool m_prev_script_checks_logged{true};

public:
    //! Reference to a BlockManager instance which itself is shared across all
    //! Chainstate instances.
    node::BlockManager& m_blockman;

    //! The chainstate manager that owns this chainstate. The reference is
    //! necessary so that this instance can check whether it is the active
    //! chainstate within deeply nested method calls.
    ChainstateManager& m_chainman;

    explicit Chainstate(
        CTxMemPool* mempool,
        node::BlockManager& blockman,
        ChainstateManager& chainman,
        std::optional<uint256> from_snapshot_blockhash = std::nullopt);

    //! Return the current role of the chainstate. See `ChainstateManager`
    //! documentation for a description of the different types of chainstates.
    //!
    //! @sa ChainstateRole
    ChainstateRole GetRole() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);

    /**
     * Initialize the CoinsViews UTXO set database management data structures. The in-memory

Review comment (suggestion):
https://github.com/bitcoin/bitcoin/pull/33336/commits/64ba2821b5a55aa6d51fbb7a16470d4f7c41c92e:
I believe you now need to add `GUARDED_BY(::cs_main)` here to use Clang's Thread Safety Analysis

Code after:
    Mutex m_chainstate_mutex;

    //! Optional mempool that is kept in sync with the chain.
    //! Only the active chainstate has a mempool.
    CTxMemPool* m_mempool;

    //! Manages the UTXO set, which is a reflection of the contents of `m_chain`.
    std::unique_ptr<CoinsViews> m_coins_views;

    //! This toggle exists for use when doing background validation for UTXO
    //! snapshots.
    //!
    //! In the expected case, it is set once the background validation chain reaches the
    //! same height as the base of the snapshot and its UTXO set is found to hash to
    //! the expected assumeutxo value. It signals that we should no longer connect
    //! blocks to the background chainstate. When set on the background validation
    //! chainstate, it signifies that we have fully validated the snapshot chainstate.
    //!
    //! In the unlikely case that the snapshot chainstate is found to be invalid, this
    //! is set to true on the snapshot chainstate.
    bool m_disabled GUARDED_BY(::cs_main) {false};

    //! Cached result of LookupBlockIndex(*m_from_snapshot_blockhash)
    mutable const CBlockIndex* m_cached_snapshot_base GUARDED_BY(::cs_main){nullptr};

    std::optional<const char*> m_last_script_check_reason_logged GUARDED_BY(::cs_main){};

public:
    //! Reference to a BlockManager instance which itself is shared across all
    //! Chainstate instances.
    node::BlockManager& m_blockman;

    //! The chainstate manager that owns this chainstate. The reference is
    //! necessary so that this instance can check whether it is the active
    //! chainstate within deeply nested method calls.
    ChainstateManager& m_chainman;

    explicit Chainstate(
        CTxMemPool* mempool,
        node::BlockManager& blockman,
        ChainstateManager& chainman,
        std::optional<uint256> from_snapshot_blockhash = std::nullopt);

    //! Return the current role of the chainstate. See `ChainstateManager`
    //! documentation for a description of the different types of chainstates.
    //!
    //! @sa ChainstateRole
    ChainstateRole GetRole() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);

    /**
     * Initialize the CoinsViews UTXO set database management data structures. The in-memory