aboutsummaryrefslogtreecommitdiff
path: root/src/txmempool.h
diff options
context:
space:
mode:
authorSuhas Daftuar <sdaftuar@gmail.com>2015-10-19 15:15:12 -0400
committerSuhas Daftuar <sdaftuar@gmail.com>2016-03-14 12:13:34 -0400
commite2eeb5dda790cf301aa669704a25fb35f67400e7 (patch)
treeaeac40ffcbe1d93d5822b92f3bb5363d5758c6ed /src/txmempool.h
parent72abd2ce3c5ad8157d3a993693df1919a6ad79c3 (diff)
downloadbitcoin-e2eeb5dda790cf301aa669704a25fb35f67400e7.tar.xz
Add ancestor feerate index to mempool
Diffstat (limited to 'src/txmempool.h')
-rw-r--r--src/txmempool.h32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/txmempool.h b/src/txmempool.h
index 0db3d5bd27..3f80a6ec24 100644
--- a/src/txmempool.h
+++ b/src/txmempool.h
@@ -244,10 +244,34 @@ public:
}
};
+class CompareTxMemPoolEntryByAncestorFee
+{
+public:
+ bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b)
+ {
+ double aFees = a.GetModFeesWithAncestors();
+ double aSize = a.GetSizeWithAncestors();
+
+ double bFees = b.GetModFeesWithAncestors();
+ double bSize = b.GetSizeWithAncestors();
+
+ // Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
+ double f1 = aFees * bSize;
+ double f2 = aSize * bFees;
+
+ if (f1 == f2) {
+ return a.GetTx().GetHash() < b.GetTx().GetHash();
+ }
+
+ return f1 > f2;
+ }
+};
+
// Multi_index tag names
struct descendant_score {};
struct entry_time {};
struct mining_score {};
+struct ancestor_score {};
class CBlockPolicyEstimator;
@@ -380,12 +404,18 @@ public:
boost::multi_index::tag<entry_time>,
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>,
+ boost::multi_index::identity<CTxMemPoolEntry>,
+ CompareTxMemPoolEntryByAncestorFee
>
>
> indexed_transaction_set;