PIVX Core  5.6.99
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

struct  CompareIteratorByHash
 
struct  TxLinks
 

Public Types

typedef boost::multi_index_container< CTxMemPoolEntry, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< mempoolentry_txid, SaltedIdHasher >, 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_unique< boost::multi_index::tag< mining_score >, boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByScore >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ancestor_score >, boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByAncestorFee > > > indexed_transaction_set
 
typedef indexed_transaction_set::nth_index< 0 >::type::iterator txiter
 
typedef std::set< txiter, CompareIteratorByHashsetEntries
 

Public Member Functions

const setEntriesGetMemPoolParents (txiter entry) const
 
const setEntriesGetMemPoolChildren (txiter entry) const
 
 CTxMemPool (const CFeeRate &_minReasonableRelayFee)
 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)
 
bool addUnchecked (const uint256 &hash, const CTxMemPoolEntry &entry, bool validFeeEstimate=true)
 
bool addUnchecked (const uint256 &hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate=true)
 
void removeRecursive (const CTransaction &tx, MemPoolRemovalReason reason=MemPoolRemovalReason::UNKNOWN)
 
void removeForReorg (const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags)
 
void removeWithAnchor (const uint256 &invalidRoot)
 
void removeConflicts (const CTransaction &tx)
 
void removeForBlock (const std::vector< CTransactionRef > &vtx, unsigned int nBlockHeight)
 Called when a block is connected. More...
 
void clear ()
 
void _clear ()
 
bool CompareDepthAndScore (const uint256 &hasha, const uint256 &hashb)
 
void queryHashes (std::vector< uint256 > &vtxid)
 
void getTransactions (std::set< uint256 > &setTxid)
 
bool isSpent (const COutPoint &outpoint)
 
unsigned int GetTransactionsUpdated () const
 
void AddTransactionsUpdated (unsigned int n)
 
bool 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. More...
 
void PrioritiseTransaction (const uint256 &hash, const CAmount &nFeeDelta)
 Affect CreateNewBlock prioritisation of transactions. More...
 
void ApplyDelta (const uint256 &hash, CAmount &nFeeDelta) const
 
void ClearPrioritisation (const uint256 hash)
 
bool nullifierExists (const uint256 &nullifier) const
 
void RemoveStaged (setEntries &stage, bool updateDescendants, MemPoolRemovalReason reason=MemPoolRemovalReason::UNKNOWN)
 Remove a set of transactions from the mempool. More...
 
void UpdateTransactionsFromBlock (const std::vector< uint256 > &hashesToUpdate)
 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
 Try to calculate all in-mempool ancestors of entry. More...
 
void CalculateDescendants (txiter it, setEntries &setDescendants)
 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)
 Remove transactions from the mempool until its dynamic size is <= sizelimit. More...
 
int Expire (int64_t time)
 Expire all transaction (and their dependencies) in the mempool older than time. More...
 
bool TransactionWithinChainLimit (const uint256 &txid, size_t chainLimit) const
 Returns false if the transaction is in the mempool and not within the chain limit specified. More...
 
bool IsLoaded () const
 
void SetIsLoaded (bool loaded)
 Sets the current loaded state. More...
 
unsigned long size () const
 
uint64_t GetTotalTxSize ()
 
bool exists (uint256 hash) const
 
bool exists (const COutPoint &outpoint) const
 
CTransactionRef get (const uint256 &hash) const
 
TxMempoolInfo info (const uint256 &hash) const
 
std::vector< TxMempoolInfoinfoAll () const
 
bool existsProviderTxConflict (const CTransaction &tx) const
 
void removeProTxReferences (const uint256 &proTxHash, MemPoolRemovalReason reason)
 
CFeeRate estimateSmartFee (int nBlocks, int *answerFoundAtBlocks=nullptr) const
 Estimate fee rate needed to get into the next nBlocks If no answer can be given at nBlocks, return an estimate at the lowest number of blocks where one can be given. More...
 
CFeeRate estimateFee (int nBlocks) const
 Estimate fee rate needed to get into the next nBlocks. More...
 
bool WriteFeeEstimates (CAutoFile &fileout) const
 Write/Read estimates to disk. More...
 
bool ReadFeeEstimates (CAutoFile &filein)
 
size_t DynamicMemoryUsage () const
 

Public Attributes

RecursiveMutex cs
 This mutex needs to be locked when accessing mapTx or other members that are guarded by it. More...
 
indexed_transaction_set mapTx
 
indirectmap< COutPoint, CTransactionRefmapNextTx
 
std::map< uint256, CAmountmapDeltas
 

