coins: introduce CoinsViewOverlay

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

Use `PeekCoin()` to look up a Coin through a stack of `CCoinsViewCache` layers without populating parent caches. 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 the 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>
This commit is contained in:
Andrew Toth
2026-02-11 20:28:51 -05:00
parent 69b01af0eb
commit 67c0d1798e
5 changed files with 201 additions and 2 deletions

View File

@@ -374,7 +374,11 @@ FUZZ_TARGET(coinscache_sim)
[&]() { // Add a cache level (if not already at the max).
if (caches.size() != MAX_CACHES) {
// Apply to real caches.
caches.emplace_back(new CCoinsViewCache(&*caches.back(), /*deterministic=*/true));
if (provider.ConsumeBool()) {
caches.emplace_back(new CCoinsViewCache(&*caches.back(), /*deterministic=*/true));
} else {
caches.emplace_back(new CoinsViewOverlay(&*caches.back(), /*deterministic=*/true));
}
// Apply to simulation data.
sim_caches[caches.size()].Wipe();
}