From 4d8e5edbaa94805be41ae4c8aa2f4bf7aaa276fe Mon Sep 17 00:00:00 2001 From: Fabian Jahr Date: Sun, 10 Mar 2024 16:08:11 +0100 Subject: assumeutxo: Add documentation on dumptxoutset serialization format --- src/rpc/blockchain.cpp | 7 +++++++ src/validation.h | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 6402819ce6..cecad55aee 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -2702,6 +2702,13 @@ UniValue CreateUTXOSnapshot( size_t written_coins_count{0}; std::vector> coins; + // To reduce space the serialization format of the snapshot avoids + // duplication 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 lambda function. + // See also https://github.com/bitcoin/bitcoin/issues/25675 auto write_coins_to_file = [&](AutoFile& afile, const Txid& last_hash, const std::vector>& coins, size_t& written_coins_count) { afile << last_hash; WriteCompactSize(afile, coins.size()); diff --git a/src/validation.h b/src/validation.h index 28b045fe80..ea6b6cad7e 100644 --- a/src/validation.h +++ b/src/validation.h @@ -885,6 +885,12 @@ private: 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 + //! duplication 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, -- cgit v1.2.3