Static Public Attributes

static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12
 

Private Types

typedef std::map< txiter, setEntries, CompareIteratorByHashcacheMap
 
typedef std::map< txiter, TxLinks, CompareIteratorByHashtxlinksMap
 

Private Member Functions

void trackPackageRemoved (const CFeeRate &rate)
 minimum fee to get into the pool, decreases exponentially More...
 
void checkNullifiers () const
 
bool m_is_loaded GUARDED_BY (cs)
 
void UpdateParent (txiter entry, txiter parent, bool add)
 
void UpdateChild (txiter entry, txiter child, bool add)
 
std::vector< indexed_transaction_set::const_iterator > GetSortedDepthAndScore () const
 
void UpdateForDescendants (txiter updateIt, cacheMap &cachedDescendants, const std::set< uint256 > &setExclude)
 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)
 Update ancestors of hash to add/remove it as a descendant transaction. More...
 
void UpdateEntryForAncestors (txiter it, const setEntries &setAncestors)
 Set ancestor state for an entry. More...
 
void UpdateForRemoveFromMempool (const setEntries &entriesToRemove, bool updateDescendants)
 For each transaction being removed, update ancestors and any direct children. More...
 
void UpdateChildrenForRemoval (txiter entry)
 Sever link between specified transaction and direct children. More...
 
void removeUnchecked (txiter entry, MemPoolRemovalReason reason=MemPoolRemovalReason::UNKNOWN)
 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...
 
void addUncheckedSpecialTx (const CTransaction &tx)
 Special txes. More...
 
void removeUncheckedSpecialTx (const CTransaction &tx)
 
void removeProTxPubKeyConflicts (const CTransaction &tx, const CKeyID &keyId)
 
void removeProTxPubKeyConflicts (const CTransaction &tx, const CBLSPublicKey &pubKey)
 
void removeProTxCollateralConflicts (const CTransaction &tx, const COutPoint &collateralOutpoint)
 
void removeProTxSpentCollateralConflicts (const CTransaction &tx)
 
void removeProTxConflicts (const CTransaction &tx)
 

Private Attributes

uint32_t nCheckFrequency
 
unsigned int nTransactionsUpdated
 Value n means that n times in 2^32 we check. More...
 
CBlockPolicyEstimatorminerPolicyEstimator
 
CFeeRate minRelayFee
 
uint64_t totalTxSize
 Passed to constructor to avoid dependency on main. More...
 
uint64_t cachedInnerUsage
 sum of all mempool tx' byte sizes More...
 
CFeeRate minReasonableRelayFee
 sum of dynamic memory usage of all the map elements (NOT the maps themselves) More...
 
int64_t lastRollingFeeUpdate
 
bool blockSinceLastRollingFeeBump
 
double rollingMinimumFeeRate
 
std::map< uint256, CTransactionRefmapSaplingNullifiers
 
txlinksMap mapLinks
 
std::multimap< uint256, uint256mapProTxRefs
 
std::map< CService, uint256mapProTxAddresses
 
std::map< CKeyID, uint256mapProTxPubKeyIDs
 
std::map< uint256, uint256mapProTxBlsPubKeyHashes
 
std::map< COutPoint, uint256mapProTxCollaterals
 

Detailed Description

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

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

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.

Adding transactions from a disconnected block can be very time consuming, because we don't have a way to limit the number of in-mempool descendants. To bound CPU processing, we limit the amount of work we're willing to do to properly update the descendant information for a tx being added from a disconnected block. If we would exceed the limit, then we instead mark the entry as "dirty", and set the feerate for sorting purposes to be equal the feerate of the transaction without any descendants.

Definition at line 383 of file txmempool.h.

Member Typedef Documentation

◆ cacheMap

Definition at line 487 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, SaltedIdHasher>, 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_unique< boost::multi_index::tag<mining_score>, boost::multi_index::identity<CTxMemPoolEntry>, CompareTxMemPoolEntryByScore >, 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 442 of file txmempool.h.

◆ setEntries

Definition at line 481 of file txmempool.h.

◆ txiter

typedef indexed_transaction_set::nth_index<0>::type::iterator CTxMemPool::txiter

Definition at line 474 of file txmempool.h.

◆ txlinksMap

Definition at line 494 of file txmempool.h.

Constructor & Destructor Documentation

◆ CTxMemPool()

CTxMemPool::CTxMemPool ( const CFeeRate _minReasonableRelayFee)
explicit

Create a new CTxMemPool.

