PIVX Core  5.6.99
P2P Digital Currency
Public Member Functions | Protected Attributes | Private Member Functions | List of all members
CCoinsViewCache Class Reference

CCoinsView that adds a memory cache for transactions to another CCoinsView. More...

#include <coins.h>

Inheritance diagram for CCoinsViewCache:
[legend]
Collaboration diagram for CCoinsViewCache:
[legend]

Public Member Functions

 CCoinsViewCache (CCoinsView *baseIn)
 
 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 GetSaplingAnchorAt (const uint256 &rt, SaplingMerkleTree &tree) const override
 Retrieve the tree (Sapling) at a particular anchored root in the chain. More...
 
bool GetNullifier (const uint256 &nullifier) const override
 Determine whether a nullifier is spent or not. More...
 
uint256 GetBestAnchor () const override
 Get the current "tip" or the latest anchored tree root in the chain. More...
 
template<typename Tree >
void PushAnchor (const Tree &tree)
 
void PopAnchor (const uint256 &rt)
 
void SetNullifiers (const CTransaction &tx, bool spent)
 
bool HaveShieldedRequirements (const CTransaction &tx) const
 Check whether all sapling spend requirements (anchors/nullifiers) are satisfied. 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 we have data for a given outpoint. More...
 
uint256 GetBestBlock () const override
 Retrieve the block hash whose state this CCoinsView currently represents. More...
 
void SetBestBlock (const uint256 &hashBlock)
 
bool GetUTXOCoin (const COutPoint &outpoint, Coin &coin) const
 Get the coin and check if it's spent. More...
 
bool BatchWrite (CCoinsMap &mapCoins, const uint256 &hashBlock, const uint256 &hashSaplingAnchor, CAnchorsSaplingMap &mapSaplingAnchors, CNullifiersMap &mapSaplingNullifiers) override
 Do a bulk modification (multiple Coin changes + BestBlock change). More...
 
bool HaveCoinInCache (const COutPoint &outpoint) const
 Check if we have the given utxo already loaded in this cache. More...
 
const CoinAccessCoin (const COutPoint &output) const
 Return a reference to a Coin in the cache, or a pruned one if not found. More...
 
void AddCoin (const COutPoint &outpoint, Coin &&coin, bool potential_overwrite)
 Add a coin. More...
 
void SpendCoin (const COutPoint &outpoint, Coin *moveto=nullptr)
 Spend a coin. More...
 
bool Flush ()
 Push the modifications applied to this cache to its base. 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...
 
CAmount GetValueIn (const CTransaction &tx) const
 Amount of pivx 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. 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...
 
int GetCoinDepthAtHeight (const COutPoint &output, int nHeight) const
 
CAmount GetTotalAmount () const
 
bool PruneInvalidEntries ()
 
template<>
void PushAnchor (const SaplingMerkleTree &tree)
 
template<>
void BringBestAnchorIntoCache (const uint256 &currentRoot, SaplingMerkleTree &tree)
 
- Public Member Functions inherited from CCoinsViewBacked
 CCoinsViewBacked (CCoinsView *viewIn)
 
std::vector< uint256GetHeadBlocks () const override
 Retrieve the range of blocks that may have been only partially written. More...
 
void SetBackend (CCoinsView &viewIn)
 
CCoinsViewCursorCursor () 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 ~CCoinsView ()
 As we use CCoinsViews polymorphically, have a virtual destructor. More...
 

Protected Attributes

uint256 hashBlock
 Make mutable so that we can "fill the cache" even from Get-methods declared as "const". More...
 
CCoinsMap cacheCoins
 
uint256 hashSaplingAnchor
 
CAnchorsSaplingMap cacheSaplingAnchors
 
CNullifiersMap cacheSaplingNullifiers
 
size_t cachedCoinsUsage
 
- Protected Attributes inherited from CCoinsViewBacked
CCoinsViewbase
 

Private Member Functions

CCoinsMap::iterator FetchCoin (const COutPoint &outpoint) const
 
template<typename Tree , typename Cache , typename CacheEntry >
void AbstractPopAnchor (const uint256 &newrt, Cache &cacheAnchors, uint256 &hash)
 Generalized interface for popping anchors. More...
 
template<typename Tree , typename Cache , typename CacheIterator , typename CacheEntry >
void AbstractPushAnchor (const Tree &tree, Cache &cacheAnchors, uint256 &hash)
 Generalized interface for pushing anchors. More...
 
