Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 19 additions & 43 deletions src/txmempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,36 +93,24 @@ class CompareTxMemPoolEntryByDescendantScore
public:
bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
{
double a_mod_fee, a_size, b_mod_fee, b_size;
FeeFrac f1 = GetModFeeAndSize(a);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this (and the others) could be const

FeeFrac f2 = GetModFeeAndSize(b);

GetModFeeAndSize(a, a_mod_fee, a_size);
GetModFeeAndSize(b, b_mod_fee, b_size);

// Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
double f1 = a_mod_fee * b_size;
double f2 = a_size * b_mod_fee;

if (f1 == f2) {
if (FeeRateCompare(f1, f2) == 0) {
return a.GetTime() >= b.GetTime();
}
return f1 < f2;
}

// Return the fee/size we're using for sorting this entry.
void GetModFeeAndSize(const CTxMemPoolEntry &a, double &mod_fee, double &size) const
FeeFrac GetModFeeAndSize(const CTxMemPoolEntry &a) const
{
// Compare feerate with descendants to feerate of the transaction, and
// return the fee/size for the max.
double f1 = (double)a.GetModifiedFee() * a.GetSizeWithDescendants();
double f2 = (double)a.GetModFeesWithDescendants() * a.GetTxSize();

if (f2 > f1) {
mod_fee = a.GetModFeesWithDescendants();
size = a.GetSizeWithDescendants();
} else {
mod_fee = a.GetModifiedFee();
size = a.GetTxSize();
}
return std::max<FeeFrac>(
FeeFrac(a.GetModFeesWithDescendants(), a.GetSizeWithDescendants()),
FeeFrac(a.GetModifiedFee(), a.GetTxSize())
);
}
};

Expand All @@ -138,9 +126,9 @@ class CompareTxMemPoolEntryByScore
public:
bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
{
double f1 = (double)a.GetFee() * b.GetTxSize();
double f2 = (double)b.GetFee() * a.GetTxSize();
if (f1 == f2) {
FeeFrac f1(a.GetFee(), a.GetTxSize());
FeeFrac f2(b.GetFee(), b.GetTxSize());
if (FeeRateCompare(f1, f2) == 0) {
return b.GetTx().GetHash() < a.GetTx().GetHash();
}
return f1 > f2;
Expand All @@ -166,37 +154,25 @@ class CompareTxMemPoolEntryByAncestorFee
template<typename T>
bool operator()(const T& a, const T& b) const
{
double a_mod_fee, a_size, b_mod_fee, b_size;
FeeFrac f1 = GetModFeeAndSize(a);
FeeFrac f2 = GetModFeeAndSize(b);

GetModFeeAndSize(a, a_mod_fee, a_size);
GetModFeeAndSize(b, b_mod_fee, b_size);

// Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
double f1 = a_mod_fee * b_size;
double f2 = a_size * b_mod_fee;

if (f1 == f2) {
if (FeeRateCompare(f1, f2) == 0) {
return a.GetTx().GetHash() < b.GetTx().GetHash();
}
return f1 > f2;
}

// Return the fee/size we're using for sorting this entry.
template <typename T>
void GetModFeeAndSize(const T &a, double &mod_fee, double &size) const
FeeFrac GetModFeeAndSize(const T &a) const
{
// Compare feerate with ancestors to feerate of the transaction, and
// return the fee/size for the min.
double f1 = (double)a.GetModifiedFee() * a.GetSizeWithAncestors();
double f2 = (double)a.GetModFeesWithAncestors() * a.GetTxSize();

if (f1 > f2) {
mod_fee = a.GetModFeesWithAncestors();
size = a.GetSizeWithAncestors();
} else {
mod_fee = a.GetModifiedFee();
size = a.GetTxSize();
}
return std::min<FeeFrac>(
FeeFrac(a.GetModFeesWithAncestors(), a.GetSizeWithAncestors()),
FeeFrac(a.GetModifiedFee(), a.GetTxSize())
);
}
};

Expand Down
Loading