12#include <validation.h>
23 const std::optional<fs::path> chaindir =
33 "[snapshot] failed to open base blockhash file for writing: %s\n",
39 if (afile.fclose() != 0) {
41 "[snapshot] failed to close base blockhash file %s after writing\n",
50 LogPrintf(
"[snapshot] cannot read base blockhash: no chainstate dir "
51 "exists at path %s\n",
59 LogPrintf(
"[snapshot] snapshot chainstate dir is malformed! no base "
60 "blockhash file exists at path %s. Try deleting %s and "
61 "calling loadtxoutset again?\n",
71 "[snapshot] failed to open base blockhash file for reading: %s\n",
75 afile >> base_blockhash;
77 if (std::fgetc(afile.Get()) != EOF) {
78 LogPrintf(
"[snapshot] warning: unexpected trailing data in %s\n",
80 }
else if (std::ferror(afile.Get())) {
81 LogPrintf(
"[snapshot] warning: i/o error reading %s\n", read_from_str);
83 return base_blockhash;
fs::path GetDataDirNet() const
Get data directory path with appended network identifier.
Non-refcounted RAII wrapper for FILE*.
std::optional< fs::path > StoragePath()
Chainstate stores and provides an API to update our local knowledge of the current best chain.
const std::optional< BlockHash > m_from_snapshot_blockhash
The blockhash which is the base of the snapshot this chainstate was created from.
CCoinsViewDB & CoinsDB() EXCLUSIVE_LOCKS_REQUIRED(
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
static path u8path(const std::string &utf8_str)
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to byte string.
FILE * fopen(const fs::path &p, const char *mode)
const fs::path SNAPSHOT_BLOCKHASH_FILENAME
The file in the snapshot chainstate dir which stores the base blockhash.
bool WriteSnapshotBaseBlockhash(Chainstate &snapshot_chainstate)
std::optional< fs::path > FindSnapshotChainstateDir()
Return a path to the snapshot-based chainstate dir, if one exists.
std::optional< BlockHash > ReadSnapshotBaseBlockhash(const fs::path &chaindir)
bool WriteSnapshotBaseBlockhash(Chainstate &snapshot_chainstate) EXCLUSIVE_LOCKS_REQUIRED(std::optional< BlockHash > ReadSnapshotBaseBlockhash(const fs::path &chaindir) EXCLUSIVE_LOCKS_REQUIRED(constexpr std::string_view SNAPSHOT_CHAINSTATE_SUFFIX
Write out the blockhash of the snapshot base block that was used to construct this chainstate.
A BlockHash is a unqiue identifier for a block.