Bitcoin ABC 0.30.5
P2P Digital Currency
utxo_snapshot.h
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-2019 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
10#include <serialize.h>
11#include <util/fs.h>
12#include <validation.h>
13
14#include <optional>
15
16struct BlockHash;
17
18namespace node {
22public:
26
29 uint64_t m_coins_count = 0;
30
32 SnapshotMetadata(const BlockHash &base_blockhash, uint64_t coins_count,
33 uint64_t nchaintx)
34 : m_base_blockhash(base_blockhash), m_coins_count(coins_count) {}
35
37 READWRITE(obj.m_base_blockhash, obj.m_coins_count);
38 }
39};
40
46const fs::path SNAPSHOT_BLOCKHASH_FILENAME{"base_blockhash"};
47
51bool WriteSnapshotBaseBlockhash(Chainstate &snapshot_chainstate)
53
56std::optional<BlockHash> ReadSnapshotBaseBlockhash(const fs::path &chaindir)
58
61constexpr std::string_view SNAPSHOT_CHAINSTATE_SUFFIX = "_snapshot";
62
64std::optional<fs::path> FindSnapshotChainstateDir();
65
66} // namespace node
67
68#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:699
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:30
Metadata describing a serialized version of a UTXO set from which an assumeutxo Chainstate can be con...
Definition: utxo_snapshot.h:21
SnapshotMetadata(const BlockHash &base_blockhash, uint64_t coins_count, uint64_t nchaintx)
Definition: utxo_snapshot.h:32
uint64_t m_coins_count
The number of coins in the UTXO set contained in this snapshot.
Definition: utxo_snapshot.h:29
BlockHash 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:25
SERIALIZE_METHODS(SnapshotMetadata, obj)
Definition: utxo_snapshot.h:36
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:7
Definition: init.h:28
const fs::path SNAPSHOT_BLOCKHASH_FILENAME
The file in the snapshot chainstate dir which stores the base blockhash.
Definition: utxo_snapshot.h:46
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.
Definition: utxo_snapshot.h:61
#define READWRITE(...)
Definition: serialize.h:166
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56