Skip to content

Commit 5ee22cd

Browse files
committed
add ChainstateManager.GetSnapshot{BaseHeight,BaseBlock}()
For use in later commits.
1 parent 73966f7 commit 5ee22cd

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/validation.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5365,3 +5365,16 @@ bool IsBIP30Unspendable(const CBlockIndex& block_index)
53655365
return (block_index.nHeight==91722 && block_index.GetBlockHash() == uint256S("0x00000000000271a2dc26e7667f8419f2e15416dc6955e5a6c6cdf3f2574dd08e")) ||
53665366
(block_index.nHeight==91812 && block_index.GetBlockHash() == uint256S("0x00000000000af0aed4792b1acee3d966af36cf5def14935db8de83d6f9306f2f"));
53675367
}
5368+
5369+
const CBlockIndex* ChainstateManager::GetSnapshotBaseBlock() const
5370+
{
5371+
const auto blockhash_op = this->SnapshotBlockhash();
5372+
if (!blockhash_op) return nullptr;
5373+
return Assert(m_blockman.LookupBlockIndex(*blockhash_op));
5374+
}
5375+
5376+
std::optional<int> ChainstateManager::GetSnapshotBaseHeight() const
5377+
{
5378+
const CBlockIndex* base = this->GetSnapshotBaseBlock();
5379+
return base ? std::make_optional(base->nHeight) : std::nullopt;
5380+
}

src/validation.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,13 @@ class ChainstateManager
869869
/** Most recent headers presync progress update, for rate-limiting. */
870870
std::chrono::time_point<std::chrono::steady_clock> m_last_presync_update GUARDED_BY(::cs_main) {};
871871

872+
//! Returns nullptr if no snapshot has been loaded.
873+
const CBlockIndex* GetSnapshotBaseBlock() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
874+
875+
//! Return the height of the base block of the snapshot in use, if one exists, else
876+
//! nullopt.
877+
std::optional<int> GetSnapshotBaseHeight() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
878+
872879
public:
873880
using Options = kernel::ChainstateManagerOpts;
874881

0 commit comments

Comments
 (0)