From 5ee22cdafd2562bcb8bf0ae6025e4b53c826382d Mon Sep 17 00:00:00 2001 From: James O'Beirne Date: Thu, 28 Oct 2021 16:59:18 -0400 Subject: [PATCH] add ChainstateManager.GetSnapshot{BaseHeight,BaseBlock}() For use in later commits. --- src/validation.cpp | 13 +++++++++++++ src/validation.h | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/src/validation.cpp b/src/validation.cpp index f0ffb748dd6..70ea99e6df0 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -5365,3 +5365,16 @@ bool IsBIP30Unspendable(const CBlockIndex& block_index) return (block_index.nHeight==91722 && block_index.GetBlockHash() == uint256S("0x00000000000271a2dc26e7667f8419f2e15416dc6955e5a6c6cdf3f2574dd08e")) || (block_index.nHeight==91812 && block_index.GetBlockHash() == uint256S("0x00000000000af0aed4792b1acee3d966af36cf5def14935db8de83d6f9306f2f")); } + +const CBlockIndex* ChainstateManager::GetSnapshotBaseBlock() const +{ + const auto blockhash_op = this->SnapshotBlockhash(); + if (!blockhash_op) return nullptr; + return Assert(m_blockman.LookupBlockIndex(*blockhash_op)); +} + +std::optional ChainstateManager::GetSnapshotBaseHeight() const +{ + const CBlockIndex* base = this->GetSnapshotBaseBlock(); + return base ? std::make_optional(base->nHeight) : std::nullopt; +} diff --git a/src/validation.h b/src/validation.h index 7170467b006..6d4959c44d1 100644 --- a/src/validation.h +++ b/src/validation.h @@ -869,6 +869,13 @@ private: /** Most recent headers presync progress update, for rate-limiting. */ std::chrono::time_point 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 GetSnapshotBaseHeight() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main); + public: using Options = kernel::ChainstateManagerOpts;