Changeset View
Changeset View
Standalone View
Standalone View
src/txmempool.h
Show First 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | public: | ||||
CTxMemPoolEntry(const CTransactionRef &_tx, const Amount _nFee, | CTxMemPoolEntry(const CTransactionRef &_tx, const Amount _nFee, | ||||
int64_t _nTime, unsigned int _entryHeight, | int64_t _nTime, unsigned int _entryHeight, | ||||
bool spendsCoinbase, int64_t _nSigOpCount, LockPoints lp); | bool spendsCoinbase, int64_t _nSigOpCount, LockPoints lp); | ||||
const CTransaction &GetTx() const { return *this->tx; } | const CTransaction &GetTx() const { return *this->tx; } | ||||
CTransactionRef GetSharedTx() const { return this->tx; } | CTransactionRef GetSharedTx() const { return this->tx; } | ||||
const Amount GetFee() const { return nFee; } | const Amount GetFee() const { return nFee; } | ||||
size_t GetTxSize() const { return nTxSize; } | size_t GetTxSize() const { return nTxSize; } | ||||
size_t GetTxVirtualSize() const; | |||||
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. | // Adjusts the descendant state. | ||||
void UpdateDescendantState(int64_t modifySize, Amount modifyFee, | void UpdateDescendantState(int64_t modifySize, Amount modifyFee, | ||||
int64_t modifyCount, int64_t modifySigOpCount); | int64_t modifyCount, int64_t modifySigOpCount); | ||||
// 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); | ||||
// Update the LockPoints after a reorg | // Update the LockPoints after a reorg | ||||
void UpdateLockPoints(const LockPoints &lp); | void UpdateLockPoints(const LockPoints &lp); | ||||
uint64_t GetCountWithDescendants() const { return nCountWithDescendants; } | uint64_t GetCountWithDescendants() const { return nCountWithDescendants; } | ||||
uint64_t GetSizeWithDescendants() const { return nSizeWithDescendants; } | uint64_t GetSizeWithDescendants() const { return nSizeWithDescendants; } | ||||
uint64_t GetVirtualSizeWithDescendants() const; | |||||
Amount GetModFeesWithDescendants() const { return nModFeesWithDescendants; } | Amount GetModFeesWithDescendants() const { return nModFeesWithDescendants; } | ||||
int64_t GetSigOpCountWithDescendants() const { | int64_t GetSigOpCountWithDescendants() const { | ||||
return nSigOpCountWithDescendants; | return nSigOpCountWithDescendants; | ||||
} | } | ||||
bool GetSpendsCoinbase() const { return spendsCoinbase; } | bool GetSpendsCoinbase() const { return spendsCoinbase; } | ||||
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; | ||||
} | } | ||||
// These incremental virtual sizes take into account the baseline | |||||
// multidimensional resources consumed by ancestors, and may be smaller (but | |||||
// not larger) than the virtual sizes that would be calculated ignoring | |||||
// ancestors. | |||||
// Prior to filling in ancestor state, these act as if there are no | |||||
// ancestors. | |||||
uint64_t GetIncrementalVirtualSize() const; | |||||
uint64_t GetIncrementalVirtualSizeWithDescendants() const; | |||||
//!< 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) | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const { | ||||
return a.GetTime() >= b.GetTime(); | return a.GetTime() >= b.GetTime(); | ||||
} | } | ||||
return f1 < f2; | return f1 < f2; | ||||
} | } | ||||
// Return the fee/size we're using for sorting this entry. | // Return the fee/size we're using for sorting this entry. | ||||
void GetModFeeAndSize(const CTxMemPoolEntry &a, double &mod_fee, | void GetModFeeAndSize(const CTxMemPoolEntry &a, double &mod_fee, | ||||
double &size) const { | double &size) const { | ||||
// note: these could be both 0 | |||||
auto vsize_inc_with_descendants = | |||||
a.GetIncrementalVirtualSizeWithDescendants(); | |||||
auto vsize_inc_justme = a.GetIncrementalVirtualSize(); | |||||
// Compare feerate with descendants to feerate of the transaction, and | // Compare feerate with descendants to feerate of the transaction, and | ||||
// return the fee/size for the max. | // return the fee/size for the max. | ||||
double f1 = | double f1 = vsize_inc_with_descendants * (a.GetModifiedFee() / SATOSHI); | ||||
a.GetVirtualSizeWithDescendants() * (a.GetModifiedFee() / SATOSHI); | |||||
double f2 = | double f2 = | ||||
a.GetTxVirtualSize() * (a.GetModFeesWithDescendants() / SATOSHI); | vsize_inc_justme * (a.GetModFeesWithDescendants() / SATOSHI); | ||||
if (f2 > f1) { | if (f2 > f1) { | ||||
mod_fee = a.GetModFeesWithDescendants() / SATOSHI; | mod_fee = a.GetModFeesWithDescendants() / SATOSHI; | ||||
size = a.GetVirtualSizeWithDescendants(); | size = vsize_inc_with_descendants; | ||||
} else { | } else { | ||||
mod_fee = a.GetModifiedFee() / SATOSHI; | mod_fee = a.GetModifiedFee() / SATOSHI; | ||||
size = a.GetTxVirtualSize(); | size = vsize_inc_justme; | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
/** \class CompareTxMemPoolEntryByScore | /** \class CompareTxMemPoolEntryByScore | ||||
* | * | ||||
* Sort by feerate of entry (fee/size) in descending order | * Sort by feerate of entry (fee/size) in descending order | ||||
* This is only used for transaction relay, so we use GetFee() | * This is only used for transaction relay, so we use GetFee() | ||||
Show All 40 Lines | template <typename T> bool operator()(const T &a, const T &b) const { | ||||
return a.GetTx().GetId() < b.GetTx().GetId(); | return a.GetTx().GetId() < b.GetTx().GetId(); | ||||
} | } | ||||
return f1 > f2; | return f1 > f2; | ||||
} | } | ||||
// Return the fee/size we're using for sorting this entry. | // Return the fee/size we're using for sorting this entry. | ||||
template <typename T> | template <typename T> | ||||
void GetModFeeAndSize(const T &a, double &mod_fee, double &size) const { | void GetModFeeAndSize(const T &a, double &mod_fee, double &size) const { | ||||
auto vsize_with_ancestors = a.GetVirtualSizeWithAncestors(); | |||||
// note: this could be 0 | |||||
auto vsize_inc_justme = a.GetIncrementalVirtualSize(); | |||||
// Compare feerate with ancestors to feerate of the transaction, and | // Compare feerate with ancestors to feerate of the transaction, and | ||||
// return the fee/size for the min. | // return the fee/size for the min. | ||||
double f1 = | double f1 = vsize_with_ancestors * (a.GetModifiedFee() / SATOSHI); | ||||
a.GetVirtualSizeWithAncestors() * (a.GetModifiedFee() / SATOSHI); | double f2 = vsize_inc_justme * (a.GetModFeesWithAncestors() / SATOSHI); | ||||
double f2 = | |||||
a.GetTxVirtualSize() * (a.GetModFeesWithAncestors() / SATOSHI); | |||||
if (f1 > f2) { | if (f1 > f2) { | ||||
mod_fee = a.GetModFeesWithAncestors() / SATOSHI; | mod_fee = a.GetModFeesWithAncestors() / SATOSHI; | ||||
size = a.GetVirtualSizeWithAncestors(); | size = vsize_with_ancestors; | ||||
} else { | } else { | ||||
mod_fee = a.GetModifiedFee() / SATOSHI; | mod_fee = a.GetModifiedFee() / SATOSHI; | ||||
size = a.GetTxVirtualSize(); | size = vsize_inc_justme; | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
// Multi_index tag names | // Multi_index tag names | ||||
struct descendant_score {}; | struct descendant_score {}; | ||||
struct entry_time {}; | struct entry_time {}; | ||||
struct ancestor_score {}; | struct ancestor_score {}; | ||||
▲ Show 20 Lines • Show All 641 Lines • Show Last 20 Lines |