Changeset View
Changeset View
Standalone View
Standalone View
src/txmempool.h
Show First 20 Lines • Show All 271 Lines • ▼ Show 20 Lines | |||||
public: | public: | ||||
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const { | bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const { | ||||
bool fUseADescendants = UseDescendantScore(a); | bool fUseADescendants = UseDescendantScore(a); | ||||
bool fUseBDescendants = UseDescendantScore(b); | bool fUseBDescendants = UseDescendantScore(b); | ||||
double aModFee = (fUseADescendants ? a.GetModFeesWithDescendants() | double aModFee = (fUseADescendants ? a.GetModFeesWithDescendants() | ||||
: a.GetModifiedFee()) / | : a.GetModifiedFee()) / | ||||
SATOSHI; | SATOSHI; | ||||
double aSize = | double aSize = fUseADescendants ? a.GetBillableSizeWithDescendants() | ||||
fUseADescendants ? a.GetSizeWithDescendants() : a.GetTxSize(); | : a.GetTxBillableSize(); | ||||
double bModFee = (fUseBDescendants ? b.GetModFeesWithDescendants() | double bModFee = (fUseBDescendants ? b.GetModFeesWithDescendants() | ||||
: b.GetModifiedFee()) / | : b.GetModifiedFee()) / | ||||
SATOSHI; | SATOSHI; | ||||
double bSize = | double bSize = fUseBDescendants ? b.GetBillableSizeWithDescendants() | ||||
fUseBDescendants ? b.GetSizeWithDescendants() : b.GetTxSize(); | : b.GetTxBillableSize(); | ||||
// Avoid division by rewriting (a/b > c/d) as (a*d > c*b). | // Avoid division by rewriting (a/b > c/d) as (a*d > c*b). | ||||
double f1 = aModFee * bSize; | double f1 = aModFee * bSize; | ||||
double f2 = aSize * bModFee; | double f2 = aSize * bModFee; | ||||
if (f1 == f2) { | if (f1 == f2) { | ||||
return a.GetTime() >= b.GetTime(); | return a.GetTime() >= b.GetTime(); | ||||
} | } | ||||
return f1 < f2; | return f1 < f2; | ||||
} | } | ||||
// Calculate which score to use for an entry (avoiding division). | // Calculate which score to use for an entry (avoiding division). | ||||
bool UseDescendantScore(const CTxMemPoolEntry &a) const { | bool UseDescendantScore(const CTxMemPoolEntry &a) const { | ||||
double f1 = a.GetSizeWithDescendants() * (a.GetModifiedFee() / SATOSHI); | double f1 = | ||||
double f2 = a.GetTxSize() * (a.GetModFeesWithDescendants() / SATOSHI); | a.GetBillableSizeWithDescendants() * (a.GetModifiedFee() / SATOSHI); | ||||
double f2 = | |||||
a.GetTxBillableSize() * (a.GetModFeesWithDescendants() / SATOSHI); | |||||
return f2 > f1; | return f2 > f1; | ||||
} | } | ||||
}; | }; | ||||
/** \class CompareTxMemPoolEntryByScore | /** \class CompareTxMemPoolEntryByScore | ||||
* | * | ||||
* Sort by score of entry ((fee+delta)/size) in descending order | * Sort by score of entry ((fee+delta)/size) in descending order | ||||
*/ | */ | ||||
class CompareTxMemPoolEntryByScore { | class CompareTxMemPoolEntryByScore { | ||||
public: | public: | ||||
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const { | bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const { | ||||
double f1 = b.GetTxSize() * (a.GetModifiedFee() / SATOSHI); | double f1 = b.GetTxBillableSize() * (a.GetModifiedFee() / SATOSHI); | ||||
double f2 = a.GetTxSize() * (b.GetModifiedFee() / SATOSHI); | double f2 = a.GetTxBillableSize() * (b.GetModifiedFee() / SATOSHI); | ||||
if (f1 == f2) { | if (f1 == f2) { | ||||
return b.GetTx().GetId() < a.GetTx().GetId(); | return b.GetTx().GetId() < a.GetTx().GetId(); | ||||
} | } | ||||
return f1 > f2; | return f1 > f2; | ||||
} | } | ||||
}; | }; | ||||
class CompareTxMemPoolEntryByEntryTime { | class CompareTxMemPoolEntryByEntryTime { | ||||
public: | public: | ||||
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const { | bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const { | ||||
return a.GetTime() < b.GetTime(); | return a.GetTime() < b.GetTime(); | ||||
} | } | ||||
}; | }; | ||||
class CompareTxMemPoolEntryByAncestorFee { | class CompareTxMemPoolEntryByAncestorFee { | ||||
public: | public: | ||||
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const { | bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const { | ||||
double aFees = a.GetModFeesWithAncestors() / SATOSHI; | double aFees = a.GetModFeesWithAncestors() / SATOSHI; | ||||
double aSize = a.GetSizeWithAncestors(); | double aSize = a.GetBillableSizeWithAncestors(); | ||||
double bFees = b.GetModFeesWithAncestors() / SATOSHI; | double bFees = b.GetModFeesWithAncestors() / SATOSHI; | ||||
double bSize = b.GetSizeWithAncestors(); | double bSize = b.GetBillableSizeWithAncestors(); | ||||
// Avoid division by rewriting (a/b > c/d) as (a*d > c*b). | // Avoid division by rewriting (a/b > c/d) as (a*d > c*b). | ||||
double f1 = aFees * bSize; | double f1 = aFees * bSize; | ||||
double f2 = aSize * bFees; | double f2 = aSize * bFees; | ||||
if (f1 == f2) { | if (f1 == f2) { | ||||
return a.GetTx().GetId() < b.GetTx().GetId(); | return a.GetTx().GetId() < b.GetTx().GetId(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 606 Lines • Show Last 20 Lines |