Bitcoin ABC  0.22.12
P2P Digital Currency
txmempool.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 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 <amount.h>
10 #include <coins.h>
11 #include <core_memusage.h>
12 #include <indirectmap.h>
13 #include <primitives/transaction.h>
14 #include <salteduint256hasher.h>
15 #include <sync.h>
16 
17 #include <boost/multi_index/hashed_index.hpp>
18 #include <boost/multi_index/ordered_index.hpp>
19 #include <boost/multi_index/sequenced_index.hpp>
20 #include <boost/multi_index_container.hpp>
21 
22 #include <atomic>
23 #include <map>
24 #include <set>
25 #include <string>
26 #include <utility>
27 #include <vector>
28 
29 class CBlockIndex;
30 class Config;
31 
32 extern RecursiveMutex cs_main;
33 
38 static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
39 
40 struct LockPoints {
41  // Will be set to the blockchain height and median time past values that
42  // would be necessary to satisfy all relative locktime constraints (BIP68)
43  // of this tx given our view of block chain history
44  int height;
45  int64_t time;
46  // As long as the current chain descends from the highest height block
47  // containing one of the inputs used in the calculation, then the cached
48  // values are still valid even after a reorg.
50 
51  LockPoints() : height(0), time(0), maxInputBlock(nullptr) {}
52 };
53 
66 private:
69  const Amount nFee;
71  const size_t nTxSize;
73  const size_t nUsageSize;
75  const int64_t nTime;
77  const unsigned int entryHeight;
79  const bool spendsCoinbase;
86  const int64_t sigOpCount;
92 
93  // Information about descendants of this transaction that are in the
94  // mempool; if we remove this transaction we must remove all of these
95  // descendants as well.
104 
105  // Analogous statistics for ancestor transactions
110 
111 public:
112  CTxMemPoolEntry(const CTransactionRef &_tx, const Amount _nFee,
113  int64_t _nTime, unsigned int _entryHeight,
114  bool spendsCoinbase, int64_t _nSigOpCount, LockPoints lp);
115 
116  const CTransaction &GetTx() const { return *this->tx; }
117  CTransactionRef GetSharedTx() const { return this->tx; }
118  const Amount GetFee() const { return nFee; }
119  size_t GetTxSize() const { return nTxSize; }
120  size_t GetTxVirtualSize() const;
121 
122  std::chrono::seconds GetTime() const { return std::chrono::seconds{nTime}; }
123  unsigned int GetHeight() const { return entryHeight; }
124  int64_t GetSigOpCount() const { return sigOpCount; }
125  Amount GetModifiedFee() const { return nFee + feeDelta; }
126  size_t DynamicMemoryUsage() const { return nUsageSize; }
127  const LockPoints &GetLockPoints() const { return lockPoints; }
128 
129  // Adjusts the descendant state.
130  void UpdateDescendantState(int64_t modifySize, Amount modifyFee,
131  int64_t modifyCount, int64_t modifySigOpCount);
132  // Adjusts the ancestor state
133  void UpdateAncestorState(int64_t modifySize, Amount modifyFee,
134  int64_t modifyCount, int64_t modifySigOps);
135  // Updates the fee delta used for mining priority score, and the
136  // modified fees with descendants.
137  void UpdateFeeDelta(Amount feeDelta);
138  // Update the LockPoints after a reorg
139  void UpdateLockPoints(const LockPoints &lp);
140 
141  uint64_t GetCountWithDescendants() const { return nCountWithDescendants; }
142  uint64_t GetSizeWithDescendants() const { return nSizeWithDescendants; }
143  uint64_t GetVirtualSizeWithDescendants() const;
144  Amount GetModFeesWithDescendants() const { return nModFeesWithDescendants; }
146  return nSigOpCountWithDescendants;
147  }
148 
149  bool GetSpendsCoinbase() const { return spendsCoinbase; }
150 
151  uint64_t GetCountWithAncestors() const { return nCountWithAncestors; }
152  uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; }
153  uint64_t GetVirtualSizeWithAncestors() const;
154  Amount GetModFeesWithAncestors() const { return nModFeesWithAncestors; }
155  int64_t GetSigOpCountWithAncestors() const {
156  return nSigOpCountWithAncestors;
157  }
158 
160  mutable size_t vTxHashesIdx;
162  mutable uint64_t m_epoch;
163 };
164 
165 // Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index.
167  update_descendant_state(int64_t _modifySize, Amount _modifyFee,
168  int64_t _modifyCount, int64_t _modifySigOpCount)
169  : modifySize(_modifySize), modifyFee(_modifyFee),
170  modifyCount(_modifyCount), modifySigOpCount(_modifySigOpCount) {}
171 
173  e.UpdateDescendantState(modifySize, modifyFee, modifyCount,
174  modifySigOpCount);
175  }
176 
177 private:
178  int64_t modifySize;
180  int64_t modifyCount;
182 };
183 
185  update_ancestor_state(int64_t _modifySize, Amount _modifyFee,
186  int64_t _modifyCount, int64_t _modifySigOpCount)
187  : modifySize(_modifySize), modifyFee(_modifyFee),
188  modifyCount(_modifyCount), modifySigOpCount(_modifySigOpCount) {}
189 
191  e.UpdateAncestorState(modifySize, modifyFee, modifyCount,
192  modifySigOpCount);
193  }
194 
195 private:
196  int64_t modifySize;
198  int64_t modifyCount;
200 };
201 
203  explicit update_fee_delta(Amount _feeDelta) : feeDelta(_feeDelta) {}
204 
205  void operator()(CTxMemPoolEntry &e) { e.UpdateFeeDelta(feeDelta); }
206 
207 private:
209 };
210 
212  explicit update_lock_points(const LockPoints &_lp) : lp(_lp) {}
213 
215 
216 private:
217  const LockPoints &lp;
218 };
219 
220 // extracts a transaction id from CTxMemPoolEntry or CTransactionRef
222  typedef TxId result_type;
223  result_type operator()(const CTxMemPoolEntry &entry) const {
224  return entry.GetTx().GetId();
225  }
226 
227  result_type operator()(const CTransactionRef &tx) const {
228  return tx->GetId();
229  }
230 };
231 
238 public:
239  bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const {
240  double a_mod_fee, a_size, b_mod_fee, b_size;
241 
242  GetModFeeAndSize(a, a_mod_fee, a_size);
243  GetModFeeAndSize(b, b_mod_fee, b_size);
244 
245  // Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
246  double f1 = a_mod_fee * b_size;
247  double f2 = a_size * b_mod_fee;
248 
249  if (f1 == f2) {
250  return a.GetTime() >= b.GetTime();
251  }
252  return f1 < f2;
253  }
254 
255  // Return the fee/size we're using for sorting this entry.
256  void GetModFeeAndSize(const CTxMemPoolEntry &a, double &mod_fee,
257  double &size) const {
258  // Compare feerate with descendants to feerate of the transaction, and
259  // return the fee/size for the max.
260  double f1 =
262  double f2 =
264 
265  if (f2 > f1) {
266  mod_fee = a.GetModFeesWithDescendants() / SATOSHI;
268  } else {
269  mod_fee = a.GetModifiedFee() / SATOSHI;
270  size = a.GetTxVirtualSize();
271  }
272  }
273 };
274 
283 public:
284  bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const {
285  double f1 = b.GetTxSize() * (a.GetFee() / SATOSHI);
286  double f2 = a.GetTxSize() * (b.GetFee() / SATOSHI);
287  if (f1 == f2) {
288  return b.GetTx().GetId() < a.GetTx().GetId();
289  }
290  return f1 > f2;
291  }
292 };
293 
295 public:
296  bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const {
297  return a.GetTime() < b.GetTime();
298  }
299 };
300 
307 public:
308  template <typename T> bool operator()(const T &a, const T &b) const {
309  double a_mod_fee, a_size, b_mod_fee, b_size;
310 
311  GetModFeeAndSize(a, a_mod_fee, a_size);
312  GetModFeeAndSize(b, b_mod_fee, b_size);
313 
314  // Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
315  double f1 = a_mod_fee * b_size;
316  double f2 = a_size * b_mod_fee;
317 
318  if (f1 == f2) {
319  return a.GetTx().GetId() < b.GetTx().GetId();
320  }
321  return f1 > f2;
322  }
323 
324  // Return the fee/size we're using for sorting this entry.
325  template <typename T>
326  void GetModFeeAndSize(const T &a, double &mod_fee, double &size) const {
327  // Compare feerate with ancestors to feerate of the transaction, and
328  // return the fee/size for the min.
329  double f1 =
330  a.GetVirtualSizeWithAncestors() * (a.GetModifiedFee() / SATOSHI);
331  double f2 =
332  a.GetTxVirtualSize() * (a.GetModFeesWithAncestors() / SATOSHI);
333 
334  if (f1 > f2) {
335  mod_fee = a.GetModFeesWithAncestors() / SATOSHI;
336  size = a.GetVirtualSizeWithAncestors();
337  } else {
338  mod_fee = a.GetModifiedFee() / SATOSHI;
339  size = a.GetTxVirtualSize();
340  }
341  }
342 };
343 
344 // Multi_index tag names
346 struct entry_time {};
347 struct ancestor_score {};
348 
355 
357  std::chrono::seconds m_time;
358 
361 
363  size_t vsize;
364 
367 };
368 
375  EXPIRY,
377  SIZELIMIT,
379  REORG,
381  BLOCK,
383  CONFLICT,
385  REPLACED
386 };
387 
389 public:
391 
392  size_t operator()(const TxId &txid) const { return hash(txid); }
393 };
394 
468 class CTxMemPool {
469 private:
471  uint32_t nCheckFrequency GUARDED_BY(cs);
473  std::atomic<uint32_t> nTransactionsUpdated;
474 
476  uint64_t totalTxSize;
480 
481  mutable int64_t lastRollingFeeUpdate;
484  mutable double rollingMinimumFeeRate;
485  mutable uint64_t m_epoch;
486  mutable bool m_has_epoch_guard;
487 
488  void trackPackageRemoved(const CFeeRate &rate) EXCLUSIVE_LOCKS_REQUIRED(cs);
489 
490  bool m_is_loaded GUARDED_BY(cs){false};
491 
492 public:
493  // public only for testing
494  static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12;
495 
496  typedef boost::multi_index_container<
497  CTxMemPoolEntry, boost::multi_index::indexed_by<
498  // sorted by txid
499  boost::multi_index::hashed_unique<
501  // sorted by fee rate
502  boost::multi_index::ordered_non_unique<
503  boost::multi_index::tag<descendant_score>,
504  boost::multi_index::identity<CTxMemPoolEntry>,
506  // sorted by entry time
507  boost::multi_index::ordered_non_unique<
508  boost::multi_index::tag<entry_time>,
509  boost::multi_index::identity<CTxMemPoolEntry>,
511  // sorted by fee rate with ancestors
512  boost::multi_index::ordered_non_unique<
513  boost::multi_index::tag<ancestor_score>,
514  boost::multi_index::identity<CTxMemPoolEntry>,
517 
547 
548  using txiter = indexed_transaction_set::nth_index<0>::type::const_iterator;
550  std::vector<std::pair<TxHash, txiter>> vTxHashes GUARDED_BY(cs);
551 
553  bool operator()(const txiter &a, const txiter &b) const {
554  return a->GetTx().GetId() < b->GetTx().GetId();
555  }
556  };
557  typedef std::set<txiter, CompareIteratorById> setEntries;
558 
559  const setEntries &GetMemPoolParents(txiter entry) const
561  const setEntries &GetMemPoolChildren(txiter entry) const
563  uint64_t CalculateDescendantMaximum(txiter entry) const
565 
566 private:
567  typedef std::map<txiter, setEntries, CompareIteratorById> cacheMap;
568 
569  struct TxLinks {
570  setEntries parents;
571  setEntries children;
572  };
573 
574  typedef std::map<txiter, TxLinks, CompareIteratorById> txlinksMap;
575  txlinksMap mapLinks;
576 
577  void UpdateParent(txiter entry, txiter parent, bool add);
578  void UpdateChild(txiter entry, txiter child, bool add);
579 
580  std::vector<indexed_transaction_set::const_iterator>
581  GetSortedDepthAndScore() const EXCLUSIVE_LOCKS_REQUIRED(cs);
582 
583 public:
584  indirectmap<COutPoint, const CTransaction *> mapNextTx GUARDED_BY(cs);
585  std::map<TxId, Amount> mapDeltas;
586 
590  CTxMemPool();
591  ~CTxMemPool();
592 
599  void check(const CCoinsViewCache *pcoins) const;
600  void setSanityCheck(double dFrequency = 1.0) {
601  LOCK(cs);
602  nCheckFrequency = static_cast<uint32_t>(dFrequency * 4294967295.0);
603  }
604 
605  // addUnchecked must updated state for all ancestors of a given transaction,
606  // to track size/count of descendant transactions. First version of
607  // addUnchecked can be used to have it call CalculateMemPoolAncestors(), and
608  // then invoke the second version.
609  // Note that addUnchecked is ONLY called from ATMP outside of tests
610  // and any other callers may break wallet's in-mempool tracking (due to
611  // lack of CValidationInterface::TransactionAddedToMempool callbacks).
612  void addUnchecked(const CTxMemPoolEntry &entry)
614  void addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAncestors)
615  EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main);
616 
617  void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason)
619  void removeForReorg(const Config &config, const CCoinsViewCache *pcoins,
620  unsigned int nMemPoolHeight, int flags)
621  EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main);
622  void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs);
623  void removeForBlock(const std::vector<CTransactionRef> &vtx,
624  unsigned int nBlockHeight) EXCLUSIVE_LOCKS_REQUIRED(cs);
625 
626  void clear();
627  // lock free
628  void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs);
629  bool CompareDepthAndScore(const TxId &txida, const TxId &txidb);
630  void queryHashes(std::vector<uint256> &vtxid) const;
631  bool isSpent(const COutPoint &outpoint) const;
632  unsigned int GetTransactionsUpdated() const;
633  void AddTransactionsUpdated(unsigned int n);
639  bool HasNoInputsOf(const CTransaction &tx) const
641 
643  void PrioritiseTransaction(const TxId &txid, const Amount nFeeDelta);
644  void ApplyDelta(const TxId &txid, Amount &nFeeDelta) const;
645  void ClearPrioritisation(const TxId &txid);
646 
648  const CTransaction *GetConflictTx(const COutPoint &prevout) const
650 
652  std::optional<txiter> GetIter(const TxId &txid) const
654 
659  setEntries GetIterSet(const std::set<TxId> &txids) const
661 
669  void RemoveStaged(setEntries &stage, bool updateDescendants,
671 
683  void UpdateTransactionsFromBlock(const std::vector<TxId> &txidsToUpdate)
684  EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main);
685 
698  bool CalculateMemPoolAncestors(
699  const CTxMemPoolEntry &entry, setEntries &setAncestors,
700  uint64_t limitAncestorCount, uint64_t limitAncestorSize,
701  uint64_t limitDescendantCount, uint64_t limitDescendantSize,
702  std::string &errString, bool fSearchForParents = true) const
704 
710  void CalculateDescendants(txiter it, setEntries &setDescendants) const
712 
720  CFeeRate GetMinFee(size_t sizelimit) const;
721 
728  void TrimToSize(size_t sizelimit,
729  std::vector<COutPoint> *pvNoSpendsRemaining = nullptr)
731 
736  int Expire(std::chrono::seconds time) EXCLUSIVE_LOCKS_REQUIRED(cs);
737 
741  void LimitSize(size_t limit, std::chrono::seconds age)
742  EXCLUSIVE_LOCKS_REQUIRED(cs, ::cs_main);
743 
748  void GetTransactionAncestry(const TxId &txid, size_t &ancestors,
749  size_t &descendants) const;
750 
752  bool IsLoaded() const;
753 
755  void SetIsLoaded(bool loaded);
756 
757  unsigned long size() const {
758  LOCK(cs);
759  return mapTx.size();
760  }
761 
762  uint64_t GetTotalTxSize() const {
763  LOCK(cs);
764  return totalTxSize;
765  }
766 
767  bool exists(const TxId &txid) const {
768  LOCK(cs);
769  return mapTx.count(txid) != 0;
770  }
771 
772  CTransactionRef get(const TxId &txid) const;
773  TxMempoolInfo info(const TxId &txid) const;
774  std::vector<TxMempoolInfo> infoAll() const;
775 
776  CFeeRate estimateFee() const;
777 
778  size_t DynamicMemoryUsage() const;
779 
780 private:
794  void UpdateForDescendants(txiter updateIt, cacheMap &cachedDescendants,
795  const std::set<TxId> &setExclude)
800  void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors)
803  void UpdateEntryForAncestors(txiter it, const setEntries &setAncestors)
810  void UpdateForRemoveFromMempool(const setEntries &entriesToRemove,
811  bool updateDescendants)
814  void UpdateChildrenForRemoval(txiter entry) EXCLUSIVE_LOCKS_REQUIRED(cs);
815 
824  void removeUnchecked(txiter entry, MemPoolRemovalReason reason)
826 
827 public:
848  class EpochGuard {
849  const CTxMemPool &pool;
850 
851  public:
852  EpochGuard(const CTxMemPool &in);
853  ~EpochGuard();
854  };
855  // N.B. GetFreshEpoch modifies mutable state via the EpochGuard construction
856  // (and later destruction)
857  EpochGuard GetFreshEpoch() const EXCLUSIVE_LOCKS_REQUIRED(cs);
858 
868  bool visited(txiter it) const EXCLUSIVE_LOCKS_REQUIRED(cs) {
869  assert(m_has_epoch_guard);
870  bool ret = it->m_epoch >= m_epoch;
871  it->m_epoch = std::max(it->m_epoch, m_epoch);
872  return ret;
873  }
874 
875  bool visited(std::optional<txiter> it) const EXCLUSIVE_LOCKS_REQUIRED(cs) {
876  assert(m_has_epoch_guard);
877  return !it || visited(*it);
878  }
879 };
880 
894 protected:
896 
897 public:
898  CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn);
899  bool GetCoin(const COutPoint &outpoint, Coin &coin) const override;
900 };
901 
920 // multi_index tag names
921 struct txid_index {};
922 struct insertion_order {};
923 
925 private:
926  typedef boost::multi_index_container<
927  CTransactionRef, boost::multi_index::indexed_by<
928  // sorted by txid
929  boost::multi_index::hashed_unique<
930  boost::multi_index::tag<txid_index>,
932  // sorted by order in the blockchain
933  boost::multi_index::sequenced<
934  boost::multi_index::tag<insertion_order>>>>
936 
938  uint64_t cachedInnerUsage = 0;
939 
940  void addTransaction(const CTransactionRef &tx) {
941  queuedTx.insert(tx);
942  cachedInnerUsage += RecursiveDynamicUsage(tx);
943  }
944 
945 public:
946  // It's almost certainly a logic bug if we don't clear out queuedTx before
947  // destruction, as we add to it while disconnecting blocks, and then we
948  // need to re-process remaining transactions to ensure mempool consistency.
949  // For now, assert() that we've emptied out this object on destruction.
950  // This assert() can always be removed if the reorg-processing code were
951  // to be refactored such that this assumption is no longer true (for
952  // instance if there was some other way we cleaned up the mempool after a
953  // reorg, besides draining this object).
954  ~DisconnectedBlockTransactions() { assert(queuedTx.empty()); }
955 
956  // Estimate the overhead of queuedTx to be 6 pointers + an allocation, as
957  // no exact formula for boost::multi_index_contained is implemented.
958  size_t DynamicMemoryUsage() const {
959  return memusage::MallocUsage(sizeof(CTransactionRef) +
960  6 * sizeof(void *)) *
961  queuedTx.size() +
962  cachedInnerUsage;
963  }
964 
966  return queuedTx;
967  }
968 
969  // Import mempool entries in topological order into queuedTx and clear the
970  // mempool. Caller should call updateMempoolForReorg to reprocess these
971  // transactions
972  void importMempool(CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(pool.cs);
973 
974  // Add entries for a block while reconstructing the topological ordering so
975  // they can be added back to the mempool simply.
976  void addForBlock(const std::vector<CTransactionRef> &vtx, CTxMemPool &pool)
978 
979  // Remove entries based on txid_index, and update memory usage.
980  void removeForBlock(const std::vector<CTransactionRef> &vtx) {
981  // Short-circuit in the common case of a block being added to the tip
982  if (queuedTx.empty()) {
983  return;
984  }
985  for (auto const &tx : vtx) {
986  auto it = queuedTx.find(tx->GetId());
987  if (it != queuedTx.end()) {
988  cachedInnerUsage -= RecursiveDynamicUsage(*it);
989  queuedTx.erase(it);
990  }
991  }
992  }
993 
994  // Remove an entry by insertion_order index, and update memory usage.
995  void removeEntry(indexed_disconnected_transactions::index<
996  insertion_order>::type::iterator entry) {
997  cachedInnerUsage -= RecursiveDynamicUsage(*entry);
998  queuedTx.get<insertion_order>().erase(entry);
999  }
1000 
1001  bool isEmpty() const { return queuedTx.empty(); }
1002 
1003  void clear() {
1004  cachedInnerUsage = 0;
1005  queuedTx.clear();
1006  }
1007 
1021  void updateMempoolForReorg(const Config &config, bool fAddToMempool,
1022  CTxMemPool &pool)
1023  EXCLUSIVE_LOCKS_REQUIRED(cs_main, pool.cs);
1024 };
1025 
1026 #endif // BITCOIN_TXMEMPOOL_H
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:338
size_t vTxHashesIdx
Index in mempool&#39;s vTxHashes.
Definition: txmempool.h:160
const int64_t sigOpCount
Total sigop plus P2SH sigops count.
Definition: txmempool.h:86
const bool spendsCoinbase
keep track of transactions that spend a coinbase
Definition: txmempool.h:79
Information about a mempool transaction.
Definition: txmempool.h:352
int64_t GetSigOpCountWithAncestors() const
Definition: txmempool.h:155
const CTransactionRef tx
Definition: txmempool.h:67
uint64_t GetSizeWithAncestors() const
Definition: txmempool.h:152
bool m_has_epoch_guard
Definition: txmempool.h:486
void UpdateLockPoints(const LockPoints &lp)
Definition: txmempool.cpp:73
uint64_t m_epoch
Definition: txmempool.h:485
std::map< txiter, TxLinks, CompareIteratorById > txlinksMap
Definition: txmempool.h:574
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
Definition: txmempool.h:548
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:516
bool visited(std::optional< txiter > it) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:875
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:90
bool exists(const TxId &txid) const
Definition: txmempool.h:767
A UTXO entry.
Definition: coins.h:27
size_t GetTxSize() const
Definition: txmempool.h:119
int64_t GetSigOpCount() const
Definition: txmempool.h:124
static void pool cs
LockPoints()
Definition: txmempool.h:51
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:296
int height
Definition: txmempool.h:44
Removed in size limiting.
void UpdateAncestorState(int64_t modifySize, Amount modifyFee, int64_t modifyCount, int64_t modifySigOps)
Definition: txmempool.cpp:380
const unsigned int entryHeight
Chain height when entering the mempool.
Definition: txmempool.h:77
Definition: amount.h:17
size_t operator()(const TxId &txid) const
Definition: txmempool.h:392
uint64_t GetTotalTxSize() const
Definition: txmempool.h:762
uint64_t m_epoch
epoch when last touched, useful for graph algorithms
Definition: txmempool.h:162
uint64_t GetSizeWithDescendants() const
Definition: txmempool.h:142
void UpdateDescendantState(int64_t modifySize, Amount modifyFee, int64_t modifyCount, int64_t modifySigOpCount)
Definition: txmempool.cpp:367
static constexpr Amount SATOSHI
Definition: amount.h:151
size_t vsize
Virtual size of the transaction.
Definition: txmempool.h:363
void operator()(CTxMemPoolEntry &e)
Definition: txmempool.h:172
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
Definition: txmempool.h:373
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:239
bool GetSpendsCoinbase() const
Definition: txmempool.h:149
void addTransaction(const CTransactionRef &tx)
Definition: txmempool.h:940
const int64_t nTime
Local time when entering the mempool.
Definition: txmempool.h:75
update_descendant_state(int64_t _modifySize, Amount _modifyFee, int64_t _modifyCount, int64_t _modifySigOpCount)
Definition: txmempool.h:167
uint64_t nCountWithDescendants
number of descendant transactions
Definition: txmempool.h:97
int64_t lastRollingFeeUpdate
Definition: txmempool.h:481
void operator()(CTxMemPoolEntry &e)
Definition: txmempool.h:214
update_ancestor_state(int64_t _modifySize, Amount _modifyFee, int64_t _modifyCount, int64_t _modifySigOpCount)
Definition: txmempool.h:185
CTransactionRef tx
The transaction itself.
Definition: txmempool.h:354
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
Definition: txmempool.h:65
Amount nModFeesWithAncestors
Definition: txmempool.h:108
void GetModFeeAndSize(const T &a, double &mod_fee, double &size) const
Definition: txmempool.h:326
bool operator()(const T &a, const T &b) const
Definition: txmempool.h:308
size_t GetTxVirtualSize() const
Definition: txmempool.cpp:49
bool blockSinceLastRollingFeeBump
Definition: txmempool.h:482
Removed for reorganization.
static const uint32_t MEMPOOL_HEIGHT
Fake height value used in Coins to signify they are only in the memory pool(since 0...
Definition: txmempool.h:38
const indexed_disconnected_transactions & GetQueuedTx() const
Definition: txmempool.h:965
result_type operator()(const CTxMemPoolEntry &entry) const
Definition: txmempool.h:223
Definition: config.h:19
Definition: txmempool.h:306
uint64_t nSizeWithAncestors
Definition: txmempool.h:107
Abstract view on the open txout dataset.
Definition: coins.h:148
size_t DynamicMemoryUsage() const
Definition: txmempool.h:126
unsigned int GetHeight() const
Definition: txmempool.h:123
Amount nFeeDelta
The fee delta.
Definition: txmempool.h:366
Amount GetModFeesWithAncestors() const
Definition: txmempool.h:154
#define LOCK(cs)
Definition: sync.h:230
Removed for conflict with in-block transaction.
DisconnectedBlockTransactions.
Definition: txmempool.h:921
CTransactionRef GetSharedTx() const
Definition: txmempool.h:117
Removed for block.
void removeForBlock(const std::vector< CTransactionRef > &vtx)
Definition: txmempool.h:980
Amount fee
Fee of the transaction.
Definition: txmempool.h:360
std::set< txiter, CompareIteratorById > setEntries
Definition: txmempool.h:557
const size_t nTxSize
... and avoid recomputing tx size
Definition: txmempool.h:71
uint64_t cachedInnerUsage
sum of dynamic memory usage of all the map elements (NOT the maps themselves)
Definition: txmempool.h:479
Sort an entry by max(score/size of entry&#39;s tx, score/size with all descendants).
Definition: txmempool.h:237
Expired from mempool.
std::chrono::seconds GetTime() const
Definition: txmempool.h:122
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:22
uint64_t nSizeWithDescendants
... and size
Definition: txmempool.h:99
uint64_t GetCountWithDescendants() const
Definition: txmempool.h:141
int64_t GetSigOpCountWithDescendants() const
Definition: txmempool.h:145
const size_t nUsageSize
... and total memory usage
Definition: txmempool.h:73
uint64_t totalTxSize
sum of all mempool tx&#39;s sizes.
Definition: txmempool.h:476
static size_t MallocUsage(size_t alloc)
Compute the total memory used by allocating alloc bytes.
Definition: memusage.h:72
update_fee_delta(Amount _feeDelta)
Definition: txmempool.h:203
int flags
Definition: bitcoin-tx.cpp:529
int64_t nSigOpCountWithAncestors
Definition: txmempool.h:109
uint64_t GetCountWithAncestors() const
Definition: txmempool.h:151
pool addUnchecked(CTxMemPoolEntry(tx, nFee, nTime, nHeight, spendsCoinbase, nSigOpCount, lp))
void removeEntry(indexed_disconnected_transactions::index< insertion_order >::type::iterator entry)
Definition: txmempool.h:995
256-bit opaque blob.
Definition: uint256.h:120
Map whose keys are pointers, but are compared by their dereferenced values.
Definition: indirectmap.h:26
const Amount GetFee() const
Definition: txmempool.h:118
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:468
int64_t modifySigOpCount
Definition: txmempool.h:199
void operator()(CTxMemPoolEntry &e)
Definition: txmempool.h:190
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: blockindex.h:23
indexed_disconnected_transactions queuedTx
Definition: txmempool.h:937
LockPoints lockPoints
Track the height and time at which tx was final.
Definition: txmempool.h:91
const CTransaction & GetTx() const
Definition: txmempool.h:116
A TxId is the identifier of a transaction.
Definition: txid.h:14
const LockPoints & lp
Definition: txmempool.h:217
uint64_t nCountWithAncestors
Definition: txmempool.h:106
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
#define GUARDED_BY(x)
Definition: threadsafety.h:45
bool spendsCoinbase
static size_t RecursiveDynamicUsage(const CScript &script)
Definition: core_memusage.h:12
Amount GetModFeesWithDescendants() const
Definition: txmempool.h:144
update_lock_points(const LockPoints &_lp)
Definition: txmempool.h:212
int64_t time
Definition: txmempool.h:45
uint64_t GetVirtualSizeWithDescendants() const
Definition: txmempool.cpp:53
Amount nModFeesWithDescendants
... and total fees (all including us)
Definition: txmempool.h:101
size_t DynamicMemoryUsage() const
Definition: txmempool.h:958
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:211
CCoinsView backed by another CCoinsView.
Definition: coins.h:185
const LockPoints & GetLockPoints() const
Definition: txmempool.h:127
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:204
Sort by feerate of entry (fee/size) in descending order This is only used for transaction relay...
Definition: txmempool.h:282
Amount feeDelta
Used for determining the priority of the transaction for mining in a block.
Definition: txmempool.h:89
const CTxMemPool & mempool
Definition: txmempool.h:895
bool operator()(const txiter &a, const txiter &b) const
Definition: txmempool.h:553
const Amount nFee
Cached to avoid expensive parent-transaction lookups.
Definition: txmempool.h:69
txlinksMap mapLinks
Definition: txmempool.h:575
result_type operator()(const CTransactionRef &tx) const
Definition: txmempool.h:227
Removed for replacement.
std::chrono::seconds m_time
Time the transaction entered the mempool.
Definition: txmempool.h:357
CBlockIndex * maxInputBlock
Definition: txmempool.h:49
void GetModFeeAndSize(const CTxMemPoolEntry &a, double &mod_fee, double &size) const
Definition: txmempool.h:256
double rollingMinimumFeeRate
minimum fee to get into the pool, decreases exponentially
Definition: txmempool.h:484
std::map< txiter, setEntries, CompareIteratorById > cacheMap
Definition: txmempool.h:567
CCoinsView that brings transactions from a mempool into view.
Definition: txmempool.h:893
EpochGuard: RAII-style guard for using epoch-based graph traversal algorithms.
Definition: txmempool.h:848
bool m_is_loaded GUARDED_BY(cs)
Definition: txmempool.h:490
Amount GetModifiedFee() const
Definition: txmempool.h:125
int64_t nSigOpCountWithDescendants
... and sigop count
Definition: txmempool.h:103
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:284
const CTxMemPool & pool
Definition: txmempool.h:849
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it...
Definition: txmempool.h:545
void operator()(CTxMemPoolEntry &e)
Definition: txmempool.h:205
const TxId GetId() const
Definition: transaction.h:261
Definition: txmempool.h:294
LockPoints lp
std::atomic< uint32_t > nTransactionsUpdated
Used by getblocktemplate to trigger CreateNewBlock() invocation.
Definition: txmempool.h:473
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:935
void UpdateFeeDelta(Amount feeDelta)
Definition: txmempool.cpp:67