Problem
Review on #34124 made it clear that the new PeekCoin method is hard to distinguish from the existing GetCoin at call sites where caching does not matter.
Fix
Merge PeekCoin into GetCoin by adding a peek_only flag to the CCoinsView interface and removing the separate virtual method.
This preserves the non-caching lookup behavior in CCoinsViewCache and CoinsViewOverlay, while allowing backends without caches to ignore the flag.
Details
Tests and fuzz scaffolding now call GetCoin(..., true) only where side-effect-free reads matter, and CCoinsViewCache now shares the common result handling between peeking and caching lookups.
The post-Flush() overlay assertions use plain GetCoin() because they only check the flushed spentness and do not need to preserve parent cache state.
Context
The unclear boundary between PeekCoin and GetCoin was flagged during review by:
- Russ Yanofsky in #34165 (review), whose original suggestion (prototyped in https://github.com/bitcoin/bitcoin/commit/642fa06f0af7321d35959f599e2edf74e72c6bd9) was a different approach — making
GetCoin,PeekCoin, andHaveCoinnon-virtual public methods implemented on top of two simpler virtual hooks (LookupCoinandMutableLookupCoin), so subclasses couldn't accidentally violate the caching contract. Russ noted that a fuller solution would enforce the distinction at compile time withconst, which would in turn require splitting the coin lookup interface from the coin writing interface (droppingBatchWritefrom the "view" side into a separate "store" interface). - Anthony Towns in #34124 (comment), who sketched out the single-method
GetCoin(outpoint, peek_only)shape this PR takes (see https://github.com/ajtowns/bitcoin/commit/bff58741b76ef4ca5f4a26da29e9582a49f71d2c). This change is forward-compatible with #31132 as well.