![]() |
Bitcoin Core
23.99.0
P2P Digital Currency
|
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the next block. More...
#include <txmempool.h>
Public Types | |
typedef boost::multi_index_container< CTxMemPoolEntry, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< mempoolentry_txid, SaltedTxidHasher >, boost::multi_index::hashed_unique< boost::multi_index::tag< index_by_wtxid >, mempoolentry_wtxid, 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, CompareIteratorByHash > | setEntries |
Public Member Functions | |
indexed_transaction_set mapTx | GUARDED_BY (cs) |
std::vector< std::pair< uint256, txiter > > vTxHashes | GUARDED_BY (cs) |
All tx witness 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) |
std::map< uint256, CAmount > mapDeltas | GUARDED_BY (cs) |
CTxMemPool (CBlockPolicyEstimator *estimator=nullptr, int check_ratio=0) | |
Create a new CTxMemPool. More... | |
void | addUnchecked (const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate=true) EXCLUSIVE_LOCKS_REQUIRED(cs |
void | removeRecursive (const CTransaction &tx, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs) |
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. More... | |
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 uint256 &hasha, const uint256 &hashb, bool wtxid=false) |
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 uint256 &hash, const CAmount &nFeeDelta) |
Affect CreateNewBlock prioritisation of transactions. More... | |
void | ApplyDelta (const uint256 &hash, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs) |
void | ClearPrioritisation (const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs) |
const CTransaction * | GetConflictTx (const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs) |
Get the transaction in the pool that spends the same prevout. More... | |
std::optional< txiter > | GetIter (const uint256 &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs) |
Returns an iterator to the given hash, if found. More... | |
setEntries | GetIterSet (const std::set< uint256 > &hashes) const EXCLUSIVE_LOCKS_REQUIRED(cs) |
Translate a set of hashes 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< uint256 > &vHashesToUpdate, uint64_t ancestor_size_limit, uint64_t ancestor_count_limit) 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). More... | |
void cs_main | LOCKS_EXCLUDED (m_epoch) |
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... | |
bool | CheckPackageLimits (const Package &package, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString) const EXCLUSIVE_LOCKS_REQUIRED(cs) |
Calculate all in-mempool ancestors of a set of transactions not already in the mempool and check ancestor and descendant limits. 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 | GetTransactionAncestry (const uint256 &txid, size_t &ancestors, size_t &descendants, size_t *ancestorsize=nullptr, CAmount *ancestorfees=nullptr) 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) |
CAmount | GetTotalFee () const EXCLUSIVE_LOCKS_REQUIRED(cs) |
bool | exists (const GenTxid >xid) const |
CTransactionRef | get (const uint256 &hash) const |
txiter | get_iter_from_wtxid (const uint256 &wtxid) const EXCLUSIVE_LOCKS_REQUIRED(cs) |
TxMempoolInfo | info (const GenTxid >xid) const |
std::vector< TxMempoolInfo > | infoAll () const |
size_t | DynamicMemoryUsage () const |
void | AddUnbroadcastTx (const uint256 &txid) |
Adds a transaction to the unbroadcast set. More... | |
void | RemoveUnbroadcastTx (const uint256 &txid, const bool unchecked=false) |
Removes a transaction from the unbroadcast set. More... | |
std::set< uint256 > | GetUnbroadcastTxs () const |
Returns transactions in unbroadcast set. More... | |
bool | IsUnbroadcastTx (const uint256 &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) |
bool | visited (const txiter it) const EXCLUSIVE_LOCKS_REQUIRED(cs |
visited marks a CTxMemPoolEntry as having been traversed during the lifetime of the most recently created Epoch::Guard 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... | |
void check(const CCoinsViewCache &active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(void | addUnchecked (const CTxMemPoolEntry &entry, bool validFeeEstimate=true) 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). More... | |
void check(const CCoinsViewCache &active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(void | cs_main |
void | cs_main |
bool | m_epoch |
return !it visited * | it |
Static Public Attributes | |
static const int | ROLLING_FEE_HALFLIFE = 60 * 60 * 12 |
Protected Member Functions | |
uint64_t totalTxSize | 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. More... | |
CAmount m_total_fee | GUARDED_BY (cs) |
sum of all mempool tx's fees (NOT modified fee) More... | |
uint64_t cachedInnerUsage | GUARDED_BY (cs) |
sum of dynamic memory usage of all the map elements (NOT the maps themselves) More... | |
int64_t lastRollingFeeUpdate | GUARDED_BY (cs) |
bool blockSinceLastRollingFeeBump | GUARDED_BY (cs) |
double rollingMinimumFeeRate | GUARDED_BY (cs) |
minimum fee to get into the pool, decreases exponentially More... | |
Epoch m_epoch | GUARDED_BY (cs) |
uint64_t m_sequence_number | GUARDED_BY (cs) |
void | trackPackageRemoved (const CFeeRate &rate) EXCLUSIVE_LOCKS_REQUIRED(cs) |
bool m_is_loaded | GUARDED_BY (cs) |
Protected Attributes | |
const int | m_check_ratio |
Value n means that 1 times in n we check. More... | |
std::atomic< unsigned int > | nTransactionsUpdated {0} |
Used by getblocktemplate to trigger CreateNewBlock() invocation. More... | |
CBlockPolicyEstimator *const | minerPolicyEstimator |
Private Types | |
typedef std::map< txiter, setEntries, CompareIteratorByHash > | cacheMap |
Private Member Functions | |
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< uint256 > m_unbroadcast_txids | GUARDED_BY (cs) |
Track locally submitted transactions to periodically retry initial broadcast. More... | |
bool | CalculateAncestorsAndCheckLimits (size_t entry_size, size_t entry_count, setEntries &setAncestors, CTxMemPoolEntry::Parents &staged_ancestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString) const EXCLUSIVE_LOCKS_REQUIRED(cs) |
Helper function to calculate all in-mempool ancestors of staged_ancestors and apply ancestor and descendant limits (including staged_ancestors thsemselves, entry_size and entry_count). More... | |
void | UpdateForDescendants (txiter updateIt, cacheMap &cachedDescendants, const std::set< uint256 > &setExclude, std::set< uint256 > &descendants_to_remove, uint64_t ancestor_size_limit, uint64_t ancestor_count_limit) 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... | |
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 5 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 429 of file txmempool.h.
|
private |
Definition at line 527 of file txmempool.h.
typedef boost::multi_index_container< CTxMemPoolEntry, boost::multi_index::indexed_by< boost::multi_index::hashed_unique<mempoolentry_txid, SaltedTxidHasher>, boost::multi_index::hashed_unique< boost::multi_index::tag<index_by_wtxid>, mempoolentry_wtxid, 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 488 of file txmempool.h.
typedef std::set<txiter, CompareIteratorByHash> CTxMemPool::setEntries |
Definition at line 523 of file txmempool.h.
using CTxMemPool::txiter = indexed_transaction_set::nth_index<0>::type::const_iterator |
Definition at line 520 of file txmempool.h.
|
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.
[in] | estimator | is used to estimate appropriate transaction fees. |
[in] | check_ratio | is the ratio used to determine how often sanity checks will run. |
Definition at line 454 of file txmempool.cpp.
void CTxMemPool::_clear | ( | ) |
Definition at line 693 of file txmempool.cpp.
void CTxMemPool::AddTransactionsUpdated | ( | unsigned int | n | ) |
Definition at line 471 of file txmempool.cpp.
|
inline |
Adds a transaction to the unbroadcast set.
Definition at line 768 of file txmempool.h.
void CTxMemPool::addUnchecked | ( | const CTxMemPoolEntry & | entry, |
setEntries & | setAncestors, | ||
bool | validFeeEstimate = true |
||
) |
|
private |
Helper function to calculate all in-mempool ancestors of staged_ancestors and apply ancestor and descendant limits (including staged_ancestors thsemselves, entry_size and entry_count).
param@[in] entry_size Virtual size to include in the limits. param@[in] entry_count How many entries to include in the limits. param@[in] staged_ancestors Should contain entries in the mempool. param@[out] setAncestors Will be populated with all mempool ancestors.
Definition at line 214 of file txmempool.cpp.
uint64_t CTxMemPool::CalculateDescendantMaximum | ( | txiter | entry | ) | const |
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 570 of file txmempool.cpp.
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 298 of file txmempool.cpp.
bool CTxMemPool::CheckPackageLimits | ( | const Package & | package, |
uint64_t | limitAncestorCount, | ||
uint64_t | limitAncestorSize, | ||
uint64_t | limitDescendantCount, | ||
uint64_t | limitDescendantSize, | ||
std::string & | errString | ||
) | const |
Calculate all in-mempool ancestors of a set of transactions not already in the mempool and check ancestor and descendant limits.
Heuristics are used to estimate the ancestor and descendant count of all entries if the package were to be added to the mempool. The limits are applied to the union of all package transactions. For example, if the package has 3 transactions and limitAncestorCount = 25, the union of all 3 sets of ancestors (including the transactions themselves) must be <= 22.
[in] | package | Transaction package being evaluated for acceptance to mempool. The transactions need not be direct ancestors/descendants of each other. |
[in] | limitAncestorCount | Max number of txns including ancestors. |
[in] | limitAncestorSize | Max virtual size including ancestors. |
[in] | limitDescendantCount | Max number of txns including descendants. |
[in] | limitDescendantSize | Max virtual size including descendants. |
[out] | errString | Populated with error reason if a limit is hit. |
Definition at line 263 of file txmempool.cpp.
void CTxMemPool::clear | ( | ) |
void CTxMemPool::ClearPrioritisation | ( | const uint256 & | hash | ) |
Definition at line 955 of file txmempool.cpp.
size_t CTxMemPool::DynamicMemoryUsage | ( | ) | const |
Definition at line 1024 of file txmempool.cpp.
|
inline |
Definition at line 747 of file txmempool.h.
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 1047 of file txmempool.cpp.
CTransactionRef CTxMemPool::get | ( | const uint256 & | hash | ) | const |
Definition at line 757 of file txmempool.h.
|
inline |
Guards this internal counter for external reporting.
Definition at line 794 of file txmempool.h.
const CTransaction * CTxMemPool::GetConflictTx | ( | const COutPoint & | prevout | ) | const |
Get the transaction in the pool that spends the same prevout.
Definition at line 961 of file txmempool.cpp.
std::optional< CTxMemPool::txiter > CTxMemPool::GetIter | ( | const uint256 & | txid | ) | const |
Returns an iterator to the given hash, if found.
Definition at line 967 of file txmempool.cpp.
CTxMemPool::setEntries CTxMemPool::GetIterSet | ( | const std::set< uint256 > & | hashes | ) | const |
Translate a set of hashes into a set of pool iterators to avoid repeated lookups.
Definition at line 974 of file txmempool.cpp.
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 1095 of file txmempool.cpp.
|
inline |
|
private |
Definition at line 852 of file txmempool.cpp.
|
inline |
Definition at line 741 of file txmempool.h.
|
inline |
Definition at line 735 of file txmempool.h.
void CTxMemPool::GetTransactionAncestry | ( | const uint256 & | txid, |
size_t & | ancestors, | ||
size_t & | descendants, | ||
size_t * | ancestorsize = nullptr , |
||
CAmount * | ancestorfees = nullptr |
||
) | const |
Calculate the ancestor and descendant 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 1192 of file txmempool.cpp.
unsigned int CTxMemPool::GetTransactionsUpdated | ( | ) | const |
|
inline |
Returns transactions in unbroadcast set.
Definition at line 780 of file txmempool.h.
|
protected |
sum of all mempool tx's virtual sizes. Differs from serialized tx size since witness data is discounted. Defined in BIP 141.
sum of all mempool tx's fees (NOT modified fee)
|
protected |
sum of dynamic memory usage of all the map elements (NOT the maps themselves)
|
mutableprotected |
|
mutableprotected |
|
mutableprotected |
minimum fee to get into the pool, decreases exponentially
|
inlinemutableprotected |
Definition at line 448 of file txmempool.h.
|
inlineprotected |
Definition at line 452 of file txmempool.h.
indexed_transaction_set mapTx CTxMemPool::GUARDED_BY | ( | cs | ) |
All tx witness hashes/entries in mapTx, in random order.
Track locally submitted transactions to periodically retry initial broadcast.
indirectmap<COutPoint, const CTransaction*> mapNextTx CTxMemPool::GUARDED_BY | ( | cs | ) |
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 984 of file txmempool.cpp.
TxMempoolInfo CTxMemPool::info | ( | const GenTxid & | gtxid | ) | const |
std::vector< TxMempoolInfo > CTxMemPool::infoAll | ( | ) | const |
Definition at line 883 of file txmempool.cpp.
bool CTxMemPool::IsLoaded | ( | ) | const |
Definition at line 1204 of file txmempool.cpp.
bool CTxMemPool::isSpent | ( | const COutPoint & | outpoint | ) | const |
|
inline |
Returns whether a txid is in the unbroadcast set.
Definition at line 787 of file txmempool.h.
Affect CreateNewBlock prioritisation of transactions.
Definition at line 915 of file txmempool.cpp.
void CTxMemPool::queryHashes | ( | std::vector< uint256 > & | vtxid | ) | const |
Definition at line 866 of file txmempool.cpp.
void CTxMemPool::removeConflicts | ( | const CTransaction & | tx | ) |
Definition at line 644 of file txmempool.cpp.
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 664 of file txmempool.cpp.
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 appplies the callable function and removes the ones for which it returns true.
[in] | filter_final_and_mature | Predicate that checks the relevant validation rules and updates an entry's LockPoints. |
Definition at line 624 of file txmempool.cpp.
void CTxMemPool::removeRecursive | ( | const CTransaction & | tx, |
MemPoolRemovalReason | reason | ||
) |
Definition at line 594 of file txmempool.cpp.
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 1039 of file txmempool.cpp.
void CTxMemPool::RemoveUnbroadcastTx | ( | const uint256 & | txid, |
const bool | unchecked = false |
||
) |
Removes a transaction from the unbroadcast set.
Definition at line 1030 of file txmempool.cpp.
|
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 526 of file txmempool.cpp.
void CTxMemPool::SetIsLoaded | ( | bool | loaded | ) |
Sets the current loaded state.
Definition at line 1210 of file txmempool.cpp.
|
inline |
|
protected |
Definition at line 1119 of file txmempool.cpp.
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 1127 of file txmempool.cpp.
|
private |
Update ancestors of hash to add/remove it as a descendant transaction.
Definition at line 337 of file txmempool.cpp.
Definition at line 1073 of file txmempool.cpp.
|
private |
Sever link between specified transaction and direct children.
Definition at line 366 of file txmempool.cpp.
|
private |
Set ancestor state for an entry.
Definition at line 352 of file txmempool.cpp.
|
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.
[in] | updateIt | the entry to update for its descendants |
[in,out] | cachedDescendants | a cache where each line corresponds to all descendants. It 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. |
[in] | setExclude | 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). |
[out] | descendants_to_remove | Populated with the txids of entries that exceed ancestor limits. It's the responsibility of the caller to removeRecursive them. |
[in] | ancestor_size_limit | the max number of ancestral bytes allowed for any descendant |
[in] | ancestor_count_limit | the max number of ancestor transactions allowed for any descendant |
Definition at line 109 of file txmempool.cpp.
|
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 374 of file txmempool.cpp.
Definition at line 1084 of file txmempool.cpp.
void CTxMemPool::UpdateTransactionsFromBlock | ( | const std::vector< uint256 > & | vHashesToUpdate, |
uint64_t | ancestor_size_limit, | ||
uint64_t | ancestor_count_limit | ||
) |
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).
[in] | vHashesToUpdate | The set of txids from the disconnected block that have been accepted back into the mempool. |
[in] | ancestor_size_limit | The maximum allowed size in virtual bytes of an entry and its ancestors |
[in] | ancestor_count_limit | The maximum allowed number of transactions including the entry and its ancestors. |
Definition at line 159 of file txmempool.cpp.
bool CTxMemPool::visited | ( | const txiter | it | ) | const |
visited marks a CTxMemPoolEntry as having been traversed during the lifetime of the most recently created Epoch::Guard and returns false if we are the first visitor, true otherwise.
An Epoch::Guard must be held when visited is called or an assert will be triggered.
bool CTxMemPool::visited | ( | std::optional< txiter > | it | ) | const |
void CTxMemPool::addUnchecked |
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 588 of file txmempool.h.
|
mutable |
This mutex needs to be locked when accessing mapTx
or other members that are guarded by it.
By design, it is guaranteed that:
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.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 517 of file txmempool.h.
void CTxMemPool::cs_main |
Definition at line 588 of file txmempool.h.
void CTxMemPool::cs_main |
Definition at line 589 of file txmempool.h.
Definition at line 875 of file txmempool.h.
|
protected |
Value n means that 1 times in n we check.
Definition at line 432 of file txmempool.h.
bool CTxMemPool::m_epoch |
Definition at line 868 of file txmempool.h.
|
protected |
Definition at line 434 of file txmempool.h.
|
protected |
Used by getblocktemplate to trigger CreateNewBlock() invocation.
Definition at line 433 of file txmempool.h.
|
static |
Definition at line 456 of file txmempool.h.