Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
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>

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

Classes

struct  CTxMemPoolEntry_Indices
struct  delta_info
class  ChangeSet

Public Types

typedef boost::multi_index_container< CTxMemPoolEntry, CTxMemPoolEntry_Indicesindexed_transaction_set
using txiter = indexed_transaction_set::nth_index<0>::type::const_iterator
typedef std::set< txiter, CompareIteratorByHashsetEntries
using Limits = kernel::MemPoolLimits
using Options = kernel::MemPoolOptions

Public Member Functions

std::unique_ptr< TxGraph > m_txgraph GUARDED_BY (cs)
std::unique_ptr< TxGraph::BlockBuilder > m_builder GUARDED_BY (cs)
indexed_transaction_set mapTx GUARDED_BY (cs)
std::vector< std::pair< Wtxid, txiter > > txns_randomized GUARDED_BY (cs)
 All transactions in mapTx with their wtxids, in arbitrary order.
std::tuple< size_t, size_t, CAmountCalculateAncestorData (const CTxMemPoolEntry &entry) const EXCLUSIVE_LOCKS_REQUIRED(cs)
std::tuple< size_t, size_t, CAmountCalculateDescendantData (const CTxMemPoolEntry &entry) const EXCLUSIVE_LOCKS_REQUIRED(cs)
int64_t GetDescendantCount (txiter it) const
int64_t GetDescendantCount (const CTxMemPoolEntry &e) const
int64_t GetAncestorCount (const CTxMemPoolEntry &e) const
std::vector< CTxMemPoolEntry::CTxMemPoolEntryRefGetChildren (const CTxMemPoolEntry &entry) const
std::vector< CTxMemPoolEntry::CTxMemPoolEntryRefGetParents (const CTxMemPoolEntry &entry) const
indirectmap< COutPoint, txiter > mapNextTx GUARDED_BY (cs)
std::map< Txid, CAmount > mapDeltas GUARDED_BY (cs)
 CTxMemPool (Options opts, bilingual_str &error)
 Create a new CTxMemPool.
