From 67cff8bec9094e968f36d351fb2e38c9bf563757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Fri, 18 Apr 2025 22:02:08 +0200 Subject: [PATCH] refactor: assert newly-created parent cache entry has zero memory usage During `BatchWrite`, the parent entry is created under a guard that guarantees insertion, so the new `Coin` is default-constructed and empty. Assert this invariant to document why there is no `cachedCoinsUsage` decrement before the assignment at this site. Co-authored-by: Andrew Toth --- src/coins.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coins.cpp b/src/coins.cpp index 24a102b0bc1..59c7d67c445 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -195,6 +195,7 @@ bool CCoinsViewCache::BatchWrite(CoinsViewCacheCursor& cursor, const uint256 &ha // and mark it as dirty. itUs = cacheCoins.try_emplace(it->first).first; CCoinsCacheEntry& entry{itUs->second}; + assert(entry.coin.DynamicMemoryUsage() == 0); if (cursor.WillErase(*it)) { // Since this entry will be erased, // we can move the coin into us instead of copying it