template<typename Tree >
void BringBestAnchorIntoCache (const uint256 &currentRoot, Tree &tree)
 Interface for bringing an anchor into the cache. More...
 

Detailed Description

CCoinsView that adds a memory cache for transactions to another CCoinsView.

Definition at line 282 of file coins.h.

Constructor & Destructor Documentation

◆ CCoinsViewCache() [1/2]

CCoinsViewCache::CCoinsViewCache ( CCoinsView baseIn)

Definition at line 57 of file coins.cpp.

◆ CCoinsViewCache() [2/2]

CCoinsViewCache::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.

Member Function Documentation

◆ AbstractPopAnchor()

template<typename Tree , typename Cache , typename CacheEntry >
void CCoinsViewCache::AbstractPopAnchor ( const uint256 newrt,
Cache &  cacheAnchors,
uint256 hash 
)
private

Generalized interface for popping anchors.

Definition at line 512 of file coins.cpp.

Here is the call graph for this function:

◆ AbstractPushAnchor()

template<typename Tree , typename Cache , typename CacheIterator , typename CacheEntry >
void CCoinsViewCache::AbstractPushAnchor ( const Tree &  tree,
Cache &  cacheAnchors,
uint256 hash 
)
private

Generalized interface for pushing anchors.

Definition at line 461 of file coins.cpp.

Here is the call graph for this function:

◆ AccessCoin()

const Coin & CCoinsViewCache::AccessCoin ( const COutPoint output) const

Return a reference to a Coin in the cache, or a pruned one if not found.

This is more efficient than GetCoin. Modifications to other cache entries are allowed while accessing the returned pointer.

Definition at line 151 of file coins.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AddCoin()

void CCoinsViewCache::AddCoin ( const COutPoint outpoint,
Coin &&  coin,
bool  potential_overwrite 
)

Add a coin.

Set potential_overwrite to true if a non-pruned version may already exist.

Definition at line 94 of file coins.cpp.

Here is the caller graph for this function:

◆ BatchWrite()

bool CCoinsViewCache::BatchWrite ( CCoinsMap mapCoins,
const uint256 hashBlock,
const uint256 hashSaplingAnchor,
CAnchorsSaplingMap mapSaplingAnchors,
CNullifiersMap mapSaplingNullifiers 
)
overridevirtual

Do a bulk modification (multiple Coin changes + BestBlock change).

The passed mapCoins can be modified.

Reimplemented from CCoinsViewBacked.

Definition at line 240 of file coins.cpp.

Here is the call graph for this function:

◆ BringBestAnchorIntoCache() [1/2]

template<>
void CCoinsViewCache::BringBestAnchorIntoCache ( const uint256 currentRoot,
SaplingMerkleTree tree 
)

Definition at line 503 of file coins.cpp.

Here is the call graph for this function:

◆ BringBestAnchorIntoCache() [2/2]

template<typename Tree >
void CCoinsViewCache::BringBestAnchorIntoCache ( const uint256 currentRoot,
Tree &  tree 
)
private

Interface for bringing an anchor into the cache.

Here is the caller graph for this function:

◆ DynamicMemoryUsage()

size_t CCoinsViewCache::DynamicMemoryUsage ( ) const

Calculate the size of the cache (in bytes)

Definition at line 59 of file coins.cpp.

◆ FetchCoin()

CCoinsMap::iterator CCoinsViewCache::FetchCoin ( const COutPoint outpoint) const
private

Definition at line 66 of file coins.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 309 of file coins.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBestAnchor()

uint256 CCoinsViewCache::GetBestAnchor ( ) const
overridevirtual

Get the current "tip" or the latest anchored tree root in the chain.

Reimplemented from CCoinsViewBacked.

Definition at line 561 of file coins.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBestBlock()

uint256 CCoinsViewCache::GetBestBlock ( ) const
overridevirtual

Retrieve the block hash whose state this CCoinsView currently represents.

Reimplemented from CCoinsViewBacked.

Definition at line 173 of file coins.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCacheSize()

unsigned int CCoinsViewCache::GetCacheSize ( ) const

Calculate the size of the cache (in number of transaction outputs)

Definition at line 332 of file coins.cpp.

◆ GetCoin()

bool CCoinsViewCache::GetCoin ( const COutPoint outpoint,
Coin coin 
) const
overridevirtual

Retrieve the Coin (unspent transaction output) for a given outpoint.

Reimplemented from CCoinsViewBacked.

Definition at line 84 of file coins.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCoinDepthAtHeight()

int CCoinsViewCache::GetCoinDepthAtHeight ( const COutPoint output,
int  nHeight 
) const

