PRCYCoin  2.0.0.7rc1
P2P Digital Currency
Public Member Functions | Public Attributes | Private Attributes | List of all members
CTxMemPool Class Reference

CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the next block. More...

#include <txmempool.h>

Collaboration diagram for CTxMemPool:
[legend]

Public Member Functions

 CTxMemPool (const CFeeRate &_minRelayFee)
 
 ~CTxMemPool ()
 
void check (const CCoinsViewCache *pcoins) const
 If sanity-checking is turned on, check makes sure the pool is consistent (does not contain two transactions that spend the same inputs, all inputs are in the mapNextTx array). More...
 
void setSanityCheck (bool _fSanityCheck)
 
bool addUnchecked (const uint256 &hash, const CTxMemPoolEntry &entry)
 
void remove (const CTransaction &tx, std::list< CTransaction > &removed, bool fRecursive=false)
 
void removeCoinbaseSpends (const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight)
 
void removeConflicts (const CTransaction &tx, std::list< CTransaction > &removed)
 
void removeForBlock (const std::vector< CTransaction > &vtx, unsigned int nBlockHeight, std::list< CTransaction > &conflicts)
 Called when a block is connected. More...
 
void clear ()
 
void queryHashes (std::vector< uint256 > &vtxid)
 
void pruneSpent (const uint256 &hash, CCoins &coins)
 
unsigned int GetTransactionsUpdated () const
 
void AddTransactionsUpdated (unsigned int n)
 
void PrioritiseTransaction (const uint256 hash, const std::string strHash, double dPriorityDelta, const CAmount &nFeeDelta)
 Affect CreateNewBlock prioritisation of transactions. More...
 
void ApplyDeltas (const uint256 hash, double &dPriorityDelta, CAmount &nFeeDelta)
 
void ClearPrioritisation (const uint256 hash)
 
unsigned long size ()
 
uint64_t GetTotalTxSize ()
 
bool exists (uint256 hash)
 
bool lookup (uint256 hash, CTransaction &result) const
 
CFeeRate estimateFee (int nBlocks) const
 Estimate fee rate needed to get into the next nBlocks. More...
 
double estimatePriority (int nBlocks) const
 Estimate priority needed to get into the next nBlocks. More...
 
bool WriteFeeEstimates (CAutoFile &fileout) const
 Write/Read estimates to disk. More...
 
bool ReadFeeEstimates (CAutoFile &filein)
 

Public Attributes

RecursiveMutex cs
 sum of all mempool tx' byte sizes More...
 
std::map< uint256, CTxMemPoolEntrymapTx
 
std::map< COutPoint, CInPointmapNextTx
 
std::map< uint256, std::pair< double, CAmount > > mapDeltas
 

Private Attributes

bool fSanityCheck
 
unsigned int nTransactionsUpdated
 Normally false, true if -checkmempool or -regtest. More...
 
CMinerPolicyEstimatorminerPolicyEstimator
 
CFeeRate minRelayFee
 
uint64_t totalTxSize
 Passed to constructor to avoid dependency on main. More...
 

Detailed Description

CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the next block.

Transactions are added when they are seen on the network (or created by the local node), but not all transactions seen are added to the pool: if a new transaction double-spends an input of a transaction in the pool, it is dropped, as are non-standard transactions.

Definition at line 97 of file txmempool.h.

Constructor & Destructor Documentation

◆ CTxMemPool()

CTxMemPool::CTxMemPool ( const CFeeRate _minRelayFee)

Definition at line 355 of file txmempool.cpp.

◆ ~CTxMemPool()

CTxMemPool::~CTxMemPool ( )

Definition at line 371 of file txmempool.cpp.

Member Function Documentation

◆ AddTransactionsUpdated()

void CTxMemPool::AddTransactionsUpdated ( unsigned int  n)

Definition at line 395 of file txmempool.cpp.

Here is the caller graph for this function:

◆ addUnchecked()

bool CTxMemPool::addUnchecked ( const uint256 hash,
const CTxMemPoolEntry entry 
)

Definition at line 402 of file txmempool.cpp.

Here is the call graph for this function:

◆ ApplyDeltas()

void CTxMemPool::ApplyDeltas ( const uint256  hash,
double &  dPriorityDelta,
CAmount nFeeDelta 
)

Definition at line 686 of file txmempool.cpp.

Here is the caller graph for this function:

◆ check()

void CTxMemPool::check ( const CCoinsViewCache pcoins) const

If sanity-checking is turned on, check makes sure the pool is consistent (does not contain two transactions that spend the same inputs, all inputs are in the mapNextTx array).

If sanity-checking is turned off, check does nothing.

Definition at line 540 of file txmempool.cpp.

Here is the call graph for this function:

◆ clear()

void CTxMemPool::clear ( )

Definition at line 531 of file txmempool.cpp.

Here is the caller graph for this function:

◆ ClearPrioritisation()

void CTxMemPool::ClearPrioritisation ( const uint256  hash)

Definition at line 697 of file txmempool.cpp.

Here is the caller graph for this function:

◆ estimateFee()

CFeeRate CTxMemPool::estimateFee ( int  nBlocks) const

Estimate fee rate needed to get into the next nBlocks.

Definition at line 633 of file txmempool.cpp.

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

◆ estimatePriority()

double CTxMemPool::estimatePriority ( int  nBlocks) const

Estimate priority needed to get into the next nBlocks.

