Bitcoin ABC 0.30.7
P2P Digital Currency
|
CCoinsView that adds a memory cache for transactions to another CCoinsView. More...
#include <coins.h>
Public Member Functions | |
CCoinsViewCache (CCoinsView *baseIn, bool deterministic=false) | |
CCoinsViewCache (const CCoinsViewCache &)=delete | |
By deleting the copy constructor, we prevent accidentally using it when one intends to create a cache on top of a base cache. More... | |
bool | GetCoin (const COutPoint &outpoint, Coin &coin) const override |
Retrieve the Coin (unspent transaction output) for a given outpoint. More... | |
bool | HaveCoin (const COutPoint &outpoint) const override |
Just check whether a given outpoint is unspent. More... | |
BlockHash | GetBestBlock () const override |
Retrieve the block hash whose state this CCoinsView currently represents. More... | |
void | SetBestBlock (const BlockHash &hashBlock) |
bool | BatchWrite (CCoinsMap &mapCoins, const BlockHash &hashBlock, bool erase=true) override |
Do a bulk modification (multiple Coin changes + BestBlock change). More... | |
CCoinsViewCursor * | Cursor () const override |
Get a cursor to iterate over the whole state. More... | |
bool | HaveCoinInCache (const COutPoint &outpoint) const |
Check if we have the given utxo already loaded in this cache. More... | |
const Coin & | AccessCoin (const COutPoint &output) const |
Return a reference to Coin in the cache, or coinEmpty if not found. More... | |
void | AddCoin (const COutPoint &outpoint, Coin coin, bool possible_overwrite) |
Add a coin. More... | |
void | EmplaceCoinInternalDANGER (COutPoint &&outpoint, Coin &&coin) |
Emplace a coin into cacheCoins without performing any checks, marking the emplaced coin as dirty. More... | |
bool | SpendCoin (const COutPoint &outpoint, Coin *moveto=nullptr) |
Spend a coin. More... | |
bool | Flush () |
Push the modifications applied to this cache to its base and wipe local state. More... | |
bool | Sync () |
Push the modifications applied to this cache to its base while retaining the contents of this cache (except for spent coins, which we erase). More... | |
void | Uncache (const COutPoint &outpoint) |
Removes the UTXO with the given outpoint from the cache, if it is not modified. More... | |
unsigned int | GetCacheSize () const |
Calculate the size of the cache (in number of transaction outputs) More... | |
size_t | DynamicMemoryUsage () const |
Calculate the size of the cache (in bytes) More... | |
bool | HaveInputs (const CTransaction &tx) const |
Check whether all prevouts of the transaction are present in the UTXO set represented by this view. More... | |
void | ReallocateCache () |
Force a reallocation of the cache map. More... | |
void | SanityCheck () const |
Run an internal sanity check on the cache data structure. More... | |
Public Member Functions inherited from CCoinsViewBacked | |
CCoinsViewBacked (CCoinsView *viewIn) | |
bool | GetCoin (const COutPoint &outpoint, Coin &coin) const override |
Retrieve the Coin (unspent transaction output) for a given outpoint. More... | |
bool | HaveCoin (const COutPoint &outpoint) const override |
Just check whether a given outpoint is unspent. More... | |
BlockHash | GetBestBlock () const override |
Retrieve the block hash whose state this CCoinsView currently represents. More... | |
std::vector< BlockHash > | GetHeadBlocks () const override |
Retrieve the range of blocks that may have been only partially written. More... | |
void | SetBackend (CCoinsView &viewIn) |
bool | BatchWrite (CCoinsMap &mapCoins, const BlockHash &hashBlock, bool erase=true) override |
Do a bulk modification (multiple Coin changes + BestBlock change). More... | |
CCoinsViewCursor * | Cursor () const override |
Get a cursor to iterate over the whole state. More... | |
size_t | EstimateSize () const override |
Estimate database size (0 if not implemented) More... | |
Public Member Functions inherited from CCoinsView | |
virtual bool | GetCoin (const COutPoint &outpoint, Coin &coin) const |
Retrieve the Coin (unspent transaction output) for a given outpoint. More... | |
virtual bool | HaveCoin (const COutPoint &outpoint) const |
Just check whether a given outpoint is unspent. More... | |
virtual BlockHash | GetBestBlock () const |
Retrieve the block hash whose state this CCoinsView currently represents. More... | |
virtual std::vector< BlockHash > | GetHeadBlocks () const |
Retrieve the range of blocks that may have been only partially written. More... | |
virtual bool | BatchWrite (CCoinsMap &mapCoins, const BlockHash &hashBlock, bool erase=true) |
Do a bulk modification (multiple Coin changes + BestBlock change). More... | |
virtual CCoinsViewCursor * | Cursor () const |
Get a cursor to iterate over the whole state. More... | |
virtual | ~CCoinsView () |
As we use CCoinsViews polymorphically, have a virtual destructor. More... | |
virtual size_t | EstimateSize () const |
Estimate database size (0 if not implemented) More... | |
Protected Attributes | |
BlockHash | hashBlock |
Make mutable so that we can "fill the cache" even from Get-methods declared as "const". More... | |
CCoinsMapMemoryResource | m_cache_coins_memory_resource {} |
CCoinsMap | cacheCoins |
size_t | cachedCoinsUsage |
Protected Attributes inherited from CCoinsViewBacked | |
CCoinsView * | base |
Private Member Functions | |
CCoinsMap::iterator | FetchCoin (const COutPoint &outpoint) const |
Private Attributes | |
const bool | m_deterministic |
CCoinsView that adds a memory cache for transactions to another CCoinsView.
CCoinsViewCache::CCoinsViewCache | ( | CCoinsView * | baseIn, |
bool | deterministic = false |
||
) |
|
delete |
By deleting the copy constructor, we prevent accidentally using it when one intends to create a cache on top of a base cache.
Return a reference to Coin in the cache, or coinEmpty if not found.
This is more efficient than GetCoin.
Generally, do not hold the reference returned for more than a short scope. While the current implementation allows for modifications to the contents of the cache while holding the reference, this behavior should not be relied on! To be safe, best to not hold the returned reference through any other calls to this cache.
Definition at line 196 of file coins.cpp.
|
overridevirtual |
Do a bulk modification (multiple Coin changes + BestBlock change).
The passed mapCoins can be modified.
Reimplemented from CCoinsViewBacked.
Definition at line 225 of file coins.cpp.
|
inlineoverridevirtual |
Get a cursor to iterate over the whole state.
Reimplemented from CCoinsViewBacked.
size_t CCoinsViewCache::DynamicMemoryUsage | ( | ) | const |
|
private |
bool CCoinsViewCache::Flush | ( | ) |
Push the modifications applied to this cache to its base and wipe local state.
Failure to call this method or Sync() before destruction will cause the changes to be forgotten. If false is returned, the state of this cache (and its backing view) will be undefined.
Definition at line 301 of file coins.cpp.
|
overridevirtual |
Retrieve the block hash whose state this CCoinsView currently represents.
Reimplemented from CCoinsViewBacked.
Definition at line 214 of file coins.cpp.
unsigned int CCoinsViewCache::GetCacheSize | ( | ) | const |
Retrieve the Coin (unspent transaction output) for a given outpoint.
Returns true only when an unspent coin was found, which is returned in coin. When false is returned, coin's value is unspecified.
Reimplemented from CCoinsViewBacked.
Definition at line 95 of file coins.cpp.
|
overridevirtual |
Just check whether a given outpoint is unspent.
Reimplemented from CCoinsViewBacked.
Definition at line 204 of file coins.cpp.
bool CCoinsViewCache::HaveCoinInCache | ( | const COutPoint & | outpoint | ) | const |
Check if we have the given utxo already loaded in this cache.
The semantics are the same as HaveCoin(), but no calls to the backing CCoinsView are made.
bool CCoinsViewCache::HaveInputs | ( | const CTransaction & | tx | ) | const |
void CCoinsViewCache::ReallocateCache | ( | ) |
Force a reallocation of the cache map.
This is required when downsizing the cache because the map's allocator may be hanging onto a lot of memory despite having called .clear().
See: https://stackoverflow.com/questions/42114044/how-to-release-unordered-map-memory
Definition at line 360 of file coins.cpp.
void CCoinsViewCache::SanityCheck | ( | ) | const |
void CCoinsViewCache::SetBestBlock | ( | const BlockHash & | hashBlock | ) |
bool CCoinsViewCache::Sync | ( | ) |
Push the modifications applied to this cache to its base while retaining the contents of this cache (except for spent coins, which we erase).
Failure to call this method or Flush() before destruction will cause the changes to be forgotten. If false is returned, the state of this cache (and its backing view) will be undefined.
Definition at line 314 of file coins.cpp.
void CCoinsViewCache::Uncache | ( | const COutPoint & | outpoint | ) |
|
mutableprotected |
|
mutableprotected |