Changeset View
Changeset View
Standalone View
Standalone View
src/txmempool.h
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* CTxMemPoolEntry stores data about the corresponding transaction, as well as | * CTxMemPoolEntry stores data about the corresponding transaction, as well as | ||||
* data about all in-mempool transactions that depend on the transaction | * data about all in-mempool transactions that depend on the transaction | ||||
* ("descendant" transactions). | * ("descendant" transactions). | ||||
* | * | ||||
* 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. | ||||
* | |||||
* If updating the descendant state is skipped, we can mark the entry as | |||||
* "dirty", and set nSizeWithDescendants/nModFeesWithDescendants to equal | |||||
* nTxSize/nFee+feeDelta. (This can potentially happen during a reorg, where we | |||||
* limit the amount of work we're willing to do to avoid consuming too much | |||||
* CPU.) | |||||
*/ | */ | ||||
class CTxMemPoolEntry { | class CTxMemPoolEntry { | ||||
private: | private: | ||||
CTransactionRef tx; | CTransactionRef tx; | ||||
//!< Cached to avoid expensive parent-transaction lookups | //!< Cached to avoid expensive parent-transaction lookups | ||||
Amount nFee; | Amount nFee; | ||||
//!< ... and avoid recomputing tx size | //!< ... and avoid recomputing tx size | ||||
Show All 17 Lines | private: | ||||
//!< 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. if nCountWithDescendants is 0, treat this entry as | // descendants as well. | ||||
// dirty, and nSizeWithDescendants and nModFeesWithDescendants will not be | |||||
// correct. | |||||
//!< 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; | ||||
Show All 21 Lines | public: | ||||
int64_t GetTime() const { return nTime; } | int64_t GetTime() const { return nTime; } | ||||
unsigned int GetHeight() const { return entryHeight; } | unsigned int GetHeight() const { return entryHeight; } | ||||
int64_t GetSigOpCount() const { return sigOpCount; } | int64_t GetSigOpCount() const { return sigOpCount; } | ||||
Amount GetModifiedFee() const { return nFee + feeDelta; } | Amount GetModifiedFee() const { return nFee + feeDelta; } | ||||
size_t DynamicMemoryUsage() const { return nUsageSize; } | size_t DynamicMemoryUsage() const { return nUsageSize; } | ||||
const LockPoints &GetLockPoints() const { return lockPoints; } | const LockPoints &GetLockPoints() const { return lockPoints; } | ||||
// Adjusts the descendant state, if this entry is not dirty. | // Adjusts the descendant state. | ||||
void UpdateDescendantState(int64_t modifySize, Amount modifyFee, | void UpdateDescendantState(int64_t modifySize, Amount modifyFee, | ||||
int64_t modifyCount); | int64_t modifyCount); | ||||
// Adjusts the ancestor state | // Adjusts the ancestor state | ||||
void UpdateAncestorState(int64_t modifySize, Amount modifyFee, | void UpdateAncestorState(int64_t modifySize, Amount modifyFee, | ||||
int64_t modifyCount, int modifySigOps); | int64_t modifyCount, int modifySigOps); | ||||
// Updates the fee delta used for mining priority score, and the | // Updates the fee delta used for mining priority score, and the | ||||
// modified fees with descendants. | // modified fees with descendants. | ||||
void UpdateFeeDelta(Amount feeDelta); | void UpdateFeeDelta(Amount feeDelta); | ||||
▲ Show 20 Lines • Show All 292 Lines • ▼ Show 20 Lines | |||||
* walk the mempool are not generally safe to use). | * walk the mempool are not generally safe to use). | ||||
* | * | ||||
* Computational limits: | * Computational limits: | ||||
* | * | ||||
* 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. | ||||
* | |||||
* 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. | |||||
*/ | */ | ||||
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; | ||||
▲ Show 20 Lines • Show All 466 Lines • Show Last 20 Lines |