@@ -266,27 +266,46 @@ class CompareTxMemPoolEntryByEntryTime
266
266
}
267
267
};
268
268
269
+ /* * \class CompareTxMemPoolEntryByAncestorScore
270
+ *
271
+ * Sort an entry by min(score/size of entry's tx, score/size with all ancestors).
272
+ */
269
273
class CompareTxMemPoolEntryByAncestorFee
270
274
{
271
275
public:
272
276
bool operator ()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
273
277
{
274
- double aFees = a.GetModFeesWithAncestors ();
275
- double aSize = a.GetSizeWithAncestors ();
278
+ double a_mod_fee, a_size, b_mod_fee, b_size;
276
279
277
- double bFees = b. GetModFeesWithAncestors ( );
278
- double bSize = b. GetSizeWithAncestors ( );
280
+ GetModFeeAndSize (a, a_mod_fee, a_size );
281
+ GetModFeeAndSize (b, b_mod_fee, b_size );
279
282
280
283
// Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
281
- double f1 = aFees * bSize ;
282
- double f2 = aSize * bFees ;
284
+ double f1 = a_mod_fee * b_size ;
285
+ double f2 = a_size * b_mod_fee ;
283
286
284
287
if (f1 == f2) {
285
288
return a.GetTx ().GetHash () < b.GetTx ().GetHash ();
286
289
}
287
-
288
290
return f1 > f2;
289
291
}
292
+
293
+ // Return the fee/size we're using for sorting this entry.
294
+ void GetModFeeAndSize (const CTxMemPoolEntry &a, double &mod_fee, double &size) const
295
+ {
296
+ // Compare feerate with ancestors to feerate of the transaction, and
297
+ // return the fee/size for the min.
298
+ double f1 = (double )a.GetModifiedFee () * a.GetSizeWithAncestors ();
299
+ double f2 = (double )a.GetModFeesWithAncestors () * a.GetTxSize ();
300
+
301
+ if (f1 > f2) {
302
+ mod_fee = a.GetModFeesWithAncestors ();
303
+ size = a.GetSizeWithAncestors ();
304
+ } else {
305
+ mod_fee = a.GetModifiedFee ();
306
+ size = a.GetTxSize ();
307
+ }
308
+ }
290
309
};
291
310
292
311
// Multi_index tag names
0 commit comments