minReasonableRelayFee should be a feerate which is, roughly, somewhere around what it "costs" to relay a transaction around the network and below which we would reasonably say a transaction has 0-effective-fee.

Definition at line 326 of file txmempool.cpp.

Here is the call graph for this function:

◆ ~CTxMemPool()

CTxMemPool::~CTxMemPool ( )

Definition at line 340 of file txmempool.cpp.

Member Function Documentation

◆ _clear()

void CTxMemPool::_clear ( )

Definition at line 872 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 357 of file txmempool.cpp.

◆ addUnchecked() [1/2]

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

Definition at line 1366 of file txmempool.cpp.

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

◆ addUnchecked() [2/2]

bool CTxMemPool::addUnchecked ( const uint256 hash,
const CTxMemPoolEntry entry,
setEntries setAncestors,
bool  validFeeEstimate = true 
)
Todo:
: refactor so that the fee delta is calculated before inserting

Definition at line 415 of file txmempool.cpp.

Here is the call graph for this function:

◆ addUncheckedSpecialTx()

void CTxMemPool::addUncheckedSpecialTx ( const CTransaction tx)
private

Special txes.

Definition at line 363 of file txmempool.cpp.

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

◆ ApplyDelta()

void CTxMemPool::ApplyDelta ( const uint256 hash,
CAmount nFeeDelta 
) const

Definition at line 1265 of file txmempool.cpp.

Here is the caller graph for this function:

◆ CalculateDescendants()

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

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

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

Here is the call graph for this function:

◆ checkNullifiers()

void CTxMemPool::checkNullifiers ( ) const
private

Definition at line 1032 of file txmempool.cpp.

Here is the caller graph for this function:

◆ clear()

void CTxMemPool::clear ( )

Definition at line 887 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 uint256  hash)

Definition at line 1275 of file txmempool.cpp.

Here is the caller graph for this function:

◆ CompareDepthAndScore()

bool CTxMemPool::CompareDepthAndScore ( const uint256 hasha,
const uint256 hashb 
)

Definition at line 1043 of file txmempool.cpp.

Here is the caller graph for this function:

◆ DynamicMemoryUsage()

size_t CTxMemPool::DynamicMemoryUsage ( ) const

Definition at line 1327 of file txmempool.cpp.

Here is the caller graph for this function:

◆ estimateFee()

CFeeRate CTxMemPool::estimateFee ( int  nBlocks) const

Estimate fee rate needed to get into the next nBlocks.

Definition at line 1200 of file txmempool.cpp.

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

◆ estimateSmartFee()

CFeeRate CTxMemPool::estimateSmartFee ( int  nBlocks,
int *  answerFoundAtBlocks = nullptr 
) const

Estimate fee rate needed to get into the next nBlocks If no answer can be given at nBlocks, return an estimate at the lowest number of blocks where one can be given.

Definition at line 1206 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 COutPoint outpoint) const
inline

Definition at line 646 of file txmempool.h.

◆ exists() [2/2]

bool CTxMemPool::exists ( uint256  hash) const
inline

Definition at line 640 of file txmempool.h.

Here is the caller graph for this function:

◆ existsProviderTxConflict()

bool CTxMemPool::existsProviderTxConflict ( const CTransaction tx) const

Definition at line 1146 of file txmempool.cpp.

Here is the call graph for this function:

◆ Expire()

int CTxMemPool::Expire ( int64_t  time)

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

Return the number of removed transactions.

Definition at line 1349 of file txmempool.cpp.

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

◆ get()

std::shared_ptr< const CTransaction > CTxMemPool::get ( const uint256 hash) const

Definition at line 1128 of file txmempool.cpp.

Here is the caller graph for this function:

◆ GetMemPoolChildren()

const CTxMemPool::setEntries & CTxMemPool::GetMemPoolChildren ( txiter  entry) const

Definition at line 1404 of file txmempool.cpp.

Here is the caller graph for this function:

◆ GetMemPoolParents()

const CTxMemPool::setEntries & CTxMemPool::GetMemPoolParents ( txiter  entry) const

Definition at line 1396 of file txmempool.cpp.

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 minReasonableRelayFee constructor arg 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 1412 of file txmempool.cpp.

Here is the call graph for this function:

◆ GetSortedDepthAndScore()

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

Definition at line 1074 of file txmempool.cpp.

Here is the caller graph for this function:

◆ GetTotalTxSize()

uint64_t CTxMemPool::GetTotalTxSize ( )
inline

Definition at line 634 of file txmempool.h.

Here is the caller graph for this function:

◆ getTransactions()

void CTxMemPool::getTransactions ( std::set< uint256 > &  setTxid)

