Changeset View
Changeset View
Standalone View
Standalone View
src/txmempool.h
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | |||||
* When a new entry is added to the mempool, we update the descendant state | * When a new entry is added to the mempool, we update the descendant state | ||||
* (nCountWithDescendants, nSizeWithDescendants, and nModFeesWithDescendants) | * (nCountWithDescendants, nSizeWithDescendants, and nModFeesWithDescendants) | ||||
* for all ancestors of the newly added transaction. | * for all ancestors of the newly added transaction. | ||||
*/ | */ | ||||
class CTxMemPoolEntry { | class CTxMemPoolEntry { | ||||
private: | private: | ||||
const CTransactionRef tx; | const CTransactionRef tx; | ||||
//!< Cached to avoid expensive parent-transaction lookups | //! Cached to avoid expensive parent-transaction lookups | ||||
const Amount nFee; | const Amount nFee; | ||||
//!< ... and avoid recomputing tx size | //! ... and avoid recomputing tx size | ||||
const size_t nTxSize; | const size_t nTxSize; | ||||
//!< ... and total memory usage | //! ... and total memory usage | ||||
const size_t nUsageSize; | const size_t nUsageSize; | ||||
//!< Local time when entering the mempool | //! Local time when entering the mempool | ||||
const int64_t nTime; | const int64_t nTime; | ||||
//!< Chain height when entering the mempool | //! Chain height when entering the mempool | ||||
const unsigned int entryHeight; | const unsigned int entryHeight; | ||||
//!< keep track of transactions that spend a coinbase | //! keep track of transactions that spend a coinbase | ||||
const bool spendsCoinbase; | const bool spendsCoinbase; | ||||
//!< Total sigop plus P2SH sigops count | //! Total sigop plus P2SH sigops count | ||||
const int64_t sigOpCount; | const int64_t sigOpCount; | ||||
//!< Used for determining the priority of the transaction for mining in a | //! Used for determining the priority of the transaction for mining in a | ||||
//! block | //! block | ||||
Amount feeDelta; | Amount feeDelta; | ||||
//!< Track the height and time at which tx was final | //! Track the height and time at which tx was final | ||||
LockPoints lockPoints; | LockPoints lockPoints; | ||||
// Information about descendants of this transaction that are in the | // Information about descendants of this transaction that are in the | ||||
// mempool; if we remove this transaction we must remove all of these | // mempool; if we remove this transaction we must remove all of these | ||||
// descendants as well. | // descendants as well. | ||||
//!< number of descendant transactions | //! number of descendant transactions | ||||
uint64_t nCountWithDescendants; | uint64_t nCountWithDescendants; | ||||
//!< ... and size | //! ... and size | ||||
uint64_t nSizeWithDescendants; | uint64_t nSizeWithDescendants; | ||||
//!< ... and total fees (all including us) | //! ... and total fees (all including us) | ||||
Amount nModFeesWithDescendants; | Amount nModFeesWithDescendants; | ||||
//!< ... and sigop count | //! ... and sigop count | ||||
int64_t nSigOpCountWithDescendants; | int64_t nSigOpCountWithDescendants; | ||||
// Analogous statistics for ancestor transactions | // Analogous statistics for ancestor transactions | ||||
uint64_t nCountWithAncestors; | uint64_t nCountWithAncestors; | ||||
uint64_t nSizeWithAncestors; | uint64_t nSizeWithAncestors; | ||||
Amount nModFeesWithAncestors; | Amount nModFeesWithAncestors; | ||||
int64_t nSigOpCountWithAncestors; | int64_t nSigOpCountWithAncestors; | ||||
Show All 40 Lines | public: | ||||
uint64_t GetCountWithAncestors() const { return nCountWithAncestors; } | uint64_t GetCountWithAncestors() const { return nCountWithAncestors; } | ||||
uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; } | uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; } | ||||
uint64_t GetVirtualSizeWithAncestors() const; | uint64_t GetVirtualSizeWithAncestors() const; | ||||
Amount GetModFeesWithAncestors() const { return nModFeesWithAncestors; } | Amount GetModFeesWithAncestors() const { return nModFeesWithAncestors; } | ||||
int64_t GetSigOpCountWithAncestors() const { | int64_t GetSigOpCountWithAncestors() const { | ||||
return nSigOpCountWithAncestors; | return nSigOpCountWithAncestors; | ||||
} | } | ||||
//!< Index in mempool's vTxHashes | //! Index in mempool's vTxHashes | ||||
mutable size_t vTxHashesIdx; | mutable size_t vTxHashesIdx; | ||||
}; | }; | ||||
// Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index. | // Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index. | ||||
struct update_descendant_state { | struct update_descendant_state { | ||||
update_descendant_state(int64_t _modifySize, Amount _modifyFee, | update_descendant_state(int64_t _modifySize, Amount _modifyFee, | ||||
int64_t _modifyCount, int64_t _modifySigOpCount) | int64_t _modifyCount, int64_t _modifySigOpCount) | ||||
: modifySize(_modifySize), modifyFee(_modifyFee), | : modifySize(_modifySize), modifyFee(_modifyFee), | ||||
▲ Show 20 Lines • Show All 193 Lines • ▼ Show 20 Lines | struct TxMempoolInfo { | ||||
Amount nFeeDelta; | Amount nFeeDelta; | ||||
}; | }; | ||||
/** | /** | ||||
* Reason why a transaction was removed from the mempool, this is passed to the | * Reason why a transaction was removed from the mempool, this is passed to the | ||||
* notification signal. | * notification signal. | ||||
*/ | */ | ||||
enum class MemPoolRemovalReason { | enum class MemPoolRemovalReason { | ||||
//!< Manually removed or unknown reason | //! Manually removed or unknown reason | ||||
UNKNOWN = 0, | UNKNOWN = 0, | ||||
//!< Expired from mempool | //! Expired from mempool | ||||
EXPIRY, | EXPIRY, | ||||
//!< Removed in size limiting | //! Removed in size limiting | ||||
SIZELIMIT, | SIZELIMIT, | ||||
//!< Removed for reorganization | //! Removed for reorganization | ||||
REORG, | REORG, | ||||
//!< Removed for block | //! Removed for block | ||||
BLOCK, | BLOCK, | ||||
//!< Removed for conflict with in-block transaction | //! Removed for conflict with in-block transaction | ||||
CONFLICT, | CONFLICT, | ||||
//!< Removed for replacement | //! Removed for replacement | ||||
REPLACED | REPLACED | ||||
}; | }; | ||||
class SaltedTxidHasher { | class SaltedTxidHasher { | ||||
private: | private: | ||||
/** Salt */ | /** Salt */ | ||||
const uint64_t k0, k1; | const uint64_t k0, k1; | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* Updating all in-mempool ancestors of a newly added transaction can be slow, | * 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. | * if no bound exists on how many in-mempool ancestors there may be. | ||||
* CalculateMemPoolAncestors() takes configurable limits that are designed to | * CalculateMemPoolAncestors() takes configurable limits that are designed to | ||||
* prevent these calculations from being too CPU intensive. | * prevent these calculations from being too CPU intensive. | ||||
*/ | */ | ||||
class CTxMemPool { | class CTxMemPool { | ||||
private: | private: | ||||
//!< Value n means that n times in 2^32 we check. | //! Value n means that n times in 2^32 we check. | ||||
uint32_t nCheckFrequency GUARDED_BY(cs); | uint32_t nCheckFrequency GUARDED_BY(cs); | ||||
//!< Used by getblocktemplate to trigger CreateNewBlock() invocation | //! Used by getblocktemplate to trigger CreateNewBlock() invocation | ||||
unsigned int nTransactionsUpdated; | unsigned int nTransactionsUpdated; | ||||
//!< sum of all mempool tx's sizes. | //! sum of all mempool tx's sizes. | ||||
uint64_t totalTxSize; | uint64_t totalTxSize; | ||||
//!< sum of dynamic memory usage of all the map elements (NOT the maps | //! sum of dynamic memory usage of all the map elements (NOT the maps | ||||
//! themselves) | //! themselves) | ||||
uint64_t cachedInnerUsage; | uint64_t cachedInnerUsage; | ||||
mutable int64_t lastRollingFeeUpdate; | mutable int64_t lastRollingFeeUpdate; | ||||
mutable bool blockSinceLastRollingFeeBump; | mutable bool blockSinceLastRollingFeeBump; | ||||
//!< minimum fee to get into the pool, decreases exponentially | //! minimum fee to get into the pool, decreases exponentially | ||||
mutable double rollingMinimumFeeRate; | mutable double rollingMinimumFeeRate; | ||||
void trackPackageRemoved(const CFeeRate &rate) EXCLUSIVE_LOCKS_REQUIRED(cs); | void trackPackageRemoved(const CFeeRate &rate) EXCLUSIVE_LOCKS_REQUIRED(cs); | ||||
bool m_is_loaded GUARDED_BY(cs){false}; | bool m_is_loaded GUARDED_BY(cs){false}; | ||||
public: | public: | ||||
// public only for testing | // public only for testing | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | public: | ||||
* fix for third party code that needs be able to frequently poll the | * fix for third party code that needs be able to frequently poll the | ||||
* mempool without locking `cs_main` and without encountering missing | * mempool without locking `cs_main` and without encountering missing | ||||
* transactions during reorgs. | * transactions during reorgs. | ||||
*/ | */ | ||||
mutable RecursiveMutex cs; | mutable RecursiveMutex cs; | ||||
indexed_transaction_set mapTx GUARDED_BY(cs); | indexed_transaction_set mapTx GUARDED_BY(cs); | ||||
typedef indexed_transaction_set::nth_index<0>::type::iterator txiter; | typedef indexed_transaction_set::nth_index<0>::type::iterator txiter; | ||||
//!< All tx hashes/entries in mapTx, in random order | //! All tx hashes/entries in mapTx, in random order | ||||
std::vector<std::pair<TxHash, txiter>> vTxHashes; | std::vector<std::pair<TxHash, txiter>> vTxHashes; | ||||
struct CompareIteratorById { | struct CompareIteratorById { | ||||
bool operator()(const txiter &a, const txiter &b) const { | bool operator()(const txiter &a, const txiter &b) const { | ||||
return a->GetTx().GetId() < b->GetTx().GetId(); | return a->GetTx().GetId() < b->GetTx().GetId(); | ||||
} | } | ||||
}; | }; | ||||
typedef std::set<txiter, CompareIteratorById> setEntries; | typedef std::set<txiter, CompareIteratorById> setEntries; | ||||
▲ Show 20 Lines • Show All 419 Lines • Show Last 20 Lines |