diff options
Diffstat (limited to 'src/txmempool.h')
-rw-r--r-- | src/txmempool.h | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/src/txmempool.h b/src/txmempool.h index 3e1d387975..f0e9b2e2c6 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -7,10 +7,12 @@ #define BITCOIN_TXMEMPOOL_H #include <list> +#include <memory> #include <set> #include "amount.h" #include "coins.h" +#include "indirectmap.h" #include "primitives/transaction.h" #include "sync.h" @@ -74,7 +76,7 @@ class CTxMemPool; class CTxMemPoolEntry { private: - CTransaction tx; + std::shared_ptr<const CTransaction> tx; CAmount nFee; //!< Cached to avoid expensive parent-transaction lookups size_t nTxSize; //!< ... and avoid recomputing tx size size_t nModSize; //!< ... and modified size for priority @@ -111,7 +113,8 @@ public: unsigned int nSigOps, LockPoints lp); CTxMemPoolEntry(const CTxMemPoolEntry& other); - const CTransaction& GetTx() const { return this->tx; } + const CTransaction& GetTx() const { return *this->tx; } + std::shared_ptr<const CTransaction> GetSharedTx() const { return this->tx; } /** * Fast calculation of lower bound of current priority as update * from entry priority. Only inputs that were originally in-chain will age. @@ -306,18 +309,19 @@ struct ancestor_score {}; class CBlockPolicyEstimator; -/** An inpoint - a combination of a transaction and an index n into its vin */ -class CInPoint +/** + * Information about a mempool transaction. + */ +struct TxMempoolInfo { -public: - const CTransaction* ptx; - uint32_t n; - - CInPoint() { SetNull(); } - CInPoint(const CTransaction* ptxIn, uint32_t nIn) { ptx = ptxIn; n = nIn; } - void SetNull() { ptx = NULL; n = (uint32_t) -1; } - bool IsNull() const { return (ptx == NULL && n == (uint32_t) -1); } - size_t DynamicMemoryUsage() const { return 0; } + /** The transaction itself */ + std::shared_ptr<const CTransaction> tx; + + /** Time the transaction entered the mempool. */ + int64_t nTime; + + /** Feerate of the transaction. */ + CFeeRate feeRate; }; /** @@ -477,8 +481,10 @@ private: void UpdateParent(txiter entry, txiter parent, bool add); void UpdateChild(txiter entry, txiter child, bool add); + std::vector<indexed_transaction_set::const_iterator> GetSortedDepthAndScore() const; + public: - std::map<COutPoint, CInPoint> mapNextTx; + indirectmap<COutPoint, const CTransaction*> mapNextTx; std::map<uint256, std::pair<double, CAmount> > mapDeltas; /** Create a new CTxMemPool. @@ -601,8 +607,9 @@ public: return (mapTx.count(hash) != 0); } - bool lookup(uint256 hash, CTransaction& result) const; - bool lookupFeeRate(const uint256& hash, CFeeRate& feeRate) const; + std::shared_ptr<const CTransaction> get(const uint256& hash) const; + TxMempoolInfo info(const uint256& hash) const; + std::vector<TxMempoolInfo> infoAll() const; /** Estimate fee rate needed to get into the next nBlocks * If no answer can be given at nBlocks, return an estimate |