From 74d0f902628472cd0cee66121ef0311eec201c40 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 21 Oct 2015 17:41:40 -0700 Subject: [PATCH] Add method to remove a tx from CCoinsViewCache if it is unchanged --- src/coins.cpp | 9 +++++++++ src/coins.h | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/coins.cpp b/src/coins.cpp index 723e114708..060d6b7c5d 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -206,6 +206,15 @@ bool CCoinsViewCache::Flush() { return fOk; } +void CCoinsViewCache::Uncache(const uint256& hash) +{ + CCoinsMap::iterator it = cacheCoins.find(hash); + if (it != cacheCoins.end() && it->second.flags == 0) { + cachedCoinsUsage -= it->second.coins.DynamicMemoryUsage(); + cacheCoins.erase(it); + } +} + unsigned int CCoinsViewCache::GetCacheSize() const { return cacheCoins.size(); } diff --git a/src/coins.h b/src/coins.h index d174422100..5beea711b2 100644 --- a/src/coins.h +++ b/src/coins.h @@ -437,6 +437,12 @@ public: */ bool Flush(); + /** + * Removes the transaction with the given hash from the cache, if it is + * not modified. + */ + void Uncache(const uint256 &txid); + //! Calculate the size of the cache (in number of transactions) unsigned int GetCacheSize() const;