Definition at line 638 of file txmempool.cpp.

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

◆ exists()

bool CTxMemPool::exists ( uint256  hash)
inline

Definition at line 179 of file txmempool.h.

Here is the caller graph for this function:

◆ GetTotalTxSize()

uint64_t CTxMemPool::GetTotalTxSize ( )
inline

Definition at line 173 of file txmempool.h.

◆ GetTransactionsUpdated()

unsigned int CTxMemPool::GetTransactionsUpdated ( ) const

Definition at line 389 of file txmempool.cpp.

◆ lookup()

bool CTxMemPool::lookup ( uint256  hash,
CTransaction result 
) const

Definition at line 624 of file txmempool.cpp.

Here is the caller graph for this function:

◆ PrioritiseTransaction()

void CTxMemPool::PrioritiseTransaction ( const uint256  hash,
const std::string  strHash,
double  dPriorityDelta,
const CAmount nFeeDelta 
)

Affect CreateNewBlock prioritisation of transactions.

Definition at line 675 of file txmempool.cpp.

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

◆ pruneSpent()

void CTxMemPool::pruneSpent ( const uint256 hash,
CCoins coins 
)

Definition at line 376 of file txmempool.cpp.

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

◆ queryHashes()

void CTxMemPool::queryHashes ( std::vector< uint256 > &  vtxid)

Definition at line 614 of file txmempool.cpp.

◆ ReadFeeEstimates()

bool CTxMemPool::ReadFeeEstimates ( CAutoFile filein)

Definition at line 658 of file txmempool.cpp.

◆ remove()

void CTxMemPool::remove ( const CTransaction tx,
std::list< CTransaction > &  removed,
bool  fRecursive = false 
)

Definition at line 424 of file txmempool.cpp.

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

◆ removeCoinbaseSpends()

void CTxMemPool::removeCoinbaseSpends ( const CCoinsViewCache pcoins,
unsigned int  nMemPoolHeight 
)

Definition at line 468 of file txmempool.cpp.

Here is the call graph for this function:

◆ removeConflicts()

void CTxMemPool::removeConflicts ( const CTransaction tx,
std::list< CTransaction > &  removed 
)

Definition at line 493 of file txmempool.cpp.

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

◆ removeForBlock()

void CTxMemPool::removeForBlock ( const std::vector< CTransaction > &  vtx,
unsigned int  nBlockHeight,
std::list< CTransaction > &  conflicts 
)

Called when a block is connected.

Removes from mempool and updates the miner fee estimator.

Definition at line 512 of file txmempool.cpp.

Here is the call graph for this function:

◆ setSanityCheck()

void CTxMemPool::setSanityCheck ( bool  _fSanityCheck)
inline

Definition at line 150 of file txmempool.h.

◆ size()

unsigned long CTxMemPool::size ( )
inline

Definition at line 168 of file txmempool.h.

◆ WriteFeeEstimates()

bool CTxMemPool::WriteFeeEstimates ( CAutoFile fileout) const

Write/Read estimates to disk.

Definition at line 644 of file txmempool.cpp.

Member Data Documentation

◆ cs

RecursiveMutex CTxMemPool::cs
mutable

sum of all mempool tx' byte sizes

This mutex needs to be locked when accessing mapTx or other members that are guarded by it.

Consistency guarantees

By design, it is guaranteed that:

  1. Locking both cs_main and mempool.cs will give a view of mempool that is consistent with current chain tip (::ChainActive() and CoinsTip()) and is fully populated. Fully populated means that if the current active chain is missing transactions that were present in a previously active chain, all the missing transactions will have been re-added to the mempool and should be present if they meet size and consistency constraints.
  2. Locking mempool.cs without cs_main will give a view of a mempool consistent with some chain that was active since cs_main was last locked, and that is fully populated as described above. It is ok for code that only needs to query or remove transactions from the mempool to lock just mempool.cs without cs_main.

To provide these guarantees, it is necessary to lock both cs_main and mempool.cs whenever adding transactions to the mempool and whenever changing the chain tip. It's necessary to keep both mutexes locked until the mempool is consistent with the new chain tip and fully populated.

Definition at line 135 of file txmempool.h.

◆ fSanityCheck

bool CTxMemPool::fSanityCheck
private

Definition at line 100 of file txmempool.h.

◆ mapDeltas

std::map<uint256, std::pair<double, CAmount> > CTxMemPool::mapDeltas

Definition at line 138 of file txmempool.h.

◆ mapNextTx

std::map<COutPoint, CInPoint> CTxMemPool::mapNextTx

Definition at line 137 of file txmempool.h.

◆ mapTx

std::map<uint256, CTxMemPoolEntry> CTxMemPool::mapTx

Definition at line 136 of file txmempool.h.

◆ minerPolicyEstimator

CMinerPolicyEstimator* CTxMemPool::minerPolicyEstimator
private

Definition at line 102 of file txmempool.h.

◆ minRelayFee

CFeeRate CTxMemPool::minRelayFee
private

Definition at line 104 of file txmempool.h.

◆ nTransactionsUpdated

unsigned int CTxMemPool::nTransactionsUpdated
private

Normally false, true if -checkmempool or -regtest.

Definition at line 101 of file txmempool.h.

◆ totalTxSize

uint64_t CTxMemPool::totalTxSize
private

Passed to constructor to avoid dependency on main.

Definition at line 105 of file txmempool.h.


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