Bitcoin Core  24.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 <fs.h>
10 #include <kernel/cs_main.h>
11 #include <serialize.h>
12 #include <sync.h>
13 #include <uint256.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  unsigned int nchaintx) :
40  m_base_blockhash(base_blockhash),
41  m_coins_count(coins_count) { }
42 
43  SERIALIZE_METHODS(SnapshotMetadata, obj) { READWRITE(obj.m_base_blockhash, obj.m_coins_count); }
44 };
45 
51 const fs::path SNAPSHOT_BLOCKHASH_FILENAME{"base_blockhash"};
52 
56 bool WriteSnapshotBaseBlockhash(Chainstate& snapshot_chainstate)
58 
61 std::optional<uint256> ReadSnapshotBaseBlockhash(fs::path chaindir)
63 
66 constexpr std::string_view SNAPSHOT_CHAINSTATE_SUFFIX = "_snapshot";
67 
68 
70 std::optional<fs::path> FindSnapshotChainstateDir();
71 
72 } // namespace node
73 
74 #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:455
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:31
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:43
SnapshotMetadata(const uint256 &base_blockhash, uint64_t coins_count, unsigned int nchaintx)
Definition: utxo_snapshot.h:36
256-bit opaque blob.
Definition: uint256.h:105
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:51
bool WriteSnapshotBaseBlockhash(Chainstate &snapshot_chainstate)
std::optional< fs::path > FindSnapshotChainstateDir()
Return a path to the snapshot-based chainstate dir, if one exists.
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:66
#define READWRITE(...)
Definition: serialize.h:140
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49