aboutsummaryrefslogtreecommitdiff
path: root/src/coins.h
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2014-09-03 09:37:47 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2014-09-23 22:29:43 +0200
commit058b08c147a6d56b57221faa5b6fcdb83b4140b2 (patch)
treec8a44779f36d1c2b7a0fe41287eeddecb4aa4e77 /src/coins.h
parentc9d1a81ce76737a73c9706e074a4fe8440c8277e (diff)
downloadbitcoin-058b08c147a6d56b57221faa5b6fcdb83b4140b2.tar.xz
Do not keep fully spent but unwritten CCoins entries cached.
Instead of storing CCoins entries directly in CCoinsMap, store a CCoinsCacheEntry which additionally keeps track of whether a particular entry is: * dirty: potentially different from its parent view. * fresh: the parent view is known to not have a non-pruned version. This allows us to skip non-dirty cache entries when pushing batches of changes up, and to remove CCoins entries about transactions that are fully spent before the parent cache learns about them.
Diffstat (limited to 'src/coins.h')
-rw-r--r--src/coins.h19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/coins.h b/src/coins.h
index ce7a79740b..71aea79adc 100644
--- a/src/coins.h
+++ b/src/coins.h
@@ -271,7 +271,20 @@ public:
}
};
-typedef boost::unordered_map<uint256, CCoins, CCoinsKeyHasher> CCoinsMap;
+struct CCoinsCacheEntry
+{
+ CCoins coins; // The actual cached data.
+ unsigned char flags;
+
+ enum Flags {
+ DIRTY = (1 << 0), // This cache entry is potentially different from the version in the parent view.
+ FRESH = (1 << 1), // The parent view does not have this entry (or it is pruned).
+ };
+
+ CCoinsCacheEntry() : coins(), flags(0) {}
+};
+
+typedef boost::unordered_map<uint256, CCoinsCacheEntry, CCoinsKeyHasher> CCoinsMap;
struct CCoinsStats
{
@@ -343,8 +356,8 @@ private:
CCoinsModifier(CCoinsViewCache& cache_, CCoinsMap::iterator it_);
public:
- CCoins* operator->() { return &it->second; }
- CCoins& operator*() { return it->second; }
+ CCoins* operator->() { return &it->second.coins; }
+ CCoins& operator*() { return it->second.coins; }
~CCoinsModifier();
friend class CCoinsViewCache;
};