Bitcoin Core  21.99.0
P2P Digital Currency
txmempool.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2020 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 #include <txmempool.h>
7 
8 #include <consensus/consensus.h>
9 #include <consensus/tx_verify.h>
10 #include <consensus/validation.h>
11 #include <policy/fees.h>
12 #include <policy/policy.h>
13 #include <policy/settings.h>
14 #include <reverse_iterator.h>
15 #include <util/moneystr.h>
16 #include <util/system.h>
17 #include <util/time.h>
18 #include <validation.h>
19 #include <validationinterface.h>
20 
21 #include <cmath>
22 #include <optional>
23 
25  int64_t _nTime, unsigned int _entryHeight,
26  bool _spendsCoinbase, int64_t _sigOpsCost, LockPoints lp)
27  : tx(_tx), nFee(_nFee), nTxWeight(GetTransactionWeight(*tx)), nUsageSize(RecursiveDynamicUsage(tx)), nTime(_nTime), entryHeight(_entryHeight),
28  spendsCoinbase(_spendsCoinbase), sigOpCost(_sigOpsCost), lockPoints(lp)
29 {
33 
34  feeDelta = 0;
35 
40 }
41 
42 void CTxMemPoolEntry::UpdateFeeDelta(int64_t newFeeDelta)
43 {
44  nModFeesWithDescendants += newFeeDelta - feeDelta;
45  nModFeesWithAncestors += newFeeDelta - feeDelta;
46  feeDelta = newFeeDelta;
47 }
48 
50 {
51  lockPoints = lp;
52 }
53 
55 {
57 }
58 
59 // Update the given tx for any in-mempool descendants.
60 // Assumes that CTxMemPool::m_children is correct for the given tx and all
61 // descendants.
62 void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap &cachedDescendants, const std::set<uint256> &setExclude)
63 {
64  CTxMemPoolEntry::Children stageEntries, descendants;
65  stageEntries = updateIt->GetMemPoolChildrenConst();
66 
67  while (!stageEntries.empty()) {
68  const CTxMemPoolEntry& descendant = *stageEntries.begin();
69  descendants.insert(descendant);
70  stageEntries.erase(descendant);
71  const CTxMemPoolEntry::Children& children = descendant.GetMemPoolChildrenConst();
72  for (const CTxMemPoolEntry& childEntry : children) {
73  cacheMap::iterator cacheIt = cachedDescendants.find(mapTx.iterator_to(childEntry));
74  if (cacheIt != cachedDescendants.end()) {
75  // We've already calculated this one, just add the entries for this set
76  // but don't traverse again.
77  for (txiter cacheEntry : cacheIt->second) {
78  descendants.insert(*cacheEntry);
79  }
80  } else if (!descendants.count(childEntry)) {
81  // Schedule for later processing
82  stageEntries.insert(childEntry);
83  }
84  }
85  }
86  // descendants now contains all in-mempool descendants of updateIt.
87  // Update and add to cached descendant map
88  int64_t modifySize = 0;
89  CAmount modifyFee = 0;
90  int64_t modifyCount = 0;
91  for (const CTxMemPoolEntry& descendant : descendants) {
92  if (!setExclude.count(descendant.GetTx().GetHash())) {
93  modifySize += descendant.GetTxSize();
94  modifyFee += descendant.GetModifiedFee();
95  modifyCount++;
96  cachedDescendants[updateIt].insert(mapTx.iterator_to(descendant));
97  // Update ancestor state for each descendant
98  mapTx.modify(mapTx.iterator_to(descendant), update_ancestor_state(updateIt->GetTxSize(), updateIt->GetModifiedFee(), 1, updateIt->GetSigOpCost()));
99  }
100  }
101  mapTx.modify(updateIt, update_descendant_state(modifySize, modifyFee, modifyCount));
102 }
103 
104 // vHashesToUpdate is the set of transaction hashes from a disconnected block
105 // which has been re-added to the mempool.
106 // for each entry, look for descendants that are outside vHashesToUpdate, and
107 // add fee/size information for such descendants to the parent.
108 // for each such descendant, also update the ancestor state to include the parent.
109 void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashesToUpdate)
110 {
112  // For each entry in vHashesToUpdate, store the set of in-mempool, but not
113  // in-vHashesToUpdate transactions, so that we don't have to recalculate
114  // descendants when we come across a previously seen entry.
115  cacheMap mapMemPoolDescendantsToUpdate;
116 
117  // Use a set for lookups into vHashesToUpdate (these entries are already
118  // accounted for in the state of their ancestors)
119  std::set<uint256> setAlreadyIncluded(vHashesToUpdate.begin(), vHashesToUpdate.end());
120 
121  // Iterate in reverse, so that whenever we are looking at a transaction
122  // we are sure that all in-mempool descendants have already been processed.
123  // This maximizes the benefit of the descendant cache and guarantees that
124  // CTxMemPool::m_children will be updated, an assumption made in
125  // UpdateForDescendants.
126  for (const uint256 &hash : reverse_iterate(vHashesToUpdate)) {
127  // calculate children from mapNextTx
128  txiter it = mapTx.find(hash);
129  if (it == mapTx.end()) {
130  continue;
131  }
132  auto iter = mapNextTx.lower_bound(COutPoint(hash, 0));
133  // First calculate the children, and update CTxMemPool::m_children to
134  // include them, and update their CTxMemPoolEntry::m_parents to include this tx.
135  // we cache the in-mempool children to avoid duplicate updates
136  {
138  for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) {
139  const uint256 &childHash = iter->second->GetHash();
140  txiter childIter = mapTx.find(childHash);
141  assert(childIter != mapTx.end());
142  // We can skip updating entries we've encountered before or that
143  // are in the block (which are already accounted for).
144  if (!visited(childIter) && !setAlreadyIncluded.count(childHash)) {
145  UpdateChild(it, childIter, true);
146  UpdateParent(childIter, it, true);
147  }
148  }
149  } // release epoch guard for UpdateForDescendants
150  UpdateForDescendants(it, mapMemPoolDescendantsToUpdate, setAlreadyIncluded);
151  }
152 }
153 
154 bool CTxMemPool::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
155 {
156  CTxMemPoolEntry::Parents staged_ancestors;
157  const CTransaction &tx = entry.GetTx();
158 
159  if (fSearchForParents) {
160  // Get parents of this transaction that are in the mempool
161  // GetMemPoolParents() is only valid for entries in the mempool, so we
162  // iterate mapTx to find parents.
163  for (unsigned int i = 0; i < tx.vin.size(); i++) {
164  std::optional<txiter> piter = GetIter(tx.vin[i].prevout.hash);
165  if (piter) {
166  staged_ancestors.insert(**piter);
167  if (staged_ancestors.size() + 1 > limitAncestorCount) {
168  errString = strprintf("too many unconfirmed parents [limit: %u]", limitAncestorCount);
169  return false;
170  }
171  }
172  }
173  } else {
174  // If we're not searching for parents, we require this to be an
175  // entry in the mempool already.
176  txiter it = mapTx.iterator_to(entry);
177  staged_ancestors = it->GetMemPoolParentsConst();
178  }
179 
180  size_t totalSizeWithAncestors = entry.GetTxSize();
181 
182  while (!staged_ancestors.empty()) {
183  const CTxMemPoolEntry& stage = staged_ancestors.begin()->get();
184  txiter stageit = mapTx.iterator_to(stage);
185 
186  setAncestors.insert(stageit);
187  staged_ancestors.erase(stage);
188  totalSizeWithAncestors += stageit->GetTxSize();
189 
190  if (stageit->GetSizeWithDescendants() + entry.GetTxSize() > limitDescendantSize) {
191  errString = strprintf("exceeds descendant size limit for tx %s [limit: %u]", stageit->GetTx().GetHash().ToString(), limitDescendantSize);
192  return false;
193  } else if (stageit->GetCountWithDescendants() + 1 > limitDescendantCount) {
194  errString = strprintf("too many descendants for tx %s [limit: %u]", stageit->GetTx().GetHash().ToString(), limitDescendantCount);
195  return false;
196  } else if (totalSizeWithAncestors > limitAncestorSize) {
197  errString = strprintf("exceeds ancestor size limit [limit: %u]", limitAncestorSize);
198  return false;
199  }
200 
201  const CTxMemPoolEntry::Parents& parents = stageit->GetMemPoolParentsConst();
202  for (const CTxMemPoolEntry& parent : parents) {
203  txiter parent_it = mapTx.iterator_to(parent);
204 
205  // If this is a new ancestor, add it.
206  if (setAncestors.count(parent_it) == 0) {
207  staged_ancestors.insert(parent);
208  }
209  if (staged_ancestors.size() + setAncestors.size() + 1 > limitAncestorCount) {
210  errString = strprintf("too many unconfirmed ancestors [limit: %u]", limitAncestorCount);
211  return false;
212  }
213  }
214  }
215 
216  return true;
217 }
218 
219 void CTxMemPool::UpdateAncestorsOf(bool add, txiter it, setEntries &setAncestors)
220 {
221  CTxMemPoolEntry::Parents parents = it->GetMemPoolParents();
222  // add or remove this tx as a child of each parent
223  for (const CTxMemPoolEntry& parent : parents) {
224  UpdateChild(mapTx.iterator_to(parent), it, add);
225  }
226  const int64_t updateCount = (add ? 1 : -1);
227  const int64_t updateSize = updateCount * it->GetTxSize();
228  const CAmount updateFee = updateCount * it->GetModifiedFee();
229  for (txiter ancestorIt : setAncestors) {
230  mapTx.modify(ancestorIt, update_descendant_state(updateSize, updateFee, updateCount));
231  }
232 }
233 
235 {
236  int64_t updateCount = setAncestors.size();
237  int64_t updateSize = 0;
238  CAmount updateFee = 0;
239  int64_t updateSigOpsCost = 0;
240  for (txiter ancestorIt : setAncestors) {
241  updateSize += ancestorIt->GetTxSize();
242  updateFee += ancestorIt->GetModifiedFee();
243  updateSigOpsCost += ancestorIt->GetSigOpCost();
244  }
245  mapTx.modify(it, update_ancestor_state(updateSize, updateFee, updateCount, updateSigOpsCost));
246 }
247 
249 {
250  const CTxMemPoolEntry::Children& children = it->GetMemPoolChildrenConst();
251  for (const CTxMemPoolEntry& updateIt : children) {
252  UpdateParent(mapTx.iterator_to(updateIt), it, false);
253  }
254 }
255 
256 void CTxMemPool::UpdateForRemoveFromMempool(const setEntries &entriesToRemove, bool updateDescendants)
257 {
258  // For each entry, walk back all ancestors and decrement size associated with this
259  // transaction
260  const uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
261  if (updateDescendants) {
262  // updateDescendants should be true whenever we're not recursively
263  // removing a tx and all its descendants, eg when a transaction is
264  // confirmed in a block.
265  // Here we only update statistics and not data in CTxMemPool::Parents
266  // and CTxMemPoolEntry::Children (which we need to preserve until we're
267  // finished with all operations that need to traverse the mempool).
268  for (txiter removeIt : entriesToRemove) {
269  setEntries setDescendants;
270  CalculateDescendants(removeIt, setDescendants);
271  setDescendants.erase(removeIt); // don't update state for self
272  int64_t modifySize = -((int64_t)removeIt->GetTxSize());
273  CAmount modifyFee = -removeIt->GetModifiedFee();
274  int modifySigOps = -removeIt->GetSigOpCost();
275  for (txiter dit : setDescendants) {
276  mapTx.modify(dit, update_ancestor_state(modifySize, modifyFee, -1, modifySigOps));
277  }
278  }
279  }
280  for (txiter removeIt : entriesToRemove) {
281  setEntries setAncestors;
282  const CTxMemPoolEntry &entry = *removeIt;
283  std::string dummy;
284  // Since this is a tx that is already in the mempool, we can call CMPA
285  // with fSearchForParents = false. If the mempool is in a consistent
286  // state, then using true or false should both be correct, though false
287  // should be a bit faster.
288  // However, if we happen to be in the middle of processing a reorg, then
289  // the mempool can be in an inconsistent state. In this case, the set
290  // of ancestors reachable via GetMemPoolParents()/GetMemPoolChildren()
291  // will be the same as the set of ancestors whose packages include this
292  // transaction, because when we add a new transaction to the mempool in
293  // addUnchecked(), we assume it has no children, and in the case of a
294  // reorg where that assumption is false, the in-mempool children aren't
295  // linked to the in-block tx's until UpdateTransactionsFromBlock() is
296  // called.
297  // So if we're being called during a reorg, ie before
298  // UpdateTransactionsFromBlock() has been called, then
299  // GetMemPoolParents()/GetMemPoolChildren() will differ from the set of
300  // mempool parents we'd calculate by searching, and it's important that
301  // we use the cached notion of ancestor transactions as the set of
302  // things to update for removal.
303  CalculateMemPoolAncestors(entry, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false);
304  // Note that UpdateAncestorsOf severs the child links that point to
305  // removeIt in the entries for the parents of removeIt.
306  UpdateAncestorsOf(false, removeIt, setAncestors);
307  }
308  // After updating all the ancestor sizes, we can now sever the link between each
309  // transaction being removed and any mempool children (ie, update CTxMemPoolEntry::m_parents
310  // for each direct child of a transaction being removed).
311  for (txiter removeIt : entriesToRemove) {
312  UpdateChildrenForRemoval(removeIt);
313  }
314 }
315 
316 void CTxMemPoolEntry::UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
317 {
318  nSizeWithDescendants += modifySize;
319  assert(int64_t(nSizeWithDescendants) > 0);
320  nModFeesWithDescendants += modifyFee;
321  nCountWithDescendants += modifyCount;
322  assert(int64_t(nCountWithDescendants) > 0);
323 }
324 
325 void CTxMemPoolEntry::UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps)
326 {
327  nSizeWithAncestors += modifySize;
328  assert(int64_t(nSizeWithAncestors) > 0);
329  nModFeesWithAncestors += modifyFee;
330  nCountWithAncestors += modifyCount;
331  assert(int64_t(nCountWithAncestors) > 0);
332  nSigOpCostWithAncestors += modifySigOps;
333  assert(int(nSigOpCostWithAncestors) >= 0);
334 }
335 
336 CTxMemPool::CTxMemPool(CBlockPolicyEstimator* estimator, int check_ratio)
337  : m_check_ratio(check_ratio), minerPolicyEstimator(estimator)
338 {
339  _clear(); //lock free clear
340 }
341 
342 bool CTxMemPool::isSpent(const COutPoint& outpoint) const
343 {
344  LOCK(cs);
345  return mapNextTx.count(outpoint);
346 }
347 
349 {
350  return nTransactionsUpdated;
351 }
352 
354 {
356 }
357 
358 void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate)
359 {
360  // Add to memory pool without checking anything.
361  // Used by AcceptToMemoryPool(), which DOES do
362  // all the appropriate checks.
363  indexed_transaction_set::iterator newit = mapTx.insert(entry).first;
364 
365  // Update transaction for any feeDelta created by PrioritiseTransaction
366  // TODO: refactor so that the fee delta is calculated before inserting
367  // into mapTx.
368  CAmount delta{0};
369  ApplyDelta(entry.GetTx().GetHash(), delta);
370  if (delta) {
371  mapTx.modify(newit, update_fee_delta(delta));
372  }
373 
374  // Update cachedInnerUsage to include contained transaction's usage.
375  // (When we update the entry for in-mempool parents, memory usage will be
376  // further updated.)
377  cachedInnerUsage += entry.DynamicMemoryUsage();
378 
379  const CTransaction& tx = newit->GetTx();
380  std::set<uint256> setParentTransactions;
381  for (unsigned int i = 0; i < tx.vin.size(); i++) {
382  mapNextTx.insert(std::make_pair(&tx.vin[i].prevout, &tx));
383  setParentTransactions.insert(tx.vin[i].prevout.hash);
384  }
385  // Don't bother worrying about child transactions of this one.
386  // Normal case of a new transaction arriving is that there can't be any
387  // children, because such children would be orphans.
388  // An exception to that is if a transaction enters that used to be in a block.
389  // In that case, our disconnect block logic will call UpdateTransactionsFromBlock
390  // to clean up the mess we're leaving here.
391 
392  // Update ancestors with information about this tx
393  for (const auto& pit : GetIterSet(setParentTransactions)) {
394  UpdateParent(newit, pit, true);
395  }
396  UpdateAncestorsOf(true, newit, setAncestors);
397  UpdateEntryForAncestors(newit, setAncestors);
398 
400  totalTxSize += entry.GetTxSize();
401  m_total_fee += entry.GetFee();
402  if (minerPolicyEstimator) {
403  minerPolicyEstimator->processTransaction(entry, validFeeEstimate);
404  }
405 
406  vTxHashes.emplace_back(tx.GetWitnessHash(), newit);
407  newit->vTxHashesIdx = vTxHashes.size() - 1;
408 }
409 
411 {
412  // We increment mempool sequence value no matter removal reason
413  // even if not directly reported below.
414  uint64_t mempool_sequence = GetAndIncrementSequence();
415 
416  if (reason != MemPoolRemovalReason::BLOCK) {
417  // Notify clients that a transaction has been removed from the mempool
418  // for any reason except being included in a block. Clients interested
419  // in transactions included in blocks can subscribe to the BlockConnected
420  // notification.
421  GetMainSignals().TransactionRemovedFromMempool(it->GetSharedTx(), reason, mempool_sequence);
422  }
423 
424  const uint256 hash = it->GetTx().GetHash();
425  for (const CTxIn& txin : it->GetTx().vin)
426  mapNextTx.erase(txin.prevout);
427 
428  RemoveUnbroadcastTx(hash, true /* add logging because unchecked */ );
429 
430  if (vTxHashes.size() > 1) {
431  vTxHashes[it->vTxHashesIdx] = std::move(vTxHashes.back());
432  vTxHashes[it->vTxHashesIdx].second->vTxHashesIdx = it->vTxHashesIdx;
433  vTxHashes.pop_back();
434  if (vTxHashes.size() * 2 < vTxHashes.capacity())
435  vTxHashes.shrink_to_fit();
436  } else
437  vTxHashes.clear();
438 
439  totalTxSize -= it->GetTxSize();
440  m_total_fee -= it->GetFee();
441  cachedInnerUsage -= it->DynamicMemoryUsage();
442  cachedInnerUsage -= memusage::DynamicUsage(it->GetMemPoolParentsConst()) + memusage::DynamicUsage(it->GetMemPoolChildrenConst());
443  mapTx.erase(it);
446 }
447 
448 // Calculates descendants of entry that are not already in setDescendants, and adds to
449 // setDescendants. Assumes entryit is already a tx in the mempool and CTxMemPoolEntry::m_children
450 // is correct for tx and all descendants.
451 // Also assumes that if an entry is in setDescendants already, then all
452 // in-mempool descendants of it are already in setDescendants as well, so that we
453 // can save time by not iterating over those entries.
454 void CTxMemPool::CalculateDescendants(txiter entryit, setEntries& setDescendants) const
455 {
456  setEntries stage;
457  if (setDescendants.count(entryit) == 0) {
458  stage.insert(entryit);
459  }
460  // Traverse down the children of entry, only adding children that are not
461  // accounted for in setDescendants already (because those children have either
462  // already been walked, or will be walked in this iteration).
463  while (!stage.empty()) {
464  txiter it = *stage.begin();
465  setDescendants.insert(it);
466  stage.erase(it);
467 
468  const CTxMemPoolEntry::Children& children = it->GetMemPoolChildrenConst();
469  for (const CTxMemPoolEntry& child : children) {
470  txiter childiter = mapTx.iterator_to(child);
471  if (!setDescendants.count(childiter)) {
472  stage.insert(childiter);
473  }
474  }
475  }
476 }
477 
479 {
480  // Remove transaction from memory pool
482  setEntries txToRemove;
483  txiter origit = mapTx.find(origTx.GetHash());
484  if (origit != mapTx.end()) {
485  txToRemove.insert(origit);
486  } else {
487  // When recursively removing but origTx isn't in the mempool
488  // be sure to remove any children that are in the pool. This can
489  // happen during chain re-orgs if origTx isn't re-accepted into
490  // the mempool for any reason.
491  for (unsigned int i = 0; i < origTx.vout.size(); i++) {
492  auto it = mapNextTx.find(COutPoint(origTx.GetHash(), i));
493  if (it == mapNextTx.end())
494  continue;
495  txiter nextit = mapTx.find(it->second->GetHash());
496  assert(nextit != mapTx.end());
497  txToRemove.insert(nextit);
498  }
499  }
500  setEntries setAllRemoves;
501  for (txiter it : txToRemove) {
502  CalculateDescendants(it, setAllRemoves);
503  }
504 
505  RemoveStaged(setAllRemoves, false, reason);
506 }
507 
508 void CTxMemPool::removeForReorg(CChainState& active_chainstate, int flags)
509 {
510  // Remove transactions spending a coinbase which are now immature and no-longer-final transactions
512  setEntries txToRemove;
513  for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
514  const CTransaction& tx = it->GetTx();
515  LockPoints lp = it->GetLockPoints();
516  bool validLP = TestLockPointValidity(active_chainstate.m_chain, &lp);
517  CCoinsViewMemPool view_mempool(&active_chainstate.CoinsTip(), *this);
518  if (!CheckFinalTx(active_chainstate.m_chain.Tip(), tx, flags)
519  || !CheckSequenceLocks(active_chainstate.m_chain.Tip(), view_mempool, tx, flags, &lp, validLP)) {
520  // Note if CheckSequenceLocks fails the LockPoints may still be invalid
521  // So it's critical that we remove the tx and not depend on the LockPoints.
522  txToRemove.insert(it);
523  } else if (it->GetSpendsCoinbase()) {
524  for (const CTxIn& txin : tx.vin) {
525  indexed_transaction_set::const_iterator it2 = mapTx.find(txin.prevout.hash);
526  if (it2 != mapTx.end())
527  continue;
528  const Coin &coin = active_chainstate.CoinsTip().AccessCoin(txin.prevout);
529  if (m_check_ratio != 0) assert(!coin.IsSpent());
530  unsigned int nMemPoolHeight = active_chainstate.m_chain.Tip()->nHeight + 1;
531  if (coin.IsSpent() || (coin.IsCoinBase() && ((signed long)nMemPoolHeight) - coin.nHeight < COINBASE_MATURITY)) {
532  txToRemove.insert(it);
533  break;
534  }
535  }
536  }
537  if (!validLP) {
538  mapTx.modify(it, update_lock_points(lp));
539  }
540  }
541  setEntries setAllRemoves;
542  for (txiter it : txToRemove) {
543  CalculateDescendants(it, setAllRemoves);
544  }
545  RemoveStaged(setAllRemoves, false, MemPoolRemovalReason::REORG);
546 }
547 
549 {
550  // Remove transactions which depend on inputs of tx, recursively
552  for (const CTxIn &txin : tx.vin) {
553  auto it = mapNextTx.find(txin.prevout);
554  if (it != mapNextTx.end()) {
555  const CTransaction &txConflict = *it->second;
556  if (txConflict != tx)
557  {
558  ClearPrioritisation(txConflict.GetHash());
560  }
561  }
562  }
563 }
564 
568 void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight)
569 {
571  std::vector<const CTxMemPoolEntry*> entries;
572  for (const auto& tx : vtx)
573  {
574  uint256 hash = tx->GetHash();
575 
576  indexed_transaction_set::iterator i = mapTx.find(hash);
577  if (i != mapTx.end())
578  entries.push_back(&*i);
579  }
580  // Before the txs in the new block have been removed from the mempool, update policy estimates
581  if (minerPolicyEstimator) {minerPolicyEstimator->processBlock(nBlockHeight, entries);}
582  for (const auto& tx : vtx)
583  {
584  txiter it = mapTx.find(tx->GetHash());
585  if (it != mapTx.end()) {
586  setEntries stage;
587  stage.insert(it);
589  }
590  removeConflicts(*tx);
592  }
593  lastRollingFeeUpdate = GetTime();
594  blockSinceLastRollingFeeBump = true;
595 }
596 
598 {
599  mapTx.clear();
600  mapNextTx.clear();
601  totalTxSize = 0;
602  m_total_fee = 0;
603  cachedInnerUsage = 0;
604  lastRollingFeeUpdate = GetTime();
605  blockSinceLastRollingFeeBump = false;
606  rollingMinimumFeeRate = 0;
608 }
609 
611 {
612  LOCK(cs);
613  _clear();
614 }
615 
616 static void CheckInputsAndUpdateCoins(const CTransaction& tx, CCoinsViewCache& mempoolDuplicate, const int64_t spendheight)
617 {
618  TxValidationState dummy_state; // Not used. CheckTxInputs() should always pass
619  CAmount txfee = 0;
620  bool fCheckResult = tx.IsCoinBase() || Consensus::CheckTxInputs(tx, dummy_state, mempoolDuplicate, spendheight, txfee);
621  assert(fCheckResult);
622  UpdateCoins(tx, mempoolDuplicate, std::numeric_limits<int>::max());
623 }
624 
625 void CTxMemPool::check(CChainState& active_chainstate) const
626 {
627  if (m_check_ratio == 0) return;
628 
629  if (GetRand(m_check_ratio) >= 1) return;
630 
632  LOCK(cs);
633  LogPrint(BCLog::MEMPOOL, "Checking mempool with %u transactions and %u inputs\n", (unsigned int)mapTx.size(), (unsigned int)mapNextTx.size());
634 
635  uint64_t checkTotal = 0;
636  CAmount check_total_fee{0};
637  uint64_t innerUsage = 0;
638 
639  CCoinsViewCache& active_coins_tip = active_chainstate.CoinsTip();
640  CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(&active_coins_tip));
641  const int64_t spendheight = active_chainstate.m_chain.Height() + 1;
642 
643  std::list<const CTxMemPoolEntry*> waitingOnDependants;
644  for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
645  unsigned int i = 0;
646  checkTotal += it->GetTxSize();
647  check_total_fee += it->GetFee();
648  innerUsage += it->DynamicMemoryUsage();
649  const CTransaction& tx = it->GetTx();
650  innerUsage += memusage::DynamicUsage(it->GetMemPoolParentsConst()) + memusage::DynamicUsage(it->GetMemPoolChildrenConst());
651  bool fDependsWait = false;
652  CTxMemPoolEntry::Parents setParentCheck;
653  for (const CTxIn &txin : tx.vin) {
654  // Check that every mempool transaction's inputs refer to available coins, or other mempool tx's.
655  indexed_transaction_set::const_iterator it2 = mapTx.find(txin.prevout.hash);
656  if (it2 != mapTx.end()) {
657  const CTransaction& tx2 = it2->GetTx();
658  assert(tx2.vout.size() > txin.prevout.n && !tx2.vout[txin.prevout.n].IsNull());
659  fDependsWait = true;
660  setParentCheck.insert(*it2);
661  } else {
662  assert(active_coins_tip.HaveCoin(txin.prevout));
663  }
664  // Check whether its inputs are marked in mapNextTx.
665  auto it3 = mapNextTx.find(txin.prevout);
666  assert(it3 != mapNextTx.end());
667  assert(it3->first == &txin.prevout);
668  assert(it3->second == &tx);
669  i++;
670  }
671  auto comp = [](const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) -> bool {
672  return a.GetTx().GetHash() == b.GetTx().GetHash();
673  };
674  assert(setParentCheck.size() == it->GetMemPoolParentsConst().size());
675  assert(std::equal(setParentCheck.begin(), setParentCheck.end(), it->GetMemPoolParentsConst().begin(), comp));
676  // Verify ancestor state is correct.
677  setEntries setAncestors;
678  uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
679  std::string dummy;
680  CalculateMemPoolAncestors(*it, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy);
681  uint64_t nCountCheck = setAncestors.size() + 1;
682  uint64_t nSizeCheck = it->GetTxSize();
683  CAmount nFeesCheck = it->GetModifiedFee();
684  int64_t nSigOpCheck = it->GetSigOpCost();
685 
686  for (txiter ancestorIt : setAncestors) {
687  nSizeCheck += ancestorIt->GetTxSize();
688  nFeesCheck += ancestorIt->GetModifiedFee();
689  nSigOpCheck += ancestorIt->GetSigOpCost();
690  }
691 
692  assert(it->GetCountWithAncestors() == nCountCheck);
693  assert(it->GetSizeWithAncestors() == nSizeCheck);
694  assert(it->GetSigOpCostWithAncestors() == nSigOpCheck);
695  assert(it->GetModFeesWithAncestors() == nFeesCheck);
696 
697  // Check children against mapNextTx
698  CTxMemPoolEntry::Children setChildrenCheck;
699  auto iter = mapNextTx.lower_bound(COutPoint(it->GetTx().GetHash(), 0));
700  uint64_t child_sizes = 0;
701  for (; iter != mapNextTx.end() && iter->first->hash == it->GetTx().GetHash(); ++iter) {
702  txiter childit = mapTx.find(iter->second->GetHash());
703  assert(childit != mapTx.end()); // mapNextTx points to in-mempool transactions
704  if (setChildrenCheck.insert(*childit).second) {
705  child_sizes += childit->GetTxSize();
706  }
707  }
708  assert(setChildrenCheck.size() == it->GetMemPoolChildrenConst().size());
709  assert(std::equal(setChildrenCheck.begin(), setChildrenCheck.end(), it->GetMemPoolChildrenConst().begin(), comp));
710  // Also check to make sure size is greater than sum with immediate children.
711  // just a sanity check, not definitive that this calc is correct...
712  assert(it->GetSizeWithDescendants() >= child_sizes + it->GetTxSize());
713 
714  if (fDependsWait)
715  waitingOnDependants.push_back(&(*it));
716  else {
717  CheckInputsAndUpdateCoins(tx, mempoolDuplicate, spendheight);
718  }
719  }
720  unsigned int stepsSinceLastRemove = 0;
721  while (!waitingOnDependants.empty()) {
722  const CTxMemPoolEntry* entry = waitingOnDependants.front();
723  waitingOnDependants.pop_front();
724  if (!mempoolDuplicate.HaveInputs(entry->GetTx())) {
725  waitingOnDependants.push_back(entry);
726  stepsSinceLastRemove++;
727  assert(stepsSinceLastRemove < waitingOnDependants.size());
728  } else {
729  CheckInputsAndUpdateCoins(entry->GetTx(), mempoolDuplicate, spendheight);
730  stepsSinceLastRemove = 0;
731  }
732  }
733  for (auto it = mapNextTx.cbegin(); it != mapNextTx.cend(); it++) {
734  uint256 hash = it->second->GetHash();
735  indexed_transaction_set::const_iterator it2 = mapTx.find(hash);
736  const CTransaction& tx = it2->GetTx();
737  assert(it2 != mapTx.end());
738  assert(&tx == it->second);
739  }
740 
741  assert(totalTxSize == checkTotal);
742  assert(m_total_fee == check_total_fee);
743  assert(innerUsage == cachedInnerUsage);
744 }
745 
746 bool CTxMemPool::CompareDepthAndScore(const uint256& hasha, const uint256& hashb, bool wtxid)
747 {
748  LOCK(cs);
749  indexed_transaction_set::const_iterator i = wtxid ? get_iter_from_wtxid(hasha) : mapTx.find(hasha);
750  if (i == mapTx.end()) return false;
751  indexed_transaction_set::const_iterator j = wtxid ? get_iter_from_wtxid(hashb) : mapTx.find(hashb);
752  if (j == mapTx.end()) return true;
753  uint64_t counta = i->GetCountWithAncestors();
754  uint64_t countb = j->GetCountWithAncestors();
755  if (counta == countb) {
756  return CompareTxMemPoolEntryByScore()(*i, *j);
757  }
758  return counta < countb;
759 }
760 
761 namespace {
762 class DepthAndScoreComparator
763 {
764 public:
765  bool operator()(const CTxMemPool::indexed_transaction_set::const_iterator& a, const CTxMemPool::indexed_transaction_set::const_iterator& b)
766  {
767  uint64_t counta = a->GetCountWithAncestors();
768  uint64_t countb = b->GetCountWithAncestors();
769  if (counta == countb) {
770  return CompareTxMemPoolEntryByScore()(*a, *b);
771  }
772  return counta < countb;
773  }
774 };
775 } // namespace
776 
777 std::vector<CTxMemPool::indexed_transaction_set::const_iterator> CTxMemPool::GetSortedDepthAndScore() const
778 {
779  std::vector<indexed_transaction_set::const_iterator> iters;
781 
782  iters.reserve(mapTx.size());
783 
784  for (indexed_transaction_set::iterator mi = mapTx.begin(); mi != mapTx.end(); ++mi) {
785  iters.push_back(mi);
786  }
787  std::sort(iters.begin(), iters.end(), DepthAndScoreComparator());
788  return iters;
789 }
790 
791 void CTxMemPool::queryHashes(std::vector<uint256>& vtxid) const
792 {
793  LOCK(cs);
794  auto iters = GetSortedDepthAndScore();
795 
796  vtxid.clear();
797  vtxid.reserve(mapTx.size());
798 
799  for (auto it : iters) {
800  vtxid.push_back(it->GetTx().GetHash());
801  }
802 }
803 
804 static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it) {
805  return TxMempoolInfo{it->GetSharedTx(), it->GetTime(), it->GetFee(), it->GetTxSize(), it->GetModifiedFee() - it->GetFee()};
806 }
807 
808 std::vector<TxMempoolInfo> CTxMemPool::infoAll() const
809 {
810  LOCK(cs);
811  auto iters = GetSortedDepthAndScore();
812 
813  std::vector<TxMempoolInfo> ret;
814  ret.reserve(mapTx.size());
815  for (auto it : iters) {
816  ret.push_back(GetInfo(it));
817  }
818 
819  return ret;
820 }
821 
823 {
824  LOCK(cs);
825  indexed_transaction_set::const_iterator i = mapTx.find(hash);
826  if (i == mapTx.end())
827  return nullptr;
828  return i->GetSharedTx();
829 }
830 
832 {
833  LOCK(cs);
834  indexed_transaction_set::const_iterator i = (gtxid.IsWtxid() ? get_iter_from_wtxid(gtxid.GetHash()) : mapTx.find(gtxid.GetHash()));
835  if (i == mapTx.end())
836  return TxMempoolInfo();
837  return GetInfo(i);
838 }
839 
840 TxMempoolInfo CTxMemPool::info(const uint256& txid) const { return info(GenTxid{false, txid}); }
841 
842 void CTxMemPool::PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta)
843 {
844  {
845  LOCK(cs);
846  CAmount &delta = mapDeltas[hash];
847  delta += nFeeDelta;
848  txiter it = mapTx.find(hash);
849  if (it != mapTx.end()) {
850  mapTx.modify(it, update_fee_delta(delta));
851  // Now update all ancestors' modified fees with descendants
852  setEntries setAncestors;
853  uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
854  std::string dummy;
855  CalculateMemPoolAncestors(*it, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false);
856  for (txiter ancestorIt : setAncestors) {
857  mapTx.modify(ancestorIt, update_descendant_state(0, nFeeDelta, 0));
858  }
859  // Now update all descendants' modified fees with ancestors
860  setEntries setDescendants;
861  CalculateDescendants(it, setDescendants);
862  setDescendants.erase(it);
863  for (txiter descendantIt : setDescendants) {
864  mapTx.modify(descendantIt, update_ancestor_state(0, nFeeDelta, 0, 0));
865  }
867  }
868  }
869  LogPrintf("PrioritiseTransaction: %s feerate += %s\n", hash.ToString(), FormatMoney(nFeeDelta));
870 }
871 
872 void CTxMemPool::ApplyDelta(const uint256& hash, CAmount &nFeeDelta) const
873 {
875  std::map<uint256, CAmount>::const_iterator pos = mapDeltas.find(hash);
876  if (pos == mapDeltas.end())
877  return;
878  const CAmount &delta = pos->second;
879  nFeeDelta += delta;
880 }
881 
883 {
885  mapDeltas.erase(hash);
886 }
887 
889 {
890  const auto it = mapNextTx.find(prevout);
891  return it == mapNextTx.end() ? nullptr : it->second;
892 }
893 
894 std::optional<CTxMemPool::txiter> CTxMemPool::GetIter(const uint256& txid) const
895 {
896  auto it = mapTx.find(txid);
897  if (it != mapTx.end()) return it;
898  return std::nullopt;
899 }
900 
901 CTxMemPool::setEntries CTxMemPool::GetIterSet(const std::set<uint256>& hashes) const
902 {
904  for (const auto& h : hashes) {
905  const auto mi = GetIter(h);
906  if (mi) ret.insert(*mi);
907  }
908  return ret;
909 }
910 
912 {
913  for (unsigned int i = 0; i < tx.vin.size(); i++)
914  if (exists(tx.vin[i].prevout.hash))
915  return false;
916  return true;
917 }
918 
919 CCoinsViewMemPool::CCoinsViewMemPool(CCoinsView* baseIn, const CTxMemPool& mempoolIn) : CCoinsViewBacked(baseIn), mempool(mempoolIn) { }
920 
921 bool CCoinsViewMemPool::GetCoin(const COutPoint &outpoint, Coin &coin) const {
922  // Check to see if the inputs are made available by another tx in the package.
923  // These Coins would not be available in the underlying CoinsView.
924  if (auto it = m_temp_added.find(outpoint); it != m_temp_added.end()) {
925  coin = it->second;
926  return true;
927  }
928 
929  // If an entry in the mempool exists, always return that one, as it's guaranteed to never
930  // conflict with the underlying cache, and it cannot have pruned entries (as it contains full)
931  // transactions. First checking the underlying cache risks returning a pruned entry instead.
932  CTransactionRef ptx = mempool.get(outpoint.hash);
933  if (ptx) {
934  if (outpoint.n < ptx->vout.size()) {
935  coin = Coin(ptx->vout[outpoint.n], MEMPOOL_HEIGHT, false);
936  return true;
937  } else {
938  return false;
939  }
940  }
941  return base->GetCoin(outpoint, coin);
942 }
943 
945 {
946  for (unsigned int n = 0; n < tx->vout.size(); ++n) {
947  m_temp_added.emplace(COutPoint(tx->GetHash(), n), Coin(tx->vout[n], MEMPOOL_HEIGHT, false));
948  }
949 }
950 
952  LOCK(cs);
953  // Estimate the overhead of mapTx to be 15 pointers + an allocation, as no exact formula for boost::multi_index_contained is implemented.
954  return memusage::MallocUsage(sizeof(CTxMemPoolEntry) + 15 * sizeof(void*)) * mapTx.size() + memusage::DynamicUsage(mapNextTx) + memusage::DynamicUsage(mapDeltas) + memusage::DynamicUsage(vTxHashes) + cachedInnerUsage;
955 }
956 
957 void CTxMemPool::RemoveUnbroadcastTx(const uint256& txid, const bool unchecked) {
958  LOCK(cs);
959 
960  if (m_unbroadcast_txids.erase(txid))
961  {
962  LogPrint(BCLog::MEMPOOL, "Removed %i from set of unbroadcast txns%s\n", txid.GetHex(), (unchecked ? " before confirmation that txn was sent out" : ""));
963  }
964 }
965 
966 void CTxMemPool::RemoveStaged(setEntries &stage, bool updateDescendants, MemPoolRemovalReason reason) {
968  UpdateForRemoveFromMempool(stage, updateDescendants);
969  for (txiter it : stage) {
970  removeUnchecked(it, reason);
971  }
972 }
973 
974 int CTxMemPool::Expire(std::chrono::seconds time)
975 {
977  indexed_transaction_set::index<entry_time>::type::iterator it = mapTx.get<entry_time>().begin();
978  setEntries toremove;
979  while (it != mapTx.get<entry_time>().end() && it->GetTime() < time) {
980  toremove.insert(mapTx.project<0>(it));
981  it++;
982  }
983  setEntries stage;
984  for (txiter removeit : toremove) {
985  CalculateDescendants(removeit, stage);
986  }
988  return stage.size();
989 }
990 
991 void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, bool validFeeEstimate)
992 {
993  setEntries setAncestors;
994  uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
995  std::string dummy;
996  CalculateMemPoolAncestors(entry, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy);
997  return addUnchecked(entry, setAncestors, validFeeEstimate);
998 }
999 
1000 void CTxMemPool::UpdateChild(txiter entry, txiter child, bool add)
1001 {
1002  AssertLockHeld(cs);
1004  if (add && entry->GetMemPoolChildren().insert(*child).second) {
1005  cachedInnerUsage += memusage::IncrementalDynamicUsage(s);
1006  } else if (!add && entry->GetMemPoolChildren().erase(*child)) {
1007  cachedInnerUsage -= memusage::IncrementalDynamicUsage(s);
1008  }
1009 }
1010 
1011 void CTxMemPool::UpdateParent(txiter entry, txiter parent, bool add)
1012 {
1013  AssertLockHeld(cs);
1015  if (add && entry->GetMemPoolParents().insert(*parent).second) {
1016  cachedInnerUsage += memusage::IncrementalDynamicUsage(s);
1017  } else if (!add && entry->GetMemPoolParents().erase(*parent)) {
1018  cachedInnerUsage -= memusage::IncrementalDynamicUsage(s);
1019  }
1020 }
1021 
1022 CFeeRate CTxMemPool::GetMinFee(size_t sizelimit) const {
1023  LOCK(cs);
1024  if (!blockSinceLastRollingFeeBump || rollingMinimumFeeRate == 0)
1025  return CFeeRate(llround(rollingMinimumFeeRate));
1026 
1027  int64_t time = GetTime();
1028  if (time > lastRollingFeeUpdate + 10) {
1029  double halflife = ROLLING_FEE_HALFLIFE;
1030  if (DynamicMemoryUsage() < sizelimit / 4)
1031  halflife /= 4;
1032  else if (DynamicMemoryUsage() < sizelimit / 2)
1033  halflife /= 2;
1034 
1035  rollingMinimumFeeRate = rollingMinimumFeeRate / pow(2.0, (time - lastRollingFeeUpdate) / halflife);
1036  lastRollingFeeUpdate = time;
1037 
1038  if (rollingMinimumFeeRate < (double)incrementalRelayFee.GetFeePerK() / 2) {
1039  rollingMinimumFeeRate = 0;
1040  return CFeeRate(0);
1041  }
1042  }
1043  return std::max(CFeeRate(llround(rollingMinimumFeeRate)), incrementalRelayFee);
1044 }
1045 
1047  AssertLockHeld(cs);
1048  if (rate.GetFeePerK() > rollingMinimumFeeRate) {
1049  rollingMinimumFeeRate = rate.GetFeePerK();
1050  blockSinceLastRollingFeeBump = false;
1051  }
1052 }
1053 
1054 void CTxMemPool::TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpendsRemaining) {
1055  AssertLockHeld(cs);
1056 
1057  unsigned nTxnRemoved = 0;
1058  CFeeRate maxFeeRateRemoved(0);
1059  while (!mapTx.empty() && DynamicMemoryUsage() > sizelimit) {
1060  indexed_transaction_set::index<descendant_score>::type::iterator it = mapTx.get<descendant_score>().begin();
1061 
1062  // We set the new mempool min fee to the feerate of the removed set, plus the
1063  // "minimum reasonable fee rate" (ie some value under which we consider txn
1064  // to have 0 fee). This way, we don't allow txn to enter mempool with feerate
1065  // equal to txn which were removed with no block in between.
1066  CFeeRate removed(it->GetModFeesWithDescendants(), it->GetSizeWithDescendants());
1067  removed += incrementalRelayFee;
1068  trackPackageRemoved(removed);
1069  maxFeeRateRemoved = std::max(maxFeeRateRemoved, removed);
1070 
1071  setEntries stage;
1072  CalculateDescendants(mapTx.project<0>(it), stage);
1073  nTxnRemoved += stage.size();
1074 
1075  std::vector<CTransaction> txn;
1076  if (pvNoSpendsRemaining) {
1077  txn.reserve(stage.size());
1078  for (txiter iter : stage)
1079  txn.push_back(iter->GetTx());
1080  }
1082  if (pvNoSpendsRemaining) {
1083  for (const CTransaction& tx : txn) {
1084  for (const CTxIn& txin : tx.vin) {
1085  if (exists(txin.prevout.hash)) continue;
1086  pvNoSpendsRemaining->push_back(txin.prevout);
1087  }
1088  }
1089  }
1090  }
1091 
1092  if (maxFeeRateRemoved > CFeeRate(0)) {
1093  LogPrint(BCLog::MEMPOOL, "Removed %u txn, rolling minimum fee bumped to %s\n", nTxnRemoved, maxFeeRateRemoved.ToString());
1094  }
1095 }
1096 
1098  // find parent with highest descendant count
1099  std::vector<txiter> candidates;
1100  setEntries counted;
1101  candidates.push_back(entry);
1102  uint64_t maximum = 0;
1103  while (candidates.size()) {
1104  txiter candidate = candidates.back();
1105  candidates.pop_back();
1106  if (!counted.insert(candidate).second) continue;
1107  const CTxMemPoolEntry::Parents& parents = candidate->GetMemPoolParentsConst();
1108  if (parents.size() == 0) {
1109  maximum = std::max(maximum, candidate->GetCountWithDescendants());
1110  } else {
1111  for (const CTxMemPoolEntry& i : parents) {
1112  candidates.push_back(mapTx.iterator_to(i));
1113  }
1114  }
1115  }
1116  return maximum;
1117 }
1118 
1119 void CTxMemPool::GetTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) const {
1120  LOCK(cs);
1121  auto it = mapTx.find(txid);
1122  ancestors = descendants = 0;
1123  if (it != mapTx.end()) {
1124  ancestors = it->GetCountWithAncestors();
1125  descendants = CalculateDescendantMaximum(it);
1126  }
1127 }
1128 
1130 {
1131  LOCK(cs);
1132  return m_is_loaded;
1133 }
1134 
1135 void CTxMemPool::SetIsLoaded(bool loaded)
1136 {
1137  LOCK(cs);
1138  m_is_loaded = loaded;
1139 }
CTxIn
An input of a transaction.
Definition: transaction.h:65
CTxMemPoolEntry::nSigOpCostWithAncestors
int64_t nSigOpCostWithAncestors
Definition: txmempool.h:114
CTxMemPoolEntry::nCountWithDescendants
uint64_t nCountWithDescendants
number of descendant transactions
Definition: txmempool.h:106
CTxMemPool::setEntries
std::set< txiter, CompareIteratorByHash > setEntries
Definition: txmempool.h:571
policy.h
CTransaction::vin
const std::vector< CTxIn > vin
Definition: transaction.h:270
CTxMemPool::AddTransactionsUpdated
void AddTransactionsUpdated(unsigned int n)
Definition: txmempool.cpp:353
CTxMemPool::GetMinFee
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:1022
CBlockPolicyEstimator::processTransaction
void processTransaction(const CTxMemPoolEntry &entry, bool validFeeEstimate)
Process a transaction accepted to the mempool.
Definition: fees.cpp:538
CTxMemPool::removeUnchecked
void removeUnchecked(txiter entry, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Before calling removeUnchecked for a given transaction, UpdateForRemoveFromMempool must be called on ...
Definition: txmempool.cpp:410
assert
assert(!tx.IsCoinBase())
CTxMemPoolEntry::feeDelta
int64_t feeDelta
Used for determining the priority of the transaction for mining in a block.
Definition: txmempool.h:100
update_fee_delta
Definition: txmempool.h:196
CTxMemPoolEntry::Children
std::set< CTxMemPoolEntryRef, CompareIteratorByHash > Children
Definition: txmempool.h:87
CTxMemPoolEntry::nCountWithAncestors
uint64_t nCountWithAncestors
Definition: txmempool.h:111
Consensus::CheckTxInputs
bool CheckTxInputs(const CTransaction &tx, TxValidationState &state, const CCoinsViewCache &inputs, int nSpendHeight, CAmount &txfee)
Check whether all inputs of this transaction are valid (no double spends and amounts) This does not m...
Definition: tx_verify.cpp:159
CTxMemPoolEntry::GetFee
const CAmount & GetFee() const
Definition: txmempool.h:124
CTxMemPool::ROLLING_FEE_HALFLIFE
static const int ROLLING_FEE_HALFLIFE
Definition: txmempool.h:504
GenTxid
A generic txid reference (txid or wtxid).
Definition: transaction.h:390
COINBASE_MATURITY
static const int COINBASE_MATURITY
Coinbase transaction outputs can only be spent after this number of new blocks (network rule)
Definition: consensus.h:19
settings.h
flags
int flags
Definition: bitcoin-tx.cpp:512
UpdateCoins
void UpdateCoins(const CTransaction &tx, CCoinsViewCache &inputs, CTxUndo &txundo, int nHeight)
Definition: validation.cpp:1335
CTxMemPoolEntry::lockPoints
LockPoints lockPoints
Track the height and time at which tx was final.
Definition: txmempool.h:101
update_lock_points
Definition: txmempool.h:206
CTxMemPool::GetSortedDepthAndScore
std::vector< indexed_transaction_set::const_iterator > GetSortedDepthAndScore() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:777
CTxMemPool::visited
bool visited(const txiter it) const EXCLUSIVE_LOCKS_REQUIRED(cs
visited marks a CTxMemPoolEntry as having been traversed during the lifetime of the most recently cre...
CCoinsViewCache::HaveCoin
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Definition: coins.cpp:146
moneystr.h
CTxMemPool::cs_main
void check(CChainState &active_chainstate) const EXCLUSIVE_LOCKS_REQUIRED(void cs_main
Definition: txmempool.h:617
CTxMemPool::txiter
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
Definition: txmempool.h:568
CTxMemPool::IsLoaded
bool IsLoaded() const
Definition: txmempool.cpp:1129
COutPoint::hash
uint256 hash
Definition: transaction.h:29
CTxMemPool::GetTransactionAncestry
void GetTransactionAncestry(const uint256 &txid, size_t &ancestors, size_t &descendants) const
Calculate the ancestor and descendant count for the given transaction.
Definition: txmempool.cpp:1119
CTxMemPool::get_iter_from_wtxid
txiter get_iter_from_wtxid(const uint256 &wtxid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:747
CTxMemPool
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:477
CBlockIndex::nHeight
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:150
CTxMemPool::TrimToSize
void TrimToSize(size_t sizelimit, std::vector< COutPoint > *pvNoSpendsRemaining=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs)
Remove transactions from the mempool until its dynamic size is <= sizelimit.
Definition: txmempool.cpp:1054
validationinterface.h
CTxMemPool::ClearPrioritisation
void ClearPrioritisation(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:882
validation.h
CBlockPolicyEstimator::removeTx
bool removeTx(uint256 hash, bool inBlock)
Remove a transaction from the mempool tracking stats.
Definition: fees.cpp:493
GetTime
int64_t GetTime()
DEPRECATED Use either GetTimeSeconds (not mockable) or GetTime<T> (mockable)
Definition: time.cpp:26
CTxMemPool::SetIsLoaded
void SetIsLoaded(bool loaded)
Sets the current loaded state.
Definition: txmempool.cpp:1135
CTxMemPool::m_epoch
bool m_epoch
Definition: txmempool.h:840
descendant_score
Definition: txmempool.h:364
MemPoolRemovalReason::EXPIRY
@ EXPIRY
Expired from mempool.
CCoinsViewCache::AccessCoin
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
Definition: coins.cpp:137
CTxMemPool::UpdateChildrenForRemoval
void UpdateChildrenForRemoval(txiter entry) EXCLUSIVE_LOCKS_REQUIRED(cs)
Sever link between specified transaction and direct children.
Definition: txmempool.cpp:248
CTxMemPool::ApplyDelta
void ApplyDelta(const uint256 &hash, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:872
CTxMemPool::CalculateMemPoolAncestors
bool CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntries &setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString, bool fSearchForParents=true) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Try to calculate all in-mempool ancestors of entry.
Definition: txmempool.cpp:154
CTxMemPoolEntry::nTxWeight
const size_t nTxWeight
... and avoid recomputing tx weight (also used for GetTxSize())
Definition: txmempool.h:94
CTxMemPoolEntry::Parents
std::set< CTxMemPoolEntryRef, CompareIteratorByHash > Parents
Definition: txmempool.h:86
memusage::DynamicUsage
static size_t DynamicUsage(const int8_t &v)
Dynamic memory usage for built-in types is zero.
Definition: memusage.h:29
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:386
CCoinsViewMemPool::PackageAddTransaction
void PackageAddTransaction(const CTransactionRef &tx)
Add the coins created by this transaction.
Definition: txmempool.cpp:944
CTxMemPool::GetTransactionsUpdated
unsigned int GetTransactionsUpdated() const
Definition: txmempool.cpp:348
CChain::Tip
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
Definition: chain.h:403
CTxMemPool::CalculateDescendantMaximum
uint64_t CalculateDescendantMaximum(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:1097
update_ancestor_state
Definition: txmempool.h:180
CTxMemPoolEntry::nSizeWithAncestors
uint64_t nSizeWithAncestors
Definition: txmempool.h:112
CCoinsViewMemPool::CCoinsViewMemPool
CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn)
Definition: txmempool.cpp:919
GetRand
uint64_t GetRand(uint64_t nMax) noexcept
Generate a uniform random integer in the range [0..range).
Definition: random.cpp:591
CFeeRate
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:29
CTxMemPool::queryHashes
void queryHashes(std::vector< uint256 > &vtxid) const
Definition: txmempool.cpp:791
CTxMemPool::UpdateEntryForAncestors
void UpdateEntryForAncestors(txiter it, const setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs)
Set ancestor state for an entry.
Definition: txmempool.cpp:234
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:259
CCoinsViewBacked::base
CCoinsView * base
Definition: coins.h:197
CCoinsView::GetCoin
virtual bool GetCoin(const COutPoint &outpoint, Coin &coin) const
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: coins.cpp:12
GetMainSignals
CMainSignals & GetMainSignals()
Definition: validationinterface.cpp:116
txmempool.h
CCoinsView
Abstract view on the open txout dataset.
Definition: coins.h:157
CTxMemPoolEntry::nSizeWithDescendants
uint64_t nSizeWithDescendants
... and size
Definition: txmempool.h:107
CTxMemPoolEntry::nModFeesWithDescendants
CAmount nModFeesWithDescendants
... and total fees (all including us)
Definition: txmempool.h:108
CTxMemPool::UpdateForDescendants
void UpdateForDescendants(txiter updateIt, cacheMap &cachedDescendants, const std::set< uint256 > &setExclude) EXCLUSIVE_LOCKS_REQUIRED(cs)
UpdateForDescendants is used by UpdateTransactionsFromBlock to update the descendants for a single tr...
Definition: txmempool.cpp:62
CCoinsViewMemPool::mempool
const CTxMemPool & mempool
Definition: txmempool.h:872
GenTxid::IsWtxid
bool IsWtxid() const
Definition: transaction.h:396
TxValidationState
Definition: validation.h:139
CTxMemPool::it
return !it visited * it
Definition: txmempool.h:847
CTransaction::IsCoinBase
bool IsCoinBase() const
Definition: transaction.h:315
RecursiveDynamicUsage
static size_t RecursiveDynamicUsage(const CScript &script)
Definition: core_memusage.h:12
CTxMemPool::CTxMemPool
CTxMemPool(CBlockPolicyEstimator *estimator=nullptr, int check_ratio=0)
Create a new CTxMemPool.
Definition: txmempool.cpp:336
entry_time
Definition: txmempool.h:365
CTxMemPool::cs
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:565
CTxMemPool::GetAndIncrementSequence
uint64_t GetAndIncrementSequence() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Guards this internal counter for external reporting.
Definition: txmempool.h:785
CTxMemPool::get
CTransactionRef get(const uint256 &hash) const
Definition: txmempool.cpp:822
CCoinsViewMemPool::m_temp_added
std::unordered_map< COutPoint, Coin, SaltedOutpointHasher > m_temp_added
Coins made available by transactions being validated.
Definition: txmempool.h:870
CTxMemPool::GetIterSet
setEntries GetIterSet(const std::set< uint256 > &hashes) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Translate a set of hashes into a set of pool iterators to avoid repeated lookups.
Definition: txmempool.cpp:901
CTxMemPool::nTransactionsUpdated
std::atomic< unsigned int > nTransactionsUpdated
Used by getblocktemplate to trigger CreateNewBlock() invocation.
Definition: txmempool.h:481
CTxMemPoolEntry::nModFeesWithAncestors
CAmount nModFeesWithAncestors
Definition: txmempool.h:113
update_descendant_state
Definition: txmempool.h:165
tx_verify.h
Coin
A UTXO entry.
Definition: coins.h:30
Coin::nHeight
uint32_t nHeight
at which height this containing transaction was included in the active block chain
Definition: coins.h:40
CTxMemPool::UpdateChild
void UpdateChild(txiter entry, txiter child, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:1000
CTransaction::vout
const std::vector< CTxOut > vout
Definition: transaction.h:271
reverse_iterator.h
CTxMemPoolEntry::UpdateAncestorState
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps)
Definition: txmempool.cpp:325
CTxMemPool::HasNoInputsOf
bool HasNoInputsOf(const CTransaction &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Check that none of this transactions inputs are in the mempool, and thus the tx is not dependent on o...
Definition: txmempool.cpp:911
CMainSignals::TransactionRemovedFromMempool
void TransactionRemovedFromMempool(const CTransactionRef &, MemPoolRemovalReason, uint64_t mempool_sequence)
Definition: validationinterface.cpp:211
CheckInputsAndUpdateCoins
static void CheckInputsAndUpdateCoins(const CTransaction &tx, CCoinsViewCache &mempoolDuplicate, const int64_t spendheight)
Definition: txmempool.cpp:616
consensus.h
CTxMemPoolEntry::UpdateDescendantState
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
Definition: txmempool.cpp:316
CBlockPolicyEstimator
Definition: fees.h:131
time.h
LogPrintf
#define LogPrintf(...)
Definition: logging.h:184
CAmount
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
base_blob::GetHex
std::string GetHex() const
Definition: uint256.cpp:20
MemPoolRemovalReason::SIZELIMIT
@ SIZELIMIT
Removed in size limiting.
CTxMemPool::removeConflicts
void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:548
CTxMemPool::m_check_ratio
const int m_check_ratio
Value n means that 1 times in n we check.
Definition: txmempool.h:480
CTxMemPool::UpdateParent
void UpdateParent(txiter entry, txiter parent, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:1011
AssertLockHeld
#define AssertLockHeld(cs)
Definition: sync.h:81
CTxMemPool::RemoveUnbroadcastTx
void RemoveUnbroadcastTx(const uint256 &txid, const bool unchecked=false)
Removes a transaction from the unbroadcast set.
Definition: txmempool.cpp:957
CTxMemPool::UpdateTransactionsFromBlock
void UpdateTransactionsFromBlock(const std::vector< uint256 > &vHashesToUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs
When adding transactions from a disconnected block back to the mempool, new mempool entries may have ...
Definition: txmempool.cpp:109
base_blob::ToString
std::string ToString() const
Definition: uint256.cpp:64
uint256
256-bit opaque blob.
Definition: uint256.h:124
CTxMemPoolEntry::nFee
const CAmount nFee
Cached to avoid expensive parent-transaction lookups.
Definition: txmempool.h:93
CFeeRate::ToString
std::string ToString(const FeeEstimateMode &fee_estimate_mode=FeeEstimateMode::BTC_KVB) const
Definition: feerate.cpp:35
CChainState
CChainState stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:566
LogPrint
#define LogPrint(category,...)
Definition: logging.h:188
CompareTxMemPoolEntryByScore
Definition: txmempool.h:296
CTxMemPoolEntry::UpdateFeeDelta
void UpdateFeeDelta(int64_t feeDelta)
Definition: txmempool.cpp:42
TestLockPointValidity
bool TestLockPointValidity(CChain &active_chain, const LockPoints *lp)
Test whether the LockPoints height and time are still valid on the current chain.
Definition: validation.cpp:213
CCoinsViewMemPool::GetCoin
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: txmempool.cpp:921
CTxMemPool::GetIter
std::optional< txiter > GetIter(const uint256 &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns an iterator to the given hash, if found.
Definition: txmempool.cpp:894
CTxMemPoolEntry::DynamicMemoryUsage
size_t DynamicMemoryUsage() const
Definition: txmempool.h:131
CChain::Height
int Height() const
Return the maximal height in the chain.
Definition: chain.h:428
CTxMemPool::PrioritiseTransaction
void PrioritiseTransaction(const uint256 &hash, const CAmount &nFeeDelta)
Affect CreateNewBlock prioritisation of transactions.
Definition: txmempool.cpp:842
CTxMemPool::UpdateForRemoveFromMempool
void UpdateForRemoveFromMempool(const setEntries &entriesToRemove, bool updateDescendants) EXCLUSIVE_LOCKS_REQUIRED(cs)
For each transaction being removed, update ancestors and any direct children.
Definition: txmempool.cpp:256
CTxMemPoolEntry::GetMemPoolChildrenConst
const Children & GetMemPoolChildrenConst() const
Definition: txmempool.h:156
CTxMemPool::Expire
int Expire(std::chrono::seconds time) EXCLUSIVE_LOCKS_REQUIRED(cs)
Expire all transaction (and their dependencies) in the mempool older than time.
Definition: txmempool.cpp:974
GetInfo
static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it)
Definition: txmempool.cpp:804
system.h
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1164
CTxMemPool::exists
bool exists(const GenTxid &gtxid) const
Definition: txmempool.h:736
incrementalRelayFee
CFeeRate incrementalRelayFee
Definition: settings.cpp:12
CTxMemPool::UpdateAncestorsOf
void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs)
Update ancestors of hash to add/remove it as a descendant transaction.
Definition: txmempool.cpp:219
CheckSequenceLocks
bool CheckSequenceLocks(CBlockIndex *tip, const CCoinsView &coins_view, const CTransaction &tx, int flags, LockPoints *lp, bool useExistingLockPoints)
Check if transaction will be BIP68 final in the next block to be created on top of tip.
Definition: validation.cpp:231
GetTransactionWeight
static int64_t GetTransactionWeight(const CTransaction &tx)
Definition: validation.h:146
GenTxid::GetHash
const uint256 & GetHash() const
Definition: transaction.h:397
BCLog::MEMPOOL
@ MEMPOOL
Definition: logging.h:40
fees.h
CCoinsViewCache
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:213
CCoinsViewBacked
CCoinsView backed by another CCoinsView.
Definition: coins.h:194
CTxMemPool::addUnchecked
void check(CChainState &active_chainstate) const EXCLUSIVE_LOCKS_REQUIRED(void addUnchecked(const CTxMemPoolEntry &entry, bool validFeeEstimate=true) EXCLUSIVE_LOCKS_REQUIRED(cs
If sanity-checking is turned on, check makes sure the pool is consistent (does not contain two transa...
Definition: txmempool.h:617
COutPoint::n
uint32_t n
Definition: transaction.h:30
CTxMemPoolEntry
Definition: txmempool.h:81
LOCK
#define LOCK(cs)
Definition: sync.h:232
MemPoolRemovalReason
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
Definition: txmempool.h:395
CTxMemPool::infoAll
std::vector< TxMempoolInfo > infoAll() const
Definition: txmempool.cpp:808
CTxMemPool::GetConflictTx
const CTransaction * GetConflictTx(const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Get the transaction in the pool that spends the same prevout.
Definition: txmempool.cpp:888
CheckFinalTx
bool CheckFinalTx(const CBlockIndex *active_chain_tip, const CTransaction &tx, int flags)
Transaction validation functions.
Definition: validation.cpp:180
memusage::IncrementalDynamicUsage
static size_t IncrementalDynamicUsage(const std::set< X, Y > &s)
Definition: memusage.h:105
LockPoints
Definition: txmempool.h:39
CTxIn::prevout
COutPoint prevout
Definition: transaction.h:68
CTxMemPool::trackPackageRemoved
void trackPackageRemoved(const CFeeRate &rate) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:1046
CTxMemPool::RemoveStaged
void RemoveStaged(setEntries &stage, bool updateDescendants, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Remove a set of transactions from the mempool.
Definition: txmempool.cpp:966
CCoinsViewMemPool
CCoinsView that brings transactions from a mempool into view.
Definition: txmempool.h:864
CTxMemPoolEntry::CTxMemPoolEntry
CTxMemPoolEntry(const CTransactionRef &_tx, const CAmount &_nFee, int64_t _nTime, unsigned int _entryHeight, bool spendsCoinbase, int64_t nSigOpsCost, LockPoints lp)
Definition: txmempool.cpp:24
spendsCoinbase
bool spendsCoinbase
Definition: mempool_eviction.cpp:15
TxMempoolInfo
Information about a mempool transaction.
Definition: txmempool.h:374
CTxMemPoolEntry::UpdateLockPoints
void UpdateLockPoints(const LockPoints &lp)
Definition: txmempool.cpp:49
memusage::MallocUsage
static size_t MallocUsage(size_t alloc)
Compute the total memory used by allocating alloc bytes.
Definition: memusage.h:50
CTxMemPool::CompareDepthAndScore
bool CompareDepthAndScore(const uint256 &hasha, const uint256 &hashb, bool wtxid=false)
Definition: txmempool.cpp:746
MEMPOOL_HEIGHT
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:37
CTransaction::GetWitnessHash
const uint256 & GetWitnessHash() const
Definition: transaction.h:303
CTxMemPool::info
TxMempoolInfo info(const uint256 &hash) const
Definition: txmempool.cpp:840
CTxMemPool::DynamicMemoryUsage
size_t DynamicMemoryUsage() const
Definition: txmempool.cpp:951
CTxMemPoolEntry::GetTxSize
size_t GetTxSize() const
Definition: txmempool.cpp:54
CTransaction::GetHash
const uint256 & GetHash() const
Definition: transaction.h:302
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
CBlockPolicyEstimator::processBlock
void processBlock(unsigned int nBlockHeight, std::vector< const CTxMemPoolEntry * > &entries)
Process all the transactions that have been included in a block.
Definition: fees.cpp:604
lp
LockPoints lp
Definition: mempool_eviction.cpp:17
MemPoolRemovalReason::BLOCK
@ BLOCK
Removed for block.
Coin::IsSpent
bool IsSpent() const
Either this coin never existed (see e.g.
Definition: coins.h:79
WITH_FRESH_EPOCH
#define WITH_FRESH_EPOCH(epoch)
Definition: epochguard.h:89
CFeeRate::GetFeePerK
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition: feerate.h:56
CTxMemPool::cacheMap
std::map< txiter, setEntries, CompareIteratorByHash > cacheMap
Definition: txmempool.h:575
CTxMemPool::isSpent
bool isSpent(const COutPoint &outpoint) const
Definition: txmempool.cpp:342
CTxMemPoolEntry::sigOpCost
const int64_t sigOpCost
Total sigop cost.
Definition: txmempool.h:99
CTxMemPool::clear
void clear()
Definition: txmempool.cpp:610
CTxMemPool::_clear
void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:597
reverse_iterate
reverse_range< T > reverse_iterate(T &x)
Definition: reverse_iterator.h:34
CTxMemPool::minerPolicyEstimator
CBlockPolicyEstimator *const minerPolicyEstimator
Definition: txmempool.h:482
GetVirtualTransactionSize
int64_t GetVirtualTransactionSize(int64_t nWeight, int64_t nSigOpCost, unsigned int bytes_per_sigop)
Compute the virtual transaction size (weight reinterpreted as bytes).
Definition: policy.cpp:280
sigOpCost
unsigned int sigOpCost
Definition: mempool_eviction.cpp:16
MemPoolRemovalReason::CONFLICT
@ CONFLICT
Removed for conflict with in-block transaction.
MemPoolRemovalReason::REORG
@ REORG
Removed for reorganization.
CChainState::CoinsTip
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:649
CChainState::m_chain
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:632
it
auto it
Definition: validation.cpp:355
CTxMemPool::removeForBlock
void removeForBlock(const std::vector< CTransactionRef > &vtx, unsigned int nBlockHeight) EXCLUSIVE_LOCKS_REQUIRED(cs)
Called when a block is connected.
Definition: txmempool.cpp:568
CTxMemPool::removeForReorg
void removeForReorg(CChainState &active_chainstate, int flags) EXCLUSIVE_LOCKS_REQUIRED(cs
Definition: txmempool.cpp:508
CTxMemPool::removeRecursive
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:478
CTxMemPool::CalculateDescendants
void CalculateDescendants(txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Populate setDescendants with all in-mempool descendants of hash.
Definition: txmempool.cpp:454
FormatMoney
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
Definition: moneystr.cpp:12
Coin::IsCoinBase
bool IsCoinBase() const
Definition: coins.h:55
CTxMemPoolEntry::GetTx
const CTransaction & GetTx() const
Definition: txmempool.h:122