What changed, and why it matters
This commit adds a new Reset() method to an internal Bitcoin Core cache class. It simply clears in-memory data without saving anything to disk. There is no indication in the commit that this fixes a security bug or is being used to address an active vulnerability. It appears to be a routine code-cleanup or performance helper.
No security action required. Review future commits that begin calling Reset() to ensure it is invoked only in safe contexts (e.g., after failed validation or during reorg handling) where discarding unflushed cache state is intended.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch introduces CCoinsViewCache::Reset(), which clears cacheCoins, cachedCoinsUsage, and hashBlock without calling BatchWrite()/Sync() on the base view. The header comment states it is intended to let a cache instance be reused across multiple operations. No call sites are added in this commit, and no existing behavior is changed. The method is declared noexcept and is not exposed to network input directly.
Changed components
src/coins.cppsrc/coins.hCCoinsViewCacheInspect captured patch +13 / −0
diff --git a/src/coins.cpp b/src/coins.cpp
index 7f2ffc38..2afbbbff 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 6da53829..beb3bb37 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);
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.