Skip to content

Commit 3322b3a

Browse files
committed
mempool: use FeeFrac for calculating ancestor score
1 parent ac9c113 commit 3322b3a

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
@@ -154,37 +154,25 @@ class CompareTxMemPoolEntryByAncestorFee
154154
template<typename T>
155155
bool operator()(const T& a, const T& b) const
156156
{
157-
double a_mod_fee, a_size, b_mod_fee, b_size;
158-
159-
GetModFeeAndSize(a, a_mod_fee, a_size);
160-
GetModFeeAndSize(b, b_mod_fee, b_size);
161-
162-
// Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
163-
double f1 = a_mod_fee * b_size;
164-
double f2 = a_size * b_mod_fee;
157+
FeeFrac f1 = GetModFeeAndSize(a);
158+
FeeFrac f2 = GetModFeeAndSize(b);
165159

166-
if (f1 == f2) {
160+
if (FeeRateCompare(f1, f2) == 0) {
167161
return a.GetTx().GetHash() < b.GetTx().GetHash();
168162
}
169163
return f1 > f2;
170164
}
171165

172166
// Return the fee/size we're using for sorting this entry.
173167
template <typename T>
174-
void GetModFeeAndSize(const T &a, double &mod_fee, double &size) const
168+
FeeFrac GetModFeeAndSize(const T &a) const
175169
{
176170
// Compare feerate with ancestors to feerate of the transaction, and
177171
// return the fee/size for the min.
178-
double f1 = (double)a.GetModifiedFee() * a.GetSizeWithAncestors();
179-
double f2 = (double)a.GetModFeesWithAncestors() * a.GetTxSize();
180-
181-
if (f1 > f2) {
182-
mod_fee = a.GetModFeesWithAncestors();
183-
size = a.GetSizeWithAncestors();
184-
} else {
185-
mod_fee = a.GetModifiedFee();
186-
size = a.GetTxSize();
187-
}
172+
return std::min<FeeFrac>(
173+
FeeFrac(a.GetModFeesWithAncestors(), a.GetSizeWithAncestors()),
174+
FeeFrac(a.GetModifiedFee(), a.GetTxSize())
175+
);
188176
}
189177
};
190178

0 commit comments

Comments
 (0)