Raven Core  3.0.0
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 // Copyright (c) 2017-2019 The Raven Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef RAVEN_TXMEMPOOL_H
8 #define RAVEN_TXMEMPOOL_H
9 
10 #include <memory>
11 #include <set>
12 #include <map>
13 #include <vector>
14 #include <utility>
15 #include <string>
16 
17 #include "addressindex.h"
18 #include "spentindex.h"
19 #include "amount.h"
20 #include "coins.h"
21 #include "indirectmap.h"
22 #include "policy/feerate.h"
23 #include "primitives/transaction.h"
24 #include "sync.h"
25 #include "random.h"
26 
27 #include <boost/multi_index_container.hpp>
28 #include <boost/multi_index/hashed_index.hpp>
29 #include <boost/multi_index/ordered_index.hpp>
30 #include <boost/multi_index/sequenced_index.hpp>
31 #include <boost/signals2/signal.hpp>
32 
33 class CBlockIndex;
35 
37 static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
38 
39 struct LockPoints
40 {
41  // Will be set to the blockchain height and median time past
42  // values that would be necessary to satisfy all relative locktime
43  // constraints (BIP68) 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 
54 class CTxMemPool;
55 
69 {
70 private:
73  size_t nTxWeight;
74  size_t nUsageSize;
75  int64_t nTime;
76  unsigned int entryHeight;
78  int64_t sigOpCost;
79  int64_t feeDelta;
81 
82  // Information about descendants of this transaction that are in the
83  // mempool; if we remove this transaction we must remove all of these
84  // descendants as well.
88 
89  // Analogous statistics for ancestor transactions
94 
95 public:
96  CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
97  int64_t _nTime, unsigned int _entryHeight,
98  bool spendsCoinbase,
99  int64_t nSigOpsCost, LockPoints lp);
100 
101  const CTransaction& GetTx() const { return *this->tx; }
102  CTransactionRef GetSharedTx() const { return this->tx; }
103  const CAmount& GetFee() const { return nFee; }
104  size_t GetTxSize() const;
105  size_t GetTxWeight() const { return nTxWeight; }
106  int64_t GetTime() const { return nTime; }
107  unsigned int GetHeight() const { return entryHeight; }
108  int64_t GetSigOpCost() const { return sigOpCost; }
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, int 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; }
125  CAmount GetModFeesWithDescendants() const { return nModFeesWithDescendants; }
126 
127  bool GetSpendsCoinbase() const { return spendsCoinbase; }
128 
129  uint64_t GetCountWithAncestors() const { return nCountWithAncestors; }
130  uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; }
131  CAmount GetModFeesWithAncestors() const { return nModFeesWithAncestors; }
132  int64_t GetSigOpCostWithAncestors() const { return nSigOpCostWithAncestors; }
133 
134  mutable size_t vTxHashesIdx;
135 };
136 
137 // Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index.
139 {
140  update_descendant_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount) :
141  modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount)
142  {}
143 
144  void operator() (CTxMemPoolEntry &e)
145  { e.UpdateDescendantState(modifySize, modifyFee, modifyCount); }
146 
147  private:
148  int64_t modifySize;
150  int64_t modifyCount;
151 };
152 
154 {
155  update_ancestor_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int64_t _modifySigOpsCost) :
156  modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount), modifySigOpsCost(_modifySigOpsCost)
157  {}
158 
159  void operator() (CTxMemPoolEntry &e)
160  { e.UpdateAncestorState(modifySize, modifyFee, modifyCount, modifySigOpsCost); }
161 
162  private:
163  int64_t modifySize;
165  int64_t modifyCount;
167 };
168 
170 {
171  explicit update_fee_delta(int64_t _feeDelta) : feeDelta(_feeDelta) { }
172 
173  void operator() (CTxMemPoolEntry &e) { e.UpdateFeeDelta(feeDelta); }
174 
175 private:
176  int64_t feeDelta;
177 };
178 
180 {
181  explicit update_lock_points(const LockPoints& _lp) : lp(_lp) { }
182 
183  void operator() (CTxMemPoolEntry &e) { e.UpdateLockPoints(lp); }
184 
185 private:
186  const LockPoints& lp;
187 };
188 
189 // extracts a transaction hash from CTxMempoolEntry or CTransactionRef
191 {
193  result_type operator() (const CTxMemPoolEntry &entry) const
194  {
195  return entry.GetTx().GetHash();
196  }
197 
198  result_type operator() (const CTransactionRef& tx) const
199  {
200  return tx->GetHash();
201  }
202 };
203 
209 {
210 public:
211  bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
212  {
213  bool fUseADescendants = UseDescendantScore(a);
214  bool fUseBDescendants = UseDescendantScore(b);
215 
216  double aModFee = fUseADescendants ? a.GetModFeesWithDescendants() : a.GetModifiedFee();
217  double aSize = fUseADescendants ? a.GetSizeWithDescendants() : a.GetTxSize();
218 
219  double bModFee = fUseBDescendants ? b.GetModFeesWithDescendants() : b.GetModifiedFee();
220  double bSize = fUseBDescendants ? b.GetSizeWithDescendants() : b.GetTxSize();
221 
222  // Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
223  double f1 = aModFee * bSize;
224  double f2 = aSize * bModFee;
225 
226  if (f1 == f2) {
227  return a.GetTime() >= b.GetTime();
228  }
229  return f1 < f2;
230  }
231 
232  // Calculate which score to use for an entry (avoiding division).
233  bool UseDescendantScore(const CTxMemPoolEntry &a) const
234  {
235  double f1 = (double)a.GetModifiedFee() * a.GetSizeWithDescendants();
236  double f2 = (double)a.GetModFeesWithDescendants() * a.GetTxSize();
237  return f2 > f1;
238  }
239 };
240 
246 {
247 public:
248  bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
249  {
250  double f1 = (double)a.GetModifiedFee() * b.GetTxSize();
251  double f2 = (double)b.GetModifiedFee() * a.GetTxSize();
252  if (f1 == f2) {
253  return b.GetTx().GetHash() < a.GetTx().GetHash();
254  }
255  return f1 > f2;
256  }
257 };
258 
260 {
261 public:
262  bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
263  {
264  return a.GetTime() < b.GetTime();
265  }
266 };
267 
269 {
270 public:
271  bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
272  {
273  double aFees = a.GetModFeesWithAncestors();
274  double aSize = a.GetSizeWithAncestors();
275 
276  double bFees = b.GetModFeesWithAncestors();
277  double bSize = b.GetSizeWithAncestors();
278 
279  // Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
280  double f1 = aFees * bSize;
281  double f2 = aSize * bFees;
282 
283  if (f1 == f2) {
284  return a.GetTx().GetHash() < b.GetTx().GetHash();
285  }
286 
287  return f1 > f2;
288  }
289 };
290 
291 // Multi_index tag names
293 struct entry_time {};
294 struct mining_score {};
295 struct ancestor_score {};
296 
298 
303 {
306 
308  int64_t nTime;
309 
312 
314  int64_t nFeeDelta;
315 };
316 
321  UNKNOWN = 0,
322  EXPIRY,
323  SIZELIMIT,
324  REORG,
325  BLOCK,
326  CONFLICT,
327  REPLACED
328 };
329 
331 {
332 private:
334  const uint64_t k0, k1;
335 
336 public:
338 
339  size_t operator()(const uint256& txid) const {
340  return SipHashUint256(k0, k1, txid);
341  }
342 };
343 
417 {
418 private:
419  uint32_t nCheckFrequency;
420  unsigned int nTransactionsUpdated;
422 
423  uint64_t totalTxSize;
424  uint64_t cachedInnerUsage;
425 
426  mutable int64_t lastRollingFeeUpdate;
428  mutable double rollingMinimumFeeRate;
429 
430  void trackPackageRemoved(const CFeeRate& rate);
431 
432 public:
433 
434  static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12; // public only for testing
435 
436  typedef boost::multi_index_container<
438  boost::multi_index::indexed_by<
439  // sorted by txid
440  boost::multi_index::hashed_unique<mempoolentry_txid, SaltedTxidHasher>,
441  // sorted by fee rate
442  boost::multi_index::ordered_non_unique<
443  boost::multi_index::tag<descendant_score>,
444  boost::multi_index::identity<CTxMemPoolEntry>,
446  >,
447  // sorted by entry time
448  boost::multi_index::ordered_non_unique<
449  boost::multi_index::tag<entry_time>,
450  boost::multi_index::identity<CTxMemPoolEntry>,
452  >,
453  // sorted by score (for mining prioritization)
454  boost::multi_index::ordered_unique<
455  boost::multi_index::tag<mining_score>,
456  boost::multi_index::identity<CTxMemPoolEntry>,
458  >,
459  // sorted by fee rate with ancestors
460  boost::multi_index::ordered_non_unique<
461  boost::multi_index::tag<ancestor_score>,
462  boost::multi_index::identity<CTxMemPoolEntry>,
464  >
465  >
467 
470 
471  std::map<std::string, uint256> mapAssetToHash;
472  std::map<uint256, std::string> mapHashToAsset;
473 
475  // Helper maps for when addresses are marked as frozen
476  std::map<std::pair<std::string, std::string>, std::set<uint256> > mapAddressesMarkedFrozen;
477  std::map<uint256, std::set<std::pair<std::string, std::string>>> mapHashToAddressMarkedFrozen;
478 
479  // Helper maps for when restricted assets are globally frozen
480  std::map<std::string, std::set<uint256>> mapAssetMarkedGlobalFrozen;
481  std::map<uint256, std::set<std::string>> mapHashMarkedGlobalFrozen;
482 
483  // Helper maps for when qualifiers are added or removed from addresses
484  std::map<std::string, std::set<uint256>> mapAddressesQualifiersChanged;
485  std::map<uint256, std::set<std::string>> mapHashQualifiersChanged;
486 
487  // Helper maps for when verifier string are changed
488  std::map<std::string, std::set<uint256>> mapAssetVerifierChanged;
489  std::map<uint256, std::set<std::string>> mapHashVerifierChanged;
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 {
507  setEntries parents;
508  setEntries children;
509  };
510 
511  typedef std::map<txiter, TxLinks, CompareIteratorByHash> txlinksMap;
512  txlinksMap mapLinks;
513 
514  typedef std::map<CMempoolAddressDeltaKey, CMempoolAddressDelta, CMempoolAddressDeltaKeyCompare> addressDeltaMap;
515  addressDeltaMap mapAddress;
516 
517  typedef std::map<uint256, std::vector<CMempoolAddressDeltaKey> > addressDeltaMapInserted;
518  addressDeltaMapInserted mapAddressInserted;
519 
520  typedef std::map<CSpentIndexKey, CSpentIndexValue, CSpentIndexKeyCompare> mapSpentIndex;
521  mapSpentIndex mapSpent;
522 
523  typedef std::map<uint256, std::vector<CSpentIndexKey> > mapSpentIndexInserted;
524  mapSpentIndexInserted mapSpentInserted;
525 
526  void UpdateParent(txiter entry, txiter parent, bool add);
527  void UpdateChild(txiter entry, txiter child, bool add);
528 
529  std::vector<indexed_transaction_set::const_iterator> GetSortedDepthAndScore() const;
530 
531 public:
533  std::map<uint256, CAmount> mapDeltas;
534 
537  explicit CTxMemPool(CBlockPolicyEstimator* estimator = nullptr);
538 
545  void check(const CCoinsViewCache *pcoins) const;
546  void setSanityCheck(double dFrequency = 1.0) { nCheckFrequency = static_cast<uint32_t>(dFrequency * 4294967295.0); }
547 
548  // addUnchecked must updated state for all ancestors of a given transaction,
549  // to track size/count of descendant transactions. First version of
550  // addUnchecked can be used to have it call CalculateMemPoolAncestors(), and
551  // then invoke the second version.
552  bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool validFeeEstimate = true);
553  bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate = true);
554 
555  void addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view);
556  bool getAddressIndex(std::vector<std::pair<uint160, int> > &addresses, std::string assetName,
557  std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> > &results);
558  bool getAddressIndex(std::vector<std::pair<uint160, int> > &addresses,
559  std::vector<std::pair<CMempoolAddressDeltaKey, CMempoolAddressDelta> > &results);
560  bool removeAddressIndex(const uint256 txhash);
561 
562  void addSpentIndex(const CTxMemPoolEntry &entry, const CCoinsViewCache &view);
563  bool getSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value);
564  bool removeSpentIndex(const uint256 txhash);
565 
566  void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN);
567  void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags);
568  void removeConflicts(const CTransaction &tx);
569  void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight, ConnectedBlockAssetData& connectedBlockData );
570  void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight);
571 
572  void clear();
573  void _clear(); //lock free
574  bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb);
575  void queryHashes(std::vector<uint256>& vtxid);
576  bool isSpent(const COutPoint& outpoint);
577  unsigned int GetTransactionsUpdated() const;
578  void AddTransactionsUpdated(unsigned int n);
583  bool HasNoInputsOf(const CTransaction& tx) const;
584 
586  void PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta);
587  void ApplyDelta(const uint256 hash, CAmount &nFeeDelta) const;
588  void ClearPrioritisation(const uint256 hash);
589 
590 public:
598  void RemoveStaged(setEntries &stage, bool updateDescendants, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN);
599 
609  void UpdateTransactionsFromBlock(const std::vector<uint256> &vHashesToUpdate);
610 
621  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;
622 
626  void CalculateDescendants(txiter it, setEntries &setDescendants);
627 
634  CFeeRate GetMinFee(size_t sizelimit) const;
635 
640  void TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpendsRemaining=nullptr);
641 
643  int Expire(int64_t time);
644 
646  bool TransactionWithinChainLimit(const uint256& txid, size_t chainLimit) const;
647 
648  unsigned long size()
649  {
650  LOCK(cs);
651  return mapTx.size();
652  }
653 
654  uint64_t GetTotalTxSize() const
655  {
656  LOCK(cs);
657  return totalTxSize;
658  }
659 
660  bool exists(uint256 hash) const
661  {
662  LOCK(cs);
663  return (mapTx.count(hash) != 0);
664  }
665 
666  CTransactionRef get(const uint256& hash) const;
667  TxMempoolInfo info(const uint256& hash) const;
668  std::vector<TxMempoolInfo> infoAll() const;
669 
670  size_t DynamicMemoryUsage() const;
671 
672  boost::signals2::signal<void (CTransactionRef)> NotifyEntryAdded;
673  boost::signals2::signal<void (CTransactionRef, MemPoolRemovalReason)> NotifyEntryRemoved;
674 
675 private:
689  void UpdateForDescendants(txiter updateIt,
690  cacheMap &cachedDescendants,
691  const std::set<uint256> &setExclude);
693  void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors);
695  void UpdateEntryForAncestors(txiter it, const setEntries &setAncestors);
699  void UpdateForRemoveFromMempool(const setEntries &entriesToRemove, bool updateDescendants);
701  void UpdateChildrenForRemoval(txiter entry);
702 
711  void removeUnchecked(txiter entry, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN);
712 };
713 
726 {
727 protected:
729 
730 public:
731  CCoinsViewMemPool(CCoinsView* baseIn, const CTxMemPool& mempoolIn);
732  bool GetCoin(const COutPoint &outpoint, Coin &coin) const override;
733 };
734 
750 // multi_index tag names
751 struct txid_index {};
752 struct insertion_order {};
753 
755  typedef boost::multi_index_container<
757  boost::multi_index::indexed_by<
758  // sorted by txid
759  boost::multi_index::hashed_unique<
760  boost::multi_index::tag<txid_index>,
763  >,
764  // sorted by order in the blockchain
765  boost::multi_index::sequenced<
766  boost::multi_index::tag<insertion_order>
767  >
768  >
770 
771  // It's almost certainly a logic bug if we don't clear out queuedTx before
772  // destruction, as we add to it while disconnecting blocks, and then we
773  // need to re-process remaining transactions to ensure mempool consistency.
774  // For now, assert() that we've emptied out this object on destruction.
775  // This assert() can always be removed if the reorg-processing code were
776  // to be refactored such that this assumption is no longer true (for
777  // instance if there was some other way we cleaned up the mempool after a
778  // reorg, besides draining this object).
779  ~DisconnectedBlockTransactions() { assert(queuedTx.empty()); }
780 
782  uint64_t cachedInnerUsage = 0;
783 
784  // Estimate the overhead of queuedTx to be 6 pointers + an allocation, as
785  // no exact formula for boost::multi_index_contained is implemented.
786  size_t DynamicMemoryUsage() const {
787  return memusage::MallocUsage(sizeof(CTransactionRef) + 6 * sizeof(void*)) * queuedTx.size() + cachedInnerUsage;
788  }
789 
790  void addTransaction(const CTransactionRef& tx)
791  {
792  queuedTx.insert(tx);
793  cachedInnerUsage += RecursiveDynamicUsage(tx);
794  }
795 
796  // Remove entries based on txid_index, and update memory usage.
797  void removeForBlock(const std::vector<CTransactionRef>& vtx)
798  {
799  // Short-circuit in the common case of a block being added to the tip
800  if (queuedTx.empty()) {
801  return;
802  }
803  for (auto const &tx : vtx) {
804  auto it = queuedTx.find(tx->GetHash());
805  if (it != queuedTx.end()) {
806  cachedInnerUsage -= RecursiveDynamicUsage(*it);
807  queuedTx.erase(it);
808  }
809  }
810  }
811 
812  // Remove an entry by insertion_order index, and update memory usage.
813  void removeEntry(indexed_disconnected_transactions::index<insertion_order>::type::iterator entry)
814  {
815  cachedInnerUsage -= RecursiveDynamicUsage(*entry);
816  queuedTx.get<insertion_order>().erase(entry);
817  }
818 
819  void clear()
820  {
821  cachedInnerUsage = 0;
822  queuedTx.clear();
823  }
824 };
825 
827 {
828  std::set<CAssetCacheNewAsset> newAssetsToAdd;
829  std::set<CAssetCacheRestrictedVerifiers> newVerifiersToAdd;
830  std::set<CAssetCacheRestrictedAddress> newAddressRestrictionsToAdd;
831  std::set<CAssetCacheRestrictedGlobal> newGlobalRestrictionsToAdd;
832  std::set<CAssetCacheQualifierAddress> newQualifiersToAdd;
833 };
834 
835 #endif // RAVEN_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
Information about a mempool transaction.
Definition: txmempool.h:302
update_fee_delta(int64_t _feeDelta)
Definition: txmempool.h:171
uint64_t GetSizeWithAncestors() const
Definition: txmempool.h:130
CAmount nModFeesWithDescendants
... and total fees (all including us)
Definition: txmempool.h:87
void UpdateLockPoints(const LockPoints &lp)
Definition: txmempool.cpp:51
std::map< txiter, TxLinks, CompareIteratorByHash > txlinksMap
Definition: txmempool.h:511
std::set< CAssetCacheNewAsset > newAssetsToAdd
Definition: txmempool.h:828
size_t nTxWeight
... and avoid recomputing tx weight (also used for GetTxSize())
Definition: txmempool.h:73
std::map< uint256, std::set< std::string > > mapHashQualifiersChanged
Definition: txmempool.h:485
int flags
Definition: raven-tx.cpp:500
A UTXO entry.
Definition: coins.h:32
addressDeltaMap mapAddress
Definition: txmempool.h:515
size_t GetTxSize() const
Definition: txmempool.cpp:56
size_t GetTxWeight() const
Definition: txmempool.h:105
boost::signals2::signal< void(CTransactionRef)> NotifyEntryAdded
Definition: txmempool.h:672
LockPoints()
Definition: txmempool.h:51
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:262
int height
Definition: txmempool.h:44
Expired from mempool.
std::map< uint256, std::set< std::string > > mapHashVerifierChanged
Definition: txmempool.h:489
std::map< uint256, std::set< std::string > > mapHashMarkedGlobalFrozen
Definition: txmempool.h:481
std::set< CAssetCacheRestrictedGlobal > newGlobalRestrictionsToAdd
Definition: txmempool.h:831
CAmount GetModFeesWithDescendants() const
Definition: txmempool.h:125
int64_t feeDelta
Definition: txmempool.h:176
uint64_t GetTotalTxSize() const
Definition: txmempool.h:654
bool operator()(const txiter &a, const txiter &b) const
Definition: txmempool.h:495
uint64_t GetSizeWithDescendants() const
Definition: txmempool.h:124
std::set< CAssetCacheRestrictedAddress > newAddressRestrictionsToAdd
Definition: txmempool.h:830
std::set< txiter, CompareIteratorByHash > setEntries
Definition: txmempool.h:499
void addTransaction(const CTransactionRef &tx)
Definition: txmempool.h:790
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
Definition: txmempool.h:320
const uint64_t k1
Definition: txmempool.h:334
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:211
bool GetSpendsCoinbase() const
Definition: txmempool.h:127
int64_t sigOpCost
Total sigop cost.
Definition: txmempool.h:78
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:436
uint64_t nCountWithDescendants
number of descendant transactions
Definition: txmempool.h:85
int64_t lastRollingFeeUpdate
Definition: txmempool.h:426
CAmount nFee
Cached to avoid expensive parent-transaction lookups.
Definition: txmempool.h:72
int64_t nFeeDelta
The fee delta.
Definition: txmempool.h:314
indirectmap< COutPoint, const CTransaction * > mapNextTx
Definition: txmempool.h:532
update_descendant_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount)
Definition: txmempool.h:140
CTransactionRef tx
The transaction itself.
Definition: txmempool.h:305
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
Definition: txmempool.h:68
indexed_transaction_set mapTx
Definition: txmempool.h:469
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:769
int64_t CAmount
Amount in corbies (Can be negative)
Definition: amount.h:13
std::map< CSpentIndexKey, CSpentIndexValue, CSpentIndexKeyCompare > mapSpentIndex
Definition: txmempool.h:520
bool blockSinceLastRollingFeeBump
Definition: txmempool.h:427
std::map< uint256, std::vector< CSpentIndexKey > > mapSpentIndexInserted
Definition: txmempool.h:523
Removed in size limiting.
indexed_disconnected_transactions queuedTx
Definition: txmempool.h:781
int64_t nSigOpCostWithAncestors
Definition: txmempool.h:93
void setSanityCheck(double dFrequency=1.0)
Definition: txmempool.h:546
std::vector< std::pair< uint256, txiter > > vTxHashes
All tx witness hashes/entries in mapTx, in random order.
Definition: txmempool.h:492
void UpdateFeeDelta(int64_t feeDelta)
Definition: txmempool.cpp:44
std::map< uint256, std::string > mapHashToAsset
Definition: txmempool.h:472
size_t nUsageSize
... and total memory usage
Definition: txmempool.h:74
Definition: txmempool.h:268
unsigned long size()
Definition: txmempool.h:648
uint64_t nSizeWithAncestors
Definition: txmempool.h:91
int64_t feeDelta
Used for determining the priority of the transaction for mining in a block.
Definition: txmempool.h:79
Abstract view on the open txout dataset.
Definition: coins.h:152
size_t DynamicMemoryUsage() const
Definition: txmempool.h:110
unsigned int GetHeight() const
Definition: txmempool.h:107
void removeForBlock(const std::vector< CTransactionRef > &vtx)
Definition: txmempool.h:797
#define LOCK(cs)
Definition: sync.h:176
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:139
const uint256 & GetHash() const
Definition: transaction.h:320
const CAmount & GetFee() const
Definition: txmempool.h:103
DisconnectedBlockTransactions.
Definition: txmempool.h:751
CTransactionRef GetSharedTx() const
Definition: txmempool.h:102
Removed for reorganization.
std::map< uint256, CAmount > mapDeltas
Definition: txmempool.h:533
std::map< std::string, std::set< uint256 > > mapAssetVerifierChanged
Definition: txmempool.h:488
std::map< std::string, std::set< uint256 > > mapAddressesQualifiersChanged
Definition: txmempool.h:484
uint64_t cachedInnerUsage
sum of dynamic memory usage of all the map elements (NOT the maps themselves)
Definition: txmempool.h:424
Sort an entry by max(score/size of entry&#39;s tx, score/size with all descendants).
Definition: txmempool.h:208
bool exists(uint256 hash) const
Definition: txmempool.h:660
CAmount nModFeesWithAncestors
Definition: txmempool.h:92
unsigned int nTransactionsUpdated
Used by getblocktemplate to trigger CreateNewBlock() invocation.
Definition: txmempool.h:420
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int modifySigOps)
Definition: txmempool.cpp:322
Manually removed or unknown reason.
int64_t nTime
Local time when entering the mempool.
Definition: txmempool.h:75
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:86
uint256 result_type
Definition: txmempool.h:192
uint64_t GetCountWithDescendants() const
Definition: txmempool.h:123
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:423
indexed_transaction_set::nth_index< 0 >::type::iterator txiter
Definition: txmempool.h:491
CCriticalSection cs
Definition: txmempool.h:468
std::map< std::pair< std::string, std::string >, std::set< uint256 > > mapAddressesMarkedFrozen
Restricted assets maps.
Definition: txmempool.h:476
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:271
int64_t GetSigOpCostWithAncestors() const
Definition: txmempool.h:132
uint64_t GetCountWithAncestors() const
Definition: txmempool.h:129
int64_t nTime
Time the transaction entered the mempool.
Definition: txmempool.h:308
bool spendsCoinbase
keep track of transactions that spend a coinbase
Definition: txmempool.h:77
256-bit opaque blob.
Definition: uint256.h:123
mapSpentIndex mapSpent
Definition: txmempool.h:521
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:416
std::map< uint256, std::set< std::pair< std::string, std::string > > > mapHashToAddressMarkedFrozen
Definition: txmempool.h:477
std::map< txiter, setEntries, CompareIteratorByHash > cacheMap
Definition: txmempool.h:504
std::map< std::string, uint256 > mapAssetToHash
Definition: txmempool.h:471
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:172
int64_t GetTime() const
Definition: txmempool.h:106
LockPoints lockPoints
Track the height and time at which tx was final.
Definition: txmempool.h:80
uint32_t nCheckFrequency
Value n means that n times in 2^32 we check.
Definition: txmempool.h:419
std::set< CAssetCacheQualifierAddress > newQualifiersToAdd
Definition: txmempool.h:832
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
Definition: txmempool.cpp:313
const CTransaction & GetTx() const
Definition: txmempool.h:101
const LockPoints & lp
Definition: txmempool.h:186
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_unique< boost::multi_index::tag< mining_score >, boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByScore >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ancestor_score >, boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByAncestorFee > > > indexed_transaction_set
Definition: txmempool.h:466
update_ancestor_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int64_t _modifySigOpsCost)
Definition: txmempool.h:155
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:173
uint64_t nCountWithAncestors
Definition: txmempool.h:90
std::map< uint256, std::vector< CMempoolAddressDeltaKey > > addressDeltaMapInserted
Definition: txmempool.h:517
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:20
int64_t GetSigOpCost() const
Definition: txmempool.h:108
size_t operator()(const uint256 &txid) const
Definition: txmempool.h:339
std::set< CAssetCacheRestrictedVerifiers > newVerifiersToAdd
Definition: txmempool.h:829
update_lock_points(const LockPoints &_lp)
Definition: txmempool.h:181
int64_t time
Definition: txmempool.h:45
CTransactionRef tx
Definition: txmempool.h:71
boost::signals2::signal< void(CTransactionRef, MemPoolRemovalReason)> NotifyEntryRemoved
Definition: txmempool.h:673
mapSpentIndexInserted mapSpentInserted
Definition: txmempool.h:524
std::map< std::string, std::set< uint256 > > mapAssetMarkedGlobalFrozen
Definition: txmempool.h:480
size_t DynamicMemoryUsage() const
Definition: txmempool.h:786
CFeeRate feeRate
Feerate of the transaction.
Definition: txmempool.h:311
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:189
const LockPoints & GetLockPoints() const
Definition: txmempool.h:111
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:208
Sort by score of entry ((fee+delta)/size) in descending order.
Definition: txmempool.h:245
const CTxMemPool & mempool
Definition: txmempool.h:728
txlinksMap mapLinks
Definition: txmempool.h:512
Removed for conflict with in-block transaction.
CBlockPolicyEstimator * minerPolicyEstimator
Definition: txmempool.h:421
CBlockIndex * maxInputBlock
Definition: txmempool.h:49
double rollingMinimumFeeRate
minimum fee to get into the pool, decreases exponentially
Definition: txmempool.h:428
CCoinsView that brings transactions from a memorypool into view.
Definition: txmempool.h:725
bool UseDescendantScore(const CTxMemPoolEntry &a) const
Definition: txmempool.h:233
void removeEntry(indexed_disconnected_transactions::index< insertion_order >::type::iterator entry)
Definition: txmempool.h:813
int64_t modifySigOpsCost
Definition: txmempool.h:166
std::map< CMempoolAddressDeltaKey, CMempoolAddressDelta, CMempoolAddressDeltaKeyCompare > addressDeltaMap
Definition: txmempool.h:514
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:248
Wrapped boost mutex: supports recursive locking, but no waiting TODO: We should move away from using ...
Definition: sync.h:92
Definition: txmempool.h:259
unsigned int entryHeight
Chain height when entering the mempool.
Definition: txmempool.h:76