Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/node/chainstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <deploymentstatus.h>
#include <node/blockstorage.h>
#include <node/caches.h>
#include <node/utxo_snapshot.h>
#include <sync.h>
#include <threadsafety.h>
#include <tinyformat.h>
Expand Down Expand Up @@ -39,9 +40,12 @@ namespace node {
static bool RecoverSnapshotCleanup(CEvoDB& evodb, const fs::path& data_dir, bilingual_str& error)
{
const fs::path normal{data_dir / "chainstate"};
const fs::path snapshot{data_dir / "chainstate_snapshot"};
const fs::path to_delete{data_dir / "chainstate_todelete"};
const fs::path invalid{data_dir / "chainstate_snapshot_INVALID"};
fs::path snapshot{normal};
snapshot += SNAPSHOT_CHAINSTATE_SUFFIX;
fs::path to_delete{normal};
to_delete += SNAPSHOT_TODELETE_SUFFIX;
fs::path invalid{snapshot};
invalid += SNAPSHOT_INVALID_SUFFIX;

uint256 snapshot_tip;
const bool has_snapshot_tip{evodb.ReadBestBlock(EvoDbIdentity::SNAPSHOT, snapshot_tip)};
Expand Down
8 changes: 8 additions & 0 deletions src/node/utxo_snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ std::optional<uint256> ReadSnapshotBaseBlockhash(fs::path chaindir)
//! a snapshot.
constexpr std::string_view SNAPSHOT_CHAINSTATE_SUFFIX = "_snapshot";

//! Suffix appended to the snapshot chainstate dir when the snapshot fails
//! validation and the directory is set aside for later inspection.
constexpr std::string_view SNAPSHOT_INVALID_SUFFIX = "_INVALID";

//! Suffix appended to the background chainstate dir while a fully validated
//! snapshot chainstate is moved into its place.
constexpr std::string_view SNAPSHOT_TODELETE_SUFFIX = "_todelete";


//! Return a path to the snapshot-based chainstate dir, if one exists.
std::optional<fs::path> FindSnapshotChainstateDir();
Expand Down
10 changes: 6 additions & 4 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3848,9 +3848,10 @@ void Chainstate::ResetBlockFailureFlags(CBlockIndex *pindex, bool ignore_chainlo

// Failure flags and m_best_invalid are shared by all chainstates, so
// candidate admission must be recomputed for all of them as well.
const auto chainstates{m_chainman.GetAll()};
for (CBlockIndex* reconsidered : reconsidered_blocks) {
if (!reconsidered->IsValid(BLOCK_VALID_TRANSACTIONS) || !reconsidered->HaveTxsDownloaded()) continue;
for (Chainstate* chainstate : m_chainman.GetAll()) {
for (Chainstate* chainstate : chainstates) {
chainstate->TryAddBlockIndexCandidate(reconsidered);
}
}
Expand Down Expand Up @@ -6096,7 +6097,6 @@ SnapshotCompletionResult ChainstateManager::MaybeCompleteSnapshotValidation(
int curr_height = m_ibd_chainstate->m_chain.Height();

assert(snapshot_base_height == curr_height);
assert(snapshot_base_height == index_new.nHeight);
assert(this->IsUsable(m_snapshot_chainstate.get()));
assert(this->GetAll().size() == 2);

Expand Down Expand Up @@ -6404,7 +6404,8 @@ util::Result<void> Chainstate::InvalidateCoinsDBOnDisk()
// Coins views no longer usable.
m_coins_views.reset();

auto invalid_path = snapshot_datadir + "_INVALID";
fs::path invalid_path{snapshot_datadir};
invalid_path += node::SNAPSHOT_INVALID_SUFFIX;
std::string dbpath = fs::PathToString(snapshot_datadir);
std::string target = fs::PathToString(invalid_path);
LogPrintf("[snapshot] renaming snapshot datadir %s to %s\n", dbpath, target);
Expand Down Expand Up @@ -6486,7 +6487,8 @@ bool ChainstateManager::ValidatedSnapshotCleanup()
LogPrintf("[snapshot] deleting background chainstate directory (now unnecessary) (%s)\n",
fs::PathToString(ibd_chainstate_path));

fs::path tmp_old{ibd_chainstate_path + "_todelete"};
fs::path tmp_old{ibd_chainstate_path};
tmp_old += node::SNAPSHOT_TODELETE_SUFFIX;

auto rename_failed_abort = [](
fs::path p_old,
Expand Down
Loading