From 8dd9200fc9b0d263f8f75943ce581a925d061378 Mon Sep 17 00:00:00 2001 From: Andrew Toth Date: Sat, 24 Jan 2026 13:58:46 -0500 Subject: [PATCH] coins: add Reset on CCoinsViewCache Add a Reset() method to CCoinsViewCache that clears cacheCoins, cachedCoinsUsage, and hashBlock without flushing to the base view. Co-authored-by: l0rinc Co-authored-by: sedited --- src/coins.cpp | 7 +++++++ src/coins.h | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/coins.cpp b/src/coins.cpp index 7f2ffc38efa..2afbbbff38c 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -274,6 +274,13 @@ void CCoinsViewCache::Sync() } } +void CCoinsViewCache::Reset() noexcept +{ + cacheCoins.clear(); + cachedCoinsUsage = 0; + hashBlock.SetNull(); +} + void CCoinsViewCache::Uncache(const COutPoint& hash) { CCoinsMap::iterator it = cacheCoins.find(hash); diff --git a/src/coins.h b/src/coins.h index 6da53829996..beb3bb37a35 100644 --- a/src/coins.h +++ b/src/coins.h @@ -376,6 +376,12 @@ protected: /* Cached dynamic memory usage for the inner Coin objects. */ mutable size_t cachedCoinsUsage{0}; + /** + * Discard all modifications made to this cache without flushing to the base view. + * This can be used to efficiently reuse a cache instance across multiple operations. + */ + void Reset() noexcept; + public: CCoinsViewCache(CCoinsView *baseIn, bool deterministic = false);