Bitcoin Core  0.18.99
P2P Digital Currency
txmempool.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2018 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_TXMEMPOOL_H
7 #define BITCOIN_TXMEMPOOL_H
8 
9 #include <atomic>
10 #include <map>
11 #include <memory>
12 #include <set>
13 #include <string>
14 #include <utility>
15 #include <vector>
16 
17 #include <amount.h>
18 #include <coins.h>
19 #include <crypto/siphash.h>
20 #include <indirectmap.h>
21 #include <policy/feerate.h>
22 #include <primitives/transaction.h>
23 #include <sync.h>
24 #include <random.h>
25 
26 #include <boost/multi_index_container.hpp>
27 #include <boost/multi_index/hashed_index.hpp>
28 #include <boost/multi_index/ordered_index.hpp>
29 #include <boost/multi_index/sequenced_index.hpp>
30 #include <boost/signals2/signal.hpp>
31 
32 class CBlockIndex;
34 
36 static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
37 
38 struct LockPoints
39 {
40  // Will be set to the blockchain height and median time past
41  // values that would be necessary to satisfy all relative locktime
42  // constraints (BIP68) of this tx given our view of block chain history
43  int height;
44  int64_t time;
45  // As long as the current chain descends from the highest height block
46  // containing one of the inputs used in the calculation, then the cached
47  // values are still valid even after a reorg.
49 
50  LockPoints() : height(0), time(0), maxInputBlock(nullptr) { }
51 };
52 
53 class CTxMemPool;
54 
68 {
69 private:
71  const CAmount nFee;
72  const size_t nTxWeight;
73  const size_t nUsageSize;
74  const int64_t nTime;
75  const unsigned int entryHeight;
76  const bool spendsCoinbase;
77  const int64_t sigOpCost;
78  int64_t feeDelta;
80 
81  // Information about descendants of this transaction that are in the
82  // mempool; if we remove this transaction we must remove all of these
83  // descendants as well.
87 
88  // Analogous statistics for ancestor transactions
93 
94 public:
95  CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
96  int64_t _nTime, unsigned int _entryHeight,
97  bool spendsCoinbase,
98  int64_t nSigOpsCost, LockPoints lp);
99 
100  const CTransaction& GetTx() const { return *this->tx; }
101  CTransactionRef GetSharedTx() const { return this->tx; }
102  const CAmount& GetFee() const { return nFee; }
103  size_t GetTxSize() const;
104  size_t GetTxWeight() const { return nTxWeight; }
105  int64_t GetTime() const { return nTime; }
106  unsigned int GetHeight() const { return entryHeight; }
107  int64_t GetSigOpCost() const { return sigOpCost; }
108  int64_t GetModifiedFee() const { return nFee + feeDelta; }
109  size_t DynamicMemoryUsage() const { return nUsageSize; }
110  const LockPoints& GetLockPoints() const { return lockPoints; }
111 
112  // Adjusts the descendant state.
113  void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount);
114  // Adjusts the ancestor state
115  void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps);
116  // Updates the fee delta used for mining priority score, and the
117  // modified fees with descendants.
118  void UpdateFeeDelta(int64_t feeDelta);
119  // Update the LockPoints after a reorg
120  void UpdateLockPoints(const LockPoints& lp);
121 
122  uint64_t GetCountWithDescendants() const { return nCountWithDescendants; }
123  uint64_t GetSizeWithDescendants() const { return nSizeWithDescendants; }
124  CAmount GetModFeesWithDescendants() const { return nModFeesWithDescendants; }
125 
126  bool GetSpendsCoinbase() const { return spendsCoinbase; }
127 
128  uint64_t GetCountWithAncestors() const { return nCountWithAncestors; }
129  uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; }
130  CAmount GetModFeesWithAncestors() const { return nModFeesWithAncestors; }
131  int64_t GetSigOpCostWithAncestors() const { return nSigOpCostWithAncestors; }
132 
133  mutable size_t vTxHashesIdx;
134 };
135 
136 // Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index.
138 {
139  update_descendant_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount) :
140  modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount)
141  {}
142 
143  void operator() (CTxMemPoolEntry &e)
144  { e.UpdateDescendantState(modifySize, modifyFee, modifyCount); }
145 
146  private:
147  int64_t modifySize;
149  int64_t modifyCount;
150 };
151 
153 {
154  update_ancestor_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int64_t _modifySigOpsCost) :
155  modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount), modifySigOpsCost(_modifySigOpsCost)
156  {}
157 
158  void operator() (CTxMemPoolEntry &e)
159  { e.UpdateAncestorState(modifySize, modifyFee, modifyCount, modifySigOpsCost); }
160 
161  private:
162  int64_t modifySize;
164  int64_t modifyCount;
166 };
167 
169 {
170  explicit update_fee_delta(int64_t _feeDelta) : feeDelta(_feeDelta) { }
171 
172  void operator() (CTxMemPoolEntry &e) { e.UpdateFeeDelta(feeDelta); }
173 
174 private:
175  int64_t feeDelta;
176 };
177 
179 {
180  explicit update_lock_points(const LockPoints& _lp) : lp(_lp) { }
181 
182  void operator() (CTxMemPoolEntry &e) { e.UpdateLockPoints(lp); }
183 
184 private:
185  const LockPoints& lp;
186 };
187 
188 // extracts a transaction hash from CTxMemPoolEntry or CTransactionRef
190 {
192  result_type operator() (const CTxMemPoolEntry &entry) const
193  {
194  return entry.GetTx().GetHash();
195  }
196 
197  result_type operator() (const CTransactionRef& tx) const
198  {
199  return tx->GetHash();
200  }
201 };
202 
208 {
209 public:
210  bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
211  {
212  double a_mod_fee, a_size, b_mod_fee, b_size;
213 
214  GetModFeeAndSize(a, a_mod_fee, a_size);
215  GetModFeeAndSize(b, b_mod_fee, b_size);
216 
217  // Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
218  double f1 = a_mod_fee * b_size;
219  double f2 = a_size * b_mod_fee;
220 
221  if (f1 == f2) {
222  return a.GetTime() >= b.GetTime();
223  }
224  return f1 < f2;
225  }
226 
227  // Return the fee/size we're using for sorting this entry.
228  void GetModFeeAndSize(const CTxMemPoolEntry &a, double &mod_fee, double &size) const
229  {
230  // Compare feerate with descendants to feerate of the transaction, and
231  // return the fee/size for the max.
232  double f1 = (double)a.GetModifiedFee() * a.GetSizeWithDescendants();
233  double f2 = (double)a.GetModFeesWithDescendants() * a.GetTxSize();
234 
235  if (f2 > f1) {
236  mod_fee = a.GetModFeesWithDescendants();
237  size = a.GetSizeWithDescendants();
238  } else {
239  mod_fee = a.GetModifiedFee();
240  size = a.GetTxSize();
241  }
242  }
243 };
244 
253 {
254 public:
255  bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
256  {
257  double f1 = (double)a.GetFee() * b.GetTxSize();
258  double f2 = (double)b.GetFee() * a.GetTxSize();
259  if (f1 == f2) {
260  return b.GetTx().GetHash() < a.GetTx().GetHash();
261  }
262  return f1 > f2;
263  }
264 };
265 
267 {
268 public:
269  bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
270  {
271  return a.GetTime() < b.GetTime();
272  }
273 };
274 
280 {
281 public:
282  template<typename T>
283  bool operator()(const T& a, const T& b) const
284  {
285  double a_mod_fee, a_size, b_mod_fee, b_size;
286 
287  GetModFeeAndSize(a, a_mod_fee, a_size);
288  GetModFeeAndSize(b, b_mod_fee, b_size);
289 
290  // Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
291  double f1 = a_mod_fee * b_size;
292  double f2 = a_size * b_mod_fee;
293 
294  if (f1 == f2) {
295  return a.GetTx().GetHash() < b.GetTx().GetHash();
296  }
297  return f1 > f2;
298  }
299 
300  // Return the fee/size we're using for sorting this entry.
301  template <typename T>
302  void GetModFeeAndSize(const T &a, double &mod_fee, double &size) const
303  {
304  // Compare feerate with ancestors to feerate of the transaction, and
305  // return the fee/size for the min.
306  double f1 = (double)a.GetModifiedFee() * a.GetSizeWithAncestors();
307  double f2 = (double)a.GetModFeesWithAncestors() * a.GetTxSize();
308 
309  if (f1 > f2) {
310  mod_fee = a.GetModFeesWithAncestors();
311  size = a.GetSizeWithAncestors();
312  } else {
313  mod_fee = a.GetModifiedFee();
314  size = a.GetTxSize();
315  }
316  }
317 };
318 
319 // Multi_index tag names
321 struct entry_time {};
322 struct ancestor_score {};
323 
325 
330 {
333 
335  int64_t nTime;
336 
339 
341  int64_t nFeeDelta;
342 };
343 
348  UNKNOWN = 0,
349  EXPIRY,
350  SIZELIMIT,
351  REORG,
352  BLOCK,
353  CONFLICT,
354  REPLACED,
355 };
356 
358 {
359 private:
361  const uint64_t k0, k1;
362 
363 public:
365 
366  size_t operator()(const uint256& txid) const {
367  return SipHashUint256(k0, k1, txid);
368  }
369 };
370 
444 {
445 private:
446  uint32_t nCheckFrequency GUARDED_BY(cs);
447  std::atomic<unsigned int> nTransactionsUpdated;
449 
450  uint64_t totalTxSize;
451  uint64_t cachedInnerUsage;
452 
453  mutable int64_t lastRollingFeeUpdate;
455  mutable double rollingMinimumFeeRate;
456 
457  void trackPackageRemoved(const CFeeRate& rate) EXCLUSIVE_LOCKS_REQUIRED(cs);
458 
459  bool m_is_loaded GUARDED_BY(cs){false};
460 
461 public:
462 
463  static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12; // public only for testing
464 
465  typedef boost::multi_index_container<
467  boost::multi_index::indexed_by<
468  // sorted by txid
469  boost::multi_index::hashed_unique<mempoolentry_txid, SaltedTxidHasher>,
470  // sorted by fee rate
471  boost::multi_index::ordered_non_unique<
472  boost::multi_index::tag<descendant_score>,
473  boost::multi_index::identity<CTxMemPoolEntry>,
475  >,
476  // sorted by entry time
477  boost::multi_index::ordered_non_unique<
478  boost::multi_index::tag<entry_time>,
479  boost::multi_index::identity<CTxMemPoolEntry>,
481  >,
482  // sorted by fee rate with ancestors
483  boost::multi_index::ordered_non_unique<
484  boost::multi_index::tag<ancestor_score>,
485  boost::multi_index::identity<CTxMemPoolEntry>,
487  >
488  >
490 
520 
521  using txiter = indexed_transaction_set::nth_index<0>::type::const_iterator;
522  std::vector<std::pair<uint256, txiter>> vTxHashes GUARDED_BY(cs);
523 
525  bool operator()(const txiter &a, const txiter &b) const {
526  return a->GetTx().GetHash() < b->GetTx().GetHash();
527  }
528  };
529  typedef std::set<txiter, CompareIteratorByHash> setEntries;
530 
531  const setEntries & GetMemPoolParents(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
532  const setEntries & GetMemPoolChildren(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
533  uint64_t CalculateDescendantMaximum(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
534 private:
535  typedef std::map<txiter, setEntries, CompareIteratorByHash> cacheMap;
536 
537  struct TxLinks {
538  setEntries parents;
539  setEntries children;
540  };
541 
542  typedef std::map<txiter, TxLinks, CompareIteratorByHash> txlinksMap;
543  txlinksMap mapLinks;
544 
545  void UpdateParent(txiter entry, txiter parent, bool add);
546  void UpdateChild(txiter entry, txiter child, bool add);
547 
548  std::vector<indexed_transaction_set::const_iterator> GetSortedDepthAndScore() const EXCLUSIVE_LOCKS_REQUIRED(cs);
549 
550 public:
551  indirectmap<COutPoint, const CTransaction*> mapNextTx GUARDED_BY(cs);
552  std::map<uint256, CAmount> mapDeltas;
553 
556  explicit CTxMemPool(CBlockPolicyEstimator* estimator = nullptr);
557 
564  void check(const CCoinsViewCache *pcoins) const;
565  void setSanityCheck(double dFrequency = 1.0) { LOCK(cs); nCheckFrequency = static_cast<uint32_t>(dFrequency * 4294967295.0); }
566 
567  // addUnchecked must updated state for all ancestors of a given transaction,
568  // to track size/count of descendant transactions. First version of
569  // addUnchecked can be used to have it call CalculateMemPoolAncestors(), and
570  // then invoke the second version.
571  // Note that addUnchecked is ONLY called from ATMP outside of tests
572  // and any other callers may break wallet's in-mempool tracking (due to
573  // lack of CValidationInterface::TransactionAddedToMempool callbacks).
574  void addUnchecked(const CTxMemPoolEntry& entry, bool validFeeEstimate = true) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main);
575  void addUnchecked(const CTxMemPoolEntry& entry, setEntries& setAncestors, bool validFeeEstimate = true) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main);
576 
577  void removeRecursive(const CTransaction& tx, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN) EXCLUSIVE_LOCKS_REQUIRED(cs);
578  void removeForReorg(const CCoinsViewCache* pcoins, unsigned int nMemPoolHeight, int flags) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main);
579  void removeConflicts(const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(cs);
580  void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight) EXCLUSIVE_LOCKS_REQUIRED(cs);
581 
582  void clear();
583  void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs); //lock free
584  bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb);
585  void queryHashes(std::vector<uint256>& vtxid) const;
586  bool isSpent(const COutPoint& outpoint) const;
587  unsigned int GetTransactionsUpdated() const;
588  void AddTransactionsUpdated(unsigned int n);
593  bool HasNoInputsOf(const CTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs);
594 
596  void PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta);
597  void ApplyDelta(const uint256 hash, CAmount &nFeeDelta) const;
598  void ClearPrioritisation(const uint256 hash);
599 
601  const CTransaction* GetConflictTx(const COutPoint& prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs);
602 
604  boost::optional<txiter> GetIter(const uint256& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs);
605 
607  setEntries GetIterSet(const std::set<uint256>& hashes) const EXCLUSIVE_LOCKS_REQUIRED(cs);
608 
616  void RemoveStaged(setEntries &stage, bool updateDescendants, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN) EXCLUSIVE_LOCKS_REQUIRED(cs);
617 
627  void UpdateTransactionsFromBlock(const std::vector<uint256>& vHashesToUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main);
628 
639  bool CalculateMemPoolAncestors(const CTxMemPoolEntry& entry, setEntries& setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string& errString, bool fSearchForParents = true) const EXCLUSIVE_LOCKS_REQUIRED(cs);
640 
644  void CalculateDescendants(txiter it, setEntries& setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs);
645 
652  CFeeRate GetMinFee(size_t sizelimit) const;
653 
658  void TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpendsRemaining = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs);
659 
661  int Expire(int64_t time) EXCLUSIVE_LOCKS_REQUIRED(cs);
662 
667  void GetTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) const;
668 
670  bool IsLoaded() const;
671 
673  void SetIsLoaded(bool loaded);
674 
675  unsigned long size() const
676  {
677  LOCK(cs);
678  return mapTx.size();
679  }
680 
681  uint64_t GetTotalTxSize() const
682  {
683  LOCK(cs);
684  return totalTxSize;
685  }
686 
687  bool exists(const uint256& hash) const
688  {
689  LOCK(cs);
690  return (mapTx.count(hash) != 0);
691  }
692 
693  CTransactionRef get(const uint256& hash) const;
694  TxMempoolInfo info(const uint256& hash) const;
695  std::vector<TxMempoolInfo> infoAll() const;
696 
697  size_t DynamicMemoryUsage() const;
698 
699  boost::signals2::signal<void (CTransactionRef)> NotifyEntryAdded;
700  boost::signals2::signal<void (CTransactionRef, MemPoolRemovalReason)> NotifyEntryRemoved;
701 
702 private:
716  void UpdateForDescendants(txiter updateIt,
717  cacheMap &cachedDescendants,
718  const std::set<uint256> &setExclude) EXCLUSIVE_LOCKS_REQUIRED(cs);
720  void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs);
722  void UpdateEntryForAncestors(txiter it, const setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs);
726  void UpdateForRemoveFromMempool(const setEntries &entriesToRemove, bool updateDescendants) EXCLUSIVE_LOCKS_REQUIRED(cs);
728  void UpdateChildrenForRemoval(txiter entry) EXCLUSIVE_LOCKS_REQUIRED(cs);
729 
738  void removeUnchecked(txiter entry, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN) EXCLUSIVE_LOCKS_REQUIRED(cs);
739 };
740 
754 {
755 protected:
757 
758 public:
759  CCoinsViewMemPool(CCoinsView* baseIn, const CTxMemPool& mempoolIn);
760  bool GetCoin(const COutPoint &outpoint, Coin &coin) const override;
761 };
762 
778 // multi_index tag names
779 struct txid_index {};
780 struct insertion_order {};
781 
783  typedef boost::multi_index_container<
785  boost::multi_index::indexed_by<
786  // sorted by txid
787  boost::multi_index::hashed_unique<
788  boost::multi_index::tag<txid_index>,
791  >,
792  // sorted by order in the blockchain
793  boost::multi_index::sequenced<
794  boost::multi_index::tag<insertion_order>
795  >
796  >
798 
799  // It's almost certainly a logic bug if we don't clear out queuedTx before
800  // destruction, as we add to it while disconnecting blocks, and then we
801  // need to re-process remaining transactions to ensure mempool consistency.
802  // For now, assert() that we've emptied out this object on destruction.
803  // This assert() can always be removed if the reorg-processing code were
804  // to be refactored such that this assumption is no longer true (for
805  // instance if there was some other way we cleaned up the mempool after a
806  // reorg, besides draining this object).
807  ~DisconnectedBlockTransactions() { assert(queuedTx.empty()); }
808 
810  uint64_t cachedInnerUsage = 0;
811 
812  // Estimate the overhead of queuedTx to be 6 pointers + an allocation, as
813  // no exact formula for boost::multi_index_contained is implemented.
814  size_t DynamicMemoryUsage() const {
815  return memusage::MallocUsage(sizeof(CTransactionRef) + 6 * sizeof(void*)) * queuedTx.size() + cachedInnerUsage;
816  }
817 
818  void addTransaction(const CTransactionRef& tx)
819  {
820  queuedTx.insert(tx);
821  cachedInnerUsage += RecursiveDynamicUsage(tx);
822  }
823 
824  // Remove entries based on txid_index, and update memory usage.
825  void removeForBlock(const std::vector<CTransactionRef>& vtx)
826  {
827  // Short-circuit in the common case of a block being added to the tip
828  if (queuedTx.empty()) {
829  return;
830  }
831  for (auto const &tx : vtx) {
832  auto it = queuedTx.find(tx->GetHash());
833  if (it != queuedTx.end()) {
834  cachedInnerUsage -= RecursiveDynamicUsage(*it);
835  queuedTx.erase(it);
836  }
837  }
838  }
839 
840  // Remove an entry by insertion_order index, and update memory usage.
841  void removeEntry(indexed_disconnected_transactions::index<insertion_order>::type::iterator entry)
842  {
843  cachedInnerUsage -= RecursiveDynamicUsage(*entry);
844  queuedTx.get<insertion_order>().erase(entry);
845  }
846 
847  void clear()
848  {
849  cachedInnerUsage = 0;
850  queuedTx.clear();
851  }
852 };
853 
854 #endif // BITCOIN_TXMEMPOOL_H
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:408
CAmount GetModFeesWithAncestors() const
Definition: txmempool.h:130
size_t vTxHashesIdx
Index in mempool&#39;s vTxHashes.
Definition: txmempool.h:133
const bool spendsCoinbase
keep track of transactions that spend a coinbase
Definition: txmempool.h:76
uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256 &val)
Optimized SipHash-2-4 implementation for uint256.
Definition: siphash.cpp:94
Information about a mempool transaction.
Definition: txmempool.h:329
update_fee_delta(int64_t _feeDelta)
Definition: txmempool.h:170
const CTransactionRef tx
Definition: txmempool.h:70
uint64_t GetSizeWithAncestors() const
Definition: txmempool.h:129
CAmount nModFeesWithDescendants
... and total fees (all including us)
Definition: txmempool.h:86
void UpdateLockPoints(const LockPoints &lp)
Definition: txmempool.cpp:45
std::map< txiter, TxLinks, CompareIteratorByHash > txlinksMap
Definition: txmempool.h:542
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
Definition: txmempool.h:521
Definition: init.h:25
A UTXO entry.
Definition: coins.h:29
size_t GetTxSize() const
Definition: txmempool.cpp:50
size_t GetTxWeight() const
Definition: txmempool.h:104
boost::signals2::signal< void(CTransactionRef)> NotifyEntryAdded
Definition: txmempool.h:699
static void pool cs
LockPoints()
Definition: txmempool.h:50
Manually removed or unknown reason.
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:269
int height
Definition: txmempool.h:43
Removed in size limiting.
const unsigned int entryHeight
Chain height when entering the mempool.
Definition: txmempool.h:75
CAmount GetModFeesWithDescendants() const
Definition: txmempool.h:124
int64_t feeDelta
Definition: txmempool.h:175
uint64_t GetTotalTxSize() const
Definition: txmempool.h:681
bool operator()(const txiter &a, const txiter &b) const
Definition: txmempool.h:525
uint64_t GetSizeWithDescendants() const
Definition: txmempool.h:123
std::set< txiter, CompareIteratorByHash > setEntries
Definition: txmempool.h:529
void addTransaction(const CTransactionRef &tx)
Definition: txmempool.h:818
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
Definition: txmempool.h:347
const uint64_t k1
Definition: txmempool.h:361
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:210
bool GetSpendsCoinbase() const
Definition: txmempool.h:126
std::atomic< unsigned int > nTransactionsUpdated
Used by getblocktemplate to trigger CreateNewBlock() invocation.
Definition: txmempool.h:447
const int64_t nTime
Local time when entering the mempool.
Definition: txmempool.h:74
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps)
Definition: txmempool.cpp:314
uint64_t nCountWithDescendants
number of descendant transactions
Definition: txmempool.h:84
int64_t lastRollingFeeUpdate
Definition: txmempool.h:453
int64_t nFeeDelta
The fee delta.
Definition: txmempool.h:341
update_descendant_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount)
Definition: txmempool.h:139
CTransactionRef tx
The transaction itself.
Definition: txmempool.h:332
disconnectpool queuedTx clear()
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
Definition: txmempool.h:67
void GetModFeeAndSize(const T &a, double &mod_fee, double &size) const
Definition: txmempool.h:302
boost::multi_index_container< CTransactionRef, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::tag< txid_index >, mempoolentry_txid, SaltedTxidHasher >, boost::multi_index::sequenced< boost::multi_index::tag< insertion_order > > > > indexed_disconnected_transactions
Definition: txmempool.h:797
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
bool operator()(const T &a, const T &b) const
Definition: txmempool.h:283
bool blockSinceLastRollingFeeBump
Definition: txmempool.h:454
Removed for reorganization.
indexed_disconnected_transactions queuedTx
Definition: txmempool.h:809
static const uint32_t MEMPOOL_HEIGHT
Fake height value used in Coin to signify they are only in the memory pool (since 0...
Definition: txmempool.h:36
int64_t nSigOpCostWithAncestors
Definition: txmempool.h:92
const size_t nTxWeight
... and avoid recomputing tx weight (also used for GetTxSize())
Definition: txmempool.h:72
void UpdateFeeDelta(int64_t feeDelta)
Definition: txmempool.cpp:38
Definition: txmempool.h:279
uint64_t nSizeWithAncestors
Definition: txmempool.h:90
int64_t feeDelta
Used for determining the priority of the transaction for mining in a block.
Definition: txmempool.h:78
Abstract view on the open txout dataset.
Definition: coins.h:145
size_t DynamicMemoryUsage() const
Definition: txmempool.h:109
unsigned int GetHeight() const
Definition: txmempool.h:106
bool exists(const uint256 &hash) const
Definition: txmempool.h:687
void removeForBlock(const std::vector< CTransactionRef > &vtx)
Definition: txmempool.h:825
#define LOCK(cs)
Definition: sync.h:182
The BlockPolicyEstimator is used for estimating the feerate needed for a transaction to be included i...
Definition: fees.h:131
const uint256 & GetHash() const
Definition: transaction.h:322
const CAmount & GetFee() const
Definition: txmempool.h:102
Removed for conflict with in-block transaction.
DisconnectedBlockTransactions.
Definition: txmempool.h:779
CTransactionRef GetSharedTx() const
Definition: txmempool.h:101
Removed for block.
mempool UpdateTransactionsFromBlock(vHashUpdate)
CCriticalSection cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Definition: validation.cpp:100
uint64_t cachedInnerUsage
sum of dynamic memory usage of all the map elements (NOT the maps themselves)
Definition: txmempool.h:451
Sort an entry by max(score/size of entry&#39;s tx, score/size with all descendants).
Definition: txmempool.h:207
CAmount nModFeesWithAncestors
Definition: txmempool.h:91
Expired from mempool.
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:18
uint64_t nSizeWithDescendants
... and size
Definition: txmempool.h:85
uint256 result_type
Definition: txmempool.h:191
uint64_t GetCountWithDescendants() const
Definition: txmempool.h:122
const size_t nUsageSize
... and total memory usage
Definition: txmempool.h:73
uint64_t totalTxSize
sum of all mempool tx&#39;s virtual sizes. Differs from serialized tx size since witness data is discount...
Definition: txmempool.h:450
static size_t MallocUsage(size_t alloc)
Compute the total memory used by allocating alloc bytes.
Definition: memusage.h:48
int64_t GetSigOpCostWithAncestors() const
Definition: txmempool.h:131
const int64_t sigOpCost
Total sigop cost.
Definition: txmempool.h:77
int flags
Definition: bitcoin-tx.cpp:507
uint64_t GetCountWithAncestors() const
Definition: txmempool.h:128
int64_t nTime
Time the transaction entered the mempool.
Definition: txmempool.h:335
256-bit opaque blob.
Definition: uint256.h:121
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:51
mempool removeForReorg(pcoinsTip.get(), ::ChainActive().Tip() ->nHeight+1, STANDARD_LOCKTIME_VERIFY_FLAGS)
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:443
std::map< txiter, setEntries, CompareIteratorByHash > cacheMap
Definition: txmempool.h:535
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:139
int64_t GetTime() const
Definition: txmempool.h:105
LockPoints lockPoints
Track the height and time at which tx was final.
Definition: txmempool.h:79
pool addUnchecked(CTxMemPoolEntry(tx, nFee, nTime, nHeight, spendsCoinbase, sigOpCost, lp))
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
Definition: txmempool.cpp:305
const CTransaction & GetTx() const
Definition: txmempool.h:100
const LockPoints & lp
Definition: txmempool.h:185
update_ancestor_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int64_t _modifySigOpsCost)
Definition: txmempool.h:154
int64_t GetModifiedFee() const
Definition: txmempool.h:108
unsigned int sigOpCost
boost::multi_index_container< CTxMemPoolEntry, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< mempoolentry_txid, SaltedTxidHasher >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< descendant_score >, boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByDescendantScore >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< entry_time >, boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByEntryTime >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ancestor_score >, boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByAncestorFee > > > indexed_transaction_set
Definition: txmempool.h:489
uint64_t nCountWithAncestors
Definition: txmempool.h:89
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:19
int64_t GetSigOpCost() const
Definition: txmempool.h:107
#define GUARDED_BY(x)
Definition: threadsafety.h:38
const CAmount nFee
Cached to avoid expensive parent-transaction lookups.
Definition: txmempool.h:71
bool spendsCoinbase
size_t operator()(const uint256 &txid) const
Definition: txmempool.h:366
static size_t RecursiveDynamicUsage(const CScript &script)
Definition: core_memusage.h:12
update_lock_points(const LockPoints &_lp)
Definition: txmempool.h:180
int64_t time
Definition: txmempool.h:44
boost::signals2::signal< void(CTransactionRef, MemPoolRemovalReason)> NotifyEntryRemoved
Definition: txmempool.h:700
size_t DynamicMemoryUsage() const
Definition: txmempool.h:814
CFeeRate feeRate
Feerate of the transaction.
Definition: txmempool.h:338
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:270
CCoinsView backed by another CCoinsView.
Definition: coins.h:182
const LockPoints & GetLockPoints() const
Definition: txmempool.h:110
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:201
Sort by feerate of entry (fee/size) in descending order This is only used for transaction relay...
Definition: txmempool.h:252
const CTxMemPool & mempool
Definition: txmempool.h:756
auto it
Definition: validation.cpp:360
txlinksMap mapLinks
Definition: txmempool.h:543
Removed for replacement.
CBlockPolicyEstimator * minerPolicyEstimator
Definition: txmempool.h:448
CBlockIndex * maxInputBlock
Definition: txmempool.h:48
void GetModFeeAndSize(const CTxMemPoolEntry &a, double &mod_fee, double &size) const
Definition: txmempool.h:228
double rollingMinimumFeeRate
minimum fee to get into the pool, decreases exponentially
Definition: txmempool.h:455
CCoinsView that brings transactions from a mempool into view.
Definition: txmempool.h:753
void removeEntry(indexed_disconnected_transactions::index< insertion_order >::type::iterator entry)
Definition: txmempool.h:841
int64_t modifySigOpsCost
Definition: txmempool.h:165
bool m_is_loaded GUARDED_BY(cs)
Definition: txmempool.h:459
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:255
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it...
Definition: txmempool.h:518
Definition: txmempool.h:266
LockPoints lp