Changeset 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; | ||||
} | } | ||||
size_t GetVirtualSizeOnlyAncestors() const; | |||||
deadalnix: Why not WithAncestor? This API seems confusing to me. | |||||
deadalnixUnsubmitted Done Inline ActionsOk So I dug a bit more and I understand this better. I'm still convinced that this is not a good API. What you effectively want is GetIncrementalVirtualSize and GetIncrementalVirtualSizeWithDescendants . The rest is not something you want to expose in the API, or it simply looks lieka mixed bag of thing ou expose or not withut really any logic behind it. GetVirtualSizeWithAncestorsAndDescendants specifically has one call site, which is a good indicator that this is not something that is generally useful and is just adding indirections in the code for no good reasons. Just inline it. GetVirtualSizeOnlyAncestors can be renamed to something less confusing, such as GetVirtualSizeOfAncestors, only kinda imply that there is more to it, like a more complete version that don't do only that.You can also make it private and declare it at the end of the class as to not mix it up with the API that is intended for consumption. You would generally benefit from clearer grouping in the API. For instance, GetVirtualSizeOfAncestors needs to come immediately before/after GetVirtualSizeWithAncestors. deadalnix: Ok So I dug a bit more and I understand this better. I'm still convinced that this is not a… | |||||
size_t GetVirtualSizeWithAncestorsAndDescendants() const; | |||||
deadalnixUnsubmitted Done Inline ActionsCan you explain why this is wanted? deadalnix: Can you explain why this is wanted? | |||||
// 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. | |||||
size_t GetIncrementalVirtualSize() const { | |||||
return GetVirtualSizeWithAncestors() - GetVirtualSizeOnlyAncestors(); | |||||
} | |||||
size_t GetIncrementalVirtualSizeWithDescendants() const { | |||||
return GetVirtualSizeWithAncestorsAndDescendants() - | |||||
GetVirtualSizeOnlyAncestors(); | |||||
} | |||||
//!< 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 642 Lines • Show Last 20 Lines |
Why not WithAncestor? This API seems confusing to me.