Skip to content

Commit ac9c113

Browse files
committed
mempool: use FeeFrac for calculating descendant score
1 parent e95bfc1 commit ac9c113

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

src/txmempool.h

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,36 +93,24 @@ class CompareTxMemPoolEntryByDescendantScore
9393
public:
9494
bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
9595
{
96-
double a_mod_fee, a_size, b_mod_fee, b_size;
97-
98-
GetModFeeAndSize(a, a_mod_fee, a_size);
99-
GetModFeeAndSize(b, b_mod_fee, b_size);
100-
101-
// Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
102-
double f1 = a_mod_fee * b_size;
103-
double f2 = a_size * b_mod_fee;
96+
FeeFrac f1 = GetModFeeAndSize(a);
97+
FeeFrac f2 = GetModFeeAndSize(b);
10498

105-
if (f1 == f2) {
99+
if (FeeRateCompare(f1, f2) == 0) {
106100
return a.GetTime() >= b.GetTime();
107101
}
108102
return f1 < f2;
109103
}
110104

111105
// Return the fee/size we're using for sorting this entry.
112-
void GetModFeeAndSize(const CTxMemPoolEntry &a, double &mod_fee, double &size) const
106+
FeeFrac GetModFeeAndSize(const CTxMemPoolEntry &a) const
113107
{
114108
// Compare feerate with descendants to feerate of the transaction, and
115109
// return the fee/size for the max.
116-
double f1 = (double)a.GetModifiedFee() * a.GetSizeWithDescendants();
117-
double f2 = (double)a.GetModFeesWithDescendants() * a.GetTxSize();
118-
119-
if (f2 > f1) {
120-
mod_fee = a.GetModFeesWithDescendants();
121-
size = a.GetSizeWithDescendants();
122-
} else {
123-
mod_fee = a.GetModifiedFee();
124-
size = a.GetTxSize();
125-
}
110+
return std::max<FeeFrac>(
111+
FeeFrac(a.GetModFeesWithDescendants(), a.GetSizeWithDescendants()),
112+
FeeFrac(a.GetModifiedFee(), a.GetTxSize())
113+
);
126114
}
127115
};
128116

0 commit comments

Comments
 (0)