Definition at line 1119 of file txmempool.cpp.

◆ GetTransactionsUpdated()

unsigned int CTxMemPool::GetTransactionsUpdated ( ) const

Definition at line 351 of file txmempool.cpp.

◆ GUARDED_BY()

bool m_is_loaded CTxMemPool::GUARDED_BY ( cs  )
inlineprivate

Definition at line 406 of file txmempool.h.

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

Here is the call graph for this function:

◆ info()

TxMempoolInfo CTxMemPool::info ( const uint256 hash) const

Definition at line 1137 of file txmempool.cpp.

◆ infoAll()

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

Definition at line 1105 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 1497 of file txmempool.cpp.

Here is the caller graph for this function:

◆ isSpent()

bool CTxMemPool::isSpent ( const COutPoint outpoint)

Definition at line 345 of file txmempool.cpp.

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

◆ nullifierExists()

bool CTxMemPool::nullifierExists ( const uint256 nullifier) const

Definition at line 1281 of file txmempool.cpp.

Here is the caller graph for this function:

◆ PrioritiseTransaction()

void CTxMemPool::PrioritiseTransaction ( const uint256 hash,
const CAmount nFeeDelta 
)

Affect CreateNewBlock prioritisation of transactions.

Definition at line 1243 of file txmempool.cpp.

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

◆ queryHashes()

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

Definition at line 1088 of file txmempool.cpp.

Here is the call graph for this function:

◆ ReadFeeEstimates()

bool CTxMemPool::ReadFeeEstimates ( CAutoFile filein)

Definition at line 1226 of file txmempool.cpp.

◆ removeConflicts()

void CTxMemPool::removeConflicts ( const CTransaction tx)

Definition at line 688 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 844 of file txmempool.cpp.

Here is the call graph for this function:

◆ removeForReorg()

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

Definition at line 633 of file txmempool.cpp.

Here is the call graph for this function:

◆ removeProTxCollateralConflicts()

void CTxMemPool::removeProTxCollateralConflicts ( const CTransaction tx,
const COutPoint collateralOutpoint 
)
private

Definition at line 738 of file txmempool.cpp.

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

◆ removeProTxConflicts()

void CTxMemPool::removeProTxConflicts ( const CTransaction tx)
private

Definition at line 785 of file txmempool.cpp.

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

◆ removeProTxPubKeyConflicts() [1/2]

void CTxMemPool::removeProTxPubKeyConflicts ( const CTransaction tx,
const CBLSPublicKey pubKey 
)
private

Definition at line 728 of file txmempool.cpp.

Here is the call graph for this function:

◆ removeProTxPubKeyConflicts() [2/2]

void CTxMemPool::removeProTxPubKeyConflicts ( const CTransaction tx,
const CKeyID keyId 
)
private

Definition at line 718 of file txmempool.cpp.

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

◆ removeProTxReferences()

void CTxMemPool::removeProTxReferences ( const uint256 proTxHash,
MemPoolRemovalReason  reason 
)

Definition at line 748 of file txmempool.cpp.

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

◆ removeProTxSpentCollateralConflicts()

void CTxMemPool::removeProTxSpentCollateralConflicts ( const CTransaction tx)
private

Definition at line 768 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 = MemPoolRemovalReason::UNKNOWN 
)

Definition at line 601 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 = MemPoolRemovalReason::UNKNOWN 
)

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 1340 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 = MemPoolRemovalReason::UNKNOWN 
)
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 540 of file txmempool.cpp.

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

◆ removeUncheckedSpecialTx()

void CTxMemPool::removeUncheckedSpecialTx ( const CTransaction tx)
private

Definition at line 480 of file txmempool.cpp.

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

◆ removeWithAnchor()

void CTxMemPool::removeWithAnchor ( const uint256 invalidRoot)

Definition at line 664 of file txmempool.cpp.

Here is the call graph for this function:

◆ SetIsLoaded()

void CTxMemPool::SetIsLoaded ( bool  loaded)

Sets the current loaded state.

Definition at line 1503 of file txmempool.cpp.

◆ setSanityCheck()

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

Definition at line 527 of file txmempool.h.

◆ size()

unsigned long CTxMemPool::size ( ) const
inline

Definition at line 629 of file txmempool.h.

Here is the caller graph for this function:

◆ trackPackageRemoved()

void CTxMemPool::trackPackageRemoved ( const CFeeRate rate)
private

minimum fee to get into the pool, decreases exponentially

Definition at line 1437 of file txmempool.cpp.

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

◆ TransactionWithinChainLimit()

