Dash Core  0.12.2.1
P2P Digital Currency
CCoinsViewCache Class Reference

#include <coins.h>

+ Inheritance diagram for CCoinsViewCache:

Public Member Functions

 CCoinsViewCache (CCoinsView *baseIn)
 
 ~CCoinsViewCache ()
 
bool GetCoins (const uint256 &txid, CCoins &coins) const
 Retrieve the CCoins (unspent transaction outputs) for a given txid. More...
 
bool HaveCoins (const uint256 &txid) const
 
uint256 GetBestBlock () const
 Retrieve the block hash whose state this CCoinsView currently represents. More...
 
void SetBestBlock (const uint256 &hashBlock)
 
bool BatchWrite (CCoinsMap &mapCoins, const uint256 &hashBlock)
 
bool HaveCoinsInCache (const uint256 &txid) const
 
const CCoinsAccessCoins (const uint256 &txid) const
 
CCoinsModifier ModifyCoins (const uint256 &txid)
 
CCoinsModifier ModifyNewCoins (const uint256 &txid)
 
bool Flush ()
 
void Uncache (const uint256 &txid)
 
unsigned int GetCacheSize () const
 Calculate the size of the cache (in number of transactions) More...
 
size_t DynamicMemoryUsage () const
 Calculate the size of the cache (in bytes) More...
 
CAmount GetValueIn (const CTransaction &tx) const
 
bool HaveInputs (const CTransaction &tx) const
 Check whether all prevouts of the transaction are present in the UTXO set represented by this view. More...
 
double GetPriority (const CTransaction &tx, int nHeight, CAmount &inChainInputValue) const
 
const CTxOutGetOutputFor (const CTxIn &input) const
 
- Public Member Functions inherited from CCoinsViewBacked
 CCoinsViewBacked (CCoinsView *viewIn)
 
void SetBackend (CCoinsView &viewIn)
 
bool GetStats (CCoinsStats &stats) const
 Calculate statistics about the unspent transaction output set. More...
 
- Public Member Functions inherited from CCoinsView
virtual ~CCoinsView ()
 As we use CCoinsViews polymorphically, have a virtual destructor. More...
 

Protected Attributes

bool hasModifier
 
uint256 hashBlock
 
CCoinsMap cacheCoins
 
size_t cachedCoinsUsage
 
- Protected Attributes inherited from CCoinsViewBacked
CCoinsViewbase
 

Private Member Functions

CCoinsMap::iterator FetchCoins (const uint256 &txid)
 
CCoinsMap::const_iterator FetchCoins (const uint256 &txid) const
 
 CCoinsViewCache (const CCoinsViewCache &)
 

Friends

class CCoinsModifier
 

Detailed Description

CCoinsView that adds a memory cache for transactions to another CCoinsView

Definition at line 380 of file coins.h.

Constructor & Destructor Documentation

◆ CCoinsViewCache() [1/2]

CCoinsViewCache::CCoinsViewCache ( CCoinsView baseIn)

Definition at line 61 of file coins.cpp.

◆ ~CCoinsViewCache()

CCoinsViewCache::~CCoinsViewCache ( )

Definition at line 63 of file coins.cpp.

◆ CCoinsViewCache() [2/2]

CCoinsViewCache::CCoinsViewCache ( const CCoinsViewCache )
private

By making the copy constructor private, we prevent accidentally using it when one intends to create a cache on top of a base cache.

Member Function Documentation

◆ AccessCoins()

const CCoins * CCoinsViewCache::AccessCoins ( const uint256 txid) const

Return a pointer to CCoins in the cache, or NULL if not found. This is more efficient than GetCoins. Modifications to other cache entries are allowed while accessing the returned pointer.

Definition at line 129 of file coins.cpp.

Referenced by AcceptToMemoryPoolWorker(), CTxMemPool::check(), CheckInputs(), Consensus::CheckTxInputs(), ConnectBlock(), GetOutputFor(), GetPriority(), GetTransaction(), HaveInputs(), MutateTxSign(), CTxMemPool::removeForReorg(), sendrawtransaction(), and signrawtransaction().

◆ BatchWrite()

bool CCoinsViewCache::BatchWrite ( CCoinsMap mapCoins,
const uint256 hashBlock 
)
virtual

Do a bulk modification (multiple CCoins changes + BestBlock change). The passed mapCoins can be modified.

Reimplemented from CCoinsViewBacked.

Definition at line 162 of file coins.cpp.

◆ DynamicMemoryUsage()

size_t CCoinsViewCache::DynamicMemoryUsage ( ) const

Calculate the size of the cache (in bytes)

Definition at line 68 of file coins.cpp.

Referenced by FlushStateToDisk(), UpdateTip(), and CVerifyDB::VerifyDB().

◆ FetchCoins() [1/2]

CCoinsMap::iterator CCoinsViewCache::FetchCoins ( const uint256 txid)
private

Referenced by AccessCoins(), GetCoins(), and HaveCoins().

◆ FetchCoins() [2/2]

CCoinsMap::const_iterator CCoinsViewCache::FetchCoins ( const uint256 txid) const
private

Definition at line 72 of file coins.cpp.

◆ Flush()

bool CCoinsViewCache::Flush ( )

Push the modifications applied to this cache to its base. Failure to call this method 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 207 of file coins.cpp.

Referenced by ConnectTip(), DisconnectTip(), and FlushStateToDisk().

◆ GetBestBlock()

uint256 CCoinsViewCache::GetBestBlock ( ) const
virtual

