Branch data Line data Source code
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 { 22 : : //! Metadata describing a serialized version of a UTXO set from which an 23 : : //! assumeutxo Chainstate can be constructed. 24 : : class SnapshotMetadata 25 : : { 26 : : public: 27 : : //! The hash of the block that reflects the tip of the chain for the 28 : : //! UTXO set contained in this snapshot. 29 : : uint256 m_base_blockhash; 30 : : 31 : : //! The number of coins in the UTXO set contained in this snapshot. Used 32 : : //! during snapshot load to estimate progress of UTXO set reconstruction. 33 : 0 : uint64_t m_coins_count = 0; 34 : : 35 : 0 : SnapshotMetadata() { } 36 : 0 : SnapshotMetadata( 37 : : const uint256& base_blockhash, 38 : : uint64_t coins_count) : 39 : 0 : m_base_blockhash(base_blockhash), 40 : 0 : m_coins_count(coins_count) { } 41 : : 42 : 0 : SERIALIZE_METHODS(SnapshotMetadata, obj) { READWRITE(obj.m_base_blockhash, obj.m_coins_count); } 43 : : }; 44 : : 45 : : //! The file in the snapshot chainstate dir which stores the base blockhash. This is 46 : : //! needed to reconstruct snapshot chainstates on init. 47 : : //! 48 : : //! Because we only allow loading a single snapshot at a time, there will only be one 49 : : //! chainstate directory with this filename present within it. 50 : : const fs::path SNAPSHOT_BLOCKHASH_FILENAME{"base_blockhash"}; 51 : : 52 : : //! Write out the blockhash of the snapshot base block that was used to construct 53 : : //! this chainstate. This value is read in during subsequent initializations and 54 : : //! used to reconstruct snapshot-based chainstates. 55 : : bool WriteSnapshotBaseBlockhash(Chainstate& snapshot_chainstate) 56 : : EXCLUSIVE_LOCKS_REQUIRED(::cs_main); 57 : : 58 : : //! Read the blockhash of the snapshot base block that was used to construct the 59 : : //! chainstate. 60 : : std::optional<uint256> ReadSnapshotBaseBlockhash(fs::path chaindir) 61 : : EXCLUSIVE_LOCKS_REQUIRED(::cs_main); 62 : : 63 : : //! Suffix appended to the chainstate (leveldb) dir when created based upon 64 : : //! a snapshot. 65 : : constexpr std::string_view SNAPSHOT_CHAINSTATE_SUFFIX = "_snapshot"; 66 : : 67 : : 68 : : //! Return a path to the snapshot-based chainstate dir, if one exists. 69 : : std::optional<fs::path> FindSnapshotChainstateDir(const fs::path& data_dir); 70 : : 71 : : } // namespace node 72 : : 73 : : #endif // BITCOIN_NODE_UTXO_SNAPSHOT_H