Bitcoin Core  27.99.0
P2P Digital Currency
utxo_snapshot.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2022 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_NODE_UTXO_SNAPSHOT_H
7 #define BITCOIN_NODE_UTXO_SNAPSHOT_H
8 
9 #include <kernel/cs_main.h>
10 #include <serialize.h>
11 #include <sync.h>
12 #include <uint256.h>
13 #include <util/fs.h>
14 
15 #include <cstdint>
16 #include <optional>
17 #include <string_view>
18 
19 class Chainstate;
20 
21 namespace node {
25 {
26 public:
30 
33  uint64_t m_coins_count = 0;
34 
37  const uint256& base_blockhash,
38  uint64_t coins_count) :
39  m_base_blockhash(base_blockhash),
40  m_coins_count(coins_count) { }
41 
42  SERIALIZE_METHODS(SnapshotMetadata, obj) { READWRITE(obj.m_base_blockhash, obj.m_coins_count); }
43 };
44 
50 const fs::path SNAPSHOT_BLOCKHASH_FILENAME{"base_blockhash"};
51 
55 bool WriteSnapshotBaseBlockhash(Chainstate& snapshot_chainstate)
57 
60 std::optional<uint256> ReadSnapshotBaseBlockhash(fs::path chaindir)
62 
65 constexpr std::string_view SNAPSHOT_CHAINSTATE_SUFFIX = "_snapshot";
66 
67 
69 std::optional<fs::path> FindSnapshotChainstateDir(const fs::path& data_dir);
70 
71 } // namespace node
72 
73 #endif // BITCOIN_NODE_UTXO_SNAPSHOT_H
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:490
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:33
Metadata describing a serialized version of a UTXO set from which an assumeutxo Chainstate can be con...
Definition: utxo_snapshot.h:25
uint256 m_base_blockhash
The hash of the block that reflects the tip of the chain for the UTXO set contained in this snapshot.
Definition: utxo_snapshot.h:29
uint64_t m_coins_count
The number of coins in the UTXO set contained in this snapshot.
Definition: utxo_snapshot.h:33
SERIALIZE_METHODS(SnapshotMetadata, obj)
Definition: utxo_snapshot.h:42
SnapshotMetadata(const uint256 &base_blockhash, uint64_t coins_count)
Definition: utxo_snapshot.h:36
256-bit opaque blob.
Definition: uint256.h:106
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:8
Definition: init.h:25
const fs::path SNAPSHOT_BLOCKHASH_FILENAME
The file in the snapshot chainstate dir which stores the base blockhash.
Definition: utxo_snapshot.h:50
bool WriteSnapshotBaseBlockhash(Chainstate &snapshot_chainstate)
std::optional< uint256 > ReadSnapshotBaseBlockhash(fs::path chaindir)
bool WriteSnapshotBaseBlockhash(Chainstate &snapshot_chainstate) EXCLUSIVE_LOCKS_REQUIRED(std::optional< uint256 > constexpr ReadSnapshotBaseBlockhash(fs::path chaindir) EXCLUSIVE_LOCKS_REQUIRED(std::string_view SNAPSHOT_CHAINSTATE_SUFFIX
Write out the blockhash of the snapshot base block that was used to construct this chainstate.
Definition: utxo_snapshot.h:65
std::optional< fs::path > FindSnapshotChainstateDir(const fs::path &data_dir)
Return a path to the snapshot-based chainstate dir, if one exists.
#define READWRITE(...)
Definition: serialize.h:156
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49