diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 9504f87d8898c..8b6b85d2688d6 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -2677,6 +2677,13 @@ UniValue CreateUTXOSnapshot( unsigned int iter{0}; std::vector> 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>& coins) { afile << last_hash; WriteCompactSize(afile, coins.size()); diff --git a/src/validation.h b/src/validation.h index 71aac46f81247..8a1fbb86c040e 100644 --- a/src/validation.h +++ b/src/validation.h @@ -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,