coins: add PeekCoin()

Introduce a helper to look up a Coin through a stack of CCoinsViewCache layers without populating parent caches.

This is useful for ephemeral views (e.g. during ConnectBlock) that want to avoid polluting CoinsTip() when validating invalid blocks.

Co-authored-by: l0rinc <pap.lorinc@gmail.com>
Co-authored-by: Pieter Wuille <pieter@wuille.net>
Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
This commit is contained in:
Andrew Toth
2025-12-24 09:00:10 +02:00
parent 6750744eb3
commit 69b01af0eb
4 changed files with 48 additions and 1 deletions

View File

@@ -257,7 +257,9 @@ FUZZ_TARGET(coinscache_sim)
// Look up in simulation data.
auto sim = lookup(outpointidx);
// Look up in real caches.
auto realcoin = caches.back()->GetCoin(data.outpoints[outpointidx]);
auto realcoin = provider.ConsumeBool() ?
caches.back()->PeekCoin(data.outpoints[outpointidx]) :
caches.back()->GetCoin(data.outpoints[outpointidx]);
// Compare results.
if (!sim.has_value()) {
assert(!realcoin);