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 <optional>
22 
24  int64_t _nTime, unsigned int _entryHeight,
25  bool _spendsCoinbase, int64_t _sigOpsCost, LockPoints lp)
26  : tx(_tx), nFee(_nFee), nTxWeight(GetTransactionWeight(*tx)), nUsageSize(RecursiveDynamicUsage(tx)), nTime(_nTime), entryHeight(_entryHeight),
27  spendsCoinbase(_spendsCoinbase), sigOpCost(_sigOpsCost), lockPoints(lp)
28 {
32 
33  feeDelta = 0;
34 
39 }
40 
41 void CTxMemPoolEntry::UpdateFeeDelta(int64_t newFeeDelta)
42 {
43  nModFeesWithDescendants += newFeeDelta - feeDelta;
44  nModFeesWithAncestors += newFeeDelta - feeDelta;
45  feeDelta = newFeeDelta;
46 }
47 
49 {
50  lockPoints = lp;
51 }
52 
54 {
56 }
57 
58 // Update the given tx for any in-mempool descendants.
59 // Assumes that CTxMemPool::m_children is correct for the given tx and all
60 // descendants.
61 void CTxMemPool::UpdateForDescendants(txiter updateIt, cacheMap &cachedDescendants, const std::set<uint256> &setExclude)
62 {
63  CTxMemPoolEntry::Children stageEntries, descendants;
64  stageEntries = updateIt->GetMemPoolChildrenConst();
65 
66  while (!stageEntries.empty()) {
67  const CTxMemPoolEntry& descendant = *stageEntries.begin();
68  descendants.insert(descendant);
69  stageEntries.erase(descendant);
70  const CTxMemPoolEntry::Children& children = descendant.GetMemPoolChildrenConst();
71  for (const CTxMemPoolEntry& childEntry : children) {
72  cacheMap::iterator cacheIt = cachedDescendants.find(mapTx.iterator_to(childEntry));
73  if (cacheIt != cachedDescendants.end()) {
74  // We've already calculated this one, just add the entries for this set
75  // but don't traverse again.
76  for (txiter cacheEntry : cacheIt->second) {
77  descendants.insert(*cacheEntry);
78  }
79  } else if (!descendants.count(childEntry)) {
80  // Schedule for later processing
81  stageEntries.insert(childEntry);
82  }
83  }
84  }
85  // descendants now contains all in-mempool descendants of updateIt.
86  // Update and add to cached descendant map
87  int64_t modifySize = 0;
88  CAmount modifyFee = 0;
89  int64_t modifyCount = 0;
90  for (const CTxMemPoolEntry& descendant : descendants) {
91  if (!setExclude.count(descendant.GetTx().GetHash())) {
92  modifySize += descendant.GetTxSize();
93  modifyFee += descendant.GetModifiedFee();
94  modifyCount++;
95  cachedDescendants[updateIt].insert(mapTx.iterator_to(descendant));
96  // Update ancestor state for each descendant
97  mapTx.modify(mapTx.iterator_to(descendant), update_ancestor_state(updateIt->GetTxSize(), updateIt->GetModifiedFee(), 1, updateIt->GetSigOpCost()));
98  }
99  }
100  mapTx.modify(updateIt, update_descendant_state(modifySize, modifyFee, modifyCount));
101 }
102 
103 // vHashesToUpdate is the set of transaction hashes from a disconnected block
104 // which has been re-added to the mempool.
105 // for each entry, look for descendants that are outside vHashesToUpdate, and
106 // add fee/size information for such descendants to the parent.
107 // for each such descendant, also update the ancestor state to include the parent.
108 void CTxMemPool::UpdateTransactionsFromBlock(const std::vector<uint256> &vHashesToUpdate)
109 {
111  // For each entry in vHashesToUpdate, store the set of in-mempool, but not
112  // in-vHashesToUpdate transactions, so that we don't have to recalculate
113  // descendants when we come across a previously seen entry.
114  cacheMap mapMemPoolDescendantsToUpdate;
115 
116  // Use a set for lookups into vHashesToUpdate (these entries are already
117  // accounted for in the state of their ancestors)
118  std::set<uint256> setAlreadyIncluded(vHashesToUpdate.begin(), vHashesToUpdate.end());
119 
120  // Iterate in reverse, so that whenever we are looking at a transaction
121  // we are sure that all in-mempool descendants have already been processed.
122  // This maximizes the benefit of the descendant cache and guarantees that
123  // CTxMemPool::m_children will be updated, an assumption made in
124  // UpdateForDescendants.
125  for (const uint256 &hash : reverse_iterate(vHashesToUpdate)) {
126  // calculate children from mapNextTx
127  txiter it = mapTx.find(hash);
128  if (it == mapTx.end()) {
129  continue;
130  }
131  auto iter = mapNextTx.lower_bound(COutPoint(hash, 0));
132  // First calculate the children, and update CTxMemPool::m_children to
133  // include them, and update their CTxMemPoolEntry::m_parents to include this tx.
134  // we cache the in-mempool children to avoid duplicate updates
135  {
137  for (; iter != mapNextTx.end() && iter->first->hash == hash; ++iter) {
138  const uint256 &childHash = iter->second->GetHash();
139  txiter childIter = mapTx.find(childHash);
140  assert(childIter != mapTx.end());
141  // We can skip updating entries we've encountered before or that
142  // are in the block (which are already accounted for).
143  if (!visited(childIter) && !setAlreadyIncluded.count(childHash)) {
144  UpdateChild(it, childIter, true);
145  UpdateParent(childIter, it, true);
146  }
147  }
148  } // release epoch guard for UpdateForDescendants
149  UpdateForDescendants(it, mapMemPoolDescendantsToUpdate, setAlreadyIncluded);
150  }
151 }
152 
153 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
154 {
155  CTxMemPoolEntry::Parents staged_ancestors;
156  const CTransaction &tx = entry.GetTx();
157 
158  if (fSearchForParents) {
159  // Get parents of this transaction that are in the mempool
160  // GetMemPoolParents() is only valid for entries in the mempool, so we
161  // iterate mapTx to find parents.
162  for (unsigned int i = 0; i < tx.vin.size(); i++) {
163  std::optional<txiter> piter = GetIter(tx.vin[i].prevout.hash);
164  if (piter) {
165  staged_ancestors.insert(**piter);
166  if (staged_ancestors.size() + 1 > limitAncestorCount) {
167  errString = strprintf("too many unconfirmed parents [limit: %u]", limitAncestorCount);
168  return false;
169  }
170  }
171  }
172  } else {
173  // If we're not searching for parents, we require this to be an
174  // entry in the mempool already.
175  txiter it = mapTx.iterator_to(entry);
176  staged_ancestors = it->GetMemPoolParentsConst();
177  }
178 
179  size_t totalSizeWithAncestors = entry.GetTxSize();
180 
181  while (!staged_ancestors.empty()) {
182  const CTxMemPoolEntry& stage = staged_ancestors.begin()->get();
183  txiter stageit = mapTx.iterator_to(stage);
184 
185  setAncestors.insert(stageit);
186  staged_ancestors.erase(stage);
187  totalSizeWithAncestors += stageit->GetTxSize();
188 
189  if (stageit->GetSizeWithDescendants() + entry.GetTxSize() > limitDescendantSize) {
190  errString = strprintf("exceeds descendant size limit for tx %s [limit: %u]", stageit->GetTx().GetHash().ToString(), limitDescendantSize);
191  return false;
192  } else if (stageit->GetCountWithDescendants() + 1 > limitDescendantCount) {
193  errString = strprintf("too many descendants for tx %s [limit: %u]", stageit->GetTx().GetHash().ToString(), limitDescendantCount);
194  return false;
195  } else if (totalSizeWithAncestors > limitAncestorSize) {
196  errString = strprintf("exceeds ancestor size limit [limit: %u]", limitAncestorSize);
197  return false;
198  }
199 
200  const CTxMemPoolEntry::Parents& parents = stageit->GetMemPoolParentsConst();
201  for (const CTxMemPoolEntry& parent : parents) {
202  txiter parent_it = mapTx.iterator_to(parent);
203 
204  // If this is a new ancestor, add it.
205  if (setAncestors.count(parent_it) == 0) {
206  staged_ancestors.insert(parent);
207  }
208  if (staged_ancestors.size() + setAncestors.size() + 1 > limitAncestorCount) {
209  errString = strprintf("too many unconfirmed ancestors [limit: %u]", limitAncestorCount);
210  return false;
211  }
212  }
213  }
214 
215  return true;
216 }
217 
218 void CTxMemPool::UpdateAncestorsOf(bool add, txiter it, setEntries &setAncestors)
219 {
220  CTxMemPoolEntry::Parents parents = it->GetMemPoolParents();
221  // add or remove this tx as a child of each parent
222  for (const CTxMemPoolEntry& parent : parents) {
223  UpdateChild(mapTx.iterator_to(parent), it, add);
224  }
225  const int64_t updateCount = (add ? 1 : -1);
226  const int64_t updateSize = updateCount * it->GetTxSize();
227  const CAmount updateFee = updateCount * it->GetModifiedFee();
228  for (txiter ancestorIt : setAncestors) {
229  mapTx.modify(ancestorIt, update_descendant_state(updateSize, updateFee, updateCount));
230  }
231 }
232 
234 {
235  int64_t updateCount = setAncestors.size();
236  int64_t updateSize = 0;
237  CAmount updateFee = 0;
238  int64_t updateSigOpsCost = 0;
239  for (txiter ancestorIt : setAncestors) {
240  updateSize += ancestorIt->GetTxSize();
241  updateFee += ancestorIt->GetModifiedFee();
242  updateSigOpsCost += ancestorIt->GetSigOpCost();
243  }
244  mapTx.modify(it, update_ancestor_state(updateSize, updateFee, updateCount, updateSigOpsCost));
245 }
246 
248 {
249  const CTxMemPoolEntry::Children& children = it->GetMemPoolChildrenConst();
250  for (const CTxMemPoolEntry& updateIt : children) {
251  UpdateParent(mapTx.iterator_to(updateIt), it, false);
252  }
253 }
254 
255 void CTxMemPool::UpdateForRemoveFromMempool(const setEntries &entriesToRemove, bool updateDescendants)
256 {
257  // For each entry, walk back all ancestors and decrement size associated with this
258  // transaction
259  const uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
260  if (updateDescendants) {
261  // updateDescendants should be true whenever we're not recursively
262  // removing a tx and all its descendants, eg when a transaction is
263  // confirmed in a block.
264  // Here we only update statistics and not data in CTxMemPool::Parents
265  // and CTxMemPoolEntry::Children (which we need to preserve until we're
266  // finished with all operations that need to traverse the mempool).
267  for (txiter removeIt : entriesToRemove) {
268  setEntries setDescendants;
269  CalculateDescendants(removeIt, setDescendants);
270  setDescendants.erase(removeIt); // don't update state for self
271  int64_t modifySize = -((int64_t)removeIt->GetTxSize());
272  CAmount modifyFee = -removeIt->GetModifiedFee();
273  int modifySigOps = -removeIt->GetSigOpCost();
274  for (txiter dit : setDescendants) {
275  mapTx.modify(dit, update_ancestor_state(modifySize, modifyFee, -1, modifySigOps));
276  }
277  }
278  }
279  for (txiter removeIt : entriesToRemove) {
280  setEntries setAncestors;
281  const CTxMemPoolEntry &entry = *removeIt;
282  std::string dummy;
283  // Since this is a tx that is already in the mempool, we can call CMPA
284  // with fSearchForParents = false. If the mempool is in a consistent
285  // state, then using true or false should both be correct, though false
286  // should be a bit faster.
287  // However, if we happen to be in the middle of processing a reorg, then
288  // the mempool can be in an inconsistent state. In this case, the set
289  // of ancestors reachable via GetMemPoolParents()/GetMemPoolChildren()
290  // will be the same as the set of ancestors whose packages include this
291  // transaction, because when we add a new transaction to the mempool in
292  // addUnchecked(), we assume it has no children, and in the case of a
293  // reorg where that assumption is false, the in-mempool children aren't
294  // linked to the in-block tx's until UpdateTransactionsFromBlock() is
295  // called.
296  // So if we're being called during a reorg, ie before
297  // UpdateTransactionsFromBlock() has been called, then
298  // GetMemPoolParents()/GetMemPoolChildren() will differ from the set of
299  // mempool parents we'd calculate by searching, and it's important that
300  // we use the cached notion of ancestor transactions as the set of
301  // things to update for removal.
302  CalculateMemPoolAncestors(entry, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy, false);
303  // Note that UpdateAncestorsOf severs the child links that point to
304  // removeIt in the entries for the parents of removeIt.
305  UpdateAncestorsOf(false, removeIt, setAncestors);
306  }
307  // After updating all the ancestor sizes, we can now sever the link between each
308  // transaction being removed and any mempool children (ie, update CTxMemPoolEntry::m_parents
309  // for each direct child of a transaction being removed).
310  for (txiter removeIt : entriesToRemove) {
311  UpdateChildrenForRemoval(removeIt);
312  }
313 }
314 
315 void CTxMemPoolEntry::UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
316 {
317  nSizeWithDescendants += modifySize;
318  assert(int64_t(nSizeWithDescendants) > 0);
319  nModFeesWithDescendants += modifyFee;
320  nCountWithDescendants += modifyCount;
321  assert(int64_t(nCountWithDescendants) > 0);
322 }
323 
324 void CTxMemPoolEntry::UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int64_t modifySigOps)
325 {
326  nSizeWithAncestors += modifySize;
327  assert(int64_t(nSizeWithAncestors) > 0);
328  nModFeesWithAncestors += modifyFee;
329  nCountWithAncestors += modifyCount;
330  assert(int64_t(nCountWithAncestors) > 0);
331  nSigOpCostWithAncestors += modifySigOps;
332  assert(int(nSigOpCostWithAncestors) >= 0);
333 }
334 
335 CTxMemPool::CTxMemPool(CBlockPolicyEstimator* estimator, int check_ratio)
336  : m_check_ratio(check_ratio), minerPolicyEstimator(estimator)
337 {
338  _clear(); //lock free clear
339 }
340 
341 bool CTxMemPool::isSpent(const COutPoint& outpoint) const
342 {
343  LOCK(cs);
344  return mapNextTx.count(outpoint);
345 }
346 
348 {
349  return nTransactionsUpdated;
350 }
351 
353 {
355 }
356 
357 void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate)
358 {
359  // Add to memory pool without checking anything.
360  // Used by AcceptToMemoryPool(), which DOES do
361  // all the appropriate checks.
362  indexed_transaction_set::iterator newit = mapTx.insert(entry).first;
363 
364  // Update transaction for any feeDelta created by PrioritiseTransaction
365  // TODO: refactor so that the fee delta is calculated before inserting
366  // into mapTx.
367  CAmount delta{0};
368  ApplyDelta(entry.GetTx().GetHash(), delta);
369  if (delta) {
370  mapTx.modify(newit, update_fee_delta(delta));
371  }
372 
373  // Update cachedInnerUsage to include contained transaction's usage.
374  // (When we update the entry for in-mempool parents, memory usage will be
375  // further updated.)
376  cachedInnerUsage += entry.DynamicMemoryUsage();
377 
378  const CTransaction& tx = newit->GetTx();
379  std::set<uint256> setParentTransactions;
380  for (unsigned int i = 0; i < tx.vin.size(); i++) {
381  mapNextTx.insert(std::make_pair(&tx.vin[i].prevout, &tx));
382  setParentTransactions.insert(tx.vin[i].prevout.hash);
383  }
384  // Don't bother worrying about child transactions of this one.
385  // Normal case of a new transaction arriving is that there can't be any
386  // children, because such children would be orphans.
387  // An exception to that is if a transaction enters that used to be in a block.
388  // In that case, our disconnect block logic will call UpdateTransactionsFromBlock
389  // to clean up the mess we're leaving here.
390 
391  // Update ancestors with information about this tx
392  for (const auto& pit : GetIterSet(setParentTransactions)) {
393  UpdateParent(newit, pit, true);
394  }
395  UpdateAncestorsOf(true, newit, setAncestors);
396  UpdateEntryForAncestors(newit, setAncestors);
397 
399  totalTxSize += entry.GetTxSize();
400  m_total_fee += entry.GetFee();
401  if (minerPolicyEstimator) {
402  minerPolicyEstimator->processTransaction(entry, validFeeEstimate);
403  }
404 
405  vTxHashes.emplace_back(tx.GetWitnessHash(), newit);
406  newit->vTxHashesIdx = vTxHashes.size() - 1;
407 }
408 
410 {
411  // We increment mempool sequence value no matter removal reason
412  // even if not directly reported below.
413  uint64_t mempool_sequence = GetAndIncrementSequence();
414 
415  if (reason != MemPoolRemovalReason::BLOCK) {
416  // Notify clients that a transaction has been removed from the mempool
417  // for any reason except being included in a block. Clients interested
418  // in transactions included in blocks can subscribe to the BlockConnected
419  // notification.
420  GetMainSignals().TransactionRemovedFromMempool(it->GetSharedTx(), reason, mempool_sequence);
421  }
422 
423  const uint256 hash = it->GetTx().GetHash();
424  for (const CTxIn& txin : it->GetTx().vin)
425  mapNextTx.erase(txin.prevout);
426 
427  RemoveUnbroadcastTx(hash, true /* add logging because unchecked */ );
428 
429  if (vTxHashes.size() > 1) {
430  vTxHashes[it->vTxHashesIdx] = std::move(vTxHashes.back());
431  vTxHashes[it->vTxHashesIdx].second->vTxHashesIdx = it->vTxHashesIdx;
432  vTxHashes.pop_back();
433  if (vTxHashes.size() * 2 < vTxHashes.capacity())
434  vTxHashes.shrink_to_fit();
435  } else
436  vTxHashes.clear();
437 
438  totalTxSize -= it->GetTxSize();
439  m_total_fee -= it->GetFee();
440  cachedInnerUsage -= it->DynamicMemoryUsage();
441  cachedInnerUsage -= memusage::DynamicUsage(it->GetMemPoolParentsConst()) + memusage::DynamicUsage(it->GetMemPoolChildrenConst());
442  mapTx.erase(it);
445 }
446 
447 // Calculates descendants of entry that are not already in setDescendants, and adds to
448 // setDescendants. Assumes entryit is already a tx in the mempool and CTxMemPoolEntry::m_children
449 // is correct for tx and all descendants.
450 // Also assumes that if an entry is in setDescendants already, then all
451 // in-mempool descendants of it are already in setDescendants as well, so that we
452 // can save time by not iterating over those entries.
453 void CTxMemPool::CalculateDescendants(txiter entryit, setEntries& setDescendants) const
454 {
455  setEntries stage;
456  if (setDescendants.count(entryit) == 0) {
457  stage.insert(entryit);
458  }
459  // Traverse down the children of entry, only adding children that are not
460  // accounted for in setDescendants already (because those children have either
461  // already been walked, or will be walked in this iteration).
462  while (!stage.empty()) {
463  txiter it = *stage.begin();
464  setDescendants.insert(it);
465  stage.erase(it);
466 
467  const CTxMemPoolEntry::Children& children = it->GetMemPoolChildrenConst();
468  for (const CTxMemPoolEntry& child : children) {
469  txiter childiter = mapTx.iterator_to(child);
470  if (!setDescendants.count(childiter)) {
471  stage.insert(childiter);
472  }
473  }
474  }
475 }
476 
478 {
479  // Remove transaction from memory pool
481  setEntries txToRemove;
482  txiter origit = mapTx.find(origTx.GetHash());
483  if (origit != mapTx.end()) {
484  txToRemove.insert(origit);
485  } else {
486  // When recursively removing but origTx isn't in the mempool
487  // be sure to remove any children that are in the pool. This can
488  // happen during chain re-orgs if origTx isn't re-accepted into
489  // the mempool for any reason.
490  for (unsigned int i = 0; i < origTx.vout.size(); i++) {
491  auto it = mapNextTx.find(COutPoint(origTx.GetHash(), i));
492  if (it == mapNextTx.end())
493  continue;
494  txiter nextit = mapTx.find(it->second->GetHash());
495  assert(nextit != mapTx.end());
496  txToRemove.insert(nextit);
497  }
498  }
499  setEntries setAllRemoves;
500  for (txiter it : txToRemove) {
501  CalculateDescendants(it, setAllRemoves);
502  }
503 
504  RemoveStaged(setAllRemoves, false, reason);
505 }
506 
507 void CTxMemPool::removeForReorg(CChainState& active_chainstate, int flags)
508 {
509  // Remove transactions spending a coinbase which are now immature and no-longer-final transactions
511  setEntries txToRemove;
512  for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
513  const CTransaction& tx = it->GetTx();
514  LockPoints lp = it->GetLockPoints();
515  assert(std::addressof(::ChainstateActive()) == std::addressof(active_chainstate));
516  bool validLP = TestLockPointValidity(active_chainstate.m_chain, &lp);
517  if (!CheckFinalTx(active_chainstate.m_chain.Tip(), tx, flags) || !CheckSequenceLocks(active_chainstate, *this, tx, flags, &lp, validLP)) {
518  // Note if CheckSequenceLocks fails the LockPoints may still be invalid
519  // So it's critical that we remove the tx and not depend on the LockPoints.
520  txToRemove.insert(it);
521  } else if (it->GetSpendsCoinbase()) {
522  for (const CTxIn& txin : tx.vin) {
523  indexed_transaction_set::const_iterator it2 = mapTx.find(txin.prevout.hash);
524  if (it2 != mapTx.end())
525  continue;
526  const Coin &coin = active_chainstate.CoinsTip().AccessCoin(txin.prevout);
527  if (m_check_ratio != 0) assert(!coin.IsSpent());
528  unsigned int nMemPoolHeight = active_chainstate.m_chain.Tip()->nHeight + 1;
529  if (coin.IsSpent() || (coin.IsCoinBase() && ((signed long)nMemPoolHeight) - coin.nHeight < COINBASE_MATURITY)) {
530  txToRemove.insert(it);
531  break;
532  }
533  }
534  }
535  if (!validLP) {
536  mapTx.modify(it, update_lock_points(lp));
537  }
538  }
539  setEntries setAllRemoves;
540  for (txiter it : txToRemove) {
541  CalculateDescendants(it, setAllRemoves);
542  }
543  RemoveStaged(setAllRemoves, false, MemPoolRemovalReason::REORG);
544 }
545 
547 {
548  // Remove transactions which depend on inputs of tx, recursively
550  for (const CTxIn &txin : tx.vin) {
551  auto it = mapNextTx.find(txin.prevout);
552  if (it != mapNextTx.end()) {
553  const CTransaction &txConflict = *it->second;
554  if (txConflict != tx)
555  {
556  ClearPrioritisation(txConflict.GetHash());
558  }
559  }
560  }
561 }
562 
566 void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight)
567 {
569  std::vector<const CTxMemPoolEntry*> entries;
570  for (const auto& tx : vtx)
571  {
572  uint256 hash = tx->GetHash();
573 
574  indexed_transaction_set::iterator i = mapTx.find(hash);
575  if (i != mapTx.end())
576  entries.push_back(&*i);
577  }
578  // Before the txs in the new block have been removed from the mempool, update policy estimates
579  if (minerPolicyEstimator) {minerPolicyEstimator->processBlock(nBlockHeight, entries);}
580  for (const auto& tx : vtx)
581  {
582  txiter it = mapTx.find(tx->GetHash());
583  if (it != mapTx.end()) {
584  setEntries stage;
585  stage.insert(it);
587  }
588  removeConflicts(*tx);
590  }
593 }
594 
596 {
597  mapTx.clear();
598  mapNextTx.clear();
599  totalTxSize = 0;
600  m_total_fee = 0;
601  cachedInnerUsage = 0;
606 }
607 
609 {
610  LOCK(cs);
611  _clear();
612 }
613 
614 static void CheckInputsAndUpdateCoins(const CTransaction& tx, CCoinsViewCache& mempoolDuplicate, const int64_t spendheight)
615 {
616  TxValidationState dummy_state; // Not used. CheckTxInputs() should always pass
617  CAmount txfee = 0;
618  bool fCheckResult = tx.IsCoinBase() || Consensus::CheckTxInputs(tx, dummy_state, mempoolDuplicate, spendheight, txfee);
619  assert(fCheckResult);
620  UpdateCoins(tx, mempoolDuplicate, std::numeric_limits<int>::max());
621 }
622 
623 void CTxMemPool::check(CChainState& active_chainstate) const
624 {
625  if (m_check_ratio == 0) return;
626 
627  if (GetRand(m_check_ratio) >= 1) return;
628 
630  LOCK(cs);
631  LogPrint(BCLog::MEMPOOL, "Checking mempool with %u transactions and %u inputs\n", (unsigned int)mapTx.size(), (unsigned int)mapNextTx.size());
632 
633  uint64_t checkTotal = 0;
634  CAmount check_total_fee{0};
635  uint64_t innerUsage = 0;
636 
637  CCoinsViewCache& active_coins_tip = active_chainstate.CoinsTip();
638  assert(std::addressof(::ChainstateActive().CoinsTip()) == std::addressof(active_coins_tip)); // TODO: REVIEW-ONLY, REMOVE IN FUTURE COMMIT
639  CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(&active_coins_tip));
640  const int64_t spendheight = active_chainstate.m_chain.Height() + 1;
641  assert(g_chainman.m_blockman.GetSpendHeight(mempoolDuplicate) == spendheight); // TODO: REVIEW-ONLY, REMOVE IN FUTURE COMMIT
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  // If an entry in the mempool exists, always return that one, as it's guaranteed to never
923  // conflict with the underlying cache, and it cannot have pruned entries (as it contains full)
924  // transactions. First checking the underlying cache risks returning a pruned entry instead.
925  CTransactionRef ptx = mempool.get(outpoint.hash);
926  if (ptx) {
927  if (outpoint.n < ptx->vout.size()) {
928  coin = Coin(ptx->vout[outpoint.n], MEMPOOL_HEIGHT, false);
929  return true;
930  } else {
931  return false;
932  }
933  }
934  return base->GetCoin(outpoint, coin);
935 }
936 
938  LOCK(cs);
939  // Estimate the overhead of mapTx to be 15 pointers + an allocation, as no exact formula for boost::multi_index_contained is implemented.
940  return memusage::MallocUsage(sizeof(CTxMemPoolEntry) + 15 * sizeof(void*)) * mapTx.size() + memusage::DynamicUsage(mapNextTx) + memusage::DynamicUsage(mapDeltas) + memusage::DynamicUsage(vTxHashes) + cachedInnerUsage;
941 }
942 
943 void CTxMemPool::RemoveUnbroadcastTx(const uint256& txid, const bool unchecked) {
944  LOCK(cs);
945 
946  if (m_unbroadcast_txids.erase(txid))
947  {
948  LogPrint(BCLog::MEMPOOL, "Removed %i from set of unbroadcast txns%s\n", txid.GetHex(), (unchecked ? " before confirmation that txn was sent out" : ""));
949  }
950 }
951 
952 void CTxMemPool::RemoveStaged(setEntries &stage, bool updateDescendants, MemPoolRemovalReason reason) {
954  UpdateForRemoveFromMempool(stage, updateDescendants);
955  for (txiter it : stage) {
956  removeUnchecked(it, reason);
957  }
958 }
959 
960 int CTxMemPool::Expire(std::chrono::seconds time)
961 {
963  indexed_transaction_set::index<entry_time>::type::iterator it = mapTx.get<entry_time>().begin();
964  setEntries toremove;
965  while (it != mapTx.get<entry_time>().end() && it->GetTime() < time) {
966  toremove.insert(mapTx.project<0>(it));
967  it++;
968  }
969  setEntries stage;
970  for (txiter removeit : toremove) {
971  CalculateDescendants(removeit, stage);
972  }
974  return stage.size();
975 }
976 
977 void CTxMemPool::addUnchecked(const CTxMemPoolEntry &entry, bool validFeeEstimate)
978 {
979  setEntries setAncestors;
980  uint64_t nNoLimit = std::numeric_limits<uint64_t>::max();
981  std::string dummy;
982  CalculateMemPoolAncestors(entry, setAncestors, nNoLimit, nNoLimit, nNoLimit, nNoLimit, dummy);
983  return addUnchecked(entry, setAncestors, validFeeEstimate);
984 }
985 
986 void CTxMemPool::UpdateChild(txiter entry, txiter child, bool add)
987 {
990  if (add && entry->GetMemPoolChildren().insert(*child).second) {
991  cachedInnerUsage += memusage::IncrementalDynamicUsage(s);
992  } else if (!add && entry->GetMemPoolChildren().erase(*child)) {
993  cachedInnerUsage -= memusage::IncrementalDynamicUsage(s);
994  }
995 }
996 
997 void CTxMemPool::UpdateParent(txiter entry, txiter parent, bool add)
998 {
1001  if (add && entry->GetMemPoolParents().insert(*parent).second) {
1002  cachedInnerUsage += memusage::IncrementalDynamicUsage(s);
1003  } else if (!add && entry->GetMemPoolParents().erase(*parent)) {
1004  cachedInnerUsage -= memusage::IncrementalDynamicUsage(s);
1005  }
1006 }
1007 
1008 CFeeRate CTxMemPool::GetMinFee(size_t sizelimit) const {
1009  LOCK(cs);
1011  return CFeeRate(llround(rollingMinimumFeeRate));
1012 
1013  int64_t time = GetTime();
1014  if (time > lastRollingFeeUpdate + 10) {
1015  double halflife = ROLLING_FEE_HALFLIFE;
1016  if (DynamicMemoryUsage() < sizelimit / 4)
1017  halflife /= 4;
1018  else if (DynamicMemoryUsage() < sizelimit / 2)
1019  halflife /= 2;
1020 
1021  rollingMinimumFeeRate = rollingMinimumFeeRate / pow(2.0, (time - lastRollingFeeUpdate) / halflife);
1022  lastRollingFeeUpdate = time;
1023 
1026  return CFeeRate(0);
1027  }
1028  }
1029  return std::max(CFeeRate(llround(rollingMinimumFeeRate)), incrementalRelayFee);
1030 }
1031 
1033  AssertLockHeld(cs);
1034  if (rate.GetFeePerK() > rollingMinimumFeeRate) {
1037  }
1038 }
1039 
1040 void CTxMemPool::TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpendsRemaining) {
1041  AssertLockHeld(cs);
1042 
1043  unsigned nTxnRemoved = 0;
1044  CFeeRate maxFeeRateRemoved(0);
1045  while (!mapTx.empty() && DynamicMemoryUsage() > sizelimit) {
1046  indexed_transaction_set::index<descendant_score>::type::iterator it = mapTx.get<descendant_score>().begin();
1047 
1048  // We set the new mempool min fee to the feerate of the removed set, plus the
1049  // "minimum reasonable fee rate" (ie some value under which we consider txn
1050  // to have 0 fee). This way, we don't allow txn to enter mempool with feerate
1051  // equal to txn which were removed with no block in between.
1052  CFeeRate removed(it->GetModFeesWithDescendants(), it->GetSizeWithDescendants());
1053  removed += incrementalRelayFee;
1054  trackPackageRemoved(removed);
1055  maxFeeRateRemoved = std::max(maxFeeRateRemoved, removed);
1056 
1057  setEntries stage;
1058  CalculateDescendants(mapTx.project<0>(it), stage);
1059  nTxnRemoved += stage.size();
1060 
1061  std::vector<CTransaction> txn;
1062  if (pvNoSpendsRemaining) {
1063  txn.reserve(stage.size());
1064  for (txiter iter : stage)
1065  txn.push_back(iter->GetTx());
1066  }
1068  if (pvNoSpendsRemaining) {
1069  for (const CTransaction& tx : txn) {
1070  for (const CTxIn& txin : tx.vin) {
1071  if (exists(txin.prevout.hash)) continue;
1072  pvNoSpendsRemaining->push_back(txin.prevout);
1073  }
1074  }
1075  }
1076  }
1077 
1078  if (maxFeeRateRemoved > CFeeRate(0)) {
1079  LogPrint(BCLog::MEMPOOL, "Removed %u txn, rolling minimum fee bumped to %s\n", nTxnRemoved, maxFeeRateRemoved.ToString());
1080  }
1081 }
1082 
1084  // find parent with highest descendant count
1085  std::vector<txiter> candidates;
1086  setEntries counted;
1087  candidates.push_back(entry);
1088  uint64_t maximum = 0;
1089  while (candidates.size()) {
1090  txiter candidate = candidates.back();
1091  candidates.pop_back();
1092  if (!counted.insert(candidate).second) continue;
1093  const CTxMemPoolEntry::Parents& parents = candidate->GetMemPoolParentsConst();
1094  if (parents.size() == 0) {
1095  maximum = std::max(maximum, candidate->GetCountWithDescendants());
1096  } else {
1097  for (const CTxMemPoolEntry& i : parents) {
1098  candidates.push_back(mapTx.iterator_to(i));
1099  }
1100  }
1101  }
1102  return maximum;
1103 }
1104 
1105 void CTxMemPool::GetTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) const {
1106  LOCK(cs);
1107  auto it = mapTx.find(txid);
1108  ancestors = descendants = 0;
1109  if (it != mapTx.end()) {
1110  ancestors = it->GetCountWithAncestors();
1111  descendants = CalculateDescendantMaximum(it);
1112  }
1113 }
1114 
1116 {
1117  LOCK(cs);
1118  return m_is_loaded;
1119 }
1120 
1121 void CTxMemPool::SetIsLoaded(bool loaded)
1122 {
1123  LOCK(cs);
1124  m_is_loaded = loaded;
1125 }
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:352
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:1008
CBlockPolicyEstimator::processTransaction
void processTransaction(const CTxMemPoolEntry &entry, bool validFeeEstimate)
Process a transaction accepted to the mempool.
Definition: fees.cpp:518
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:409
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
CheckSequenceLocks
bool CheckSequenceLocks(CChainState &active_chainstate, const CTxMemPool &pool, const CTransaction &tx, int flags, LockPoints *lp, bool useExistingLockPoints)
Definition: validation.cpp:264
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:1419
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:1115
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:1105
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:1040
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:473
GetTime
int64_t GetTime()
DEPRECATED Use either GetSystemTimeInSeconds (not mockable) or GetTime<T> (mockable)
Definition: time.cpp:26
CTxMemPool::SetIsLoaded
void SetIsLoaded(bool loaded)
Sets the current loaded state.
Definition: txmempool.cpp:1121
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:247
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:153
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
CTxMemPool::GetTransactionsUpdated
unsigned int GetTransactionsUpdated() const
Definition: txmempool.cpp:347
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:1083
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:233
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:199
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
ChainstateActive
CChainState & ChainstateActive()
Please prefer the identical ChainstateManager::ActiveChainstate.
Definition: validation.cpp:107
GetMainSignals
CMainSignals & GetMainSignals()
Definition: validationinterface.cpp:116
txmempool.h
CCoinsView
Abstract view on the open txout dataset.
Definition: coins.h:159
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:61
CCoinsViewMemPool::mempool
const CTxMemPool & mempool
Definition: txmempool.h:866
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
CTxMemPool::lastRollingFeeUpdate
int64_t lastRollingFeeUpdate
Definition: txmempool.h:488
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:335
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
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:32
CTxMemPool::mapDeltas
std::map< uint256, CAmount > mapDeltas
Definition: txmempool.h:590
Coin::nHeight
uint32_t nHeight
at which height this containing transaction was included in the active block chain
Definition: coins.h:42
CTxMemPool::UpdateChild
void UpdateChild(txiter entry, txiter child, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:986
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:324
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:614
consensus.h
CTxMemPoolEntry::UpdateDescendantState
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount)
Definition: txmempool.cpp:315
CBlockPolicyEstimator
Definition: fees.h:131
time.h
g_chainman
ChainstateManager g_chainman
Definition: validation.cpp:105
LogPrintf
#define LogPrintf(...)
Definition: logging.h:183
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:546
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:997
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:943
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:108
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:38
CTxMemPool::minerPolicyEstimator
CBlockPolicyEstimator * minerPolicyEstimator
Definition: txmempool.h:482
CChainState
CChainState stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:538
LogPrint
#define LogPrint(category,...)
Definition: logging.h:187
CompareTxMemPoolEntryByScore
Definition: txmempool.h:296
CTxMemPoolEntry::UpdateFeeDelta
void UpdateFeeDelta(int64_t feeDelta)
Definition: txmempool.cpp:41
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:245
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:255
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:960
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:218
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:215
CCoinsViewBacked
CCoinsView backed by another CCoinsView.
Definition: coins.h:196
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::blockSinceLastRollingFeeBump
bool blockSinceLastRollingFeeBump
Definition: txmempool.h:489
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:211
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:1032
CTxMemPool::rollingMinimumFeeRate
double rollingMinimumFeeRate
minimum fee to get into the pool, decreases exponentially
Definition: txmempool.h:490
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:952
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:23
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:48
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:937
CTxMemPoolEntry::GetTxSize
size_t GetTxSize() const
Definition: txmempool.cpp:53
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:584
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:81
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:59
CTxMemPool::cacheMap
std::map< txiter, setEntries, CompareIteratorByHash > cacheMap
Definition: txmempool.h:575
CTxMemPool::isSpent
bool isSpent(const COutPoint &outpoint) const
Definition: txmempool.cpp:341
CTxMemPoolEntry::sigOpCost
const int64_t sigOpCost
Total sigop cost.
Definition: txmempool.h:99
CTxMemPool::clear
void clear()
Definition: txmempool.cpp:608
CTxMemPool::_clear
void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:595
assert
assert(std::addressof(::ChainstateActive().CoinsTip())==std::addressof(coins_cache))
reverse_iterate
reverse_range< T > reverse_iterate(T &x)
Definition: reverse_iterator.h:34
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:621
CChainState::m_chain
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:604
it
auto it
Definition: validation.cpp:398
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:566
CTxMemPool::removeForReorg
void removeForReorg(CChainState &active_chainstate, int flags) EXCLUSIVE_LOCKS_REQUIRED(cs
Definition: txmempool.cpp:507
CTxMemPool::removeRecursive
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:477
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:453
FormatMoney
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
Definition: moneystr.cpp:12
Coin::IsCoinBase
bool IsCoinBase() const
Definition: coins.h:57
CTxMemPoolEntry::GetTx
const CTransaction & GetTx() const
Definition: txmempool.h:122