aboutsummaryrefslogtreecommitdiff
path: root/src/txmempool.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/txmempool.h')
-rw-r--r--src/txmempool.h88
1 files changed, 55 insertions, 33 deletions
diff --git a/src/txmempool.h b/src/txmempool.h
index 86a008d7b2..c6a1bf08ce 100644
--- a/src/txmempool.h
+++ b/src/txmempool.h
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2016 The Bitcoin Core developers
+// Copyright (c) 2009-2017 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -206,18 +206,14 @@ class CompareTxMemPoolEntryByDescendantScore
public:
bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
{
- bool fUseADescendants = UseDescendantScore(a);
- bool fUseBDescendants = UseDescendantScore(b);
+ double a_mod_fee, a_size, b_mod_fee, b_size;
- double aModFee = fUseADescendants ? a.GetModFeesWithDescendants() : a.GetModifiedFee();
- double aSize = fUseADescendants ? a.GetSizeWithDescendants() : a.GetTxSize();
-
- double bModFee = fUseBDescendants ? b.GetModFeesWithDescendants() : b.GetModifiedFee();
- double bSize = fUseBDescendants ? b.GetSizeWithDescendants() : b.GetTxSize();
+ GetModFeeAndSize(a, a_mod_fee, a_size);
+ GetModFeeAndSize(b, b_mod_fee, b_size);
// Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
- double f1 = aModFee * bSize;
- double f2 = aSize * bModFee;
+ double f1 = a_mod_fee * b_size;
+ double f2 = a_size * b_mod_fee;
if (f1 == f2) {
return a.GetTime() >= b.GetTime();
@@ -225,26 +221,38 @@ public:
return f1 < f2;
}
- // Calculate which score to use for an entry (avoiding division).
- bool UseDescendantScore(const CTxMemPoolEntry &a) const
+ // Return the fee/size we're using for sorting this entry.
+ void GetModFeeAndSize(const CTxMemPoolEntry &a, double &mod_fee, double &size) const
{
+ // Compare feerate with descendants to feerate of the transaction, and
+ // return the fee/size for the max.
double f1 = (double)a.GetModifiedFee() * a.GetSizeWithDescendants();
double f2 = (double)a.GetModFeesWithDescendants() * a.GetTxSize();
- return f2 > f1;
+
+ if (f2 > f1) {
+ mod_fee = a.GetModFeesWithDescendants();
+ size = a.GetSizeWithDescendants();
+ } else {
+ mod_fee = a.GetModifiedFee();
+ size = a.GetTxSize();
+ }
}
};
/** \class CompareTxMemPoolEntryByScore
*
- * Sort by score of entry ((fee+delta)/size) in descending order
+ * Sort by feerate of entry (fee/size) in descending order
+ * This is only used for transaction relay, so we use GetFee()
+ * instead of GetModifiedFee() to avoid leaking prioritization
+ * information via the sort order.
*/
class CompareTxMemPoolEntryByScore
{
public:
bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
{
- double f1 = (double)a.GetModifiedFee() * b.GetTxSize();
- double f2 = (double)b.GetModifiedFee() * a.GetTxSize();
+ double f1 = (double)a.GetFee() * b.GetTxSize();
+ double f2 = (double)b.GetFee() * a.GetTxSize();
if (f1 == f2) {
return b.GetTx().GetHash() < a.GetTx().GetHash();
}
@@ -261,33 +269,53 @@ public:
}
};
+/** \class CompareTxMemPoolEntryByAncestorScore
+ *
+ * Sort an entry by min(score/size of entry's tx, score/size with all ancestors).
+ */
class CompareTxMemPoolEntryByAncestorFee
{
public:
- bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
+ template<typename T>
+ bool operator()(const T& a, const T& b) const
{
- double aFees = a.GetModFeesWithAncestors();
- double aSize = a.GetSizeWithAncestors();
+ double a_mod_fee, a_size, b_mod_fee, b_size;
- double bFees = b.GetModFeesWithAncestors();
- double bSize = b.GetSizeWithAncestors();
+ GetModFeeAndSize(a, a_mod_fee, a_size);
+ GetModFeeAndSize(b, b_mod_fee, b_size);
// Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
- double f1 = aFees * bSize;
- double f2 = aSize * bFees;
+ 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 f1 > f2;
}
+
+ // Return the fee/size we're using for sorting this entry.
+ template <typename T>
+ void GetModFeeAndSize(const T &a, double &mod_fee, double &size) const
+ {
+ // Compare feerate with ancestors to feerate of the transaction, and
+ // return the fee/size for the min.
+ double f1 = (double)a.GetModifiedFee() * a.GetSizeWithAncestors();
+ double f2 = (double)a.GetModFeesWithAncestors() * a.GetTxSize();
+
+ if (f1 > f2) {
+ mod_fee = a.GetModFeesWithAncestors();
+ size = a.GetSizeWithAncestors();
+ } else {
+ mod_fee = a.GetModifiedFee();
+ size = a.GetTxSize();
+ }
+ }
};
// Multi_index tag names
struct descendant_score {};
struct entry_time {};
-struct mining_score {};
struct ancestor_score {};
class CBlockPolicyEstimator;
@@ -354,9 +382,9 @@ public:
*
* mapTx is a boost::multi_index that sorts the mempool on 4 criteria:
* - transaction hash
- * - feerate [we use max(feerate of tx, feerate of tx with all descendants)]
+ * - descendant feerate [we use max(feerate of tx, feerate of tx with all descendants)]
* - time in mempool
- * - mining score (feerate modified by any fee deltas from PrioritiseTransaction)
+ * - ancestor feerate [we use min(feerate of tx, feerate of tx with all unconfirmed ancestors)]
*
* Note: the term "descendant" refers to in-mempool transactions that depend on
* this one, while "ancestor" refers to in-mempool transactions that a given
@@ -446,12 +474,6 @@ public:
boost::multi_index::identity<CTxMemPoolEntry>,
CompareTxMemPoolEntryByEntryTime
>,
- // sorted by score (for mining prioritization)
- boost::multi_index::ordered_unique<
- boost::multi_index::tag<mining_score>,
- boost::multi_index::identity<CTxMemPoolEntry>,
- CompareTxMemPoolEntryByScore
- >,
// sorted by fee rate with ancestors
boost::multi_index::ordered_non_unique<
boost::multi_index::tag<ancestor_score>,