@@ -5111,7 +5111,7 @@ const AssumeutxoData* ExpectedAssumeutxo(
5111
5111
return nullptr ;
5112
5112
}
5113
5113
5114
- static bool DeleteCoinsDBFromDisk (const fs::path db_path, bool is_snapshot)
5114
+ [[nodiscard]] static bool DeleteCoinsDBFromDisk (const fs::path db_path, bool is_snapshot)
5115
5115
EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
5116
5116
{
5117
5117
AssertLockHeld (::cs_main);
@@ -5750,15 +5750,20 @@ bool IsBIP30Unspendable(const CBlockIndex& block_index)
5750
5750
(block_index.nHeight ==91812 && block_index.GetBlockHash () == uint256S (" 0x00000000000af0aed4792b1acee3d966af36cf5def14935db8de83d6f9306f2f" ));
5751
5751
}
5752
5752
5753
- util::Result< void > Chainstate::InvalidateCoinsDBOnDisk ( )
5753
+ static fs::path GetSnapshotCoinsDBPath ( Chainstate& cs) EXCLUSIVE_LOCKS_REQUIRED(::cs_main )
5754
5754
{
5755
5755
AssertLockHeld (::cs_main);
5756
5756
// Should never be called on a non-snapshot chainstate.
5757
- assert (m_from_snapshot_blockhash);
5758
- auto storage_path_maybe = this -> CoinsDB ().StoragePath ();
5757
+ assert (cs. m_from_snapshot_blockhash );
5758
+ auto storage_path_maybe = cs. CoinsDB ().StoragePath ();
5759
5759
// Should never be called with a non-existent storage path.
5760
5760
assert (storage_path_maybe);
5761
- fs::path snapshot_datadir = *storage_path_maybe;
5761
+ return *storage_path_maybe;
5762
+ }
5763
+
5764
+ util::Result<void > Chainstate::InvalidateCoinsDBOnDisk ()
5765
+ {
5766
+ fs::path snapshot_datadir = GetSnapshotCoinsDBPath (*this );
5762
5767
5763
5768
// Coins views no longer usable.
5764
5769
m_coins_views.reset ();
@@ -5789,6 +5794,23 @@ util::Result<void> Chainstate::InvalidateCoinsDBOnDisk()
5789
5794
return {};
5790
5795
}
5791
5796
5797
+ bool ChainstateManager::DeleteSnapshotChainstate ()
5798
+ {
5799
+ AssertLockHeld (::cs_main);
5800
+ Assert (m_snapshot_chainstate);
5801
+ Assert (m_ibd_chainstate);
5802
+
5803
+ fs::path snapshot_datadir = GetSnapshotCoinsDBPath (*m_snapshot_chainstate);
5804
+ if (!DeleteCoinsDBFromDisk (snapshot_datadir, /* is_snapshot=*/ true )) {
5805
+ LogPrintf (" Deletion of %s failed. Please remove it manually to continue reindexing.\n " ,
5806
+ fs::PathToString (snapshot_datadir));
5807
+ return false ;
5808
+ }
5809
+ m_active_chainstate = m_ibd_chainstate.get ();
5810
+ m_snapshot_chainstate.reset ();
5811
+ return true ;
5812
+ }
5813
+
5792
5814
const CBlockIndex* ChainstateManager::GetSnapshotBaseBlock () const
5793
5815
{
5794
5816
return m_active_chainstate ? m_active_chainstate->SnapshotBase () : nullptr ;
0 commit comments