Skip to content

Commit 74d0f90

Browse files
committed
Add method to remove a tx from CCoinsViewCache if it is unchanged
1 parent 4077ad2 commit 74d0f90

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/coins.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,15 @@ bool CCoinsViewCache::Flush() {
206206
return fOk;
207207
}
208208

209+
void CCoinsViewCache::Uncache(const uint256& hash)
210+
{
211+
CCoinsMap::iterator it = cacheCoins.find(hash);
212+
if (it != cacheCoins.end() && it->second.flags == 0) {
213+
cachedCoinsUsage -= it->second.coins.DynamicMemoryUsage();
214+
cacheCoins.erase(it);
215+
}
216+
}
217+
209218
unsigned int CCoinsViewCache::GetCacheSize() const {
210219
return cacheCoins.size();
211220
}

src/coins.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,12 @@ class CCoinsViewCache : public CCoinsViewBacked
437437
*/
438438
bool Flush();
439439

440+
/**
441+
* Removes the transaction with the given hash from the cache, if it is
442+
* not modified.
443+
*/
444+
void Uncache(const uint256 &txid);
445+
440446
//! Calculate the size of the cache (in number of transactions)
441447
unsigned int GetCacheSize() const;
442448

0 commit comments

Comments
 (0)