aboutsummaryrefslogtreecommitdiff
path: root/src/validation.h
diff options
context:
space:
mode:
authorJames O'Beirne <james.obeirne@pm.me>2020-08-25 13:50:23 -0400
committerJames O'Beirne <james.obeirne@pm.me>2021-02-12 07:53:29 -0600
commitf6e2da5fb7c6406c37612c838c998078ea8d2252 (patch)
treea543e8de37216084fe3cc7a32234e873377003e5 /src/validation.h
parent7a6c46b37edb8bfa0085d202aa7e9427d5e4fceb (diff)
downloadbitcoin-f6e2da5fb7c6406c37612c838c998078ea8d2252.tar.xz
simplify ChainstateManager::SnapshotBlockhash() return semantics
Don't return null snapshotblockhash values to avoid caller complexity/confusion.
Diffstat (limited to 'src/validation.h')
-rw-r--r--src/validation.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/validation.h b/src/validation.h
index 00fc87878c..5ec5a549ce 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -11,10 +11,12 @@
#endif
#include <amount.h>
+#include <attributes.h>
#include <coins.h>
#include <consensus/validation.h>
#include <crypto/common.h> // for ReadLE64
#include <fs.h>
+#include <node/utxo_snapshot.h>
#include <optional.h>
#include <policy/feerate.h>
#include <protocol.h> // For CMessageHeader::MessageStartChars
@@ -870,6 +872,12 @@ private:
//! by the background validation chainstate.
bool m_snapshot_validated{false};
+ //! Internal helper for ActivateSnapshot().
+ [[nodiscard]] bool PopulateAndValidateSnapshot(
+ CChainState& snapshot_chainstate,
+ CAutoFile& coins_file,
+ const SnapshotMetadata& metadata);
+
// For access to m_active_chainstate.
friend CChainState& ChainstateActive();
friend CChain& ChainActive();
@@ -900,6 +908,22 @@ public:
//! Get all chainstates currently being used.
std::vector<CChainState*> GetAll();
+ //! Construct and activate a Chainstate on the basis of UTXO snapshot data.
+ //!
+ //! Steps:
+ //!
+ //! - Initialize an unused CChainState.
+ //! - Load its `CoinsViews` contents from `coins_file`.
+ //! - Verify that the hash of the resulting coinsdb matches the expected hash
+ //! per assumeutxo chain parameters.
+ //! - Wait for our headers chain to include the base block of the snapshot.
+ //! - "Fast forward" the tip of the new chainstate to the base of the snapshot,
+ //! faking nTx* block index data along the way.
+ //! - Move the new chainstate to `m_snapshot_chainstate` and make it our
+ //! ChainstateActive().
+ [[nodiscard]] bool ActivateSnapshot(
+ CAutoFile& coins_file, const SnapshotMetadata& metadata, bool in_memory);
+
//! The most-work chain.
CChainState& ActiveChainstate() const;
CChain& ActiveChain() const { return ActiveChainstate().m_chain; }