coins: don’t mutate main cache when connecting block #34165

pull andrewtoth wants to merge 1 commits into bitcoin:master from andrewtoth:dont-mutate-cache changing 7 files +210 −3
  1. andrewtoth commented at 8:32 pm on December 28, 2025: contributor

    This is a slightly modified version of the second commit of #31132, which can be merged as an independent change. It has a small benefit on its own, but will help in moving the parent PR forward.

    Introduce CoinsViewCacheNonMutating, a CCoinsViewCache subclass that reads coins without mutating the underlying cache via FetchCoin().

    Add FetchCoinWithoutMutating() which walks up the cache hierarchy using only find() operations, then falls back to the base view’s GetCoin(). This prevents the main cache from caching inputs pulled from disk for a block that has not yet been fully validated. Once Flush() is called on m_connect_block_view, these inputs will be added as spent to coinsCache in the main cache via BatchWrite().

    This is the foundation for async input fetching, where worker threads must not mutate shared state.

  2. coins: don't mutate main cache when connecting block
    Introduce `CoinsViewCacheNonMutating`, a `CCoinsViewCache` subclass that reads
    coins without mutating the underlying cache via `FetchCoin()`.
    
    Add `FetchCoinWithoutMutating()` which walks up the cache hierarchy using only
    `find()` operations, then falls back to the `base` view's `GetCoin()`. This
    prevents the main cache from caching inputs pulled from disk for a block that
    has not yet been fully validated. Once `Flush()` is called on
    `m_connect_block_view`, these inputs will be added as spent to `coinsCache` in
    the main cache via `BatchWrite()`.
    
    This is the foundation for async input fetching, where worker threads must not
    mutate shared state.
    
    Co-authored-by: l0rinc <pap.lorinc@gmail.com>
    9739ce6b10
  3. DrahtBot added the label UTXO Db and Indexes on Dec 28, 2025
  4. DrahtBot commented at 8:32 pm on December 28, 2025: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34165.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.


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: 2025-12-29 00:13 UTC

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