mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 15:50:07 +01:00
refactor: Delete ChainstateManager::SnapshotBlockhash() method
SnapshotBlockhash() is only called two places outside of tests, and is used redundantly in some tests, checking the same field as other checks. Simplify by dropping the method and using the m_from_snapshot_blockhash field directly.
This commit is contained in:
@@ -4960,7 +4960,7 @@ bool ChainstateManager::LoadBlockIndex()
|
||||
AssertLockHeld(cs_main);
|
||||
// Load block index from databases
|
||||
if (m_blockman.m_blockfiles_indexed) {
|
||||
bool ret{m_blockman.LoadBlockIndexDB(SnapshotBlockhash())};
|
||||
bool ret{m_blockman.LoadBlockIndexDB(CurrentChainstate().m_from_snapshot_blockhash)};
|
||||
if (!ret) return false;
|
||||
|
||||
m_blockman.ScanAndUnlinkAlreadyPrunedFiles();
|
||||
@@ -5605,16 +5605,6 @@ double ChainstateManager::GuessVerificationProgress(const CBlockIndex* pindex) c
|
||||
return std::min<double>(pindex->m_chain_tx_count / fTxTotal, 1.0);
|
||||
}
|
||||
|
||||
std::optional<uint256> ChainstateManager::SnapshotBlockhash() const
|
||||
{
|
||||
LOCK(::cs_main);
|
||||
if (m_active_chainstate && m_active_chainstate->m_from_snapshot_blockhash) {
|
||||
// If a snapshot chainstate exists, it will always be our active.
|
||||
return m_active_chainstate->m_from_snapshot_blockhash;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::vector<Chainstate*> ChainstateManager::GetAll()
|
||||
{
|
||||
LOCK(::cs_main);
|
||||
@@ -5685,15 +5675,14 @@ util::Result<CBlockIndex*> ChainstateManager::ActivateSnapshot(
|
||||
{
|
||||
uint256 base_blockhash = metadata.m_base_blockhash;
|
||||
|
||||
if (this->SnapshotBlockhash()) {
|
||||
return util::Error{Untranslated("Can't activate a snapshot-based chainstate more than once")};
|
||||
}
|
||||
|
||||
CBlockIndex* snapshot_start_block{};
|
||||
|
||||
{
|
||||
LOCK(::cs_main);
|
||||
|
||||
if (this->CurrentChainstate().m_from_snapshot_blockhash) {
|
||||
return util::Error{Untranslated("Can't activate a snapshot-based chainstate more than once")};
|
||||
}
|
||||
if (!GetParams().AssumeutxoForBlockhash(base_blockhash).has_value()) {
|
||||
auto available_heights = GetParams().GetAvailableSnapshotHeights();
|
||||
std::string heights_formatted = util::Join(available_heights, ", ", [&](const auto& i) { return util::ToString(i); });
|
||||
|
||||
Reference in New Issue
Block a user