Retrieve the block hash whose state this CCoinsView currently represents.

Reimplemented from CCoinsViewBacked.

Definition at line 152 of file coins.cpp.

Referenced by AcceptToMemoryPoolWorker(), ConnectBlock(), DisconnectBlock(), GetSpendHeight(), gettxout(), and LoadBlockIndexDB().

◆ GetCacheSize()

unsigned int CCoinsViewCache::GetCacheSize ( ) const

Calculate the size of the cache (in number of transactions)

Definition at line 223 of file coins.cpp.

Referenced by FlushStateToDisk(), and UpdateTip().

◆ GetCoins()

bool CCoinsViewCache::GetCoins ( const uint256 txid,
CCoins coins 
) const
virtual

Retrieve the CCoins (unspent transaction outputs) for a given txid.

Reimplemented from CCoinsViewBacked.

Definition at line 90 of file coins.cpp.

Referenced by gettxout(), gettxoutproof(), GetUTXOCoins(), rest_getutxos(), and TransactionDesc::toHTML().

◆ GetOutputFor()

const CTxOut & CCoinsViewCache::GetOutputFor ( const CTxIn input) const

◆ GetPriority()

double CCoinsViewCache::GetPriority ( const CTransaction tx,
int  nHeight,
CAmount inChainInputValue 
) const

Return priority of tx at height nHeight. Also calculate the sum of the values of the inputs that are already in the chain. These are the inputs that will age and increase priority as new blocks are added to the chain.

Definition at line 260 of file coins.cpp.

Referenced by AcceptToMemoryPoolWorker().

◆ GetValueIn()

CAmount CCoinsViewCache::GetValueIn ( const CTransaction tx) const

Amount of dash coming in to a transaction Note that lightweight clients may not know anything besides the hash of previous transactions, so may not be able to calculate this.

Parameters
[in]txtransaction for which we are checking input total
Returns
Sum of value of all inputs (scriptSigs)

Definition at line 234 of file coins.cpp.

Referenced by AcceptToMemoryPoolWorker(), and ConnectBlock().

◆ HaveCoins()

bool CCoinsViewCache::HaveCoins ( const uint256 txid) const
virtual

Just check whether we have data for a given txid. This may (but cannot always) return true for fully spent transactions

Reimplemented from CCoinsViewBacked.

Definition at line 138 of file coins.cpp.

Referenced by AcceptToMemoryPoolWorker(), and AlreadyHave().

◆ HaveCoinsInCache()

bool CCoinsViewCache::HaveCoinsInCache ( const uint256 txid) const

Check if we have the given tx already loaded in this cache. The semantics are the same as HaveCoins(), but no calls to the backing CCoinsView are made.

Definition at line 147 of file coins.cpp.

Referenced by AcceptToMemoryPoolWorker().

◆ HaveInputs()

bool CCoinsViewCache::HaveInputs ( const CTransaction tx) const

Check whether all prevouts of the transaction are present in the UTXO set represented by this view.

Definition at line 246 of file coins.cpp.

Referenced by AcceptToMemoryPoolWorker(), CTxMemPool::check(), Consensus::CheckTxInputs(), and ConnectBlock().

◆ ModifyCoins()

CCoinsModifier CCoinsViewCache::ModifyCoins ( const uint256 txid)

Return a modifiable reference to a CCoins. If no entry with the given txid exists, a new one is created. Simultaneous modifications are not allowed.

Definition at line 99 of file coins.cpp.

Referenced by ApplyTxInUndo(), DisconnectBlock(), MutateTxSign(), signrawtransaction(), and UpdateCoins().

◆ ModifyNewCoins()

CCoinsModifier CCoinsViewCache::ModifyNewCoins ( const uint256 txid)

Return a modifiable reference to a CCoins. Assumes that no entry with the given txid exists and creates a new one. This saves a database access in the case where the coins were to be wiped out by FromTx anyway. This should not be called with the 2 historical coinbase duplicate pairs because the new coins are marked fresh, and in the event the duplicate coinbase was spent before a flush, the now pruned coins would not properly overwrite the first coinbase of the pair. Simultaneous modifications are not allowed.

Definition at line 120 of file coins.cpp.

Referenced by UpdateCoins().

◆ SetBestBlock()

void CCoinsViewCache::SetBestBlock ( const uint256 hashBlock)

Definition at line 158 of file coins.cpp.

Referenced by ConnectBlock(), and DisconnectBlock().

◆ Uncache()

void CCoinsViewCache::Uncache ( const uint256 txid)

Removes the transaction with the given hash from the cache, if it is not modified.

Definition at line 214 of file coins.cpp.

Referenced by AcceptToMemoryPool(), and LimitMempoolSize().

Friends And Related Function Documentation

◆ CCoinsModifier

friend class CCoinsModifier
friend

Definition at line 481 of file coins.h.

Referenced by ModifyCoins(), and ModifyNewCoins().

Member Data Documentation

◆ cacheCoins

◆ cachedCoinsUsage

size_t CCoinsViewCache::cachedCoinsUsage
mutableprotected

◆ hashBlock

uint256 CCoinsViewCache::hashBlock
mutableprotected

Make mutable so that we can "fill the cache" even from Get-methods declared as "const".

Definition at line 391 of file coins.h.

Referenced by BatchWrite(), Flush(), GetBestBlock(), and SetBestBlock().

◆ hasModifier

bool CCoinsViewCache::hasModifier
protected

The documentation for this class was generated from the following files: