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.
This commit is contained in:
19
src/coins.h
19
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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user