aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/blockchain.cpp
diff options
context:
space:
mode:
authorFabian Jahr <fjahr@protonmail.com>2024-03-10 16:08:11 +0100
committerFabian Jahr <fjahr@protonmail.com>2024-05-21 13:38:09 +0200
commit4d8e5edbaa94805be41ae4c8aa2f4bf7aaa276fe (patch)
tree797ac4431e942582daa98ea3f87a5ba3240e203a /src/rpc/blockchain.cpp
parentc14ed7f384075330361df636f40121cf25a066d6 (diff)
downloadbitcoin-4d8e5edbaa94805be41ae4c8aa2f4bf7aaa276fe.tar.xz
assumeutxo: Add documentation on dumptxoutset serialization format
Diffstat (limited to 'src/rpc/blockchain.cpp')
-rw-r--r--src/rpc/blockchain.cpp7
1 files changed, 7 insertions, 0 deletions
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<std::pair<uint32_t, Coin>> 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<std::pair<uint32_t, Coin>>& coins, size_t& written_coins_count) {
afile << last_hash;
WriteCompactSize(afile, coins.size());