mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
validation: add CChainState::m_disabled and ChainMan::isUsable
and remove m_snapshot_validated. This state can now be inferred by the number of isUsable chainstates. m_disabled is used to signal that a chainstate should no longer be used by validation logic; it is used as a sentinel when background validation completes or if the snapshot chainstate is found to be invalid. isUsable is a convenience method that incorporates m_disabled.
This commit is contained in:
@@ -473,6 +473,19 @@ protected:
|
||||
//! 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};
|
||||
|
||||
public:
|
||||
//! Reference to a BlockManager instance which itself is shared across all
|
||||
//! Chainstate instances.
|
||||
@@ -840,10 +853,6 @@ private:
|
||||
//! that call.
|
||||
Chainstate* m_active_chainstate GUARDED_BY(::cs_main) {nullptr};
|
||||
|
||||
//! If true, the assumed-valid chainstate has been fully validated
|
||||
//! by the background validation chainstate.
|
||||
bool m_snapshot_validated GUARDED_BY(::cs_main){false};
|
||||
|
||||
CBlockIndex* m_best_invalid GUARDED_BY(::cs_main){nullptr};
|
||||
|
||||
//! Internal helper for ActivateSnapshot().
|
||||
@@ -876,6 +885,15 @@ private:
|
||||
//! nullopt.
|
||||
std::optional<int> GetSnapshotBaseHeight() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||
|
||||
//! Return true if a chainstate is considered usable.
|
||||
//!
|
||||
//! This is false when a background validation chainstate has completed its
|
||||
//! validation of an assumed-valid chainstate, or when a snapshot
|
||||
//! chainstate has been found to be invalid.
|
||||
bool IsUsable(const Chainstate* const cs) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
|
||||
return cs && !cs->m_disabled;
|
||||
}
|
||||
|
||||
public:
|
||||
using Options = kernel::ChainstateManagerOpts;
|
||||
|
||||
@@ -987,7 +1005,10 @@ public:
|
||||
std::optional<uint256> SnapshotBlockhash() const;
|
||||
|
||||
//! Is there a snapshot in use and has it been fully validated?
|
||||
bool IsSnapshotValidated() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { return m_snapshot_validated; }
|
||||
bool IsSnapshotValidated() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
|
||||
{
|
||||
return m_snapshot_chainstate && m_ibd_chainstate && m_ibd_chainstate->m_disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process an incoming block. This only returns after the best known valid
|
||||
|
||||
Reference in New Issue
Block a user