6#ifndef BITCOIN_NODE_UTXO_SNAPSHOT_H
7#define BITCOIN_NODE_UTXO_SNAPSHOT_H
15#include <validation.h>
21 {
'u',
't',
'x',
'o', 0xff}};
47 template <
typename Stream>
inline void Serialize(Stream &s)
const {
55 template <
typename Stream>
inline void Unserialize(Stream &s) {
60 throw std::ios_base::failure(
61 "Invalid UTXO set snapshot magic bytes. Please check if this "
62 "is indeed a snapshot file or if you are using an outdated "
70 throw std::ios_base::failure(
71 strprintf(
"Version of snapshot %s does not match any of the "
72 "supported versions.",
79 if (!std::equal(message.begin(), message.end(),
80 Params().DiskMagic().data())) {
82 if (metadata_network) {
83 std::string network_string{
85 throw std::ios_base::failure(
86 strprintf(
"The network of the snapshot (%s) does not match "
87 "the network of this node (%s).",
88 network_string,
Params().GetChainTypeString()));
90 throw std::ios_base::failure(
91 "This snapshot has been created for an unrecognized "
92 "network. This could be a new testnet or possibly caused "
93 "by data corruption.");
const CChainParams & Params()
Return the currently selected parameters.
std::string ChainTypeToString(ChainType chain)
const CMessageHeader::MessageMagic & DiskMagic() const
Chainstate stores and provides an API to update our local knowledge of the current best chain.
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.
std::optional< ChainType > GetNetworkForMagic(CMessageHeader::MessageMagic &message)
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.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
static constexpr std::array< uint8_t, 5 > SNAPSHOT_MAGIC_BYTES