Skip to content

Commit

Permalink
assumeutxo: Add documentation on dumptxoutset serialization format
Browse files Browse the repository at this point in the history
  • Loading branch information
fjahr committed Mar 11, 2024
1 parent 8ef27a2 commit 923ec90
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/rpc/blockchain.cpp
Expand Up @@ -2677,6 +2677,13 @@ UniValue CreateUTXOSnapshot(
unsigned int iter{0};
std::vector<std::pair<uint32_t, Coin>> coins;

// To reduce space the serialization format of the snapshot avoids
// dublication of tx hashes. The code takes advantage of the guarantee by
// leveldb that keys are lexicographically sorted.
// In the coins vector we collect all coins that belong to a certain tx hash
// (key.hash) and when we have them all (key.hash != last_hash) we write
// them to file using the below lamda function.
// See also https://github.com/bitcoin/bitcoin/issues/25675
auto write_coins_to_file = [&](AutoFile& afile, const uint256& last_hash, const std::vector<std::pair<uint32_t, Coin>>& coins) {
afile << last_hash;
WriteCompactSize(afile, coins.size());
Expand Down
6 changes: 6 additions & 0 deletions src/validation.h
Expand Up @@ -883,6 +883,12 @@ class ChainstateManager
CBlockIndex* m_best_invalid GUARDED_BY(::cs_main){nullptr};

//! Internal helper for ActivateSnapshot().
//!
//! De-serialization of a snapshot that is created with
//! CreateUTXOSnapshot() in rpc/blockchain.cpp.
//! To reduce space the serialization format of the snapshot avoids
//! dublication of tx hashes. The code takes advantage of the guarantee by
//! leveldb that keys are lexicographically sorted.
[[nodiscard]] bool PopulateAndValidateSnapshot(
Chainstate& snapshot_chainstate,
AutoFile& coins_file,
Expand Down

0 comments on commit 923ec90

Please sign in to comment.