Bitcoin ABC  0.24.7
P2P Digital Currency
Classes | Public Types | Public Member Functions | Public Attributes | Static Public Attributes | Private Types | Private Member Functions | 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]

Classes

class  EpochGuard
 EpochGuard: RAII-style guard for using epoch-based graph traversal algorithms. More...
 

Public Types

typedef boost::multi_index_container< CTxMemPoolEntry, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< mempoolentry_txid, SaltedTxIdHasher >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< descendant_score >, boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByDescendantScore >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< entry_time >, boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByEntryTime >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ancestor_score >, boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByAncestorFee > > > indexed_transaction_set
 
using txiter = indexed_transaction_set::nth_index< 0 >::type::const_iterator
 
typedef std::set< txiter, CompareIteratorByIdsetEntries
 

Public Member Functions

indexed_transaction_set mapTx GUARDED_BY (cs)
 
std::vector< std::pair< TxHash, txiter > > vTxHashes GUARDED_BY (cs)
 All tx hashes/entries in mapTx, in random order. More...
 
uint64_t CalculateDescendantMaximum (txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 
indirectmap< COutPoint, const CTransaction * > mapNextTx GUARDED_BY (cs)
 
 CTxMemPool ()
 Create a new CTxMemPool. More...
 
 ~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 (double dFrequency=1.0)
 
void addUnchecked (const CTxMemPoolEntry &entry) EXCLUSIVE_LOCKS_REQUIRED(cs
 
void addUnchecked (const CTxMemPoolEntry &entry, setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs
 
void removeRecursive (const CTransaction &tx, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
 
void removeForReorg (const Config &config, const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags) EXCLUSIVE_LOCKS_REQUIRED(cs
 
void removeConflicts (const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs)
 
void removeForBlock (const std::vector< CTransactionRef > &vtx, unsigned int nBlockHeight) EXCLUSIVE_LOCKS_REQUIRED(cs)
 Called when a block is connected. More...
 
void clear ()
 
void _clear () EXCLUSIVE_LOCKS_REQUIRED(cs)
 
bool CompareDepthAndScore (const TxId &txida, const TxId &txidb)
 
void queryHashes (std::vector< uint256 > &vtxid) const
 
bool isSpent (const COutPoint &outpoint) const
 
unsigned int GetTransactionsUpdated () const
 
void AddTransactionsUpdated (unsigned int n)
 
bool HasNoInputsOf (const CTransaction &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 Check that none of this transactions inputs are in the mempool, and thus the tx is not dependent on other mempool transactions to be included in a block. More...
 
void PrioritiseTransaction (const TxId &txid, const Amount nFeeDelta)
 Affect CreateNewBlock prioritisation of transactions. More...
 
void ApplyDelta (const TxId &txid, Amount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 
void ClearPrioritisation (const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(cs)
 
const CTransactionGetConflictTx (const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 Get the transaction in the pool that spends the same prevout. More...
 
std::optional< txiterGetIter (const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 Returns an iterator to the given txid, if found. More...
 
setEntries GetIterSet (const std::set< TxId > &txids) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 Translate a set of txids into a set of pool iterators to avoid repeated lookups. More...
 
void RemoveStaged (setEntries &stage, bool updateDescendants, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
 Remove a set of transactions from the mempool. More...
 
void UpdateTransactionsFromBlock (const std::vector< TxId > &txidsToUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs
 When adding transactions from a disconnected block back to the mempool, new mempool entries may have children in the mempool (which is generally not the case when otherwise adding transactions). More...
 
bool CalculateMemPoolAncestors (const CTxMemPoolEntry &entry, setEntries &setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString, bool fSearchForParents=true) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 Try to calculate all in-mempool ancestors of entry. More...
 
void CalculateDescendants (txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 Populate setDescendants with all in-mempool descendants of hash. More...
 
CFeeRate GetMinFee (size_t sizelimit) const
 The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions. More...
 
void TrimToSize (size_t sizelimit, std::vector< COutPoint > *pvNoSpendsRemaining=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs)
 Remove transactions from the mempool until its dynamic size is <= sizelimit. More...
 
int Expire (std::chrono::seconds time) EXCLUSIVE_LOCKS_REQUIRED(cs)
 Expire all transaction (and their dependencies) in the mempool older than time. More...
 
void LimitSize (size_t limit, std::chrono::seconds age) EXCLUSIVE_LOCKS_REQUIRED(cs
 Reduce the size of the mempool by expiring and then trimming the mempool. More...
 
void GetTransactionAncestry (const TxId &txid, size_t &ancestors, size_t &descendants) const
 Calculate the ancestor and descendant count for the given transaction. More...
 
bool IsLoaded () const
 
void SetIsLoaded (bool loaded)
 Sets the current loaded state. More...
 
unsigned long size () const
 
uint64_t GetTotalTxSize () const EXCLUSIVE_LOCKS_REQUIRED(cs)
 
bool exists (const TxId &txid) const
 
CTransactionRef get (const TxId &txid) const
 
TxMempoolInfo info (const TxId &txid) const
 
std::vector< TxMempoolInfoinfoAll () const
 
CFeeRate estimateFee () const
 
size_t DynamicMemoryUsage () const
 
void AddUnbroadcastTx (const TxId &txid)
 Adds a transaction to the unbroadcast set. More...
 
void RemoveUnbroadcastTx (const TxId &txid, const bool unchecked=false)
 Removes a transaction from the unbroadcast set. More...
 
std::set< TxIdGetUnbroadcastTxs () const
 Returns transactions in unbroadcast set. More...
 
bool IsUnbroadcastTx (const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 Returns whether a txid is in the unbroadcast set. More...
 
uint64_t GetAndIncrementSequence () const EXCLUSIVE_LOCKS_REQUIRED(cs)
 Guards this internal counter for external reporting. More...
 
uint64_t GetSequence () const EXCLUSIVE_LOCKS_REQUIRED(cs)
 
EpochGuard GetFreshEpoch () const EXCLUSIVE_LOCKS_REQUIRED(cs)
 
bool visited (txiter it) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 visited marks a CTxMemPoolEntry as having been traversed during the lifetime of the most recently created EpochGuard and returns false if we are the first visitor, true otherwise. More...
 
bool visited (std::optional< txiter > it) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 

Public Attributes

RecursiveMutex cs
 This mutex needs to be locked when accessing mapTx or other members that are guarded by it. More...
 
std::map< TxId, AmountmapDeltas
 
void cs_main
 

Static Public Attributes

static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12
 

Private Types

typedef std::map< txiter, setEntries, CompareIteratorByIdcacheMap
 

Private Member Functions

uint32_t nCheckFrequency GUARDED_BY (cs)
 Value n means that n times in 2^32 we check. More...
 
void trackPackageRemoved (const CFeeRate &rate) EXCLUSIVE_LOCKS_REQUIRED(cs)
 
bool m_is_loaded GUARDED_BY (cs)
 
void UpdateParent (txiter entry, txiter parent, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
 
void UpdateChild (txiter entry, txiter child, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
 
std::vector< indexed_transaction_set::const_iterator > GetSortedDepthAndScore () const EXCLUSIVE_LOCKS_REQUIRED(cs)
 
std::set< TxId > m_unbroadcast_txids GUARDED_BY (cs)
 Track locally submitted transactions to periodically retry initial broadcast. More...
 
void UpdateForDescendants (txiter updateIt, cacheMap &cachedDescendants, const std::set< TxId > &setExclude) EXCLUSIVE_LOCKS_REQUIRED(cs)
 UpdateForDescendants is used by UpdateTransactionsFromBlock to update the descendants for a single transaction that has been added to the mempool but may have child transactions in the mempool, eg during a chain reorg. More...
 
void UpdateAncestorsOf (bool add, txiter hash, setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs)
 Update ancestors of hash to add/remove it as a descendant transaction. More...
 
void UpdateEntryForAncestors (txiter it, const setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs)
 Set ancestor state for an entry. More...
 
void UpdateForRemoveFromMempool (const setEntries &entriesToRemove, bool updateDescendants) EXCLUSIVE_LOCKS_REQUIRED(cs)
 For each transaction being removed, update ancestors and any direct children. More...
 
void UpdateChildrenForRemoval (txiter entry) EXCLUSIVE_LOCKS_REQUIRED(cs)
 Sever link between specified transaction and direct children. More...
 
void removeUnchecked (txiter entry, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
 Before calling removeUnchecked for a given transaction, UpdateForRemoveFromMempool must be called on the entire (dependent) set of transactions being removed at the same time. More...
 

Private Attributes

std::atomic< uint32_t > nTransactionsUpdated
 Used by getblocktemplate to trigger CreateNewBlock() invocation. More...
 
uint64_t totalTxSize
 sum of all mempool tx's sizes. More...
 
uint64_t cachedInnerUsage
 sum of dynamic memory usage of all the map elements (NOT the maps themselves) More...
 
int64_t lastRollingFeeUpdate
 
bool blockSinceLastRollingFeeBump
 
double rollingMinimumFeeRate
 minimum fee to get into the pool, decreases exponentially More...
 
uint64_t m_epoch
 
bool m_has_epoch_guard
 
uint64_t m_sequence_number {1}
 

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. For example, the following new transactions will not be added to the mempool:

CTxMemPool::mapTx, and CTxMemPoolEntry bookkeeping:

mapTx is a boost::multi_index that sorts the mempool on 4 criteria:

Note: the term "descendant" refers to in-mempool transactions that depend on this one, while "ancestor" refers to in-mempool transactions that a given transaction depends on.

In order for the feerate sort to remain correct, we must update transactions in the mempool when new descendants arrive. To facilitate this, we track the set of in-mempool direct parents and direct children in mapLinks. Within each CTxMemPoolEntry, we track the size and fees of all descendants.

Usually when a new transaction is added to the mempool, it has no in-mempool children (because any such children would be an orphan). So in addUnchecked(), we:

When a transaction is removed from the mempool, we must:

These happen in UpdateForRemoveFromMempool(). (Note that when removing a transaction along with its descendants, we must calculate that set of transactions to be removed before doing the removal, or else the mempool can be in an inconsistent state where it's impossible to walk the ancestors of a transaction.)

In the event of a reorg, the assumption that a newly added tx has no in-mempool children is false. In particular, the mempool is in an inconsistent state while new transactions are being added, because there may be descendant transactions of a tx coming from a disconnected block that are unreachable from just looking at transactions in the mempool (the linking transactions may also be in the disconnected block, waiting to be added). Because of this, there's not much benefit in trying to search for in-mempool children in addUnchecked(). Instead, in the special case of transactions being added from a disconnected block, we require the caller to clean up the state, to account for in-mempool, out-of-block descendants for all the in-block transactions by calling UpdateTransactionsFromBlock(). Note that until this is called, the mempool state is not consistent, and in particular mapLinks may not be correct (and therefore functions like CalculateMemPoolAncestors() and CalculateDescendants() that rely on them to walk the mempool are not generally safe to use).

Computational limits:

Updating all in-mempool ancestors of a newly added transaction can be slow, if no bound exists on how many in-mempool ancestors there may be. CalculateMemPoolAncestors() takes configurable limits that are designed to prevent these calculations from being too CPU intensive.

Definition at line 495 of file txmempool.h.

Member Typedef Documentation

◆ cacheMap

Definition at line 590 of file txmempool.h.

◆ indexed_transaction_set

typedef boost::multi_index_container< CTxMemPoolEntry, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< mempoolentry_txid, SaltedTxIdHasher>, boost::multi_index::ordered_non_unique< boost::multi_index::tag<descendant_score>, boost::multi_index::identity<CTxMemPoolEntry>, CompareTxMemPoolEntryByDescendantScore>, boost::multi_index::ordered_non_unique< boost::multi_index::tag<entry_time>, boost::multi_index::identity<CTxMemPoolEntry>, CompareTxMemPoolEntryByEntryTime>, boost::multi_index::ordered_non_unique< boost::multi_index::tag<ancestor_score>, boost::multi_index::identity<CTxMemPoolEntry>, CompareTxMemPoolEntryByAncestorFee> > > CTxMemPool::indexed_transaction_set

Definition at line 548 of file txmempool.h.

◆ setEntries

Definition at line 584 of file txmempool.h.

◆ txiter

using CTxMemPool::txiter = indexed_transaction_set::nth_index<0>::type::const_iterator

Definition at line 580 of file txmempool.h.

Constructor & Destructor Documentation

◆ CTxMemPool()

CTxMemPool::CTxMemPool ( )

Create a new CTxMemPool.

Definition at line 402 of file txmempool.cpp.

Here is the call graph for this function:

◆ ~CTxMemPool()

CTxMemPool::~CTxMemPool ( )

Definition at line 413 of file txmempool.cpp.

Member Function Documentation

◆ _clear()

void CTxMemPool::_clear ( )

Definition at line 688 of file txmempool.cpp.

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

◆ AddTransactionsUpdated()

void CTxMemPool::AddTransactionsUpdated ( unsigned int  n)

Definition at line 424 of file txmempool.cpp.

◆ AddUnbroadcastTx()

void CTxMemPool::AddUnbroadcastTx ( const TxId txid)
inline

Adds a transaction to the unbroadcast set.

Definition at line 805 of file txmempool.h.

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

◆ addUnchecked() [1/2]

void CTxMemPool::addUnchecked ( const CTxMemPoolEntry entry)

Definition at line 1142 of file txmempool.cpp.

Here is the call graph for this function:

◆ addUnchecked() [2/2]

void CTxMemPool::addUnchecked ( const CTxMemPoolEntry entry,
setEntries setAncestors 
)

Definition at line 428 of file txmempool.cpp.

Here is the call graph for this function:

◆ ApplyDelta()

void CTxMemPool::ApplyDelta ( const TxId txid,
Amount nFeeDelta 
) const

Definition at line 1007 of file txmempool.cpp.

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

◆ CalculateDescendantMaximum()

uint64_t CTxMemPool::CalculateDescendantMaximum ( txiter  entry) const

Definition at line 1255 of file txmempool.cpp.

Here is the caller graph for this function:

◆ CalculateDescendants()

void CTxMemPool::CalculateDescendants ( txiter  it,
setEntries setDescendants 
) const

Populate setDescendants with all in-mempool descendants of hash.

Assumes that setDescendants includes all in-mempool descendants of anything already in it.

Definition at line 521 of file txmempool.cpp.

Here is the caller graph for this function:

◆ CalculateMemPoolAncestors()

bool CTxMemPool::CalculateMemPoolAncestors ( const CTxMemPoolEntry entry,
setEntries setAncestors,
uint64_t  limitAncestorCount,
uint64_t  limitAncestorSize,
uint64_t  limitDescendantCount,
uint64_t  limitDescendantSize,
std::string &  errString,
bool  fSearchForParents = true 
) const

Try to calculate all in-mempool ancestors of entry.

(these are all calculated including the tx itself) limitAncestorCount = max number of ancestors limitAncestorSize = max size of ancestors limitDescendantCount = max number of descendants any ancestor can have limitDescendantSize = max size of descendants any ancestor can have errString = populated with error reason if any limits are hit fSearchForParents = whether to search a tx's vin for in-mempool parents, or look up parents from mapLinks. Must be true for entries not in the mempool

Definition at line 187 of file txmempool.cpp.

Here is the call graph for this function:
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 719 of file txmempool.cpp.

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

◆ clear()

void CTxMemPool::clear ( )

Definition at line 700 of file txmempool.cpp.

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

◆ ClearPrioritisation()

void CTxMemPool::ClearPrioritisation ( const TxId txid)

Definition at line 1017 of file txmempool.cpp.

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

◆ CompareDepthAndScore()

bool CTxMemPool::CompareDepthAndScore ( const TxId txida,
const TxId txidb 
)

Definition at line 860 of file txmempool.cpp.

◆ DynamicMemoryUsage()

size_t CTxMemPool::DynamicMemoryUsage ( ) const

Definition at line 1077 of file txmempool.cpp.

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

◆ estimateFee()

CFeeRate CTxMemPool::estimateFee ( ) const

Definition at line 960 of file txmempool.cpp.

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

◆ exists()

bool CTxMemPool::exists ( const TxId txid) const
inline

Definition at line 791 of file txmempool.h.

Here is the caller graph for this function:

◆ Expire()

int CTxMemPool::Expire ( std::chrono::seconds  time)

Expire all transaction (and their dependencies) in the mempool older than time.

Return the number of removed transactions.

Definition at line 1109 of file txmempool.cpp.

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

◆ get()

CTransactionRef CTxMemPool::get ( const TxId txid) const

Definition at line 940 of file txmempool.cpp.

Here is the caller graph for this function:

◆ GetAndIncrementSequence()

uint64_t CTxMemPool::GetAndIncrementSequence ( ) const
inline

Guards this internal counter for external reporting.

Definition at line 829 of file txmempool.h.

Here is the caller graph for this function:

◆ GetConflictTx()

const CTransaction * CTxMemPool::GetConflictTx ( const COutPoint prevout) const

Get the transaction in the pool that spends the same prevout.

Definition at line 1022 of file txmempool.cpp.

◆ GetFreshEpoch()

CTxMemPool::EpochGuard CTxMemPool::GetFreshEpoch ( ) const

Definition at line 1448 of file txmempool.cpp.

Here is the caller graph for this function:

◆ GetIter()

std::optional< CTxMemPool::txiter > CTxMemPool::GetIter ( const TxId txid) const

Returns an iterator to the given txid, if found.

Definition at line 1027 of file txmempool.cpp.

Here is the caller graph for this function:

◆ GetIterSet()

CTxMemPool::setEntries CTxMemPool::GetIterSet ( const std::set< TxId > &  txids) const

Translate a set of txids into a set of pool iterators to avoid repeated lookups.

Definition at line 1036 of file txmempool.cpp.

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

◆ GetMinFee()

CFeeRate CTxMemPool::GetMinFee ( size_t  sizelimit) const

The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions.

The incrementalRelayFee policy variable is used to bound the time it takes the fee rate to go back down all the way to 0. When the feerate would otherwise be half of this, it is set to 0 instead.

Definition at line 1171 of file txmempool.cpp.

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

◆ GetSequence()

uint64_t CTxMemPool::GetSequence ( ) const
inline

Definition at line 833 of file txmempool.h.

Here is the caller graph for this function:

◆ GetSortedDepthAndScore()

std::vector< CTxMemPool::indexed_transaction_set::const_iterator > CTxMemPool::GetSortedDepthAndScore ( ) const
private

Definition at line 895 of file txmempool.cpp.

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

◆ GetTotalTxSize()

uint64_t CTxMemPool::GetTotalTxSize ( ) const
inline

Definition at line 786 of file txmempool.h.

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

◆ GetTransactionAncestry()

void CTxMemPool::GetTransactionAncestry ( const TxId txid,
size_t &  ancestors,
size_t &  descendants 
) const

Calculate the ancestor and descendant count for the given transaction.

The counts include the transaction itself.

Definition at line 1280 of file txmempool.cpp.

Here is the call graph for this function:

◆ GetTransactionsUpdated()

unsigned int CTxMemPool::GetTransactionsUpdated ( ) const

Definition at line 420 of file txmempool.cpp.

Here is the caller graph for this function:

◆ GetUnbroadcastTxs()

std::set<TxId> CTxMemPool::GetUnbroadcastTxs ( ) const
inline

Returns transactions in unbroadcast set.

Definition at line 817 of file txmempool.h.

Here is the caller graph for this function:

◆ GUARDED_BY() [1/6]

uint32_t nCheckFrequency CTxMemPool::GUARDED_BY ( cs  )
private

Value n means that n times in 2^32 we check.

◆ GUARDED_BY() [2/6]

bool m_is_loaded CTxMemPool::GUARDED_BY ( cs  )
inlineprivate

Definition at line 522 of file txmempool.h.

◆ GUARDED_BY() [3/6]

indexed_transaction_set mapTx CTxMemPool::GUARDED_BY ( cs  )

◆ GUARDED_BY() [4/6]

std::vector<std::pair<TxHash, txiter> > vTxHashes CTxMemPool::GUARDED_BY ( cs  )

All tx hashes/entries in mapTx, in random order.

◆ GUARDED_BY() [5/6]

std::set<TxId> m_unbroadcast_txids CTxMemPool::GUARDED_BY ( cs  )
private

Track locally submitted transactions to periodically retry initial broadcast.

◆ GUARDED_BY() [6/6]

indirectmap<COutPoint, const CTransaction *> mapNextTx CTxMemPool::GUARDED_BY ( cs  )

◆ HasNoInputsOf()

bool CTxMemPool::HasNoInputsOf ( const CTransaction tx) const

Check that none of this transactions inputs are in the mempool, and thus the tx is not dependent on other mempool transactions to be included in a block.

Definition at line 1047 of file txmempool.cpp.

Here is the call graph for this function:

◆ info()

TxMempoolInfo CTxMemPool::info ( const TxId txid) const

Definition at line 950 of file txmempool.cpp.

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

◆ infoAll()

std::vector< TxMempoolInfo > CTxMemPool::infoAll ( ) const

Definition at line 927 of file txmempool.cpp.

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

◆ IsLoaded()

bool CTxMemPool::IsLoaded ( ) const
Returns
true if the mempool is fully loaded

Definition at line 1291 of file txmempool.cpp.

Here is the caller graph for this function:

◆ isSpent()

bool CTxMemPool::isSpent ( const COutPoint outpoint) const

Definition at line 415 of file txmempool.cpp.

Here is the caller graph for this function:

◆ IsUnbroadcastTx()

bool CTxMemPool::IsUnbroadcastTx ( const TxId txid) const
inline

Returns whether a txid is in the unbroadcast set.

Definition at line 823 of file txmempool.h.

Here is the call graph for this function:

◆ LimitSize()

void CTxMemPool::LimitSize ( size_t  limit,
std::chrono::seconds  age 
)

Reduce the size of the mempool by expiring and then trimming the mempool.

Definition at line 1128 of file txmempool.cpp.

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

◆ PrioritiseTransaction()

void CTxMemPool::PrioritiseTransaction ( const TxId txid,
const Amount  nFeeDelta 
)

Affect CreateNewBlock prioritisation of transactions.

Definition at line 972 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) const

Definition at line 909 of file txmempool.cpp.

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

◆ removeConflicts()

void CTxMemPool::removeConflicts ( const CTransaction tx)

Definition at line 633 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< CTransactionRef > &  vtx,
unsigned int  nBlockHeight 
)

Called when a block is connected.

Removes from mempool and updates the miner fee estimator.

Definition at line 652 of file txmempool.cpp.

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

◆ removeForReorg()

void CTxMemPool::removeForReorg ( const Config config,
const CCoinsViewCache pcoins,
unsigned int  nMemPoolHeight,
int  flags 
)

Definition at line 579 of file txmempool.cpp.

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

◆ removeRecursive()

void CTxMemPool::removeRecursive ( const CTransaction tx,
MemPoolRemovalReason  reason 
)

Definition at line 546 of file txmempool.cpp.

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

◆ RemoveStaged()

void CTxMemPool::RemoveStaged ( setEntries stage,
bool  updateDescendants,
MemPoolRemovalReason  reason 
)

Remove a set of transactions from the mempool.

If a transaction is in this set, then all in-mempool descendants must also be in the set, unless this transaction is being removed for being in a block. Set updateDescendants to true when removing a tx that was in a block, so that any in-mempool descendants have their ancestor state updated.

Definition at line 1100 of file txmempool.cpp.

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

◆ RemoveUnbroadcastTx()

void CTxMemPool::RemoveUnbroadcastTx ( const TxId txid,
const bool  unchecked = false 
)

Removes a transaction from the unbroadcast set.

Definition at line 1089 of file txmempool.cpp.

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

◆ removeUnchecked()

void CTxMemPool::removeUnchecked ( txiter  entry,
MemPoolRemovalReason  reason 
)
private

Before calling removeUnchecked for a given transaction, UpdateForRemoveFromMempool must be called on the entire (dependent) set of transactions being removed at the same time.

We use each CTxMemPoolEntry's setMemPoolParents in order to walk ancestors of a given transaction that is removed, so we can't remove intermediate transactions in a chain before we've updated all the state for the removal.

Definition at line 475 of file txmempool.cpp.

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

◆ SetIsLoaded()

void CTxMemPool::SetIsLoaded ( bool  loaded)

Sets the current loaded state.

Definition at line 1296 of file txmempool.cpp.

Here is the caller graph for this function:

◆ setSanityCheck()

void CTxMemPool::setSanityCheck ( double  dFrequency = 1.0)
inline

Definition at line 623 of file txmempool.h.

◆ size()

unsigned long CTxMemPool::size ( ) const
inline

Definition at line 781 of file txmempool.h.

Here is the caller graph for this function:

◆ trackPackageRemoved()

void CTxMemPool::trackPackageRemoved ( const CFeeRate rate)
private

Definition at line 1194 of file txmempool.cpp.

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

◆ TrimToSize()

void CTxMemPool::TrimToSize ( size_t  sizelimit,
std::vector< COutPoint > *  pvNoSpendsRemaining = nullptr 
)

Remove transactions from the mempool until its dynamic size is <= sizelimit.

pvNoSpendsRemaining, if set, will be populated with the list of outpoints which are not in mempool which no longer have any spends in this mempool.

Definition at line 1202 of file txmempool.cpp.

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

◆ UpdateAncestorsOf()

void CTxMemPool::UpdateAncestorsOf ( bool  add,
txiter  hash,
setEntries setAncestors 
)
private

Update ancestors of hash to add/remove it as a descendant transaction.

Definition at line 272 of file txmempool.cpp.

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

◆ UpdateChild()

void CTxMemPool::UpdateChild ( txiter  entry,
txiter  child,
bool  add 
)
private

Definition at line 1151 of file txmempool.cpp.

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

◆ UpdateChildrenForRemoval()

void CTxMemPool::UpdateChildrenForRemoval ( txiter  entry)
private

Sever link between specified transaction and direct children.

Definition at line 306 of file txmempool.cpp.

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

◆ UpdateEntryForAncestors()

void CTxMemPool::UpdateEntryForAncestors ( txiter  it,
const setEntries setAncestors 
)
private

Set ancestor state for an entry.

Definition at line 290 of file txmempool.cpp.

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

◆ UpdateForDescendants()

void CTxMemPool::UpdateForDescendants ( txiter  updateIt,
cacheMap cachedDescendants,
const std::set< TxId > &  setExclude 
)
private

UpdateForDescendants is used by UpdateTransactionsFromBlock to update the descendants for a single transaction that has been added to the mempool but may have child transactions in the mempool, eg during a chain reorg.

setExclude is the set of descendant transactions in the mempool that must not be accounted for (because any descendants in setExclude were added to the mempool after the transaction being updated and hence their state is already reflected in the parent state).

cachedDescendants will be updated with the descendants of the transaction being updated, so that future invocations don't need to walk the same transaction again, if encountered in another transaction chain.

Definition at line 80 of file txmempool.cpp.

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

◆ UpdateForRemoveFromMempool()

void CTxMemPool::UpdateForRemoveFromMempool ( const setEntries entriesToRemove,
bool  updateDescendants 
)
private

For each transaction being removed, update ancestors and any direct children.

If updateDescendants is true, then also update in-mempool descendants' ancestor state.

Definition at line 313 of file txmempool.cpp.

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

◆ UpdateParent()

void CTxMemPool::UpdateParent ( txiter  entry,
txiter  parent,
bool  add 
)
private

Definition at line 1161 of file txmempool.cpp.

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

◆ UpdateTransactionsFromBlock()

void CTxMemPool::UpdateTransactionsFromBlock ( const std::vector< TxId > &  txidsToUpdate)

When adding transactions from a disconnected block back to the mempool, new mempool entries may have children in the mempool (which is generally not the case when otherwise adding transactions).

UpdateTransactionsFromBlock() will find child transactions and update the descendant state for each transaction in txidsToUpdate (excluding any child transactions present in txidsToUpdate, which are already accounted for). Note: txidsToUpdate should be the set of transactions from the disconnected block that have been accepted back into the mempool.

Definition at line 137 of file txmempool.cpp.

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

◆ visited() [1/2]

bool CTxMemPool::visited ( std::optional< txiter it) const
inline

Definition at line 932 of file txmempool.h.

Here is the call graph for this function:

◆ visited() [2/2]

bool CTxMemPool::visited ( txiter  it) const
inline

visited marks a CTxMemPoolEntry as having been traversed during the lifetime of the most recently created EpochGuard and returns false if we are the first visitor, true otherwise.

An EpochGuard must be held when visited is called or an assert will be triggered.

Definition at line 925 of file txmempool.h.

Here is the caller graph for this function:

Member Data Documentation

◆ blockSinceLastRollingFeeBump

bool CTxMemPool::blockSinceLastRollingFeeBump
mutableprivate

Definition at line 509 of file txmempool.h.

◆ cachedInnerUsage

uint64_t CTxMemPool::cachedInnerUsage
private

sum of dynamic memory usage of all the map elements (NOT the maps themselves)

Definition at line 506 of file txmempool.h.

◆ cs

RecursiveMutex CTxMemPool::cs
mutable

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 577 of file txmempool.h.

◆ cs_main

void CTxMemPool::cs_main

Definition at line 636 of file txmempool.h.

◆ lastRollingFeeUpdate

int64_t CTxMemPool::lastRollingFeeUpdate
mutableprivate

Definition at line 508 of file txmempool.h.

◆ m_epoch

uint64_t CTxMemPool::m_epoch
mutableprivate

Definition at line 512 of file txmempool.h.

◆ m_has_epoch_guard

bool CTxMemPool::m_has_epoch_guard
mutableprivate

Definition at line 513 of file txmempool.h.

◆ m_sequence_number

uint64_t CTxMemPool::m_sequence_number {1}
mutableprivate

Definition at line 518 of file txmempool.h.

◆ mapDeltas

std::map<TxId, Amount> CTxMemPool::mapDeltas

Definition at line 608 of file txmempool.h.

◆ nTransactionsUpdated

std::atomic<uint32_t> CTxMemPool::nTransactionsUpdated
private

Used by getblocktemplate to trigger CreateNewBlock() invocation.

Definition at line 500 of file txmempool.h.

◆ ROLLING_FEE_HALFLIFE

const int CTxMemPool::ROLLING_FEE_HALFLIFE = 60 * 60 * 12
static

Definition at line 526 of file txmempool.h.

◆ rollingMinimumFeeRate

double CTxMemPool::rollingMinimumFeeRate
mutableprivate

minimum fee to get into the pool, decreases exponentially

Definition at line 511 of file txmempool.h.

◆ totalTxSize

uint64_t CTxMemPool::totalTxSize
private

sum of all mempool tx's sizes.

Definition at line 503 of file txmempool.h.


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