Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

txmempool.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 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 <memory>
10 #include <set>
11 #include <map>
12 #include <vector>
13 #include <utility>
14 #include <string>
15 
16 #include <addressindex.h>
17 #include <spentindex.h>
18 #include <amount.h>
19 #include <coins.h>
20 #include <indirectmap.h>
21 #include <policy/feerate.h>
22 #include <primitives/transaction.h>
23 #include <sync.h>
24 #include <random.h>
25 #include <netaddress.h>
26 #include <bls/bls.h>
27 #include <pubkey.h>
28 
29 #include <boost/multi_index_container.hpp>
30 #include <boost/multi_index/hashed_index.hpp>
31 #include <boost/multi_index/ordered_index.hpp>
32 #include <boost/multi_index/sequenced_index.hpp>
33 #include <boost/signals2/signal.hpp>
34 
35 class CBlockIndex;
36 
38 static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
39 
40 struct LockPoints
41 {
42  // Will be set to the blockchain height and median time past
43  // values that would be necessary to satisfy all relative locktime
44  // constraints (BIP68) of this tx given our view of block chain history
45  int height;
46  int64_t time;
47  // As long as the current chain descends from the highest height block
48  // containing one of the inputs used in the calculation, then the cached
49  // values are still valid even after a reorg.
51 
52  LockPoints() : height(0), time(0), maxInputBlock(nullptr) { }
53 };
54 
55 class CTxMemPool;
56 
70 {
71 private:
74  size_t nTxSize;
75  size_t nUsageSize;
76  int64_t nTime;
77  unsigned int entryHeight;
79  unsigned int sigOpCount;
80  int64_t feeDelta;
82 
83  // Information about descendants of this transaction that are in the
84  // mempool; if we remove this transaction we must remove all of these
85  // descendants as well.
89 
90  // Analogous statistics for ancestor transactions
95 
96 public:
97  CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
98  int64_t _nTime, unsigned int _entryHeight,
99  bool spendsCoinbase,
100  unsigned int nSigOps, LockPoints lp);
101 
102  const CTransaction& GetTx() const { return *this->tx; }
103  CTransactionRef GetSharedTx() const { return this->tx; }
104  const CAmount& GetFee() const { return nFee; }
105  size_t GetTxSize() const { return nTxSize; }
106  int64_t GetTime() const { return nTime; }
107  unsigned int GetHeight() const { return entryHeight; }
108  unsigned int GetSigOpCount() const { return sigOpCount; }
109  int64_t GetModifiedFee() const { return nFee + feeDelta; }
110  size_t DynamicMemoryUsage() const { return nUsageSize; }
111  const LockPoints& GetLockPoints() const { return lockPoints; }
112 
113  // Adjusts the descendant state.
114  void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount);
115  // Adjusts the ancestor state
116  void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps);
117  // Updates the fee delta used for mining priority score, and the
118  // modified fees with descendants.
119  void UpdateFeeDelta(int64_t feeDelta);
120  // Update the LockPoints after a reorg
121  void UpdateLockPoints(const LockPoints& lp);
122 
123  uint64_t GetCountWithDescendants() const { return nCountWithDescendants; }
124  uint64_t GetSizeWithDescendants() const { return nSizeWithDescendants; }
126 
127  bool GetSpendsCoinbase() const { return spendsCoinbase; }
128 
129  uint64_t GetCountWithAncestors() const { return nCountWithAncestors; }
130  uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; }
132  unsigned int GetSigOpCountWithAncestors() const { return nSigOpCountWithAncestors; }
133 
134  mutable size_t vTxHashesIdx;
135 
136  // If this is a proTx, this will be the hash of the key for which this ProTx was valid
138  mutable bool isKeyChangeProTx{false};
139 };
140 
141 // Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index.
143 {
144  update_descendant_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount) :
145  modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount)
146  {}
147 
150 
151  private:
152  int64_t modifySize;
154  int64_t modifyCount;
155 };
156 
158 {
159  update_ancestor_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int _modifySigOps) :
160  modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount), modifySigOps(_modifySigOps)
161  {}
162 
165 
166  private:
167  int64_t modifySize;
169  int64_t modifyCount;
171 };
172 
174 {
175  explicit update_fee_delta(int64_t _feeDelta) : feeDelta(_feeDelta) { }
176 
178 
179 private:
180  int64_t feeDelta;
181 };
182 
184 {
185  explicit update_lock_points(const LockPoints& _lp) : lp(_lp) { }
186 
188 
189 private:
190  const LockPoints& lp;
191 };
192 
193 // extracts a transaction hash from CTxMempoolEntry or CTransactionRef
195 {
198  {
199  return entry.GetTx().GetHash();
200  }
201 
203  {
204  return tx->GetHash();
205  }
206 };
207 
213 {
214 public:
215  bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
216  {
217  double a_mod_fee, a_size, b_mod_fee, b_size;
218 
219  GetModFeeAndSize(a, a_mod_fee, a_size);
220  GetModFeeAndSize(b, b_mod_fee, b_size);
221 
222  // Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
223  double f1 = a_mod_fee * b_size;
224  double f2 = a_size * b_mod_fee;
225 
226  if (f1 == f2) {
227  return a.GetTime() >= b.GetTime();
228  }
229  return f1 < f2;
230  }
231 
232  // Return the fee/size we're using for sorting this entry.
233  void GetModFeeAndSize(const CTxMemPoolEntry &a, double &mod_fee, double &size) const
234  {
235  // Compare feerate with descendants to feerate of the transaction, and
236  // return the fee/size for the max.
237  double f1 = (double)a.GetModifiedFee() * a.GetSizeWithDescendants();
238  double f2 = (double)a.GetModFeesWithDescendants() * a.GetTxSize();
239 
240  if (f2 > f1) {
241  mod_fee = a.GetModFeesWithDescendants();
242  size = a.GetSizeWithDescendants();
243  } else {
244  mod_fee = a.GetModifiedFee();
245  size = a.GetTxSize();
246  }
247  }
248 };
249 
255 {
256 public:
257  bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
258  {
259  double f1 = (double)a.GetModifiedFee() * b.GetTxSize();
260  double f2 = (double)b.GetModifiedFee() * a.GetTxSize();
261  if (f1 == f2) {
262  return b.GetTx().GetHash() < a.GetTx().GetHash();
263  }
264  return f1 > f2;
265  }
266 };
267 
269 {
270 public:
271  bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
272  {
273  return a.GetTime() < b.GetTime();
274  }
275 };
276 
282 {
283 public:
284  template<typename T>
285  bool operator()(const T& a, const T& b) const
286  {
287  double a_mod_fee, a_size, b_mod_fee, b_size;
288 
289  GetModFeeAndSize(a, a_mod_fee, a_size);
290  GetModFeeAndSize(b, b_mod_fee, b_size);
291 
292  // Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
293  double f1 = a_mod_fee * b_size;
294  double f2 = a_size * b_mod_fee;
295 
296  if (f1 == f2) {
297  return a.GetTx().GetHash() < b.GetTx().GetHash();
298  }
299  return f1 > f2;
300  }
301 
302  // Return the fee/size we're using for sorting this entry.
303  template <typename T>
304  void GetModFeeAndSize(const T &a, double &mod_fee, double &size) const
305  {
306  // Compare feerate with ancestors to feerate of the transaction, and
307  // return the fee/size for the min.
308  double f1 = (double)a.GetModifiedFee() * a.GetSizeWithAncestors();
309  double f2 = (double)a.GetModFeesWithAncestors() * a.GetTxSize();
310 
311  if (f1 > f2) {
312  mod_fee = a.GetModFeesWithAncestors();
313  size = a.GetSizeWithAncestors();
314  } else {
315  mod_fee = a.GetModifiedFee();
316  size = a.GetTxSize();
317  }
318  }
319 };
320 
321 // Multi_index tag names
323 struct entry_time {};
324 struct ancestor_score {};
325 
327 
332 {
335 
337  int64_t nTime;
338 
341 
343  int64_t nFeeDelta;
344 };
345 
350  UNKNOWN = 0,
351  EXPIRY,
352  SIZELIMIT,
353  REORG,
354  BLOCK,
355  CONFLICT,
356 };
357 
359 {
360 private:
362  const uint64_t k0, k1;
363 
364 public:
366 
367  size_t operator()(const uint256& txid) const {
368  return SipHashUint256(k0, k1, txid);
369  }
370 };
371 
443 {
444 private:
445  uint32_t nCheckFrequency;
446  unsigned int nTransactionsUpdated;
448 
449  uint64_t totalTxSize;
450  uint64_t cachedInnerUsage;
451 
452  mutable int64_t lastRollingFeeUpdate;
454  mutable double rollingMinimumFeeRate;
455 
456  void trackPackageRemoved(const CFeeRate& rate);
457 
458 public:
459 
460  static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12; // public only for testing
461 
462  typedef boost::multi_index_container<
464  boost::multi_index::indexed_by<
465  // sorted by txid
466  boost::multi_index::hashed_unique<mempoolentry_txid, SaltedTxidHasher>,
467  // sorted by fee rate
468  boost::multi_index::ordered_non_unique<
469  boost::multi_index::tag<descendant_score>,
470  boost::multi_index::identity<CTxMemPoolEntry>,
472  >,
473  // sorted by entry time
474  boost::multi_index::ordered_non_unique<
475  boost::multi_index::tag<entry_time>,
476  boost::multi_index::identity<CTxMemPoolEntry>,
478  >,
479  // sorted by fee rate with ancestors
480  boost::multi_index::ordered_non_unique<
481  boost::multi_index::tag<ancestor_score>,
482  boost::multi_index::identity<CTxMemPoolEntry>,
484  >
485  >
487 
490 
491  typedef indexed_transaction_set::nth_index<0>::type::iterator txiter;
492  std::vector<std::pair<uint256, txiter> > vTxHashes;
493 
495  bool operator()(const txiter &a, const txiter &b) const {
496  return a->GetTx().GetHash() < b->GetTx().GetHash();
497  }
498  };
499  typedef std::set<txiter, CompareIteratorByHash> setEntries;
500 
501  const setEntries & GetMemPoolParents(txiter entry) const;
502  const setEntries & GetMemPoolChildren(txiter entry) const;
503 private:
504  typedef std::map<txiter, setEntries, CompareIteratorByHash> cacheMap;
505 
506  struct TxLinks {
509  };
510 
511  typedef std::map<txiter, TxLinks, CompareIteratorByHash> txlinksMap;
513 
514  typedef std::map<CMempoolAddressDeltaKey, CMempoolAddressDelta, CMempoolAddressDeltaKeyCompare> addressDeltaMap;
516 
517  typedef std::map<uint256, std::vector<CMempoolAddressDeltaKey> > addressDeltaMapInserted;
519 
520  typedef std::map<CSpentIndexKey, CSpentIndexValue, CSpentIndexKeyCompare> mapSpentIndex;
522 
523  typedef std::map<uint256, std::vector<CSpentIndexKey> > mapSpentIndexInserted;
525 
526  std::multimap<uint256, uint256> mapProTxRefs; // proTxHash -> transaction (all TXs that refer to an existing proTx)
527  std::map<CService, uint256> mapProTxAddresses;
528  std::map<CKeyID, uint256> mapProTxPubKeyIDs;
529  std::map<uint256, uint256> mapProTxBlsPubKeyHashes;
530  std::map<COutPoint, uint256> mapProTxCollaterals;
531 
532  void UpdateParent(txiter entry, txiter parent, bool add);
533  void UpdateChild(txiter entry, txiter child, bool add);
534 
535  std::vector<indexed_transaction_set::const_iterator> GetSortedDepthAndScore() const;
536 
537 public:
539  std::map<uint256, CAmount> mapDeltas;
540 
543  explicit CTxMemPool(CBlockPolicyEstimator* estimator = nullptr);
544 
551  void check(const CCoinsViewCache *pcoins) const;
552  void setSanityCheck(double dFrequency = 1.0) { nCheckFrequency = static_cast<uint32_t>(dFrequency * 4294967295.0); }
553 
554  // addUnchecked must updated state for all ancestors of a given transaction,
555  // to track size/count of descendant transactions. First version of
556  // addUnchecked can be used to have it call CalculateMemPoolAncestors(), and
557  // then invoke the second version.
558  // Note that addUnchecked is ONLY called from ATMP outside of tests
559  // and any other callers may break wallet's in-mempool tracking (due to
560  // lack of CValidationInterface::TransactionAddedToMempool callbacks).
561  bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool validFeeEstimate = true);
562  bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate = true);
563 
564  void addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view);
565  bool getAddressIndex(std::vector<std::pair<uint160, int> > &addresses,
566  std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> > &results);
567  bool removeAddressIndex(const uint256 txhash);
568 
569  void addSpentIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view);
570  bool getSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value);
571  bool removeSpentIndex(const uint256 txhash);
572 
574  void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags);
575  void removeConflicts(const CTransaction &tx);
576  void removeProTxPubKeyConflicts(const CTransaction &tx, const CKeyID &keyId);
577  void removeProTxPubKeyConflicts(const CTransaction &tx, const CBLSPublicKey &pubKey);
578  void removeProTxCollateralConflicts(const CTransaction &tx, const COutPoint &collateralOutpoint);
580  void removeProTxKeyChangedConflicts(const CTransaction &tx, const uint256& proTxHash, const uint256& newKeyHash);
581  void removeProTxConflicts(const CTransaction &tx);
582  void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight);
583 
584  void clear();
585  void _clear(); //lock free
586  bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb);
587  void queryHashes(std::vector<uint256>& vtxid);
588  bool isSpent(const COutPoint& outpoint);
589  unsigned int GetTransactionsUpdated() const;
590  void AddTransactionsUpdated(unsigned int n);
595  bool HasNoInputsOf(const CTransaction& tx) const;
596 
598  void PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta);
599  void ApplyDelta(const uint256 hash, CAmount &nFeeDelta) const;
600  void ClearPrioritisation(const uint256 hash);
601 
602 public:
610  void RemoveStaged(setEntries &stage, bool updateDescendants, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN);
611 
621  void UpdateTransactionsFromBlock(const std::vector<uint256> &vHashesToUpdate);
622 
633  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;
634 
638  void CalculateDescendants(txiter it, setEntries &setDescendants);
639 
646  CFeeRate GetMinFee(size_t sizelimit) const;
647 
652  void TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpendsRemaining=nullptr);
653 
655  int Expire(int64_t time);
656 
658  bool TransactionWithinChainLimit(const uint256& txid, size_t chainLimit) const;
659 
660  unsigned long size()
661  {
662  LOCK(cs);
663  return mapTx.size();
664  }
665 
666  uint64_t GetTotalTxSize() const
667  {
668  LOCK(cs);
669  return totalTxSize;
670  }
671 
672  bool exists(uint256 hash) const
673  {
674  LOCK(cs);
675  return (mapTx.count(hash) != 0);
676  }
677 
678  CTransactionRef get(const uint256& hash) const;
679  TxMempoolInfo info(const uint256& hash) const;
680  std::vector<TxMempoolInfo> infoAll() const;
681 
682  bool existsProviderTxConflict(const CTransaction &tx) const;
683 
684  size_t DynamicMemoryUsage() const;
685 
686  boost::signals2::signal<void (CTransactionRef)> NotifyEntryAdded;
687  boost::signals2::signal<void (CTransactionRef, MemPoolRemovalReason)> NotifyEntryRemoved;
688 
689 private:
703  void UpdateForDescendants(txiter updateIt,
704  cacheMap &cachedDescendants,
705  const std::set<uint256> &setExclude);
707  void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors);
709  void UpdateEntryForAncestors(txiter it, const setEntries &setAncestors);
713  void UpdateForRemoveFromMempool(const setEntries &entriesToRemove, bool updateDescendants);
715  void UpdateChildrenForRemoval(txiter entry);
716 
726 };
727 
740 {
741 protected:
743 
744 public:
745  CCoinsViewMemPool(CCoinsView* baseIn, const CTxMemPool& mempoolIn);
746  bool GetCoin(const COutPoint &outpoint, Coin &coin) const override;
747 };
748 
764 // multi_index tag names
765 struct txid_index {};
766 struct insertion_order {};
767 
769  typedef boost::multi_index_container<
771  boost::multi_index::indexed_by<
772  // sorted by txid
773  boost::multi_index::hashed_unique<
774  boost::multi_index::tag<txid_index>,
777  >,
778  // sorted by order in the blockchain
779  boost::multi_index::sequenced<
780  boost::multi_index::tag<insertion_order>
781  >
782  >
784 
785  // It's almost certainly a logic bug if we don't clear out queuedTx before
786  // destruction, as we add to it while disconnecting blocks, and then we
787  // need to re-process remaining transactions to ensure mempool consistency.
788  // For now, assert() that we've emptied out this object on destruction.
789  // This assert() can always be removed if the reorg-processing code were
790  // to be refactored such that this assumption is no longer true (for
791  // instance if there was some other way we cleaned up the mempool after a
792  // reorg, besides draining this object).
794 
796  uint64_t cachedInnerUsage = 0;
797 
798  // Estimate the overhead of queuedTx to be 6 pointers + an allocation, as
799  // no exact formula for boost::multi_index_contained is implemented.
800  size_t DynamicMemoryUsage() const {
801  return memusage::MallocUsage(sizeof(CTransactionRef) + 6 * sizeof(void*)) * queuedTx.size() + cachedInnerUsage;
802  }
803 
805  {
806  queuedTx.insert(tx);
808  }
809 
810  // Remove entries based on txid_index, and update memory usage.
811  void removeForBlock(const std::vector<CTransactionRef>& vtx)
812  {
813  // Short-circuit in the common case of a block being added to the tip
814  if (queuedTx.empty()) {
815  return;
816  }
817  for (auto const &tx : vtx) {
818  auto it = queuedTx.find(tx->GetHash());
819  if (it != queuedTx.end()) {
821  queuedTx.erase(it);
822  }
823  }
824  }
825 
826  // Remove an entry by insertion_order index, and update memory usage.
827  void removeEntry(indexed_disconnected_transactions::index<insertion_order>::type::iterator entry)
828  {
830  queuedTx.get<insertion_order>().erase(entry);
831  }
832 
833  void clear()
834  {
835  cachedInnerUsage = 0;
836  queuedTx.clear();
837  }
838 };
839 
840 #endif // BITCOIN_TXMEMPOOL_H
addressDeltaMapInserted mapAddressInserted
Definition: txmempool.h:518
CAmount GetModFeesWithAncestors() const
Definition: txmempool.h:131
size_t vTxHashesIdx
Index in mempool&#39;s vTxHashes.
Definition: txmempool.h:134
bool existsProviderTxConflict(const CTransaction &tx) const
Definition: txmempool.cpp:1229
Information about a mempool transaction.
Definition: txmempool.h:331
int Expire(int64_t time)
Expire all transaction (and their dependencies) in the mempool older than time.
Definition: txmempool.cpp:1403
update_fee_delta(int64_t _feeDelta)
Definition: txmempool.h:175
uint64_t GetSizeWithAncestors() const
Definition: txmempool.h:130
void UpdateEntryForAncestors(txiter it, const setEntries &setAncestors)
Set ancestor state for an entry.
Definition: txmempool.cpp:233
CAmount nModFeesWithDescendants
... and total fees (all including us)
Definition: txmempool.h:88
void UpdateLockPoints(const LockPoints &lp)
Definition: txmempool.cpp:56
std::map< txiter, TxLinks, CompareIteratorByHash > txlinksMap
Definition: txmempool.h:511
void addSpentIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view)
Definition: txmempool.cpp:555
std::map< CKeyID, uint256 > mapProTxPubKeyIDs
Definition: txmempool.h:528
bool getAddressIndex(std::vector< std::pair< uint160, int > > &addresses, std::vector< std::pair< CMempoolAddressDeltaKey, CMempoolAddressDelta > > &results)
Definition: txmempool.cpp:525
void removeConflicts(const CTransaction &tx)
Definition: txmempool.cpp:794
std::vector< TxMempoolInfo > infoAll() const
Definition: txmempool.cpp:1197
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason=MemPoolRemovalReason::UNKNOWN)
Definition: txmempool.cpp:725
void trackPackageRemoved(const CFeeRate &rate)
Definition: txmempool.cpp:1494
CTxMemPoolEntry(const CTransactionRef &_tx, const CAmount &_nFee, int64_t _nTime, unsigned int _entryHeight, bool spendsCoinbase, unsigned int nSigOps, LockPoints lp)
Definition: txmempool.cpp:28
A UTXO entry.
Definition: coins.h:29
void removeProTxKeyChangedConflicts(const CTransaction &tx, const uint256 &proTxHash, const uint256 &newKeyHash)
Definition: txmempool.cpp:877
addressDeltaMap mapAddress
Definition: txmempool.h:515
size_t GetTxSize() const
Definition: txmempool.h:105
boost::signals2::signal< void(CTransactionRef)> NotifyEntryAdded
Definition: txmempool.h:686
size_t DynamicMemoryUsage() const
Definition: txmempool.cpp:1389
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: txmempool.cpp:1373
bool isSpent(const COutPoint &outpoint)
Definition: txmempool.cpp:344
LockPoints()
Definition: txmempool.h:52
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:271
int height
Definition: txmempool.h:45
TxMempoolInfo info(const uint256 &hash) const
Definition: txmempool.cpp:1220
Expired from mempool.
CTxMemPool(CBlockPolicyEstimator *estimator=nullptr)
Create a new CTxMemPool.
Definition: txmempool.cpp:333
CAmount GetModFeesWithDescendants() const
Definition: txmempool.h:125
void clear()
Definition: txmempool.cpp:998
int64_t feeDelta
Definition: txmempool.h:180
uint64_t GetTotalTxSize() const
Definition: txmempool.h:666
bool operator()(const txiter &a, const txiter &b) const
Definition: txmempool.h:495
bool HasNoInputsOf(const CTransaction &tx) const
Check that none of this transactions inputs are in the mempool, and thus the tx is not dependent on o...
Definition: txmempool.cpp:1363
uint64_t GetSizeWithDescendants() const
Definition: txmempool.h:124
std::set< txiter, CompareIteratorByHash > setEntries
Definition: txmempool.h:499
int flags
Definition: dash-tx.cpp:462
void queryHashes(std::vector< uint256 > &vtxid)
Definition: txmempool.cpp:1180
void addTransaction(const CTransactionRef &tx)
Definition: txmempool.h:804
void operator()(CTxMemPoolEntry &e)
Definition: txmempool.h:148
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
Definition: txmempool.h:349
const uint64_t k1
Definition: txmempool.h:362
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:215
bool GetSpendsCoinbase() const
Definition: txmempool.h:127
void TrimToSize(size_t sizelimit, std::vector< COutPoint > *pvNoSpendsRemaining=nullptr)
Remove transactions from the mempool until its dynamic size is <= sizelimit.
Definition: txmempool.cpp:1502
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps)
Definition: txmempool.cpp:322
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:345
uint64_t nCountWithDescendants
number of descendant transactions
Definition: txmempool.h:86
int64_t lastRollingFeeUpdate
Definition: txmempool.h:452
CAmount nFee
Cached to avoid expensive parent-transaction lookups.
Definition: txmempool.h:73
void operator()(CTxMemPoolEntry &e)
Definition: txmempool.h:187
int64_t nFeeDelta
The fee delta.
Definition: txmempool.h:343
indirectmap< COutPoint, const CTransaction * > mapNextTx
Definition: txmempool.h:538
update_descendant_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount)
Definition: txmempool.h:144
void UpdateTransactionsFromBlock(const std::vector< uint256 > &vHashesToUpdate)
When adding transactions from a disconnected block back to the mempool, new mempool entries may have ...
Definition: txmempool.cpp:111
CTransactionRef tx
The transaction itself.
Definition: txmempool.h:334
void _clear()
Definition: txmempool.cpp:983
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
Definition: txmempool.h:69
void check(const CCoinsViewCache *pcoins) const
If sanity-checking is turned on, check makes sure the pool is consistent (does not contain two transa...
Definition: txmempool.cpp:1013
void GetModFeeAndSize(const T &a, double &mod_fee, double &size) const
Definition: txmempool.h:304
indexed_transaction_set mapTx
Definition: txmempool.h:489
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:783
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
unsigned int nSigOpCountWithAncestors
Definition: txmempool.h:94
std::map< CSpentIndexKey, CSpentIndexValue, CSpentIndexKeyCompare > mapSpentIndex
Definition: txmempool.h:520
std::map< COutPoint, uint256 > mapProTxCollaterals
Definition: txmempool.h:530
bool operator()(const T &a, const T &b) const
Definition: txmempool.h:285
bool blockSinceLastRollingFeeBump
Definition: txmempool.h:453
std::map< uint256, std::vector< CSpentIndexKey > > mapSpentIndexInserted
Definition: txmempool.h:523
Removed in size limiting.
indexed_disconnected_transactions queuedTx
Definition: txmempool.h:795
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:38
void setSanityCheck(double dFrequency=1.0)
Definition: txmempool.h:552
result_type operator()(const CTxMemPoolEntry &entry) const
Definition: txmempool.h:197
std::vector< std::pair< uint256, txiter > > vTxHashes
All tx hashes/entries in mapTx, in random order.
Definition: txmempool.h:492
void UpdateFeeDelta(int64_t feeDelta)
Definition: txmempool.cpp:49
unsigned int GetSigOpCount() const
Definition: txmempool.h:108
size_t nUsageSize
... and total memory usage
Definition: txmempool.h:75
bool isKeyChangeProTx
Definition: txmempool.h:138
Definition: txmempool.h:281
unsigned long size()
Definition: txmempool.h:660
uint64_t nSizeWithAncestors
Definition: txmempool.h:92
int64_t feeDelta
Used for determining the priority of the transaction for mining in a block.
Definition: txmempool.h:80
Abstract view on the open txout dataset.
Definition: coins.h:145
size_t DynamicMemoryUsage() const
Definition: txmempool.h:110
unsigned int GetHeight() const
Definition: txmempool.h:107
void ApplyDelta(const uint256 hash, CAmount &nFeeDelta) const
Definition: txmempool.cpp:1347
void removeForBlock(const std::vector< CTransactionRef > &vtx)
Definition: txmempool.h:811
#define LOCK(cs)
Definition: sync.h:178
bool removeAddressIndex(const uint256 txhash)
Definition: txmempool.cpp:539
We want to be able to estimate feerates that are needed on tx&#39;s to be included in a certain number of...
Definition: fees.h:138
const uint256 & GetHash() const
Definition: transaction.h:256
const CAmount & GetFee() const
Definition: txmempool.h:104
DisconnectedBlockTransactions.
Definition: txmempool.h:765
std::vector< indexed_transaction_set::const_iterator > GetSortedDepthAndScore() const
Definition: txmempool.cpp:1166
CTransactionRef GetSharedTx() const
Definition: txmempool.h:103
Removed for reorganization.
void UpdateParent(txiter entry, txiter parent, bool add)
Definition: txmempool.cpp:1444
std::map< uint256, CAmount > mapDeltas
Definition: txmempool.h:539
void CalculateDescendants(txiter it, setEntries &setDescendants)
Populate setDescendants with all in-mempool descendants of hash.
Definition: txmempool.cpp:702
unsigned int GetSigOpCountWithAncestors() const
Definition: txmempool.h:132
const uint64_t k0
Salt.
Definition: txmempool.h:362
const setEntries & GetMemPoolChildren(txiter entry) const
Definition: txmempool.cpp:1462
void removeProTxSpentCollateralConflicts(const CTransaction &tx)
Definition: txmempool.cpp:841
uint64_t cachedInnerUsage
sum of dynamic memory usage of all the map elements (NOT the maps themselves)
Definition: txmempool.h:450
Sort an entry by max(score/size of entry&#39;s tx, score/size with all descendants).
Definition: txmempool.h:212
static const int ROLLING_FEE_HALFLIFE
Definition: txmempool.h:460
size_t nTxSize
... and avoid recomputing tx size
Definition: txmempool.h:74
bool exists(uint256 hash) const
Definition: txmempool.h:672
CAmount nModFeesWithAncestors
Definition: txmempool.h:93
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
Try to calculate all in-mempool ancestors of entry.
Definition: txmempool.cpp:154
unsigned int nTransactionsUpdated
Used by getblocktemplate to trigger CreateNewBlock() invocation.
Definition: txmempool.h:446
Manually removed or unknown reason.
std::map< CService, uint256 > mapProTxAddresses
Definition: txmempool.h:527
int64_t nTime
Local time when entering the mempool.
Definition: txmempool.h:76
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
uint64_t nSizeWithDescendants
... and size
Definition: txmempool.h:87
void AddTransactionsUpdated(unsigned int n)
Definition: txmempool.cpp:356
uint256 result_type
Definition: txmempool.h:196
uint64_t GetCountWithDescendants() const
Definition: txmempool.h:123
CFeeRate GetMinFee(size_t sizelimit) const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
Definition: txmempool.cpp:1470
uint64_t totalTxSize
sum of all mempool tx&#39; byte sizes
Definition: txmempool.h:449
indexed_transaction_set::nth_index< 0 >::type::iterator txiter
Definition: txmempool.h:491
CCriticalSection cs
Definition: txmempool.h:488
bool removeSpentIndex(const uint256 txhash)
Definition: txmempool.cpp:608
static size_t MallocUsage(size_t alloc)
Compute the total memory used by allocating alloc bytes.
Definition: memusage.h:48
unsigned int sigOpCount
Legacy sig ops plus P2SH sig op count.
Definition: txmempool.h:79
bool TransactionWithinChainLimit(const uint256 &txid, size_t chainLimit) const
Returns false if the transaction is in the mempool and not within the chain limit specified...
Definition: txmempool.cpp:1545
uint64_t GetCountWithAncestors() const
Definition: txmempool.h:129
int64_t nTime
Time the transaction entered the mempool.
Definition: txmempool.h:337
bool spendsCoinbase
keep track of transactions that spend a coinbase
Definition: txmempool.h:78
256-bit opaque blob.
Definition: uint256.h:123
mapSpentIndex mapSpent
Definition: txmempool.h:521
void UpdateChildrenForRemoval(txiter entry)
Sever link between specified transaction and direct children.
Definition: txmempool.cpp:247
update_ancestor_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int _modifySigOps)
Definition: txmempool.h:159
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:442
bool CompareDepthAndScore(const uint256 &hasha, const uint256 &hashb)
Definition: txmempool.cpp:1135
void operator()(CTxMemPoolEntry &e)
Definition: txmempool.h:163
std::map< txiter, setEntries, CompareIteratorByHash > cacheMap
Definition: txmempool.h:504
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
int64_t GetTime() const
Definition: txmempool.h:106
LockPoints lockPoints
Track the height and time at which tx was final.
Definition: txmempool.h:81
uint32_t nCheckFrequency
Value n means that n times in 2^32 we check.
Definition: txmempool.h:445
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
Definition: txmempool.cpp:313
const CTransaction & GetTx() const
Definition: txmempool.h:102
const LockPoints & lp
Definition: txmempool.h:190
int64_t GetModifiedFee() const
Definition: txmempool.h:109
uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256 &val)
Optimized SipHash-2-4 implementation for uint256.
Definition: hash.cpp:168
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:20
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:486
void UpdateForRemoveFromMempool(const setEntries &entriesToRemove, bool updateDescendants)
For each transaction being removed, update ancestors and any direct children.
Definition: txmempool.cpp:255
uint64_t nCountWithAncestors
Definition: txmempool.h:91
std::map< uint256, std::vector< CMempoolAddressDeltaKey > > addressDeltaMapInserted
Definition: txmempool.h:517
void removeProTxPubKeyConflicts(const CTransaction &tx, const CKeyID &keyId)
Definition: txmempool.cpp:811
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:19
void UpdateChild(txiter entry, txiter child, bool add)
Definition: txmempool.cpp:1434
unsigned int GetTransactionsUpdated() const
Definition: txmempool.cpp:350
const setEntries & GetMemPoolParents(txiter entry) const
Definition: txmempool.cpp:1454
uint256 validForProTxKey
Definition: txmempool.h:137
std::map< uint256, uint256 > mapProTxBlsPubKeyHashes
Definition: txmempool.h:529
size_t operator()(const uint256 &txid) const
Definition: txmempool.h:367
static size_t RecursiveDynamicUsage(const CScript &script)
Definition: core_memusage.h:12
update_lock_points(const LockPoints &_lp)
Definition: txmempool.h:185
void ClearPrioritisation(const uint256 hash)
Definition: txmempool.cpp:1357
int64_t time
Definition: txmempool.h:46
CTransactionRef tx
Definition: txmempool.h:72
bool getSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value)
Definition: txmempool.cpp:595
void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors)
Update ancestors of hash to add/remove it as a descendant transaction.
Definition: txmempool.cpp:218
boost::signals2::signal< void(CTransactionRef, MemPoolRemovalReason)> NotifyEntryRemoved
Definition: txmempool.h:687
bool addUnchecked(const uint256 &hash, const CTxMemPoolEntry &entry, bool validFeeEstimate=true)
Definition: txmempool.cpp:1424
void removeForBlock(const std::vector< CTransactionRef > &vtx, unsigned int nBlockHeight)
Called when a block is connected.
Definition: txmempool.cpp:953
mapSpentIndexInserted mapSpentInserted
Definition: txmempool.h:524
CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn)
Definition: txmempool.cpp:1371
std::multimap< uint256, uint256 > mapProTxRefs
Definition: txmempool.h:526
size_t DynamicMemoryUsage() const
Definition: txmempool.h:800
CFeeRate feeRate
Feerate of the transaction.
Definition: txmempool.h:340
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:198
CCoinsView backed by another CCoinsView.
Definition: coins.h:182
const LockPoints & GetLockPoints() const
Definition: txmempool.h:111
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:201
Sort by score of entry ((fee+delta)/size) in descending order.
Definition: txmempool.h:254
void removeProTxConflicts(const CTransaction &tx)
Definition: txmempool.cpp:895
const CTxMemPool & mempool
Definition: txmempool.h:742
void removeProTxCollateralConflicts(const CTransaction &tx, const COutPoint &collateralOutpoint)
Definition: txmempool.cpp:831
void addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view)
Definition: txmempool.cpp:468
txlinksMap mapLinks
Definition: txmempool.h:512
CBlockPolicyEstimator * minerPolicyEstimator
Definition: txmempool.h:447
CBlockIndex * maxInputBlock
Definition: txmempool.h:50
void GetModFeeAndSize(const CTxMemPoolEntry &a, double &mod_fee, double &size) const
Definition: txmempool.h:233
double rollingMinimumFeeRate
minimum fee to get into the pool, decreases exponentially
Definition: txmempool.h:454
CCoinsView that brings transactions from a memorypool into view.
Definition: txmempool.h:739
void PrioritiseTransaction(const uint256 &hash, const CAmount &nFeeDelta)
Affect CreateNewBlock prioritisation of transactions.
Definition: txmempool.cpp:1317
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags)
Definition: txmempool.cpp:757
void removeEntry(indexed_disconnected_transactions::index< insertion_order >::type::iterator entry)
Definition: txmempool.h:827
void removeUnchecked(txiter entry, MemPoolRemovalReason reason=MemPoolRemovalReason::UNKNOWN)
Before calling removeUnchecked for a given transaction, UpdateForRemoveFromMempool must be called on ...
Definition: txmempool.cpp:624
std::map< CMempoolAddressDeltaKey, CMempoolAddressDelta, CMempoolAddressDeltaKeyCompare > addressDeltaMap
Definition: txmempool.h:514
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:257
Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the re...
Definition: sync.h:94
void operator()(CTxMemPoolEntry &e)
Definition: txmempool.h:177
void RemoveStaged(setEntries &stage, bool updateDescendants, MemPoolRemovalReason reason=MemPoolRemovalReason::UNKNOWN)
Remove a set of transactions from the mempool.
Definition: txmempool.cpp:1395
Definition: txmempool.h:268
unsigned int entryHeight
Chain height when entering the mempool.
Definition: txmempool.h:77
void UpdateForDescendants(txiter updateIt, cacheMap &cachedDescendants, const std::set< uint256 > &setExclude)
UpdateForDescendants is used by UpdateTransactionsFromBlock to update the descendants for a single tr...
Definition: txmempool.cpp:64
Released under the MIT license