aboutsummaryrefslogtreecommitdiff
path: root/src/validation.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/validation.h')
-rw-r--r--src/validation.h70
1 files changed, 49 insertions, 21 deletions
diff --git a/src/validation.h b/src/validation.h
index 3f0a2312b5..94a00e44a4 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -13,6 +13,7 @@
#include <arith_uint256.h>
#include <attributes.h>
#include <chain.h>
+#include <kernel/chain.h>
#include <consensus/amount.h>
#include <deploymentstatus.h>
#include <kernel/chainparams.h>
@@ -511,6 +512,12 @@ public:
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
* cache is initialized separately.
@@ -848,9 +855,6 @@ private:
//! Points to either the ibd or snapshot chainstate; indicates our
//! most-work chain.
//!
- //! Once this pointer is set to a corresponding chainstate, it will not
- //! be reset until init.cpp:Shutdown().
- //!
//! 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.
@@ -881,13 +885,6 @@ private:
/** Most recent headers presync progress update, for rate-limiting. */
std::chrono::time_point<std::chrono::steady_clock> m_last_presync_update GUARDED_BY(::cs_main) {};
- //! Returns nullptr if no snapshot has been loaded.
- const CBlockIndex* GetSnapshotBaseBlock() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
-
- //! Return the height of the base block of the snapshot in use, if one exists, else
- //! nullopt.
- std::optional<int> GetSnapshotBaseHeight() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
-
std::array<ThresholdConditionCache, VERSIONBITS_NUM_BITS> m_warningcache GUARDED_BY(::cs_main);
//! Return true if a chainstate is considered usable.
@@ -904,6 +901,10 @@ public:
explicit ChainstateManager(const util::SignalInterrupt& interrupt, Options options, node::BlockManager::Options blockman_options);
+ //! Function to restart active indexes; set dynamically to avoid a circular
+ //! dependency on `base/index.cpp`.
+ std::function<void()> restart_indexes = std::function<void()>();
+
const CChainParams& GetParams() const { return m_options.chainparams; }
const Consensus::Params& GetConsensus() const { return m_options.chainparams.GetConsensus(); }
bool ShouldCheckBlockIndex() const { return *Assert(m_options.check_block_index); }
@@ -1034,12 +1035,25 @@ public:
//! Otherwise, revert to using the ibd chainstate and shutdown.
SnapshotCompletionResult MaybeCompleteSnapshotValidation() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
+ //! Returns nullptr if no snapshot has been loaded.
+ const CBlockIndex* GetSnapshotBaseBlock() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
+
//! The most-work chain.
Chainstate& ActiveChainstate() const;
CChain& ActiveChain() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) { return ActiveChainstate().m_chain; }
int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) { return ActiveChain().Height(); }
CBlockIndex* ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) { return ActiveChain().Tip(); }
+ //! The state of a background sync (for net processing)
+ bool BackgroundSyncInProgress() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) {
+ return IsUsable(m_snapshot_chainstate.get()) && IsUsable(m_ibd_chainstate.get());
+ }
+
+ //! The tip of the background sync chain
+ const CBlockIndex* GetBackgroundSyncTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) {
+ return BackgroundSyncInProgress() ? m_ibd_chainstate->m_chain.Tip() : nullptr;
+ }
+
node::BlockMap& BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
{
AssertLockHeld(::cs_main);
@@ -1193,10 +1207,13 @@ public:
void ResetChainstates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
+ //! Remove the snapshot-based chainstate and all on-disk artifacts.
+ //! Used when reindex{-chainstate} is called during snapshot use.
+ [[nodiscard]] bool DeleteSnapshotChainstate() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
+
//! Switch the active chainstate to one based on a UTXO snapshot that was loaded
//! previously.
- Chainstate& ActivateExistingSnapshot(CTxMemPool* mempool, uint256 base_blockhash)
- EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
+ Chainstate& ActivateExistingSnapshot(uint256 base_blockhash) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
//! If we have validated a snapshot chain during this runtime, copy its
//! chainstate directory over to the main `chainstate` location, completing
@@ -1209,6 +1226,26 @@ public:
//! @sa node/chainstate:LoadChainstate()
bool ValidatedSnapshotCleanup() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
+ //! @returns the chainstate that indexes should consult when ensuring that an
+ //! index is synced with a chain where we can expect block index entries to have
+ //! BLOCK_HAVE_DATA beneath the tip.
+ //!
+ //! In other words, give us the chainstate for which we can reasonably expect
+ //! that all blocks beneath the tip have been indexed. In practice this means
+ //! when using an assumed-valid chainstate based upon a snapshot, return only the
+ //! fully validated chain.
+ Chainstate& GetChainstateForIndexing() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
+
+ //! Return the [start, end] (inclusive) of block heights we can prune.
+ //!
+ //! start > end is possible, meaning no blocks can be pruned.
+ std::pair<int, int> GetPruneRange(
+ const Chainstate& chainstate, int last_height_can_prune) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
+
+ //! Return the height of the base block of the snapshot in use, if one exists, else
+ //! nullopt.
+ std::optional<int> GetSnapshotBaseHeight() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
+
~ChainstateManager();
};
@@ -1231,15 +1268,6 @@ bool DeploymentEnabled(const ChainstateManager& chainman, DEP dep)
return DeploymentEnabled(chainman.GetConsensus(), dep);
}
-/**
- * Return the expected assumeutxo value for a given height, if one exists.
- *
- * @param[in] height Get the assumeutxo value for this height.
- *
- * @returns empty if no assumeutxo configuration exists for the given height.
- */
-const AssumeutxoData* ExpectedAssumeutxo(const int height, const CChainParams& params);
-
/** Identifies blocks that overwrote an existing coinbase output in the UTXO set (see BIP30) */
bool IsBIP30Repeat(const CBlockIndex& block_index);