Fabcoin Core  0.16.2
P2P Digital Currency
txmempool.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2017 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 FABCOIN_TXMEMPOOL_H
7 #define FABCOIN_TXMEMPOOL_H
8 
9 #include <memory>
10 #include <set>
11 #include <map>
12 #include <vector>
13 #include <utility>
14 #include <string>
15 
16 #include <amount.h>
17 #include <coins.h>
18 #include <indirectmap.h>
19 #include <policy/feerate.h>
20 #include <primitives/transaction.h>
21 #include <sync.h>
22 #include <random.h>
23 
24 #include <boost/multi_index_container.hpp>
25 #include <boost/multi_index/ordered_index.hpp>
26 #include <boost/multi_index/hashed_index.hpp>
27 #include <boost/multi_index/sequenced_index.hpp>
28 
29 #include <boost/signals2/signal.hpp>
30 
31 class CBlockIndex;
32 
34 static const uint32_t MEMPOOL_HEIGHT = 0x0FFFFFFF;
35 //??? static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
36 
37 struct LockPoints
38 {
39  // Will be set to the blockchain height and median time past
40  // values that would be necessary to satisfy all relative locktime
41  // constraints (BIP68) of this tx given our view of block chain history
42  int height;
43  int64_t time;
44  // As long as the current chain descends from the highest height block
45  // containing one of the inputs used in the calculation, then the cached
46  // values are still valid even after a reorg.
48 
49  LockPoints() : height(0), time(0), maxInputBlock(nullptr) { }
50 };
51 
52 class CTxMemPool;
53 
67 {
68 private:
71  size_t nTxWeight;
72  size_t nUsageSize;
73  int64_t nTime;
74  unsigned int entryHeight;
76  int64_t sigOpCost;
77  int64_t feeDelta;
80 
81  // Information about descendants of this transaction that are in the
82  // mempool; if we remove this transaction we must remove all of these
83  // descendants as well.
87 
88  // Analogous statistics for ancestor transactions
93 
94 public:
95  CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
96  int64_t _nTime, unsigned int _entryHeight,
97  bool spendsCoinbase,
98  int64_t nSigOpsCost, LockPoints lp, CAmount _nMinGasPrice = 0);
99 
100  CTxMemPoolEntry(const CTxMemPoolEntry& other);
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;
106  size_t GetTxWeight() const { return nTxWeight; }
107  int64_t GetTime() const { return nTime; }
108  unsigned int GetHeight() const { return entryHeight; }
109  int64_t GetSigOpCost() const { return sigOpCost; }
110  int64_t GetModifiedFee() const { return nFee + feeDelta; }
111  size_t DynamicMemoryUsage() const { return nUsageSize; }
112  const LockPoints& GetLockPoints() const { return lockPoints; }
113  const CAmount& GetMinGasPrice() const { return nMinGasPrice; }
114 
115  // Adjusts the descendant state.
116  void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount);
117  // Adjusts the ancestor state
118  void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int modifySigOps);
119  // Updates the fee delta used for mining priority score, and the
120  // modified fees with descendants.
121  void UpdateFeeDelta(int64_t feeDelta);
122  // Update the LockPoints after a reorg
123  void UpdateLockPoints(const LockPoints& lp);
124 
125  uint64_t GetCountWithDescendants() const { return nCountWithDescendants; }
126  uint64_t GetSizeWithDescendants() const { return nSizeWithDescendants; }
127  CAmount GetModFeesWithDescendants() const { return nModFeesWithDescendants; }
128 
129  bool GetSpendsCoinbase() const { return spendsCoinbase; }
130 
131  uint64_t GetCountWithAncestors() const { return nCountWithAncestors; }
132  uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; }
133  CAmount GetModFeesWithAncestors() const { return nModFeesWithAncestors; }
134  int64_t GetSigOpCostWithAncestors() const { return nSigOpCostWithAncestors; }
135 
136  mutable size_t vTxHashesIdx;
137 };
138 
139 // Helpers for modifying CTxMemPool::mapTx, which is a boost multi_index.
141 {
142  update_descendant_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount) :
143  modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount)
144  {}
145 
146  void operator() (CTxMemPoolEntry &e)
147  { e.UpdateDescendantState(modifySize, modifyFee, modifyCount); }
148 
149  private:
150  int64_t modifySize;
152  int64_t modifyCount;
153 };
154 
156 {
157  update_ancestor_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int64_t _modifySigOpsCost) :
158  modifySize(_modifySize), modifyFee(_modifyFee), modifyCount(_modifyCount), modifySigOpsCost(_modifySigOpsCost)
159  {}
160 
161  void operator() (CTxMemPoolEntry &e)
162  { e.UpdateAncestorState(modifySize, modifyFee, modifyCount, modifySigOpsCost); }
163 
164  private:
165  int64_t modifySize;
167  int64_t modifyCount;
169 };
170 
172 {
173  update_fee_delta(int64_t _feeDelta) : feeDelta(_feeDelta) { }
174 
175  void operator() (CTxMemPoolEntry &e) { e.UpdateFeeDelta(feeDelta); }
176 
177 private:
178  int64_t feeDelta;
179 };
180 
182 {
183  update_lock_points(const LockPoints& _lp) : lp(_lp) { }
184 
185  void operator() (CTxMemPoolEntry &e) { e.UpdateLockPoints(lp); }
186 
187 private:
188  const LockPoints& lp;
189 };
190 
191 // extracts a transaction hash from CTxMempoolEntry or CTransactionRef
193 {
195  result_type operator() (const CTxMemPoolEntry &entry) const
196  {
197  return entry.GetTx().GetHash();
198  }
199 
200  result_type operator() (const CTransactionRef& tx) const
201  {
202  return tx->GetHash();
203  }
204 };
205 
211 {
212 public:
213  bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
214  {
215  bool fUseADescendants = UseDescendantScore(a);
216  bool fUseBDescendants = UseDescendantScore(b);
217 
218  double aModFee = fUseADescendants ? a.GetModFeesWithDescendants() : a.GetModifiedFee();
219  double aSize = fUseADescendants ? a.GetSizeWithDescendants() : a.GetTxSize();
220 
221  double bModFee = fUseBDescendants ? b.GetModFeesWithDescendants() : b.GetModifiedFee();
222  double bSize = fUseBDescendants ? b.GetSizeWithDescendants() : b.GetTxSize();
223 
224  // Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
225  double f1 = aModFee * bSize;
226  double f2 = aSize * bModFee;
227 
228  if (f1 == f2) {
229  return a.GetTime() >= b.GetTime();
230  }
231  return f1 < f2;
232  }
233 
234  // Calculate which score to use for an entry (avoiding division).
236  {
237  double f1 = (double)a.GetModifiedFee() * a.GetSizeWithDescendants();
238  double f2 = (double)a.GetModFeesWithDescendants() * a.GetTxSize();
239  return f2 > f1;
240  }
241 };
242 
248 {
249 public:
250  bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
251  {
252  double f1 = (double)a.GetModifiedFee() * b.GetTxSize();
253  double f2 = (double)b.GetModifiedFee() * a.GetTxSize();
254  if (f1 == f2) {
255  return b.GetTx().GetHash() < a.GetTx().GetHash();
256  }
257  return f1 > f2;
258  }
259 };
260 
262 {
263 public:
264  bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
265  {
266  return a.GetTime() < b.GetTime();
267  }
268 };
269 
271 {
272 public:
273  bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
274  {
275  double aFees = a.GetModFeesWithAncestors();
276  double aSize = a.GetSizeWithAncestors();
277 
278  double bFees = b.GetModFeesWithAncestors();
279  double bSize = b.GetSizeWithAncestors();
280 
281  // Avoid division by rewriting (a/b > c/d) as (a*d > c*b).
282  double f1 = aFees * bSize;
283  double f2 = aSize * bFees;
284 
285  if (f1 == f2) {
286  return a.GetTx().GetHash() < b.GetTx().GetHash();
287  }
288 
289  return f1 > f2;
290  }
291 };
292 
294 {
295 public:
296  bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
297  {
298  bool fAHasCreateOrCall = a.GetTx().HasCreateOrCall();
299  bool fBHasCreateOrCall = b.GetTx().HasCreateOrCall();
300 
301  // If either of the two entries that we are comparing has a contract scriptPubKey, the comparison here takes precedence
302  if(fAHasCreateOrCall || fBHasCreateOrCall) {
303  // Prioritze non-contract txs
304  if(fAHasCreateOrCall != fBHasCreateOrCall) {
305  return fAHasCreateOrCall ? false : true;
306  }
307 
308  // Prioritize the contract txs that have the least number of ancestors
309  // The reason for this is that otherwise it is possible to send one tx with a
310  // high gas limit but a low gas price which has a child with a low gas limit but a high gas price
311  // Without this condition that transaction chain would get priority in being included into the block.
314  }
315 
316  // Otherwise, prioritize the contract tx with the highest (minimum among its outputs) gas price
317  // The reason for using the gas price of the output that sets the minimum gas price is that there
318  // otherwise it may be possible to game the prioritization by setting a large gas price in one output
319  // that does no execution, while the real execution has a very low gas price
320  if(a.GetMinGasPrice() != b.GetMinGasPrice()) {
321  return a.GetMinGasPrice() > b.GetMinGasPrice();
322  }
323 
324  // Otherwise, prioritize the tx with the minimum size
325  if(a.GetTxSize() != b.GetTxSize()) {
326  return a.GetTxSize() < b.GetTxSize();
327  }
328 
329  // If the txs are identical in their minimum gas prices and tx size
330  // order based on the tx hash for consistency.
331  return a.GetTx().GetHash() < b.GetTx().GetHash();
332  }
333 
334  // If neither of the txs we are comparing are contract txs, use the standard comparison based on ancestor fees / ancestor size
336  }
337 };
338 
339 // Multi_index tag names
341 struct entry_time {};
342 struct mining_score {};
343 struct ancestor_score {};
345 
347 
352 {
355 
357  int64_t nTime;
358 
361 
363  int64_t nFeeDelta;
364 };
365 
370  UNKNOWN = 0,
371  EXPIRY,
372  SIZELIMIT,
373  REORG,
374  BLOCK,
375  CONFLICT,
376  REPLACED
377 };
378 
380 {
381 private:
383  const uint64_t k0, k1;
384 
385 public:
387 
388  size_t operator()(const uint256& txid) const {
389  return SipHashUint256(k0, k1, txid);
390  }
391 };
392 
466 {
467 private:
468  uint32_t nCheckFrequency;
469  unsigned int nTransactionsUpdated;
471 
472  uint64_t totalTxSize;
473  uint64_t cachedInnerUsage;
474 
475  mutable int64_t lastRollingFeeUpdate;
477  mutable double rollingMinimumFeeRate;
478 
479  void trackPackageRemoved(const CFeeRate& rate);
480 
481 public:
482 
483  static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12; // public only for testing
484 
485  typedef boost::multi_index_container<
487  boost::multi_index::indexed_by<
488  // sorted by txid
489  boost::multi_index::hashed_unique<mempoolentry_txid, SaltedTxidHasher>,
490  // sorted by fee rate
491  boost::multi_index::ordered_non_unique<
492  boost::multi_index::tag<descendant_score>,
493  boost::multi_index::identity<CTxMemPoolEntry>,
495  >,
496  // sorted by entry time
497  boost::multi_index::ordered_non_unique<
498  boost::multi_index::tag<entry_time>,
499  boost::multi_index::identity<CTxMemPoolEntry>,
501  >,
502  // sorted by score (for mining prioritization)
503  boost::multi_index::ordered_unique<
504  boost::multi_index::tag<mining_score>,
505  boost::multi_index::identity<CTxMemPoolEntry>,
507  >,
508  // sorted by fee rate with ancestors
509  boost::multi_index::ordered_non_unique<
510  boost::multi_index::tag<ancestor_score>,
511  boost::multi_index::identity<CTxMemPoolEntry>,
513  >,
514  // sorted by fee rate with gas price (if contract tx) or ancestors otherwise
515  boost::multi_index::ordered_non_unique<
516  boost::multi_index::tag<ancestor_score_or_gas_price>,
517  boost::multi_index::identity<CTxMemPoolEntry>,
519  >
520  >
522 
525 
526  typedef indexed_transaction_set::nth_index<0>::type::iterator txiter;
527  std::vector<std::pair<uint256, txiter> > vTxHashes;
528 
530  bool operator()(const txiter &a, const txiter &b) const {
531  return a->GetTx().GetHash() < b->GetTx().GetHash();
532  }
533  };
534  typedef std::set<txiter, CompareIteratorByHash> setEntries;
535 
536  const setEntries & GetMemPoolParents(txiter entry) const;
537  const setEntries & GetMemPoolChildren(txiter entry) const;
538 private:
539  typedef std::map<txiter, setEntries, CompareIteratorByHash> cacheMap;
540 
541  struct TxLinks {
542  setEntries parents;
543  setEntries children;
544  };
545 
546  typedef std::map<txiter, TxLinks, CompareIteratorByHash> txlinksMap;
547  txlinksMap mapLinks;
548 
549  void UpdateParent(txiter entry, txiter parent, bool add);
550  void UpdateChild(txiter entry, txiter child, bool add);
551 
552  std::vector<indexed_transaction_set::const_iterator> GetSortedDepthAndScore() const;
553 
554 public:
556  std::map<uint256, CAmount> mapDeltas;
557 
560  CTxMemPool(CBlockPolicyEstimator* estimator = nullptr);
561 
568  void check(const CCoinsViewCache *pcoins) const;
569  void setSanityCheck(double dFrequency = 1.0) { nCheckFrequency = dFrequency * 4294967295.0; }
570 
571  // addUnchecked must updated state for all ancestors of a given transaction,
572  // to track size/count of descendant transactions. First version of
573  // addUnchecked can be used to have it call CalculateMemPoolAncestors(), and
574  // then invoke the second version.
575  bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool validFeeEstimate = true);
576  bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate = true);
577 
578  void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN);
579  void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags);
580  void removeConflicts(const CTransaction &tx);
581  void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight);
582 
583  void clear();
584  void _clear(); //lock free
585  bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb);
586  void queryHashes(std::vector<uint256>& vtxid);
587  bool isSpent(const COutPoint& outpoint);
588  unsigned int GetTransactionsUpdated() const;
589  void AddTransactionsUpdated(unsigned int n);
594  bool HasNoInputsOf(const CTransaction& tx) const;
595 
597  void PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta);
598  void ApplyDelta(const uint256 hash, CAmount &nFeeDelta) const;
599  void ClearPrioritisation(const uint256 hash);
600 
601 public:
609  void RemoveStaged(setEntries &stage, bool updateDescendants, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN);
610 
620  void UpdateTransactionsFromBlock(const std::vector<uint256> &vHashesToUpdate);
621 
632  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;
633 
637  void CalculateDescendants(txiter it, setEntries &setDescendants);
638 
645  CFeeRate GetMinFee(size_t sizelimit) const;
646 
651  void TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpendsRemaining=nullptr);
652 
654  int Expire(int64_t time);
655 
657  bool TransactionWithinChainLimit(const uint256& txid, size_t chainLimit) const;
658 
659  unsigned long size()
660  {
661  LOCK(cs);
662  return mapTx.size();
663  }
664 
665  uint64_t GetTotalTxSize()
666  {
667  LOCK(cs);
668  return totalTxSize;
669  }
670 
671  bool exists(uint256 hash) const
672  {
673  LOCK(cs);
674  return (mapTx.count(hash) != 0);
675  }
676 
677  bool exists(const COutPoint& outpoint) const
678  {
679  LOCK(cs);
680  auto it = mapTx.find(outpoint.hash);
681  return (it != mapTx.end() && outpoint.n < it->GetTx().vout.size());
682  }
683 
684  CTransactionRef get(const uint256& hash) const;
685  TxMempoolInfo info(const uint256& hash) const;
686  std::vector<TxMempoolInfo> infoAll() const;
687 
688  size_t DynamicMemoryUsage() const;
689 
690  boost::signals2::signal<void (CTransactionRef)> NotifyEntryAdded;
691  boost::signals2::signal<void (CTransactionRef, MemPoolRemovalReason)> NotifyEntryRemoved;
692 
693 private:
707  void UpdateForDescendants(txiter updateIt,
708  cacheMap &cachedDescendants,
709  const std::set<uint256> &setExclude);
711  void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors);
713  void UpdateEntryForAncestors(txiter it, const setEntries &setAncestors);
717  void UpdateForRemoveFromMempool(const setEntries &entriesToRemove, bool updateDescendants);
719  void UpdateChildrenForRemoval(txiter entry);
720 
729  void removeUnchecked(txiter entry, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN);
730 };
731 
744 {
745 protected:
747 
748 public:
749  CCoinsViewMemPool(CCoinsView* baseIn, const CTxMemPool& mempoolIn);
750  bool GetCoin(const COutPoint &outpoint, Coin &coin) const override;
751  bool HaveCoin(const COutPoint &outpoint) const override;
752 };
753 
769 // multi_index tag names
770 struct txid_index {};
771 struct insertion_order {};
772 
774  typedef boost::multi_index_container<
776  boost::multi_index::indexed_by<
777  // sorted by txid
778  boost::multi_index::hashed_unique<
779  boost::multi_index::tag<txid_index>,
782  >,
783  // sorted by order in the blockchain
784  boost::multi_index::sequenced<
785  boost::multi_index::tag<insertion_order>
786  >
787  >
789 
790  // It's almost certainly a logic bug if we don't clear out queuedTx before
791  // destruction, as we add to it while disconnecting blocks, and then we
792  // need to re-process remaining transactions to ensure mempool consistency.
793  // For now, assert() that we've emptied out this object on destruction.
794  // This assert() can always be removed if the reorg-processing code were
795  // to be refactored such that this assumption is no longer true (for
796  // instance if there was some other way we cleaned up the mempool after a
797  // reorg, besides draining this object).
798  ~DisconnectedBlockTransactions() { assert(queuedTx.empty()); }
799 
801  uint64_t cachedInnerUsage = 0;
802 
803  // Estimate the overhead of queuedTx to be 6 pointers + an allocation, as
804  // no exact formula for boost::multi_index_contained is implemented.
805  size_t DynamicMemoryUsage() const {
806  return memusage::MallocUsage(sizeof(CTransactionRef) + 6 * sizeof(void*)) * queuedTx.size() + cachedInnerUsage;
807  }
808 
809  void addTransaction(const CTransactionRef& tx)
810  {
811  queuedTx.insert(tx);
812  cachedInnerUsage += RecursiveDynamicUsage(tx);
813  }
814 
815  // Remove entries based on txid_index, and update memory usage.
816  void removeForBlock(const std::vector<CTransactionRef>& vtx)
817  {
818  // Short-circuit in the common case of a block being added to the tip
819  if (queuedTx.empty()) {
820  return;
821  }
822  for (auto const &tx : vtx) {
823  auto it = queuedTx.find(tx->GetHash());
824  if (it != queuedTx.end()) {
825  cachedInnerUsage -= RecursiveDynamicUsage(*it);
826  queuedTx.erase(it);
827  }
828  }
829  }
830 
831  // Remove an entry by insertion_order index, and update memory usage.
832  void removeEntry(indexed_disconnected_transactions::index<insertion_order>::type::iterator entry)
833  {
834  cachedInnerUsage -= RecursiveDynamicUsage(*entry);
835  queuedTx.get<insertion_order>().erase(entry);
836  }
837 
838  void clear()
839  {
840  cachedInnerUsage = 0;
841  queuedTx.clear();
842  }
843 };
844 
845 #endif // FABCOIN_TXMEMPOOL_H
size_t vTxHashesIdx
Index in mempool&#39;s vTxHashes.
Definition: txmempool.h:136
const CAmount & GetMinGasPrice() const
Definition: txmempool.h:113
Information about a mempool transaction.
Definition: txmempool.h:351
CAmount GetModFeesWithAncestors() const
Definition: txmempool.h:133
#define f1(l, r, km, kr)
Definition: cast.cpp:17
update_fee_delta(int64_t _feeDelta)
Definition: txmempool.h:173
CAmount nModFeesWithDescendants
... and total fees (all including us)
Definition: txmempool.h:86
void UpdateLockPoints(const LockPoints &lp)
Definition: txmempool.cpp:55
std::map< txiter, TxLinks, CompareIteratorByHash > txlinksMap
Definition: txmempool.h:546
unsigned int GetHeight() const
Definition: txmempool.h:108
size_t nTxWeight
... and avoid recomputing tx weight (also used for GetTxSize())
Definition: txmempool.h:71
bool exists(const COutPoint &outpoint) const
Definition: txmempool.h:677
uint64_t GetCountWithAncestors() const
Definition: txmempool.h:131
uint64_t GetCountWithDescendants() const
Definition: txmempool.h:125
A UTXO entry.
Definition: coins.h:29
boost::signals2::signal< void(CTransactionRef)> NotifyEntryAdded
Definition: txmempool.h:690
size_t GetTxWeight() const
Definition: txmempool.h:106
LockPoints()
Definition: txmempool.h:49
int height
Definition: txmempool.h:42
Expired from mempool.
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:213
int64_t feeDelta
Definition: txmempool.h:178
size_t DynamicMemoryUsage() const
Definition: txmempool.h:111
uint64_t GetTotalTxSize()
Definition: txmempool.h:665
std::set< txiter, CompareIteratorByHash > setEntries
Definition: txmempool.h:534
void addTransaction(const CTransactionRef &tx)
Definition: txmempool.h:809
#define f2(l, r, km, kr)
Definition: cast.cpp:21
assert(len-trim+(2 *lenIndices)<=WIDTH)
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
Definition: txmempool.h:369
const uint64_t k1
Definition: txmempool.h:383
int64_t sigOpCost
Total sigop cost.
Definition: txmempool.h:76
#define nullptr
Definition: eqcuda.hpp:22
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:273
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:437
uint64_t nCountWithDescendants
number of descendant transactions
Definition: txmempool.h:84
int64_t lastRollingFeeUpdate
Definition: txmempool.h:475
const LockPoints & GetLockPoints() const
Definition: txmempool.h:112
CAmount nFee
Cached to avoid expensive parent-transaction lookups.
Definition: txmempool.h:70
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:264
int64_t nFeeDelta
The fee delta.
Definition: txmempool.h:363
indirectmap< COutPoint, const CTransaction * > mapNextTx
Definition: txmempool.h:555
update_descendant_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount)
Definition: txmempool.h:142
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:66
indexed_transaction_set mapTx
Definition: txmempool.h:524
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:788
int64_t CAmount
Amount in lius (Can be negative)
Definition: amount.h:15
uint64_t GetSizeWithDescendants() const
Definition: txmempool.h:126
#define a(i)
bool blockSinceLastRollingFeeBump
Definition: txmempool.h:476
Removed in size limiting.
indexed_disconnected_transactions queuedTx
Definition: txmempool.h:800
const CAmount & GetFee() const
Definition: txmempool.h:104
int64_t nSigOpCostWithAncestors
Definition: txmempool.h:92
void setSanityCheck(double dFrequency=1.0)
Definition: txmempool.h:569
std::vector< std::pair< uint256, txiter > > vTxHashes
All tx witness hashes/entries in mapTx, in random order.
Definition: txmempool.h:527
void UpdateFeeDelta(int64_t feeDelta)
Definition: txmempool.cpp:48
size_t nUsageSize
... and total memory usage
Definition: txmempool.h:72
CTransactionRef GetSharedTx() const
Definition: txmempool.h:103
Definition: txmempool.h:270
unsigned long size()
Definition: txmempool.h:659
uint64_t nSizeWithAncestors
Definition: txmempool.h:90
int64_t feeDelta
Used for determining the priority of the transaction for mining in a block.
Definition: txmempool.h:77
Abstract view on the open txout dataset.
Definition: coins.h:145
void removeForBlock(const std::vector< CTransactionRef > &vtx)
Definition: txmempool.h:816
#define LOCK(cs)
Definition: sync.h:175
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:162
DisconnectedBlockTransactions.
Definition: txmempool.h:770
CAmount nMinGasPrice
The minimum gas price among the contract outputs of the tx.
Definition: txmempool.h:79
size_t DynamicMemoryUsage() const
Definition: txmempool.h:805
CAmount GetModFeesWithDescendants() const
Definition: txmempool.h:127
Removed for reorganization.
std::map< uint256, CAmount > mapDeltas
Definition: txmempool.h:556
uint32_t n
Definition: transaction.h:22
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 >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< ancestor_score_or_gas_price >, boost::multi_index::identity< CTxMemPoolEntry >, CompareTxMemPoolEntryByAncestorFeeOrGasPrice > > > indexed_transaction_set
Definition: txmempool.h:521
int64_t GetSigOpCost() const
Definition: txmempool.h:109
bool GetSpendsCoinbase() const
Definition: txmempool.h:129
int64_t GetTime() const
Definition: txmempool.h:107
#define k0
Definition: ripemd.cpp:18
uint64_t cachedInnerUsage
sum of dynamic memory usage of all the map elements (NOT the maps themselves)
Definition: txmempool.h:473
Sort an entry by max(score/size of entry&#39;s tx, score/size with all descendants).
Definition: txmempool.h:210
CAmount nModFeesWithAncestors
Definition: txmempool.h:91
unsigned int nTransactionsUpdated
Used by getblocktemplate to trigger CreateNewBlock() invocation.
Definition: txmempool.h:469
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int modifySigOps)
Definition: txmempool.cpp:326
Manually removed or unknown reason.
int64_t nTime
Local time when entering the mempool.
Definition: txmempool.h:73
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:18
uint64_t nSizeWithDescendants
... and size
Definition: txmempool.h:85
uint256 result_type
Definition: txmempool.h:194
bool UseDescendantScore(const CTxMemPoolEntry &a) const
Definition: txmempool.h:235
uint64_t GetSizeWithAncestors() const
Definition: txmempool.h:132
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:472
indexed_transaction_set::nth_index< 0 >::type::iterator txiter
Definition: txmempool.h:526
Definition: txmempool.h:293
CCriticalSection cs
Definition: txmempool.h:523
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:250
#define b(i, j)
bool exists(uint256 hash) const
Definition: txmempool.h:671
int64_t nTime
Time the transaction entered the mempool.
Definition: txmempool.h:357
bool spendsCoinbase
keep track of transactions that spend a coinbase
Definition: txmempool.h:75
256-bit opaque blob.
Definition: uint256.h:132
const CTransaction & GetTx() const
Definition: txmempool.h:102
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:465
int64_t GetModifiedFee() const
Definition: txmempool.h:110
std::map< txiter, setEntries, CompareIteratorByHash > cacheMap
Definition: txmempool.h:539
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:177
LockPoints lockPoints
Track the height and time at which tx was final.
Definition: txmempool.h:78
uint32_t nCheckFrequency
Value n means that n times in 2^32 we check.
Definition: txmempool.h:468
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
Definition: txmempool.cpp:317
const LockPoints & lp
Definition: txmempool.h:188
update_ancestor_state(int64_t _modifySize, CAmount _modifyFee, int64_t _modifyCount, int64_t _modifySigOpsCost)
Definition: txmempool.h:157
uint64_t SipHashUint256(uint64_t k0, uint64_t k1, const uint256 &val)
Optimized SipHash-2-4 implementation for uint256.
Definition: hash.cpp:169
bool HasCreateOrCall() const
uint64_t nCountWithAncestors
Definition: txmempool.h:89
Fee rate in liu per kilobyte: CAmount / kB.
Definition: feerate.h:20
#define e(i)
Definition: sha.cpp:733
update_lock_points(const LockPoints &_lp)
Definition: txmempool.h:183
int64_t time
Definition: txmempool.h:43
const uint256 & GetHash() const
Definition: transaction.h:325
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:296
CTransactionRef tx
Definition: txmempool.h:69
int64_t GetSigOpCostWithAncestors() const
Definition: txmempool.h:134
boost::signals2::signal< void(CTransactionRef, MemPoolRemovalReason)> NotifyEntryRemoved
Definition: txmempool.h:691
CFeeRate feeRate
Feerate of the transaction.
Definition: txmempool.h:360
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:275
CCoinsView backed by another CCoinsView.
Definition: coins.h:182
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:247
size_t operator()(const uint256 &txid) const
Definition: txmempool.h:388
const CTxMemPool & mempool
Definition: txmempool.h:746
txlinksMap mapLinks
Definition: txmempool.h:547
Removed for conflict with in-block transaction.
CBlockPolicyEstimator * minerPolicyEstimator
Definition: txmempool.h:470
CBlockIndex * maxInputBlock
Definition: txmempool.h:47
double rollingMinimumFeeRate
minimum fee to get into the pool, decreases exponentially
Definition: txmempool.h:477
CCoinsView that brings transactions from a memorypool into view.
Definition: txmempool.h:743
void removeEntry(indexed_disconnected_transactions::index< insertion_order >::type::iterator entry)
Definition: txmempool.h:832
int64_t modifySigOpsCost
Definition: txmempool.h:168
Wrapped boost mutex: supports recursive locking, but no waiting TODO: We should move away from using ...
Definition: sync.h:91
bool operator()(const txiter &a, const txiter &b) const
Definition: txmempool.h:530
Definition: txmempool.h:261
size_t GetTxSize() const
Definition: txmempool.cpp:60
unsigned int entryHeight
Chain height when entering the mempool.
Definition: txmempool.h:74
uint256 hash
Definition: transaction.h:21