@@ -154,37 +154,25 @@ class CompareTxMemPoolEntryByAncestorFee
154
154
template <typename T>
155
155
bool operator ()(const T& a, const T& b) const
156
156
{
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);
165
159
166
- if (f1 == f2 ) {
160
+ if (FeeRateCompare (f1, f2) == 0 ) {
167
161
return a.GetTx ().GetHash () < b.GetTx ().GetHash ();
168
162
}
169
163
return f1 > f2;
170
164
}
171
165
172
166
// Return the fee/size we're using for sorting this entry.
173
167
template <typename T>
174
- void GetModFeeAndSize (const T &a, double &mod_fee, double &size ) const
168
+ FeeFrac GetModFeeAndSize (const T &a) const
175
169
{
176
170
// Compare feerate with ancestors to feerate of the transaction, and
177
171
// 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
+ );
188
176
}
189
177
};
190
178
0 commit comments