bool CTxMemPool::TransactionWithinChainLimit ( const uint256 txid,
size_t  chainLimit 
) const

Returns false if the transaction is in the mempool and not within the chain limit specified.

Definition at line 1490 of file txmempool.cpp.

◆ 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 transactions which are not in mempool which no longer have any spends in this mempool.

Definition at line 1446 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 211 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 1376 of file txmempool.cpp.

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 240 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 226 of file txmempool.cpp.

Here is the caller graph for this function:

◆ UpdateForDescendants()

void CTxMemPool::UpdateForDescendants ( txiter  updateIt,
cacheMap cachedDescendants,
const std::set< uint256 > &  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 59 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 248 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 1386 of file txmempool.cpp.

Here is the caller graph for this function:

◆ UpdateTransactionsFromBlock()

void CTxMemPool::UpdateTransactionsFromBlock ( const std::vector< uint256 > &  hashesToUpdate)

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 hashesToUpdate (excluding any child transactions present in hashesToUpdate, which are already accounted for). Note: hashesToUpdate should be the set of transactions from the disconnected block that have been accepted back into the mempool.

Definition at line 106 of file txmempool.cpp.

Here is the call graph for this function:

◆ WriteFeeEstimates()

bool CTxMemPool::WriteFeeEstimates ( CAutoFile fileout) const

Write/Read estimates to disk.

Definition at line 1212 of file txmempool.cpp.

Member Data Documentation

◆ blockSinceLastRollingFeeBump

bool CTxMemPool::blockSinceLastRollingFeeBump
mutableprivate

Definition at line 397 of file txmempool.h.

◆ cachedInnerUsage

uint64_t CTxMemPool::cachedInnerUsage
private

sum of all mempool tx' byte sizes

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

◆ lastRollingFeeUpdate

int64_t CTxMemPool::lastRollingFeeUpdate
mutableprivate

Definition at line 396 of file txmempool.h.

◆ mapDeltas

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

Definition at line 510 of file txmempool.h.

◆ mapLinks

txlinksMap CTxMemPool::mapLinks
private

Definition at line 495 of file txmempool.h.

◆ mapNextTx

indirectmap<COutPoint, CTransactionRef> CTxMemPool::mapNextTx

Definition at line 509 of file txmempool.h.

◆ mapProTxAddresses

std::map<CService, uint256> CTxMemPool::mapProTxAddresses
private

Definition at line 498 of file txmempool.h.

◆ mapProTxBlsPubKeyHashes

std::map<uint256, uint256> CTxMemPool::mapProTxBlsPubKeyHashes
private

Definition at line 500 of file txmempool.h.

◆ mapProTxCollaterals

std::map<COutPoint, uint256> CTxMemPool::mapProTxCollaterals
private

Definition at line 501 of file txmempool.h.

◆ mapProTxPubKeyIDs

std::map<CKeyID, uint256> CTxMemPool::mapProTxPubKeyIDs
private

Definition at line 499 of file txmempool.h.

◆ mapProTxRefs

std::multimap<uint256, uint256> CTxMemPool::mapProTxRefs
private

Definition at line 497 of file txmempool.h.

◆ mapSaplingNullifiers

std::map<uint256, CTransactionRef> CTxMemPool::mapSaplingNullifiers
private

Definition at line 403 of file txmempool.h.

◆ mapTx

indexed_transaction_set CTxMemPool::mapTx

Definition at line 472 of file txmempool.h.

◆ minerPolicyEstimator

CBlockPolicyEstimator* CTxMemPool::minerPolicyEstimator
private

Definition at line 388 of file txmempool.h.

◆ minReasonableRelayFee

CFeeRate CTxMemPool::minReasonableRelayFee
private

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

Definition at line 394 of file txmempool.h.

◆ minRelayFee

CFeeRate CTxMemPool::minRelayFee
private

Definition at line 390 of file txmempool.h.

◆ nCheckFrequency

uint32_t CTxMemPool::nCheckFrequency
private

Definition at line 386 of file txmempool.h.

◆ nTransactionsUpdated

unsigned int CTxMemPool::nTransactionsUpdated
private

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

Definition at line 387 of file txmempool.h.

◆ ROLLING_FEE_HALFLIFE

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

Definition at line 410 of file txmempool.h.

◆ rollingMinimumFeeRate

double CTxMemPool::rollingMinimumFeeRate
mutableprivate

Definition at line 398 of file txmempool.h.

◆ totalTxSize

uint64_t CTxMemPool::totalTxSize
private

Passed to constructor to avoid dependency on main.

Definition at line 391 of file txmempool.h.


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