Skip to content

Commit 4d8e5ed

Browse files
committed
assumeutxo: Add documentation on dumptxoutset serialization format
1 parent c14ed7f commit 4d8e5ed

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/rpc/blockchain.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,6 +2702,13 @@ UniValue CreateUTXOSnapshot(
27022702
size_t written_coins_count{0};
27032703
std::vector<std::pair<uint32_t, Coin>> coins;
27042704

2705+
// To reduce space the serialization format of the snapshot avoids
2706+
// duplication of tx hashes. The code takes advantage of the guarantee by
2707+
// leveldb that keys are lexicographically sorted.
2708+
// In the coins vector we collect all coins that belong to a certain tx hash
2709+
// (key.hash) and when we have them all (key.hash != last_hash) we write
2710+
// them to file using the below lambda function.
2711+
// See also https://github.com/bitcoin/bitcoin/issues/25675
27052712
auto write_coins_to_file = [&](AutoFile& afile, const Txid& last_hash, const std::vector<std::pair<uint32_t, Coin>>& coins, size_t& written_coins_count) {
27062713
afile << last_hash;
27072714
WriteCompactSize(afile, coins.size());

src/validation.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,12 @@ class ChainstateManager
885885
CBlockIndex* m_best_invalid GUARDED_BY(::cs_main){nullptr};
886886

887887
//! Internal helper for ActivateSnapshot().
888+
//!
889+
//! De-serialization of a snapshot that is created with
890+
//! CreateUTXOSnapshot() in rpc/blockchain.cpp.
891+
//! To reduce space the serialization format of the snapshot avoids
892+
//! duplication of tx hashes. The code takes advantage of the guarantee by
893+
//! leveldb that keys are lexicographically sorted.
888894
[[nodiscard]] bool PopulateAndValidateSnapshot(
889895
Chainstate& snapshot_chainstate,
890896
AutoFile& coins_file,

0 commit comments

Comments
 (0)