aboutsummaryrefslogtreecommitdiff
path: root/src/txmempool.h
diff options
context:
space:
mode:
authorAshley Holman <dscvlt@gmail.com>2015-06-24 03:32:20 -0500
committerSuhas Daftuar <sdaftuar@chaincode.com>2015-09-19 13:22:40 -0400
commit34628a18070064e75b35f28fd6a43d5c23832eb8 (patch)
treee73c13d25d04212b5bbbb5b0c3829421f7616d6b /src/txmempool.h
parentd5d1d2e65a1c3b91452d2428410f701bca1e53cc (diff)
downloadbitcoin-34628a18070064e75b35f28fd6a43d5c23832eb8.tar.xz
TxMemPool: Change mapTx to a boost::multi_index_container
Indexes on: - Tx Hash - Fee Rate (fee-per-kb)
Diffstat (limited to 'src/txmempool.h')
-rw-r--r--src/txmempool.h42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/txmempool.h b/src/txmempool.h
index ea36ce1ad5..6b6b05454a 100644
--- a/src/txmempool.h
+++ b/src/txmempool.h
@@ -13,6 +13,10 @@
#include "primitives/transaction.h"
#include "sync.h"
+#undef foreach
+#include "boost/multi_index_container.hpp"
+#include "boost/multi_index/ordered_index.hpp"
+
class CAutoFile;
inline double AllowFreeThreshold()
@@ -41,6 +45,7 @@ private:
size_t nTxSize; //! ... and avoid recomputing tx size
size_t nModSize; //! ... and modified size for priority
size_t nUsageSize; //! ... and total memory usage
+ CFeeRate feeRate; //! ... and fee per kB
int64_t nTime; //! Local time when entering the mempool
double dPriority; //! Priority when entering the mempool
unsigned int nHeight; //! Chain height when entering the mempool
@@ -55,6 +60,7 @@ public:
const CTransaction& GetTx() const { return this->tx; }
double GetPriority(unsigned int currentHeight) const;
CAmount GetFee() const { return nFee; }
+ CFeeRate GetFeeRate() const { return feeRate; }
size_t GetTxSize() const { return nTxSize; }
int64_t GetTime() const { return nTime; }
unsigned int GetHeight() const { return nHeight; }
@@ -62,6 +68,27 @@ public:
size_t DynamicMemoryUsage() const { return nUsageSize; }
};
+// extracts a TxMemPoolEntry's transaction hash
+struct mempoolentry_txid
+{
+ typedef uint256 result_type;
+ result_type operator() (const CTxMemPoolEntry &entry) const
+ {
+ return entry.GetTx().GetHash();
+ }
+};
+
+class CompareTxMemPoolEntryByFee
+{
+public:
+ bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b)
+ {
+ if (a.GetFeeRate() == b.GetFeeRate())
+ return a.GetTime() < b.GetTime();
+ return a.GetFeeRate() > b.GetFeeRate();
+ }
+};
+
class CBlockPolicyEstimator;
/** An inpoint - a combination of a transaction and an index n into its vin */
@@ -99,8 +126,21 @@ private:
uint64_t cachedInnerUsage; //! sum of dynamic memory usage of all the map elements (NOT the maps themselves)
public:
+ typedef boost::multi_index_container<
+ CTxMemPoolEntry,
+ boost::multi_index::indexed_by<
+ // sorted by txid
+ boost::multi_index::ordered_unique<mempoolentry_txid>,
+ // sorted by fee rate
+ boost::multi_index::ordered_non_unique<
+ boost::multi_index::identity<CTxMemPoolEntry>,
+ CompareTxMemPoolEntryByFee
+ >
+ >
+ > indexed_transaction_set;
+
mutable CCriticalSection cs;
- std::map<uint256, CTxMemPoolEntry> mapTx;
+ indexed_transaction_set mapTx;
std::map<COutPoint, CInPoint> mapNextTx;
std::map<uint256, std::pair<double, CAmount> > mapDeltas;