AssumeUTXO snapshot loading can exceed its coin-cache budget #37062

issue l0rinc opened this issue on December 2, 2026
  1. l0rinc commented at 7:42 PM on December 2, 2026: contributor

    loadtxoutset only checks the coins cache size every 120,000 coins, assuming coins average about 41 bytes. A snapshot file with 10,000-byte scripts can push the cache about 1.2 GB over budget between two checks, even if the file is later rejected for a bad content hash.

    <details> <summary>Reproducer</summary>

    diff --git a/test/functional/feature_assumeutxo.py b/test/functional/feature_assumeutxo.py
    index fa9466f2d8..5260bb0bef 100755
    --- a/test/functional/feature_assumeutxo.py
    +++ b/test/functional/feature_assumeutxo.py
    @@ -24,12 +24,14 @@ from test_framework.messages import (
         MAGIC_BYTES,
         MAX_MONEY,
         msg_headers,
    +    ser_compact_size,
         ser_varint,
         tx_from_hex,
     )
     from test_framework.p2p import (
         P2PInterface,
     )
    +from test_framework.script import MAX_SCRIPT_SIZE
     from test_framework.test_framework import BitcoinTestFramework
     from test_framework.util import (
         assert_approx,
    @@ -66,7 +68,7 @@ class AssumeutxoTest(BitcoinTestFramework):
             self.rpc_timeout = 120
             self.extra_args = [
                 [],
    -            ["-fastprune", "-prune=1", "-blockfilterindex=1", "-coinstatsindex=1"],
    +            ["-dbcache=4", "-fastprune", "-prune=1", "-blockfilterindex=1", "-coinstatsindex=1"],
                 ["-persistmempool=0","-txindex=1", "-blockfilterindex=1", "-coinstatsindex=1"],
                 []
             ]
    @@ -136,6 +138,21 @@ class AssumeutxoTest(BitcoinTestFramework):
                     f.write(valid_snapshot_contents[43 + 8:])
                 expected_error(msg="Bad snapshot - coins left over after deserializing 298 coins." if off == -1 else "Bad snapshot format or truncated snapshot after deserializing 299 coins.")
     
    +        self.log.info("  - snapshot coins exceed the configured cache before the periodic check")
    +        coins_count = 300
    +        script = bytes(MAX_SCRIPT_SIZE)
    +        coin = ser_varint(2) + ser_varint(compress_amount(0)) + ser_varint(len(script) + 6) + script
    +        with open(bad_snapshot_path, "wb") as f:
    +            f.write(valid_snapshot_contents[:43])
    +            f.write(coins_count.to_bytes(8, "little"))
    +            for txid in range(coins_count):
    +                f.write(txid.to_bytes(32, "little"))
    +                f.write(ser_compact_size(1))
    +                f.write(ser_compact_size(0))
    +                f.write(coin)
    +        with node.assert_debug_log([], ["FlushSnapshotToDisk: flushing coins cache"]):  # TODO: Flush based on actual cache memory usage
    +            expected_error(msg="Bad snapshot content hash")
    +
             self.log.info("  - snapshot file with alternated but parsable UTXO data results in different hash")
             cases = [
                 # (content, offset, wrong_hash, custom_message)
    

    </details>

    The direct fix would be to bound cache growth by bytes (as #36633 proposed before it was closed), but given that these checks keep accumulating around snapshot parsing, I'm proposing to remove AssumeUTXO entirely in #36598 instead.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-12-03 02:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me