@@ -93,36 +93,24 @@ class CompareTxMemPoolEntryByDescendantScore
93
93
public:
94
94
bool operator ()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
95
95
{
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);
104
98
105
- if (f1 == f2 ) {
99
+ if (FeeRateCompare (f1, f2) == 0 ) {
106
100
return a.GetTime () >= b.GetTime ();
107
101
}
108
102
return f1 < f2;
109
103
}
110
104
111
105
// 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
113
107
{
114
108
// Compare feerate with descendants to feerate of the transaction, and
115
109
// 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
+ );
126
114
}
127
115
};
128
116
0 commit comments