Definition at line 369 of file coins.cpp.

Here is the call graph for this function:

◆ GetNullifier()

bool CCoinsViewCache::GetNullifier ( const uint256 nullifier) const
overridevirtual

Determine whether a nullifier is spent or not.

Reimplemented from CCoinsViewBacked.

Definition at line 446 of file coins.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSaplingAnchorAt()

bool CCoinsViewCache::GetSaplingAnchorAt ( const uint256 rt,
SaplingMerkleTree tree 
) const
overridevirtual

Retrieve the tree (Sapling) at a particular anchored root in the chain.

Reimplemented from CCoinsViewBacked.

Definition at line 422 of file coins.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetTotalAmount()

CAmount CCoinsViewCache::GetTotalAmount ( ) const

Definition at line 377 of file coins.cpp.

Here is the call graph for this function:

◆ GetUTXOCoin()

bool CCoinsViewCache::GetUTXOCoin ( const COutPoint outpoint,
Coin coin 
) const

Get the coin and check if it's spent.

Definition at line 584 of file coins.cpp.

Here is the call graph for this function:

◆ GetValueIn()

CAmount CCoinsViewCache::GetValueIn ( const CTransaction tx) const

Amount of pivx 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 337 of file coins.cpp.

Here is the call graph for this function:

◆ HaveCoin()

bool CCoinsViewCache::HaveCoin ( const COutPoint outpoint) const
overridevirtual

Just check whether we have data for a given outpoint.

This may (but cannot always) return true for spent outputs.

Reimplemented from CCoinsViewBacked.

Definition at line 161 of file coins.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HaveCoinInCache()

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.

Definition at line 167 of file coins.cpp.

◆ 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 357 of file coins.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HaveShieldedRequirements()

bool CCoinsViewCache::HaveShieldedRequirements ( const CTransaction tx) const

Check whether all sapling spend requirements (anchors/nullifiers) are satisfied.

Definition at line 567 of file coins.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PopAnchor()

void CCoinsViewCache::PopAnchor ( const uint256 rt)

Definition at line 542 of file coins.cpp.

Here is the caller graph for this function:

◆ PruneInvalidEntries()

bool CCoinsViewCache::PruneInvalidEntries ( )

Definition at line 393 of file coins.cpp.

Here is the call graph for this function:

◆ PushAnchor() [1/2]

template<>
void CCoinsViewCache::PushAnchor ( const SaplingMerkleTree tree)

Definition at line 493 of file coins.cpp.

◆ PushAnchor() [2/2]

template<typename Tree >
void CCoinsViewCache::PushAnchor ( const Tree &  tree)
Here is the caller graph for this function:

◆ SetBestBlock()

void CCoinsViewCache::SetBestBlock ( const uint256 hashBlock)

Definition at line 180 of file coins.cpp.

◆ SetNullifiers()

void CCoinsViewCache::SetNullifiers ( const CTransaction tx,
bool  spent 
)

Definition at line 550 of file coins.cpp.

Here is the caller graph for this function:

◆ SpendCoin()

void CCoinsViewCache::SpendCoin ( const COutPoint outpoint,
Coin moveto = nullptr 
)

Spend a coin.

Pass moveto in order to get the deleted data. If no unspent output exists for the passed outpoint, this call has no effect.

Definition at line 133 of file coins.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Uncache()

void CCoinsViewCache::Uncache ( const COutPoint outpoint)

Removes the UTXO with the given outpoint from the cache, if it is not modified.

Definition at line 323 of file coins.cpp.

Member Data Documentation

◆ cacheCoins

CCoinsMap CCoinsViewCache::cacheCoins
mutableprotected

Definition at line 290 of file coins.h.

◆ cachedCoinsUsage

size_t CCoinsViewCache::cachedCoinsUsage
mutableprotected

Definition at line 298 of file coins.h.

◆ cacheSaplingAnchors

CAnchorsSaplingMap CCoinsViewCache::cacheSaplingAnchors
mutableprotected

Definition at line 294 of file coins.h.

◆ cacheSaplingNullifiers

CNullifiersMap CCoinsViewCache::cacheSaplingNullifiers
mutableprotected

Definition at line 295 of file coins.h.

◆ hashBlock

uint256 CCoinsViewCache::hashBlock
mutableprotected

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

Definition at line 289 of file coins.h.

◆ hashSaplingAnchor

uint256 CCoinsViewCache::hashSaplingAnchor
mutableprotected

Definition at line 293 of file coins.h.


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