assumeutxo: remove snapshot during -reindex{-chainstate}

Removing a snapshot chainstate from disk (and memory) is consistent with
existing reindex operations.
This commit is contained in:
James O'Beirne
2023-05-03 15:39:51 -04:00
parent c93ef43e4f
commit c711ca186f
3 changed files with 39 additions and 9 deletions

View File

@@ -5111,7 +5111,7 @@ const AssumeutxoData* ExpectedAssumeutxo(
return nullptr;
}
static bool DeleteCoinsDBFromDisk(const fs::path db_path, bool is_snapshot)
[[nodiscard]] static bool DeleteCoinsDBFromDisk(const fs::path db_path, bool is_snapshot)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
{
AssertLockHeld(::cs_main);
@@ -5750,15 +5750,20 @@ bool IsBIP30Unspendable(const CBlockIndex& block_index)
(block_index.nHeight==91812 && block_index.GetBlockHash() == uint256S("0x00000000000af0aed4792b1acee3d966af36cf5def14935db8de83d6f9306f2f"));
}
util::Result<void> Chainstate::InvalidateCoinsDBOnDisk()
static fs::path GetSnapshotCoinsDBPath(Chainstate& cs) EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
{
AssertLockHeld(::cs_main);
// Should never be called on a non-snapshot chainstate.
assert(m_from_snapshot_blockhash);
auto storage_path_maybe = this->CoinsDB().StoragePath();
assert(cs.m_from_snapshot_blockhash);
auto storage_path_maybe = cs.CoinsDB().StoragePath();
// Should never be called with a non-existent storage path.
assert(storage_path_maybe);
fs::path snapshot_datadir = *storage_path_maybe;
return *storage_path_maybe;
}
util::Result<void> Chainstate::InvalidateCoinsDBOnDisk()
{
fs::path snapshot_datadir = GetSnapshotCoinsDBPath(*this);
// Coins views no longer usable.
m_coins_views.reset();
@@ -5789,6 +5794,23 @@ util::Result<void> Chainstate::InvalidateCoinsDBOnDisk()
return {};
}
bool ChainstateManager::DeleteSnapshotChainstate()
{
AssertLockHeld(::cs_main);
Assert(m_snapshot_chainstate);
Assert(m_ibd_chainstate);
fs::path snapshot_datadir = GetSnapshotCoinsDBPath(*m_snapshot_chainstate);
if (!DeleteCoinsDBFromDisk(snapshot_datadir, /*is_snapshot=*/ true)) {
LogPrintf("Deletion of %s failed. Please remove it manually to continue reindexing.\n",
fs::PathToString(snapshot_datadir));
return false;
}
m_active_chainstate = m_ibd_chainstate.get();
m_snapshot_chainstate.reset();
return true;
}
const CBlockIndex* ChainstateManager::GetSnapshotBaseBlock() const
{
return m_active_chainstate ? m_active_chainstate->SnapshotBase() : nullptr;