void removeForReorg (CChain &chain, std::function< bool(txiter)> filter_final_and_mature) EXCLUSIVE_LOCKS_REQUIRED(cs
 After reorg, filter the entries that would no longer be valid in the next block, and update the entries' cached LockPoints if needed.
void removeForBlock (const std::vector< CTransactionRef > &vtx, unsigned int nBlockHeight) EXCLUSIVE_LOCKS_REQUIRED(cs)
bool CompareMiningScoreWithTopology (const Wtxid &hasha, const Wtxid &hashb) 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.
void PrioritiseTransaction (const Txid &hash, const CAmount &nFeeDelta)
 Affect CreateNewBlock prioritisation of transactions.
void ApplyDelta (const Txid &hash, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs)
void ClearPrioritisation (const Txid &hash) EXCLUSIVE_LOCKS_REQUIRED(cs)
std::vector< delta_infoGetPrioritisedTransactions () const EXCLUSIVE_LOCKS_REQUIRED(!cs)
 Return a vector of all entries in mapDeltas with their corresponding delta_info.
const CTransactionGetConflictTx (const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 Get the transaction in the pool that spends the same prevout.
std::optional< txiterGetIter (const Txid &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 Returns an iterator to the given hash, if found.
std::optional< txiterGetIter (const Wtxid &wtxid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
setEntries GetIterSet (const std::set< Txid > &hashes) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 Translate a set of hashes into a set of pool iterators to avoid repeated lookups.
std::vector< txiterGetIterVec (const std::vector< Txid > &txids) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 Translate a list of hashes into a list of mempool iterators to avoid repeated lookups.
void UpdateTransactionsFromBlock (const std::vector< Txid > &vHashesToUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs
 UpdateTransactionsFromBlock is called 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).
std::vector< FeePerWeightGetFeerateDiagram () const EXCLUSIVE_LOCKS_REQUIRED(cs)
FeePerWeight GetMainChunkFeerate (const CTxMemPoolEntry &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs)
std::vector< const CTxMemPoolEntry * > GetCluster (Txid txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
size_t GetUniqueClusterCount (const setEntries &iters_conflicting) const EXCLUSIVE_LOCKS_REQUIRED(cs)
setEntries CalculateMemPoolAncestors (const CTxMemPoolEntry &entry) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 Calculate all in-mempool ancestors of entry (not including the tx itself).
bool HasDescendants (const Txid &txid) const
std::vector< txiterGatherClusters (const std::vector< Txid > &txids) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 Collect the entire cluster of connected transactions for each transaction in txids.
void CalculateDescendants (txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 Populate setDescendants with all in-mempool descendants of given transaction.
CTxMemPool::txiter CalculateDescendants (const CTxMemPoolEntry &entry, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
CFeeRate GetMinFee () const
 The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions.
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.
int Expire (std::chrono::seconds time) EXCLUSIVE_LOCKS_REQUIRED(cs)
 Expire all transaction (and their dependencies) in the mempool older than time.
void GetTransactionAncestry (const Txid &txid, size_t &ancestors, size_t &cluster_count, size_t *ancestorsize=nullptr, CAmount *ancestorfees=nullptr) const
 Calculate the ancestor and cluster count for the given transaction.
bool GetLoadTried () const
void SetLoadTried (bool load_tried)
 Set whether or not an initial attempt to load the persisted mempool was made (regardless of whether the attempt was successful or not).
unsigned long size () const
uint64_t GetTotalTxSize () const EXCLUSIVE_LOCKS_REQUIRED(cs)
CAmount GetTotalFee () const EXCLUSIVE_LOCKS_REQUIRED(cs)
bool exists (const Txid &txid) const
bool exists (const Wtxid &wtxid) const
const CTxMemPoolEntryGetEntry (const Txid &txid) const LIFETIMEBOUND EXCLUSIVE_LOCKS_REQUIRED(cs)
CTransactionRef get (const Txid &hash) const
template<TxidOrWtxid T>
TxMempoolInfo info (const T &id) const
template<TxidOrWtxid T>
TxMempoolInfo info_for_relay (const T &id, uint64_t last_sequence) const
 Returns info for a transaction if its entry_sequence < last_sequence.
std::vector< CTxMemPoolEntryRefentryAll () const EXCLUSIVE_LOCKS_REQUIRED(cs)
std::vector< TxMempoolInfoinfoAll () const
size_t DynamicMemoryUsage () const
void AddUnbroadcastTx (const Txid &txid)
 Adds a transaction to the unbroadcast set.
bool CheckPolicyLimits (const CTransactionRef &tx)
void RemoveUnbroadcastTx (const Txid &txid, bool unchecked=false)
 Removes a transaction from the unbroadcast set.
std::set< TxidGetUnbroadcastTxs () const
 Returns transactions in unbroadcast set.
bool IsUnbroadcastTx (const Txid &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
 Returns whether a txid is in the unbroadcast set.
uint64_t GetAndIncrementSequence () const EXCLUSIVE_LOCKS_REQUIRED(cs)
 Guards this internal counter for external reporting.
uint64_t GetSequence () const EXCLUSIVE_LOCKS_REQUIRED(cs)
std::unique_ptr< ChangeSetGetChangeSet () EXCLUSIVE_LOCKS_REQUIRED(cs)
bool m_have_changeset GUARDED_BY (cs)
void StartBlockBuilding () const EXCLUSIVE_LOCKS_REQUIRED(cs)
FeePerWeight GetBlockBuilderChunk (std::vector< CTxMemPoolEntry::CTxMemPoolEntryRef > &entries) const EXCLUSIVE_LOCKS_REQUIRED(cs)
void IncludeBuilderChunk () const EXCLUSIVE_LOCKS_REQUIRED(cs)
void SkipBuilderChunk () const EXCLUSIVE_LOCKS_REQUIRED(cs)
void StopBlockBuilding () 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.
const Options m_opts
void check(const CCoinsViewCache &active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(voi removeRecursive )(const CTransaction &tx, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
 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).
void cs_main

Static Public Attributes

static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12

Protected Member Functions

uint64_t totalTxSize GUARDED_BY (cs)
CAmount m_total_fee GUARDED_BY (cs)
 sum of all mempool tx's virtual sizes. Differs from serialized tx size since witness data is discounted. Defined in BIP 141.
uint64_t cachedInnerUsage GUARDED_BY (cs)
 sum of all mempool tx's fees (NOT modified fee)
int64_t lastRollingFeeUpdate GUARDED_BY (cs)
 sum of dynamic memory usage of all the map elements (NOT the maps themselves)
bool blockSinceLastRollingFeeBump GUARDED_BY (cs)
double rollingMinimumFeeRate GUARDED_BY (cs)
uint64_t m_sequence_number GUARDED_BY (cs)
 minimum fee to get into the pool, decreases exponentially
void trackPackageRemoved (const CFeeRate &rate) EXCLUSIVE_LOCKS_REQUIRED(cs)
bool m_load_tried GUARDED_BY (cs)
CFeeRate GetMinFee (size_t sizelimit) const

Protected Attributes

std::atomic< unsigned int > nTransactionsUpdated {0}
 Used by getblocktemplate to trigger CreateNewBlock() invocation.

Private Member Functions

std::vector< indexed_transaction_set::const_iterator > GetSortedScoreWithTopology () const EXCLUSIVE_LOCKS_REQUIRED(cs)
std::set< Txid > m_unbroadcast_txids GUARDED_BY (cs)
 Track locally submitted transactions to periodically retry initial broadcast.
void removeConflicts (const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs)
void RemoveStaged (setEntries &stage, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
 Remove a set of transactions from the mempool.
void removeRecursive (txiter to_remove, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
void removeUnchecked (txiter entry, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
void Apply (CTxMemPool::ChangeSet *changeset) EXCLUSIVE_LOCKS_REQUIRED(cs)
void addNewTransaction (CTxMemPool::txiter it) EXCLUSIVE_LOCKS_REQUIRED(cs)

Static Private Member Functions

static TxMempoolInfo GetInfo (CTxMemPool::indexed_transaction_set::const_iterator it)

Friends

class CTxMemPool::ChangeSet

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:

  • a transaction which doesn't meet the minimum fee requirements.
  • a new transaction that double-spends an input of a transaction already in the pool where the new transaction does not meet the Replace-By-Fee requirements as defined in doc/policy/mempool-replacements.md.
  • a non-standard transaction.

TxGraph (CTxMemPool::m_txgraph) provides an abstraction layer for separating the transaction graph parts of the mempool from the rest of the Bitcoin-specific logic. Specifically, TxGraph handles (for each transaction) managing the in-mempool parents and children, and has knowledge of the fee and size of every transaction. It uses this to partition the mempool into connected clusters, and it implements (among other things):

  • limits on the size of a cluster (in both number of transactions and total weight)
  • sorting the mempool optimally for block inclusion, taking into account dependencies
  • selecting transactions for removal due to cluster size limit violations after a reorg. See txgraph.h and txgraph.cpp for more details.

CTxMemPool itself handles the Bitcoin-specific parts of mempool transactions; it stores the full transaction inside CTxMemPoolEntry, along with other consensus-specific fields (such as whether a transaction spends a coinbase, or the LockPoints for transaction finality). And it provides interfaces to the rest of the codebase, such as:

  • to validation for replace-by-fee calculations and cluster size limits when evaluating unconfirmed transactions
  • to validation for evicting transactions due to expiry or the mempool size limit being hit
  • to validation for updating the mempool to be consistent with the best chain after a new block is connected or after a reorg.
  • to net_processing for ordering transactions that are to-be-announced to other peers
  • to RPC code for inspecting the mempool

(Many of these interfaces are just wrappers around corresponding TxGraph functions.)

Within CTxMemPool, the mempool entries are stored in a boost::multi_index mapTx, which sorts the mempool on 3 criteria:

  • transaction hash (txid)
  • witness-transaction hash (wtxid)
  • time in mempool

We also maintain a map from COutPoint to the (in-mempool) transaction that spends it (mapNextTx). This allows us to recover from a reorg and find transactions in the mempool that conflict with transactions that are confirmed in a block.

Definition at line 186 of file txmempool.h.

Member Typedef Documentation

◆ indexed_transaction_set

Definition at line 234 of file txmempool.h.

◆ Limits

Definition at line 270 of file txmempool.h.

◆ Options

Definition at line 301 of file txmempool.h.

◆ setEntries

Definition at line 268 of file txmempool.h.

◆ txiter

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

Definition at line 265 of file txmempool.h.

Constructor & Destructor Documentation

◆ CTxMemPool()

CTxMemPool::CTxMemPool ( Options opts,
bilingual_str & error )
explicit

Create a new CTxMemPool.

Sanity checks will be off by default for performance, because otherwise accepting transactions becomes O(N^2) where N is the number of transactions in the pool.

Definition at line 176 of file txmempool.cpp.

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

Member Function Documentation

◆ addNewTransaction()

void CTxMemPool::addNewTransaction ( CTxMemPool::txiter it)
private

Definition at line 229 of file txmempool.cpp.

Here is the call graph for this function:

◆ AddTransactionsUpdated()

void CTxMemPool::AddTransactionsUpdated ( unsigned int n)

Definition at line 201 of file txmempool.cpp.

◆ AddUnbroadcastTx()

void CTxMemPool::AddUnbroadcastTx ( const Txid & txid)
inline

Adds a transaction to the unbroadcast set.

Definition at line 542 of file txmempool.h.

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

◆ Apply()

void CTxMemPool::Apply ( CTxMemPool::ChangeSet * changeset)
private

Definition at line 206 of file txmempool.cpp.

◆ ApplyDelta()

void CTxMemPool::ApplyDelta ( const Txid & hash,
CAmount & nFeeDelta ) const

Definition at line 657 of file txmempool.cpp.

◆ CalculateAncestorData()

std::tuple< size_t, size_t, CAmount > CTxMemPool::CalculateAncestorData ( const CTxMemPoolEntry & entry) const

Definition at line 913 of file txmempool.cpp.

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

◆ CalculateDescendantData()

std::tuple< size_t, size_t, CAmount > CTxMemPool::CalculateDescendantData ( const CTxMemPoolEntry & entry) const

Definition at line 928 of file txmempool.cpp.

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

◆ CalculateDescendants() [1/2]

CTxMemPool::txiter CTxMemPool::CalculateDescendants ( const CTxMemPoolEntry & entry,
setEntries & setDescendants ) const

Definition at line 315 of file txmempool.cpp.

◆ CalculateDescendants() [2/2]

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

Populate setDescendants with all in-mempool descendants of given transaction.

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

Definition at line 309 of file txmempool.cpp.

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

◆ CalculateMemPoolAncestors()

CTxMemPool::setEntries CTxMemPool::CalculateMemPoolAncestors ( const CTxMemPoolEntry & entry) const

Calculate all in-mempool ancestors of entry (not including the tx itself).

Parameters
[in]entryCTxMemPoolEntry of which all in-mempool ancestors are calculated
Returns
all in-mempool ancestors

Definition at line 130 of file txmempool.cpp.

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

◆ CheckPolicyLimits()

bool CTxMemPool::CheckPolicyLimits ( const CTransactionRef & tx)

Definition at line 800 of file txmempool.cpp.

Here is the call graph for this function:

◆ ClearPrioritisation()

void CTxMemPool::ClearPrioritisation ( const Txid & hash)

Definition at line 667 of file txmempool.cpp.

Here is the caller graph for this function:

◆ CompareMiningScoreWithTopology()

bool CTxMemPool::CompareMiningScoreWithTopology ( const Wtxid & hasha,
const Wtxid & hashb ) const

Definition at line 556 of file txmempool.cpp.

Here is the call graph for this function:

◆ DynamicMemoryUsage()

size_t CTxMemPool::DynamicMemoryUsage ( ) const

Definition at line 778 of file txmempool.cpp.

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

◆ entryAll()

std::vector< CTxMemPoolEntryRef > CTxMemPool::entryAll ( ) const

Definition at line 588 of file txmempool.cpp.

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

◆ exists() [1/2]

bool CTxMemPool::exists ( const Txid & txid) const
inline

Definition at line 503 of file txmempool.h.

Here is the caller graph for this function:

◆ exists() [2/2]

bool CTxMemPool::exists ( const Wtxid & wtxid) const
inline

Definition at line 509 of file txmempool.h.

◆ 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 811 of file txmempool.cpp.

Here is the call graph for this function:

◆ GatherClusters()

std::vector< CTxMemPool::txiter > CTxMemPool::GatherClusters ( const std::vector< Txid > & txids) const

Collect the entire cluster of connected transactions for each transaction in txids.

All txids must correspond to transaction entries in the mempool, otherwise this returns an empty vector. This call will also exit early and return an empty vector if it collects 500 or more transactions as a DoS protection.

Definition at line 968 of file txmempool.cpp.

Here is the caller graph for this function:

◆ get()

CTransactionRef CTxMemPool::get ( const Txid & hash) const

Definition at line 621 of file txmempool.cpp.

Here is the caller graph for this function:

◆ GetAncestorCount()

int64_t CTxMemPool::GetAncestorCount ( const CTxMemPoolEntry & e) const
inline

Definition at line 276 of file txmempool.h.

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

Here is the caller graph for this function:

◆ GetBlockBuilderChunk()

FeePerWeight CTxMemPool::GetBlockBuilderChunk ( std::vector< CTxMemPoolEntry::CTxMemPoolEntryRef > & entries) const
inline

Definition at line 721 of file txmempool.h.

Here is the caller graph for this function:

◆ GetChangeSet()

std::unique_ptr< ChangeSet > CTxMemPool::GetChangeSet ( )
inline

Definition at line 695 of file txmempool.h.

Here is the caller graph for this function:

◆ GetChildren()

std::vector< CTxMemPoolEntry::CTxMemPoolEntryRef > CTxMemPool::GetChildren ( const CTxMemPoolEntry & entry) const

Definition at line 57 of file txmempool.cpp.

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

◆ GetCluster()

std::vector< const CTxMemPoolEntry * > CTxMemPool::GetCluster ( Txid txid) const
inline

Definition at line 400 of file txmempool.h.

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

Here is the caller graph for this function:

◆ GetDescendantCount() [1/2]

int64_t CTxMemPool::GetDescendantCount ( const CTxMemPoolEntry & e) const
inline

Definition at line 275 of file txmempool.h.

◆ GetDescendantCount() [2/2]

int64_t CTxMemPool::GetDescendantCount ( txiter it) const
inline

Definition at line 274 of file txmempool.h.

Here is the caller graph for this function:

◆ GetEntry()

const CTxMemPoolEntry * CTxMemPool::GetEntry ( const Txid & txid) const

Definition at line 614 of file txmempool.cpp.

Here is the caller graph for this function:

◆ GetFeerateDiagram()

std::vector< FeePerWeight > CTxMemPool::GetFeerateDiagram ( ) const

Definition at line 1082 of file txmempool.cpp.

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

◆ GetInfo()

TxMempoolInfo CTxMemPool::GetInfo ( CTxMemPool::indexed_transaction_set::const_iterator it)
inlinestaticprivate

Definition at line 288 of file txmempool.h.

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

◆ GetIter() [1/2]

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

Returns an iterator to the given hash, if found.

Definition at line 695 of file txmempool.cpp.

Here is the caller graph for this function:

◆ GetIter() [2/2]

std::optional< CTxMemPool::txiter > CTxMemPool::GetIter ( const Wtxid & wtxid) const

Definition at line 702 of file txmempool.cpp.

◆ GetIterSet()

CTxMemPool::setEntries CTxMemPool::GetIterSet ( const std::set< Txid > & hashes) const

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

Does not require that all of the hashes correspond to actual transactions in the mempool, only returns the ones that exist.

Definition at line 709 of file txmempool.cpp.

Here is the call graph for this function:

◆ GetIterVec()

std::vector< CTxMemPool::txiter > CTxMemPool::GetIterVec ( const std::vector< Txid > & txids) const

Translate a list of hashes into a list of mempool iterators to avoid repeated lookups.

The nth element in txids becomes the nth element in the returned vector. If any of the txids don't actually exist in the mempool, returns an empty vector.

Definition at line 719 of file txmempool.cpp.

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

◆ GetLoadTried()

bool CTxMemPool::GetLoadTried ( ) const
Returns
true if an initial attempt to load the persisted mempool was made, regardless of whether the attempt was successful or not

Definition at line 956 of file txmempool.cpp.

Here is the caller graph for this function:

◆ GetMainChunkFeerate()

FeePerWeight CTxMemPool::GetMainChunkFeerate ( const CTxMemPoolEntry & tx) const
inline

Definition at line 397 of file txmempool.h.

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

◆ GetMinFee() [1/2]

CFeeRate CTxMemPool::GetMinFee ( ) const
inline

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

The m_incremental_relay_feerate 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 452 of file txmempool.h.

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

◆ GetMinFee() [2/2]

CFeeRate CTxMemPool::GetMinFee ( size_t sizelimit) const
protected

Definition at line 829 of file txmempool.cpp.

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

◆ GetParents()

std::vector< CTxMemPoolEntry::CTxMemPoolEntryRef > CTxMemPool::GetParents ( const CTxMemPoolEntry & entry) const

Definition at line 74 of file txmempool.cpp.

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

◆ GetPrioritisedTransactions()

std::vector< CTxMemPool::delta_info > CTxMemPool::GetPrioritisedTransactions ( ) const

Return a vector of all entries in mapDeltas with their corresponding delta_info.

Definition at line 673 of file txmempool.cpp.

Here is the caller graph for this function:

◆ GetSequence()

uint64_t CTxMemPool::GetSequence ( ) const
inline

Definition at line 574 of file txmempool.h.

Here is the caller graph for this function:

◆ GetSortedScoreWithTopology()

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

Definition at line 572 of file txmempool.cpp.

Here is the caller graph for this function:

◆ GetTotalFee()

CAmount CTxMemPool::GetTotalFee ( ) const
inline

Definition at line 497 of file txmempool.h.

Here is the caller graph for this function:

◆ GetTotalTxSize()

uint64_t CTxMemPool::GetTotalTxSize ( ) const
inline

Definition at line 491 of file txmempool.h.

Here is the caller graph for this function:

◆ GetTransactionAncestry()

void CTxMemPool::GetTransactionAncestry ( const Txid & txid,
size_t & ancestors,
size_t & cluster_count,
size_t * ancestorsize = nullptr,
CAmount * ancestorfees = nullptr ) const

Calculate the ancestor and cluster count for the given transaction.

The counts include the transaction itself. When ancestors is non-zero (ie, the transaction itself is in the mempool), ancestorsize and ancestorfees will also be set to the appropriate values.

Definition at line 943 of file txmempool.cpp.

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

◆ GetTransactionsUpdated()

unsigned int CTxMemPool::GetTransactionsUpdated ( ) const

Definition at line 196 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 556 of file txmempool.h.

Here is the caller graph for this function:

◆ GetUniqueClusterCount()

size_t CTxMemPool::GetUniqueClusterCount ( const setEntries & iters_conflicting) const
inline

Definition at line 413 of file txmempool.h.

Here is the caller graph for this function:

◆ GUARDED_BY() [1/16]

bool m_have_changeset CTxMemPool::GUARDED_BY ( cs )
inline

Definition at line 701 of file txmempool.h.

◆ GUARDED_BY() [2/16]

std::map< Txid, CAmount > mapDeltas CTxMemPool::GUARDED_BY ( cs )

◆ GUARDED_BY() [3/16]

indirectmap< COutPoint, txiter > mapNextTx CTxMemPool::GUARDED_BY ( cs )

◆ GUARDED_BY() [4/16]

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

Track locally submitted transactions to periodically retry initial broadcast.

Here is the call graph for this function:

◆ GUARDED_BY() [5/16]

std::vector< std::pair< Wtxid, txiter > > txns_randomized CTxMemPool::GUARDED_BY ( cs )

All transactions in mapTx with their wtxids, in arbitrary order.

◆ GUARDED_BY() [6/16]

indexed_transaction_set mapTx CTxMemPool::GUARDED_BY ( cs )

◆ GUARDED_BY() [7/16]

std::unique_ptr< TxGraph::BlockBuilder > m_builder CTxMemPool::GUARDED_BY ( cs )
mutable

◆ GUARDED_BY() [8/16]

std::unique_ptr< TxGraph > m_txgraph CTxMemPool::GUARDED_BY ( cs )

◆ GUARDED_BY() [9/16]

bool m_load_tried CTxMemPool::GUARDED_BY ( cs )
inlineprotected

Definition at line 206 of file txmempool.h.

◆ GUARDED_BY() [10/16]

uint64_t m_sequence_number CTxMemPool::GUARDED_BY ( cs )
inlinemutableprotected

minimum fee to get into the pool, decreases exponentially

Definition at line 202 of file txmempool.h.

◆ GUARDED_BY() [11/16]

double rollingMinimumFeeRate CTxMemPool::GUARDED_BY ( cs )
inlinemutableprotected

Definition at line 197 of file txmempool.h.

◆ GUARDED_BY() [12/16]

bool blockSinceLastRollingFeeBump CTxMemPool::GUARDED_BY ( cs )
inlinemutableprotected

Definition at line 196 of file txmempool.h.

◆ GUARDED_BY() [13/16]

int64_t lastRollingFeeUpdate CTxMemPool::GUARDED_BY ( cs )
inlinemutableprotected

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

Definition at line 195 of file txmempool.h.

Here is the call graph for this function:

◆ GUARDED_BY() [14/16]

uint64_t cachedInnerUsage CTxMemPool::GUARDED_BY ( cs )
inlineprotected

sum of all mempool tx's fees (NOT modified fee)

Definition at line 193 of file txmempool.h.

◆ GUARDED_BY() [15/16]

CAmount m_total_fee CTxMemPool::GUARDED_BY ( cs )
inlineprotected

sum of all mempool tx's virtual sizes. Differs from serialized tx size since witness data is discounted. Defined in BIP 141.

Definition at line 192 of file txmempool.h.

◆ GUARDED_BY() [16/16]

uint64_t totalTxSize CTxMemPool::GUARDED_BY ( cs )
inlineprotected

Definition at line 191 of file txmempool.h.

Here is the caller graph for this function:

◆ HasDescendants()

bool CTxMemPool::HasDescendants ( const Txid & txid) const

Definition at line 122 of file txmempool.cpp.

Here is the call graph for this function:

◆ 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 732 of file txmempool.cpp.

Here is the call graph for this function:

◆ IncludeBuilderChunk()

void CTxMemPool::IncludeBuilderChunk ( ) const
inline

Definition at line 734 of file txmempool.h.

Here is the caller graph for this function:

◆ info()

template<TxidOrWtxid T>
TxMempoolInfo CTxMemPool::info ( const T & id) const
inline

Definition at line 520 of file txmempool.h.

Here is the call graph for this function:

◆ info_for_relay()

template<TxidOrWtxid T>
TxMempoolInfo CTxMemPool::info_for_relay ( const T & id,
uint64_t last_sequence ) const
inline

Returns info for a transaction if its entry_sequence < last_sequence.

Definition at line 529 of file txmempool.h.

Here is the call graph for this function:

◆ infoAll()

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

Definition at line 600 of file txmempool.cpp.

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

◆ isSpent()

bool CTxMemPool::isSpent ( const COutPoint & outpoint) const

Definition at line 190 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 563 of file txmempool.h.

◆ PrioritiseTransaction()

void CTxMemPool::PrioritiseTransaction ( const Txid & hash,
const CAmount & nFeeDelta )

Affect CreateNewBlock prioritisation of transactions.

Definition at line 630 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)
private

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

Definition at line 405 of file txmempool.cpp.

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

◆ removeForReorg()

void CTxMemPool::removeForReorg ( CChain & chain,
std::function< bool(txiter)> filter_final_and_mature )

After reorg, filter the entries that would no longer be valid in the next block, and update the entries' cached LockPoints if needed.

The mempool does not have any knowledge of consensus rules. It just applies the callable function and removes the ones for which it returns true.

Parameters
[in]filter_final_and_maturePredicate that checks the relevant validation rules and updates an entry's LockPoints.

Definition at line 360 of file txmempool.cpp.

Here is the call graph for this function:

◆ removeRecursive()

void CTxMemPool::removeRecursive ( txiter to_remove,
MemPoolRemovalReason reason )
private

◆ RemoveStaged()

void CTxMemPool::RemoveStaged ( setEntries & stage,
MemPoolRemovalReason reason )
private

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.

Definition at line 793 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,
bool unchecked = false )

Removes a transaction from the unbroadcast set.

Definition at line 784 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

Definition at line 263 of file txmempool.cpp.

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

◆ SetLoadTried()

void CTxMemPool::SetLoadTried ( bool load_tried)

Set whether or not an initial attempt to load the persisted mempool was made (regardless of whether the attempt was successful or not).

Definition at line 962 of file txmempool.cpp.

Here is the caller graph for this function:

◆ size()

unsigned long CTxMemPool::size ( ) const
inline

Definition at line 485 of file txmempool.h.

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

◆ SkipBuilderChunk()

void CTxMemPool::SkipBuilderChunk ( ) const
inline

Definition at line 735 of file txmempool.h.

◆ StartBlockBuilding()

void CTxMemPool::StartBlockBuilding ( ) const
inline

Definition at line 720 of file txmempool.h.

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

◆ StopBlockBuilding()

void CTxMemPool::StopBlockBuilding ( ) const
inline

Definition at line 736 of file txmempool.h.

Here is the caller graph for this function:

◆ trackPackageRemoved()

void CTxMemPool::trackPackageRemoved ( const CFeeRate & rate)
protected

Definition at line 853 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 861 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 > & vHashesToUpdate)

UpdateTransactionsFromBlock is called 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).

Postcondition
updated descendant state for descendants of each transaction in vHashesToUpdate (excluding any child transactions present in vHashesToUpdate, which are already accounted for). Updated state includes add fee/size information for such descendants to the parent and updated ancestor state to include the parent.
Parameters
[in]vHashesToUpdateThe set of txids from the disconnected block that have been accepted back into the mempool.

Definition at line 91 of file txmempool.cpp.

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

◆ CTxMemPool::ChangeSet

friend class CTxMemPool::ChangeSet
friend

Definition at line 703 of file txmempool.h.

Member Data Documentation

◆ 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 (ActiveChain() 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 260 of file txmempool.h.

◆ cs_main

void CTxMemPool::cs_main

Definition at line 333 of file txmempool.h.

◆ m_opts

const Options CTxMemPool::m_opts

Definition at line 303 of file txmempool.h.

◆ nTransactionsUpdated

std::atomic<unsigned int> CTxMemPool::nTransactionsUpdated {0}
protected

Used by getblocktemplate to trigger CreateNewBlock() invocation.

Definition at line 189 of file txmempool.h.

◆ removeRecursive

void CTxMemPool::removeRecursive

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. Remove a transaction from the mempool along with any descendants. If the transaction is not already in the mempool, find any descendants and remove them.

Definition at line 325 of file txmempool.h.

◆ ROLLING_FEE_HALFLIFE

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

Definition at line 212 of file txmempool.h.


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