Bitcoin Core 28.99.0
P2P Digital Currency
Public Member Functions | Protected Attributes | Private Attributes | List of all members
CCoinsViewMemPool Class Reference

CCoinsView that brings transactions from a mempool into view. More...

#include <txmempool.h>

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

Public Member Functions

 CCoinsViewMemPool (CCoinsView *baseIn, const CTxMemPool &mempoolIn)
 
std::optional< CoinGetCoin (const COutPoint &outpoint) const override
 GetCoin, returning whether it exists and is not spent. More...
 
void PackageAddTransaction (const CTransactionRef &tx)
 Add the coins created by this transaction. More...
 
std::unordered_set< COutPoint, SaltedOutpointHasherGetNonBaseCoins () const
 Get all coins in m_non_base_coins. More...
 
void Reset ()
 Clear m_temp_added and m_non_base_coins. More...
 
- Public Member Functions inherited from CCoinsViewBacked
 CCoinsViewBacked (CCoinsView *viewIn)
 
std::optional< CoinGetCoin (const COutPoint &outpoint) 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...
 
uint256 GetBestBlock () const override
 Retrieve the block hash whose state this CCoinsView currently represents. More...
 
std::vector< uint256GetHeadBlocks () const override
 Retrieve the range of blocks that may have been only partially written. More...
 
void SetBackend (CCoinsView &viewIn)
 
bool BatchWrite (CoinsViewCacheCursor &cursor, const uint256 &hashBlock) override
 Do a bulk modification (multiple Coin changes + BestBlock change). More...
 
std::unique_ptr< 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 std::optional< CoinGetCoin (const COutPoint &outpoint) 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 uint256 GetBestBlock () const
 Retrieve the block hash whose state this CCoinsView currently represents. More...
 
virtual std::vector< uint256GetHeadBlocks () const
 Retrieve the range of blocks that may have been only partially written. More...
 
virtual bool BatchWrite (CoinsViewCacheCursor &cursor, const uint256 &hashBlock)
 Do a bulk modification (multiple Coin changes + BestBlock change). More...
 
virtual std::unique_ptr< CCoinsViewCursorCursor () const
 Get a cursor to iterate over the whole state. More...
 
virtual ~CCoinsView ()=default
 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

const CTxMemPoolmempool
 
- Protected Attributes inherited from CCoinsViewBacked
CCoinsViewbase
 

Private Attributes

std::unordered_map< COutPoint, Coin, SaltedOutpointHasherm_temp_added
 Coins made available by transactions being validated. More...
 
std::unordered_set< COutPoint, SaltedOutpointHasherm_non_base_coins
 Set of all coins that have been fetched from mempool or created using PackageAddTransaction (not base). More...
 

Detailed Description

CCoinsView that brings transactions from a mempool into view.

It does not check for spendings by memory pool transactions. Instead, it provides access to all Coins which are either unspent in the base CCoinsView, are outputs from any mempool transaction, or are tracked temporarily to allow transaction dependencies in package validation. This allows transaction replacement to work as expected, as you want to have all inputs "available" to check signatures, and any cycles in the dependency graph are checked directly in AcceptToMemoryPool. It also allows you to sign a double-spend directly in signrawtransactionwithkey and signrawtransactionwithwallet, as long as the conflicting transaction is not yet confirmed.

Definition at line 924 of file txmempool.h.

Constructor & Destructor Documentation

◆ CCoinsViewMemPool()

CCoinsViewMemPool::CCoinsViewMemPool ( CCoinsView baseIn,
const CTxMemPool mempoolIn 
)

Definition at line 1025 of file txmempool.cpp.

Member Function Documentation

◆ GetCoin()

std::optional< Coin > CCoinsViewMemPool::GetCoin ( const COutPoint outpoint) const
overridevirtual

GetCoin, returning whether it exists and is not spent.

Also updates m_non_base_coins if the coin is not fetched from base.

Reimplemented from CCoinsViewBacked.

Definition at line 1027 of file txmempool.cpp.

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

◆ GetNonBaseCoins()

std::unordered_set< COutPoint, SaltedOutpointHasher > CCoinsViewMemPool::GetNonBaseCoins ( ) const
inline

Get all coins in m_non_base_coins.

Definition at line 949 of file txmempool.h.

◆ PackageAddTransaction()

void CCoinsViewMemPool::PackageAddTransaction ( const CTransactionRef tx)

Add the coins created by this transaction.

These coins are only temporarily stored in m_temp_added and cannot be flushed to the back end. Only used for package validation.

Definition at line 1050 of file txmempool.cpp.

◆ Reset()

void CCoinsViewMemPool::Reset ( )

Clear m_temp_added and m_non_base_coins.

Definition at line 1057 of file txmempool.cpp.

Member Data Documentation

◆ m_non_base_coins

std::unordered_set<COutPoint, SaltedOutpointHasher> CCoinsViewMemPool::m_non_base_coins
mutableprivate

Set of all coins that have been fetched from mempool or created using PackageAddTransaction (not base).

Used to track the origin of a coin, see GetNonBaseCoins().

Definition at line 936 of file txmempool.h.

◆ m_temp_added

std::unordered_map<COutPoint, Coin, SaltedOutpointHasher> CCoinsViewMemPool::m_temp_added
private

Coins made available by transactions being validated.

Tracking these allows for package validation, since we can access transaction outputs without submitting them to mempool.

Definition at line 930 of file txmempool.h.

◆ mempool

const CTxMemPool& CCoinsViewMemPool::mempool
protected

Definition at line 938 of file txmempool.h.


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