mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-31 19:31:02 +02:00
mempool: use FeeFrac
for calculating ancestor score
This commit is contained in:
@@ -154,16 +154,10 @@ public:
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
bool operator()(const T& a, const T& b) const
|
bool operator()(const T& a, const T& b) const
|
||||||
{
|
{
|
||||||
double a_mod_fee, a_size, b_mod_fee, b_size;
|
FeeFrac f1 = GetModFeeAndSize(a);
|
||||||
|
FeeFrac f2 = GetModFeeAndSize(b);
|
||||||
|
|
||||||
GetModFeeAndSize(a, a_mod_fee, a_size);
|
if (FeeRateCompare(f1, f2) == 0) {
|
||||||
GetModFeeAndSize(b, b_mod_fee, b_size);
|
|
||||||
|
|
||||||
// Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
|
|
||||||
double f1 = a_mod_fee * b_size;
|
|
||||||
double f2 = a_size * b_mod_fee;
|
|
||||||
|
|
||||||
if (f1 == f2) {
|
|
||||||
return a.GetTx().GetHash() < b.GetTx().GetHash();
|
return a.GetTx().GetHash() < b.GetTx().GetHash();
|
||||||
}
|
}
|
||||||
return f1 > f2;
|
return f1 > f2;
|
||||||
@@ -171,20 +165,14 @@ public:
|
|||||||
|
|
||||||
// Return the fee/size we're using for sorting this entry.
|
// Return the fee/size we're using for sorting this entry.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void GetModFeeAndSize(const T &a, double &mod_fee, double &size) const
|
FeeFrac GetModFeeAndSize(const T &a) const
|
||||||
{
|
{
|
||||||
// Compare feerate with ancestors to feerate of the transaction, and
|
// Compare feerate with ancestors to feerate of the transaction, and
|
||||||
// return the fee/size for the min.
|
// return the fee/size for the min.
|
||||||
double f1 = (double)a.GetModifiedFee() * a.GetSizeWithAncestors();
|
return std::min<FeeFrac>(
|
||||||
double f2 = (double)a.GetModFeesWithAncestors() * a.GetTxSize();
|
FeeFrac(a.GetModFeesWithAncestors(), a.GetSizeWithAncestors()),
|
||||||
|
FeeFrac(a.GetModifiedFee(), a.GetTxSize())
|
||||||
if (f1 > f2) {
|
);
|
||||||
mod_fee = a.GetModFeesWithAncestors();
|
|
||||||
size = a.GetSizeWithAncestors();
|
|
||||||
} else {
|
|
||||||
mod_fee = a.GetModifiedFee();
|
|
||||||
size = a.GetTxSize();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user