Bitcoin ABC 0.33.10
P2P Digital Currency
txmempool.cpp
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-2016 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 <blockindex.h>
9#include <clientversion.h>
10#include <coins.h>
11#include <common/system.h>
12#include <config.h>
13#include <consensus/consensus.h>
14#include <consensus/tx_verify.h>
16#include <logging.h>
17#include <policy/fees.h>
18#include <policy/policy.h>
19#include <reverse_iterator.h>
20#include <undo.h>
21#include <util/check.h>
22#include <util/moneystr.h>
23#include <util/time.h>
24#include <validationinterface.h>
25
26#include <algorithm>
27#include <cmath>
28#include <limits>
29#include <vector>
30
32 setEntries &setAncestors,
33 CTxMemPoolEntry::Parents &staged_ancestors) const {
34 while (!staged_ancestors.empty()) {
35 const auto stage = staged_ancestors.begin()->get();
36
37 txiter stageit = mapTx.find(stage->GetTx().GetId());
38 assert(stageit != mapTx.end());
39 setAncestors.insert(stageit);
40 staged_ancestors.erase(staged_ancestors.begin());
41
42 const CTxMemPoolEntry::Parents &parents =
43 (*stageit)->GetMemPoolParentsConst();
44 for (const auto &parent : parents) {
45 txiter parent_it = mapTx.find(parent.get()->GetTx().GetId());
46 assert(parent_it != mapTx.end());
47
48 // If this is a new ancestor, add it.
49 if (setAncestors.count(parent_it) == 0) {
50 staged_ancestors.insert(parent);
51 }
52 }
53 }
54
55 return true;
56}
57
59 const CTxMemPoolEntryRef &entry, setEntries &setAncestors,
60 bool fSearchForParents /* = true */) const {
61 CTxMemPoolEntry::Parents staged_ancestors;
62 const CTransaction &tx = entry->GetTx();
63
64 if (fSearchForParents) {
65 // Get parents of this transaction that are in the mempool
66 // GetMemPoolParents() is only valid for entries in the mempool, so we
67 // iterate mapTx to find parents.
68 for (const CTxIn &in : tx.vin) {
69 std::optional<txiter> piter = GetIter(in.prevout.GetTxId());
70 if (!piter) {
71 continue;
72 }
73 staged_ancestors.insert(**piter);
74 }
75 } else {
76 // If we're not searching for parents, we require this to be an entry in
77 // the mempool already.
78 staged_ancestors = entry->GetMemPoolParentsConst();
79 }
80
81 return CalculateAncestors(setAncestors, staged_ancestors);
82}
83
85 // add or remove this tx as a child of each parent
86 for (const auto &parent : (*it)->GetMemPoolParentsConst()) {
87 auto parent_it = mapTx.find(parent.get()->GetTx().GetId());
88 assert(parent_it != mapTx.end());
89 UpdateChild(parent_it, it, add);
90 }
91}
92
94 const CTxMemPoolEntry::Children &children =
95 (*it)->GetMemPoolChildrenConst();
96 for (const auto &child : children) {
97 auto updateIt = mapTx.find(child.get()->GetTx().GetId());
98 assert(updateIt != mapTx.end());
99 UpdateParent(updateIt, it, false);
100 }
101}
102
104 for (txiter removeIt : entriesToRemove) {
105 // Note that UpdateParentsOf severs the child links that point to
106 // removeIt in the entries for the parents of removeIt.
107 UpdateParentsOf(false, removeIt);
108 }
109
110 // After updating all the parent links, we can now sever the link between
111 // each transaction being removed and any mempool children (ie, update
112 // CTxMemPoolEntry::m_parents for each direct child of a transaction being
113 // removed).
114 for (txiter removeIt : entriesToRemove) {
115 UpdateChildrenForRemoval(removeIt);
116 }
117}
118
119CTxMemPool::CTxMemPool(const Config &config, const Options &opts)
120 : m_check_ratio(opts.check_ratio),
121 m_finalizedTxsFitter(node::BlockFitter(config)),
122 m_orphanage(std::make_unique<TxOrphanage>()),
123 m_conflicting(std::make_unique<TxConflicting>()),
124 m_max_size_bytes{opts.max_size_bytes}, m_expiry{opts.expiry},
125 m_min_relay_feerate{opts.min_relay_feerate},
126 m_dust_relay_feerate{opts.dust_relay_feerate},
127 m_permit_bare_multisig{opts.permit_bare_multisig},
128 m_max_datacarrier_bytes{opts.max_datacarrier_bytes},
129 m_require_standard{opts.require_standard} {
130 // lock free clear
131 _clear();
132}
133
135
136bool CTxMemPool::isSpent(const COutPoint &outpoint) const {
137 LOCK(cs);
138 return mapNextTx.count(outpoint);
139}
140
143}
144
147}
148
150 // get a guaranteed unique id (in case tests re-use the same object)
151 entry->SetEntryId(nextEntryId++);
152
153 // Update transaction for any feeDelta created by PrioritiseTransaction
154 {
155 Amount feeDelta = Amount::zero();
156 ApplyDelta(entry->GetTx().GetId(), feeDelta);
157 // The following call to UpdateModifiedFee assumes no previous fee
158 // modifications
159 Assume(entry->GetFee() == entry->GetModifiedFee());
160 entry->UpdateModifiedFee(feeDelta);
161 }
162
163 // Add to memory pool without checking anything.
164 // Used by AcceptToMemoryPool(), which DOES do all the appropriate checks.
165 auto [newit, inserted] = mapTx.insert(entry);
166 // Sanity check: It is a programming error if insertion fails (uniqueness
167 // invariants in mapTx are violated, etc)
168 assert(inserted);
169 // Sanity check: We should always end up inserting at the end of the
170 // entry_id index
171 assert(&*mapTx.get<entry_id>().rbegin() == &*newit);
172
173 // Update cachedInnerUsage to include contained transaction's usage.
174 // (When we update the entry for in-mempool parents, memory usage will be
175 // further updated.)
176 cachedInnerUsage += entry->DynamicMemoryUsage();
177
178 const CTransactionRef tx = entry->GetSharedTx();
179 std::set<TxId> setParentTransactions;
180 for (const CTxIn &in : tx->vin) {
181 mapNextTx.insert(std::make_pair(&in.prevout, tx));
182 setParentTransactions.insert(in.prevout.GetTxId());
183 }
184 // Don't bother worrying about child transactions of this one. It is
185 // guaranteed that a new transaction arriving will not have any children,
186 // because such children would be orphans.
187
188 // Update ancestors with information about this tx
189 for (const auto &pit : GetIterSet(setParentTransactions)) {
190 UpdateParent(newit, pit, true);
191 }
192
193 UpdateParentsOf(true, newit);
194
196 totalTxSize += entry->GetTxSize();
197 m_total_fee += entry->GetFee();
198}
199
201 // We increment mempool sequence value no matter removal reason
202 // even if not directly reported below.
203 uint64_t mempool_sequence = GetAndIncrementSequence();
204
205 const TxId &txid = (*it)->GetTx().GetId();
206
207 if (reason != MemPoolRemovalReason::BLOCK) {
208 // Notify clients that a transaction has been removed from the mempool
209 // for any reason except being included in a block. Clients interested
210 // in transactions included in blocks can subscribe to the
211 // BlockConnected notification.
213 (*it)->GetSharedTx(), reason, mempool_sequence);
214
215 if (auto removed_tx = finalizedTxs.remove(txid)) {
216 m_finalizedTxsFitter.removeTxUnchecked(removed_tx->GetTxSize(),
217 removed_tx->GetSigChecks(),
218 removed_tx->GetFee());
219 }
220 }
221
222 for (const CTxIn &txin : (*it)->GetTx().vin) {
223 mapNextTx.erase(txin.prevout);
224 }
225
226 /* add logging because unchecked */
227 RemoveUnbroadcastTx(txid, true);
228
229 totalTxSize -= (*it)->GetTxSize();
230 m_total_fee -= (*it)->GetFee();
231 cachedInnerUsage -= (*it)->DynamicMemoryUsage();
232 cachedInnerUsage -=
233 memusage::DynamicUsage((*it)->GetMemPoolParentsConst()) +
234 memusage::DynamicUsage((*it)->GetMemPoolChildrenConst());
235 mapTx.erase(it);
237}
238
239// Calculates descendants of entry that are not already in setDescendants, and
240// adds to setDescendants. Assumes entryit is already a tx in the mempool and
241// CTxMemPoolEntry::m_children is correct for tx and all descendants. Also
242// assumes that if an entry is in setDescendants already, then all in-mempool
243// descendants of it are already in setDescendants as well, so that we can save
244// time by not iterating over those entries.
246 setEntries &setDescendants) const {
247 setEntries stage;
248 if (setDescendants.count(entryit) == 0) {
249 stage.insert(entryit);
250 }
251 // Traverse down the children of entry, only adding children that are not
252 // accounted for in setDescendants already (because those children have
253 // either already been walked, or will be walked in this iteration).
254 while (!stage.empty()) {
255 txiter it = *stage.begin();
256 setDescendants.insert(it);
257 stage.erase(stage.begin());
258
259 const CTxMemPoolEntry::Children &children =
260 (*it)->GetMemPoolChildrenConst();
261 for (const auto &child : children) {
262 txiter childiter = mapTx.find(child.get()->GetTx().GetId());
263 assert(childiter != mapTx.end());
264
265 if (!setDescendants.count(childiter)) {
266 stage.insert(childiter);
267 }
268 }
269 }
270}
271
272void CTxMemPool::removeRecursive(const CTransaction &origTx,
273 MemPoolRemovalReason reason) {
274 // Remove transaction from memory pool.
276 setEntries txToRemove;
277 txiter origit = mapTx.find(origTx.GetId());
278 if (origit != mapTx.end()) {
279 txToRemove.insert(origit);
280 } else {
281 // When recursively removing but origTx isn't in the mempool be sure to
282 // remove any children that are in the pool. This can happen during
283 // chain re-orgs if origTx isn't re-accepted into the mempool for any
284 // reason.
285 auto it = mapNextTx.lower_bound(COutPoint(origTx.GetId(), 0));
286 while (it != mapNextTx.end() &&
287 it->first->GetTxId() == origTx.GetId()) {
288 txiter nextit = mapTx.find(it->second->GetId());
289 assert(nextit != mapTx.end());
290 txToRemove.insert(nextit);
291 ++it;
292 }
293 }
294
295 setEntries setAllRemoves;
296 for (txiter it : txToRemove) {
297 CalculateDescendants(it, setAllRemoves);
298 }
299
300 RemoveStaged(setAllRemoves, reason);
301}
302
303void CTxMemPool::removeConflicts(const CTransaction &tx) {
304 // Remove transactions which depend on inputs of tx, recursively
306 for (const CTxIn &txin : tx.vin) {
307 auto it = mapNextTx.find(txin.prevout);
308 if (it != mapNextTx.end()) {
309 const CTransaction &txConflict = *it->second;
310 if (txConflict != tx) {
311 // We reject blocks that contains a tx conflicting with a
312 // finalized tx, so this should never happen
313 Assume(!isAvalancheFinalizedPreConsensus(txConflict.GetId()));
314 ClearPrioritisation(txConflict.GetId());
316 }
317 }
318 }
319}
320
326
327 lastRollingFeeUpdate = GetTime();
328 blockSinceLastRollingFeeBump = true;
329}
330
332 const std::unordered_set<TxId, SaltedTxIdHasher>
333 &confirmedTxIdsInNonFinalizedBlocks) {
335
336 std::vector<CTxMemPoolEntryRef> finalizedTxsToKeep;
339 if (mapTx.count(entry->GetTx().GetId()) > 0 ||
340 confirmedTxIdsInNonFinalizedBlocks.count(
341 entry->GetTx().GetId()) > 0) {
342 // The transaction is either in the mempool (not confirmed) or
343 // confirmed in a non-finalized block (which might be rejeted by
344 // avalanche), so we keep it in the radix tree.
345 finalizedTxsToKeep.push_back(entry);
346 }
347
348 // All the other transactions are either confirmed in the finalized
349 // block or in one of its ancestors.
350 return true;
351 });
352
353 // Clear the radix tree and add back the transactions that are not confirmed
354 decltype(finalizedTxs) empty;
355 std::swap(finalizedTxs, empty);
356
357 m_finalizedTxsFitter.resetBlock();
358 for (const auto &entry : finalizedTxsToKeep) {
359 // We don't need to proceed to all the checks that happen during
360 // finalization here so we only recompute the size and sigchecks.
361 if (finalizedTxs.insert(entry)) {
362 m_finalizedTxsFitter.addTx(entry->GetTxSize(),
363 entry->GetSigChecks(), entry->GetFee());
364 }
365 }
366
368}
369
371 mapTx.clear();
372 mapNextTx.clear();
373 totalTxSize = 0;
374 m_total_fee = Amount::zero();
375 cachedInnerUsage = 0;
376 lastRollingFeeUpdate = GetTime();
377 blockSinceLastRollingFeeBump = false;
378 rollingMinimumFeeRate = 0;
380}
381
382void CTxMemPool::clear(bool include_finalized_txs) {
383 LOCK(cs);
384 _clear();
385 if (include_finalized_txs) {
387 std::swap(finalizedTxs, empty);
388 m_finalizedTxsFitter.resetBlock();
389 }
390}
391
392void CTxMemPool::check(const CCoinsViewCache &active_coins_tip,
393 int64_t spendheight) const {
394 if (m_check_ratio == 0) {
395 return;
396 }
397
398 if (FastRandomContext().randrange(m_check_ratio) >= 1) {
399 return;
400 }
401
403 LOCK(cs);
405 "Checking mempool with %u transactions and %u inputs\n",
406 (unsigned int)mapTx.size(), (unsigned int)mapNextTx.size());
407
408 uint64_t checkTotal = 0;
409 Amount check_total_fee{Amount::zero()};
410 uint64_t innerUsage = 0;
411
412 CCoinsViewCache mempoolDuplicate(
413 const_cast<CCoinsViewCache *>(&active_coins_tip));
414
415 for (const CTxMemPoolEntryRef &entry : mapTx.get<entry_id>()) {
416 checkTotal += entry->GetTxSize();
417 check_total_fee += entry->GetFee();
418 innerUsage += entry->DynamicMemoryUsage();
419 const CTransaction &tx = entry->GetTx();
420 innerUsage += memusage::DynamicUsage(entry->GetMemPoolParentsConst()) +
421 memusage::DynamicUsage(entry->GetMemPoolChildrenConst());
422
423 CTxMemPoolEntry::Parents setParentCheck;
424 for (const CTxIn &txin : tx.vin) {
425 // Check that every mempool transaction's inputs refer to available
426 // coins, or other mempool tx's.
427 txiter parentIt = mapTx.find(txin.prevout.GetTxId());
428 if (parentIt != mapTx.end()) {
429 const CTransaction &parentTx = (*parentIt)->GetTx();
430 assert(parentTx.vout.size() > txin.prevout.GetN() &&
431 !parentTx.vout[txin.prevout.GetN()].IsNull());
432 setParentCheck.insert(*parentIt);
433 // also check that parents have a topological ordering before
434 // their children
435 assert((*parentIt)->GetEntryId() < entry->GetEntryId());
436 }
437 // We are iterating through the mempool entries sorted
438 // topologically.
439 // All parents must have been checked before their children and
440 // their coins added to the mempoolDuplicate coins cache.
441 assert(mempoolDuplicate.HaveCoin(txin.prevout));
442 // Check whether its inputs are marked in mapNextTx.
443 auto prevoutNextIt = mapNextTx.find(txin.prevout);
444 assert(prevoutNextIt != mapNextTx.end());
445 assert(prevoutNextIt->first == &txin.prevout);
446 assert(prevoutNextIt->second.get() == &tx);
447 }
448 auto comp = [](const auto &a, const auto &b) -> bool {
449 return a.get()->GetTx().GetId() == b.get()->GetTx().GetId();
450 };
451 assert(setParentCheck.size() == entry->GetMemPoolParentsConst().size());
452 assert(std::equal(setParentCheck.begin(), setParentCheck.end(),
453 entry->GetMemPoolParentsConst().begin(), comp));
454
455 // Verify ancestor state is correct.
456 setEntries setAncestors;
457 std::string dummy;
458
459 const bool ok = CalculateMemPoolAncestors(entry, setAncestors);
460 assert(ok);
461
462 // all ancestors should have entryId < this tx's entryId
463 for (const auto &ancestor : setAncestors) {
464 assert((*ancestor)->GetEntryId() < entry->GetEntryId());
465 }
466
467 // Check children against mapNextTx
468 CTxMemPoolEntry::Children setChildrenCheck;
469 auto iter = mapNextTx.lower_bound(COutPoint(entry->GetTx().GetId(), 0));
470 for (; iter != mapNextTx.end() &&
471 iter->first->GetTxId() == entry->GetTx().GetId();
472 ++iter) {
473 txiter childIt = mapTx.find(iter->second->GetId());
474 // mapNextTx points to in-mempool transactions
475 assert(childIt != mapTx.end());
476 setChildrenCheck.insert(*childIt);
477 }
478 assert(setChildrenCheck.size() ==
479 entry->GetMemPoolChildrenConst().size());
480 assert(std::equal(setChildrenCheck.begin(), setChildrenCheck.end(),
481 entry->GetMemPoolChildrenConst().begin(), comp));
482
483 // Not used. CheckTxInputs() should always pass
484 TxValidationState dummy_state;
485 Amount txfee{Amount::zero()};
486 assert(!tx.IsCoinBase());
487 assert(Consensus::CheckTxInputs(tx, dummy_state, mempoolDuplicate,
488 spendheight, txfee));
489 for (const auto &input : tx.vin) {
490 mempoolDuplicate.SpendCoin(input.prevout);
491 }
492 AddCoins(mempoolDuplicate, tx, std::numeric_limits<int>::max());
493 }
494
495 for (auto &[_, nextTx] : mapNextTx) {
496 txiter it = mapTx.find(nextTx->GetId());
497 assert(it != mapTx.end());
498 assert((*it)->GetSharedTx() == nextTx);
499 }
500
501 assert(totalTxSize == checkTotal);
502 assert(m_total_fee == check_total_fee);
503 assert(innerUsage == cachedInnerUsage);
504}
505
507 const TxId &txidb) const {
508 LOCK(cs);
509 auto it1 = mapTx.find(txida);
510 if (it1 == mapTx.end()) {
511 return false;
512 }
513 auto it2 = mapTx.find(txidb);
514 if (it2 == mapTx.end()) {
515 return true;
516 }
517 return (*it1)->GetEntryId() < (*it2)->GetEntryId();
518}
519
520void CTxMemPool::getAllTxIds(std::vector<TxId> &vtxid) const {
521 LOCK(cs);
522
523 vtxid.clear();
524 vtxid.reserve(mapTx.size());
525
526 for (const auto &entry : mapTx.get<entry_id>()) {
527 vtxid.push_back(entry->GetTx().GetId());
528 }
529}
530
531static TxMempoolInfo
532GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it) {
533 return TxMempoolInfo{(*it)->GetSharedTx(), (*it)->GetTime(),
534 (*it)->GetFee(), (*it)->GetTxSize(),
535 (*it)->GetModifiedFee() - (*it)->GetFee()};
536}
537
538std::vector<TxMempoolInfo> CTxMemPool::infoAll() const {
539 LOCK(cs);
540
541 std::vector<TxMempoolInfo> ret;
542 ret.reserve(mapTx.size());
543
544 const auto &index = mapTx.get<entry_id>();
545 for (auto it = index.begin(); it != index.end(); ++it) {
546 ret.push_back(GetInfo(mapTx.project<0>(it)));
547 }
548
549 return ret;
550}
551
552bool CTxMemPool::setAvalancheFinalized(const CTxMemPoolEntryRef &tx,
553 const Consensus::Params &params,
554 const CBlockIndex &active_chain_tip,
555 std::vector<TxId> &finalizedTxIds) {
558
559 auto it = mapTx.find(tx->GetTx().GetId());
560 if (it == mapTx.end()) {
561 // Trying to finalize a tx that is not in the mempool !
562 LogPrintf("Trying to finalize tx %s that is not in the mempool\n",
563 tx->GetTx().GetId().ToString());
564 return false;
565 }
566
567 setEntries setAncestors;
568 setAncestors.insert(it);
569 if (!CalculateMemPoolAncestors(tx, setAncestors,
570 /*fSearchForParents=*/false)) {
571 // Failed to get a list of parents for this tx. If we finalize it we
572 // might be missing a parent and generate an invalid block.
573 LogPrintf("Failed to calculate ancestors for tx %s\n",
574 tx->GetTx().GetId().ToString());
575 return false;
576 }
577
578 // Make sure the tx chain would fit the block before adding them.
579 uint64_t sumOfTxSize{0};
580 uint64_t sumOfTxSigChecks{0};
581 for (auto iter_it = setAncestors.begin(); iter_it != setAncestors.end();) {
582 // iter_it is an iterator of mapTx iterator (aka txiter)
583 CTxMemPoolEntryRef entry = **iter_it;
584
585 TxValidationState state;
586 if (!ContextualCheckTransactionForCurrentBlock(active_chain_tip, params,
587 entry->GetTx(), state)) {
589 "Delay storing finalized tx %s that would cause the block "
590 "to be invalid%s (%s)\n",
591 tx->GetTx().GetId().ToString(),
592 entry->GetSharedTx()->GetId() == tx->GetSharedTx()->GetId()
593 ? ""
594 : strprintf(" for parent %s",
595 entry->GetSharedTx()->GetId().ToString()),
596 state.ToString());
597 return false;
598 }
599
600 if (m_finalizedTxsFitter.isBelowBlockMinFeeRate(
601 entry->GetModifiedFeeRate())) {
603 "Delay storing finalized tx %s due to fee rate below the "
604 "block mininmum%s (see -blockmintxfee)\n",
605 tx->GetTx().GetId().ToString(),
606 entry->GetSharedTx()->GetId() == tx->GetSharedTx()->GetId()
607 ? ""
608 : strprintf(" for parent %s",
609 entry->GetSharedTx()->GetId().ToString()));
610 return false;
611 }
612
613 // It is possible (and normal) that an ancestor is already finalized.
614 // Beware to not account for it in this case.
615 if (isAvalancheFinalizedPreConsensus(entry->GetTx().GetId())) {
616 iter_it = setAncestors.erase(iter_it);
617 continue;
618 }
619
620 sumOfTxSize += entry->GetTxSize();
621 sumOfTxSigChecks += entry->GetSigChecks();
622 ++iter_it;
623 }
624
625 if (!m_finalizedTxsFitter.testTxFits(sumOfTxSize, sumOfTxSigChecks)) {
626 LogPrint(
628 "Delay storing finalized tx %s as it won't fit in the next block\n",
629 tx->GetTx().GetId().ToString());
630 return false;
631 }
632
633 finalizedTxIds.clear();
634
635 // Now let's add the txs !
636 // At this stage the set of ancestors is free if already finalized txs
637 for (txiter ancestor_it : setAncestors) {
638 if (finalizedTxs.insert(*ancestor_it)) {
639 m_finalizedTxsFitter.addTx((*ancestor_it)->GetTxSize(),
640 (*ancestor_it)->GetSigChecks(),
641 (*ancestor_it)->GetFee());
642
643 finalizedTxIds.push_back((*ancestor_it)->GetTx().GetId());
644
646 (*ancestor_it)->GetSharedTx());
647 }
648 }
649
651
652 return true;
653}
654
658
659 const TxId &txid = tx->GetId();
660 if (auto it = GetIter(txid)) {
661 CTxMemPoolEntryRef entry = **it;
662
663 // The tx is in the mempool, check it would fit the next block or if
664 // it's already full of finalized txs.
665 return !m_finalizedTxsFitter.isBelowBlockMinFeeRate(
666 entry->GetModifiedFeeRate()) &&
667 m_finalizedTxsFitter.testTxFits(entry->GetTxSize(),
668 entry->GetSigChecks());
669 }
670
671 // Otherwise check if it's in the conflicting pool. If we reach this point
672 // this means that the transaction has been rejected so no need to check if
673 // it fits the block, however we don't want to discard it either so the vote
674 // continue until the tx is invalidated.
676 return m_conflicting && m_conflicting->HaveTx(txid));
677}
678
680 LOCK(cs);
681 indexed_transaction_set::const_iterator i = mapTx.find(txid);
682 if (i == mapTx.end()) {
683 return nullptr;
684 }
685
686 return (*i)->GetSharedTx();
687}
688
690 LOCK(cs);
691 indexed_transaction_set::const_iterator i = mapTx.find(txid);
692 if (i == mapTx.end()) {
693 return TxMempoolInfo();
694 }
695
696 return GetInfo(i);
697}
698
700 LOCK(cs);
701
702 // minerPolicy uses recent blocks to figure out a reasonable fee. This
703 // may disagree with the rollingMinimumFeerate under certain scenarios
704 // where the mempool increases rapidly, or blocks are being mined which
705 // do not contain propagated transactions.
706 return std::max(m_min_relay_feerate, GetMinFee());
707}
708
710 const Amount nFeeDelta) {
711 {
712 LOCK(cs);
713 Amount &delta = mapDeltas[txid];
714 delta.SaturatingAdd(nFeeDelta);
715 txiter it = mapTx.find(txid);
716 if (it != mapTx.end()) {
717 mapTx.modify(it, [&nFeeDelta](CTxMemPoolEntryRef &e) {
718 e->UpdateModifiedFee(nFeeDelta);
719 });
721 }
722 }
723 LogPrintf("PrioritiseTransaction: %s fee += %s\n", txid.ToString(),
724 FormatMoney(nFeeDelta));
725}
726
727void CTxMemPool::ApplyDelta(const TxId &txid, Amount &nFeeDelta) const {
729 std::map<TxId, Amount>::const_iterator pos = mapDeltas.find(txid);
730 if (pos == mapDeltas.end()) {
731 return;
732 }
733
734 nFeeDelta += pos->second;
735}
736
739 mapDeltas.erase(txid);
740}
741
742CTransactionRef CTxMemPool::GetConflictTx(const COutPoint &prevout) const {
743 const auto it = mapNextTx.find(prevout);
744 return it == mapNextTx.end() ? nullptr : it->second;
745}
746
747std::optional<CTxMemPool::txiter> CTxMemPool::GetIter(const TxId &txid) const {
748 auto it = mapTx.find(txid);
749 if (it != mapTx.end()) {
750 return it;
751 }
752 return std::nullopt;
753}
754
756CTxMemPool::GetIterSet(const std::set<TxId> &txids) const {
758 for (const auto &txid : txids) {
759 const auto mi = GetIter(txid);
760 if (mi) {
761 ret.insert(*mi);
762 }
763 }
764 return ret;
765}
766
767bool CTxMemPool::HasNoInputsOf(const CTransaction &tx) const {
768 for (const CTxIn &in : tx.vin) {
769 if (exists(in.prevout.GetTxId())) {
770 return false;
771 }
772 }
773
774 return true;
775}
776
778 const CTxMemPool &mempoolIn)
779 : CCoinsViewBacked(baseIn), mempool(mempoolIn) {}
780
781std::optional<Coin>
782CCoinsViewMemPool::GetCoin(const COutPoint &outpoint) const {
783 // Check to see if the inputs are made available by another tx in the
784 // package. These Coins would not be available in the underlying CoinsView.
785 if (auto it = m_temp_added.find(outpoint); it != m_temp_added.end()) {
786 return it->second;
787 }
788
789 // If an entry in the mempool exists, always return that one, as it's
790 // guaranteed to never conflict with the underlying cache, and it cannot
791 // have pruned entries (as it contains full) transactions. First checking
792 // the underlying cache risks returning a pruned entry instead.
793 CTransactionRef ptx = mempool.get(outpoint.GetTxId());
794 if (ptx) {
795 if (outpoint.GetN() < ptx->vout.size()) {
796 Coin coin(ptx->vout[outpoint.GetN()], MEMPOOL_HEIGHT, false);
797 m_non_base_coins.emplace(outpoint);
798 return coin;
799 }
800 return std::nullopt;
801 }
802 return base->GetCoin(outpoint);
803}
804
806 for (uint32_t n = 0; n < tx->vout.size(); ++n) {
807 m_temp_added.emplace(COutPoint(tx->GetId(), n),
808 Coin(tx->vout[n], MEMPOOL_HEIGHT, false));
809 m_non_base_coins.emplace(COutPoint(tx->GetId(), n));
810 }
811}
813 m_temp_added.clear();
814 m_non_base_coins.clear();
815}
816
818 LOCK(cs);
819 // Estimate the overhead of mapTx to be 12 pointers + an allocation, as no
820 // exact formula for boost::multi_index_contained is implemented.
822 12 * sizeof(void *)) *
823 mapTx.size() +
824 memusage::DynamicUsage(mapNextTx) +
825 memusage::DynamicUsage(mapDeltas) + cachedInnerUsage;
826}
827
828void CTxMemPool::RemoveUnbroadcastTx(const TxId &txid, const bool unchecked) {
829 LOCK(cs);
830
831 if (m_unbroadcast_txids.erase(txid)) {
832 LogPrint(
833 BCLog::MEMPOOL, "Removed %i from set of unbroadcast txns%s\n",
834 txid.GetHex(),
835 (unchecked ? " before confirmation that txn was sent out" : ""));
836 }
837}
838
840 MemPoolRemovalReason reason) {
843
844 // Remove txs in reverse-topological order
845 const setRevTopoEntries stageRevTopo(stage.begin(), stage.end());
846 for (txiter it : stageRevTopo) {
847 removeUnchecked(it, reason);
848 }
849}
850
851int CTxMemPool::Expire(std::chrono::seconds time) {
853 indexed_transaction_set::index<entry_time>::type::iterator it =
854 mapTx.get<entry_time>().begin();
855 setEntries toremove;
856 size_t skippedFinalizedTxs{0};
857 while (it != mapTx.get<entry_time>().end() && (*it)->GetTime() < time) {
858 if (isAvalancheFinalizedPreConsensus((*it)->GetTx().GetId())) {
859 // Don't expire finalized transactions
860 ++skippedFinalizedTxs;
861 } else {
862 toremove.insert(mapTx.project<0>(it));
863 }
864
865 it++;
866 }
867
868 if (skippedFinalizedTxs > 0) {
869 LogPrint(BCLog::MEMPOOL, "Not expiring %u finalized transaction\n",
870 skippedFinalizedTxs);
871 }
872
873 setEntries stage;
874 for (txiter removeit : toremove) {
875 CalculateDescendants(removeit, stage);
876 }
877
879 return stage.size();
880}
881
885 int expired = Expire(GetTime<std::chrono::seconds>() - m_expiry);
886 if (expired != 0) {
888 "Expired %i transactions from the memory pool\n", expired);
889 }
890
891 std::vector<COutPoint> vNoSpendsRemaining;
892 TrimToSize(m_max_size_bytes, &vNoSpendsRemaining);
893 for (const COutPoint &removed : vNoSpendsRemaining) {
894 coins_cache.Uncache(removed);
895 }
896}
897
898void CTxMemPool::UpdateChild(txiter entry, txiter child, bool add) {
901 if (add && (*entry)->GetMemPoolChildren().insert(*child).second) {
902 cachedInnerUsage += memusage::IncrementalDynamicUsage(s);
903 } else if (!add && (*entry)->GetMemPoolChildren().erase(*child)) {
904 cachedInnerUsage -= memusage::IncrementalDynamicUsage(s);
905 }
906}
907
908void CTxMemPool::UpdateParent(txiter entry, txiter parent, bool add) {
911 if (add && (*entry)->GetMemPoolParents().insert(*parent).second) {
912 cachedInnerUsage += memusage::IncrementalDynamicUsage(s);
913 } else if (!add && (*entry)->GetMemPoolParents().erase(*parent)) {
914 cachedInnerUsage -= memusage::IncrementalDynamicUsage(s);
915 }
916}
917
918CFeeRate CTxMemPool::GetMinFee(size_t sizelimit) const {
919 LOCK(cs);
920 if (!blockSinceLastRollingFeeBump || rollingMinimumFeeRate == 0) {
921 return CFeeRate(int64_t(ceill(rollingMinimumFeeRate)) * SATOSHI);
922 }
923
924 int64_t time = GetTime();
925 if (time > lastRollingFeeUpdate + 10) {
926 double halflife = ROLLING_FEE_HALFLIFE;
927 if (DynamicMemoryUsage() < sizelimit / 4) {
928 halflife /= 4;
929 } else if (DynamicMemoryUsage() < sizelimit / 2) {
930 halflife /= 2;
931 }
932
933 rollingMinimumFeeRate =
934 rollingMinimumFeeRate /
935 pow(2.0, (time - lastRollingFeeUpdate) / halflife);
936 lastRollingFeeUpdate = time;
937 }
938 return CFeeRate(int64_t(ceill(rollingMinimumFeeRate)) * SATOSHI);
939}
940
943 if ((rate.GetFeePerK() / SATOSHI) > rollingMinimumFeeRate) {
944 rollingMinimumFeeRate = rate.GetFeePerK() / SATOSHI;
945 blockSinceLastRollingFeeBump = false;
946 }
947}
948
949void CTxMemPool::TrimToSize(size_t sizelimit,
950 std::vector<COutPoint> *pvNoSpendsRemaining) {
952
953 unsigned nTxnRemoved = 0;
954 size_t finalizedTxsSkipped = 0;
955 CFeeRate maxFeeRateRemoved(Amount::zero());
956 while (!mapTx.empty() && DynamicMemoryUsage() > sizelimit) {
957 auto &by_modified_feerate = mapTx.get<modified_feerate>();
958 // Lowest fee first
959 auto rit = by_modified_feerate.rbegin();
960
961 // We don't evict finalized transactions, even if they have lower fee
962 while (isAvalancheFinalizedPreConsensus((*rit)->GetTx().GetId())) {
963 ++finalizedTxsSkipped;
964 ++rit;
965 if (rit == by_modified_feerate.rend()) {
966 // Nothing we can trim
967 break;
968 }
969 }
970
971 // Convert to forward iterator.
972 // If rit == rend(), the forward iterator will be equivalent to begin()
973 // and we can't decrement it, there is nothing to remove. This could
974 // only happen if all the transactions are finalized, which in turns
975 // implies that the mempool cannot contain a block worth of txs.
976 // In this case we still exit the loop so we get the proper log message.
977 if (rit == by_modified_feerate.rend()) {
978 break;
979 }
980 auto it = rit.base();
981 --it;
982
983 // We set the new mempool min fee to the feerate of the removed
984 // transaction, plus the "minimum reasonable fee rate" (ie some value
985 // under which we consider txn to have 0 fee). This way, we don't allow
986 // txn to enter mempool with feerate equal to txn which were removed
987 // with no block in between.
988 CFeeRate removed = (*it)->GetModifiedFeeRate();
990
991 trackPackageRemoved(removed);
992 maxFeeRateRemoved = std::max(maxFeeRateRemoved, removed);
993
994 setEntries stage;
995 CalculateDescendants(mapTx.project<0>(it), stage);
996 nTxnRemoved += stage.size();
997
998 if (pvNoSpendsRemaining) {
999 for (const txiter &iter : stage) {
1000 for (const CTxIn &txin : (*iter)->GetTx().vin) {
1001 if (!exists(txin.prevout.GetTxId())) {
1002 pvNoSpendsRemaining->push_back(txin.prevout);
1003 }
1004 }
1005 }
1006 }
1007
1009 }
1010
1011 if (maxFeeRateRemoved > CFeeRate(Amount::zero())) {
1013 "Removed %u txn, rolling minimum fee bumped to %s\n",
1014 nTxnRemoved, maxFeeRateRemoved.ToString());
1015 }
1016
1017 if (finalizedTxsSkipped > 0) {
1019 "Not evicting %u finalized txn for low fee\n",
1020 finalizedTxsSkipped);
1021 }
1022}
1023
1025 LOCK(cs);
1026 return m_load_tried;
1027}
1028
1029void CTxMemPool::SetLoadTried(bool load_tried) {
1030 LOCK(cs);
1031 m_load_tried = load_tried;
1032}
1033
1034std::string RemovalReasonToString(const MemPoolRemovalReason &r) noexcept {
1035 switch (r) {
1037 return "expiry";
1039 return "sizelimit";
1041 return "reorg";
1043 return "block";
1045 return "conflict";
1047 return "avalanche";
1049 return "manual";
1050 }
1051 assert(false);
1052}
static constexpr Amount SATOSHI
Definition: amount.h:153
#define Assume(val)
Assume is the identity function.
Definition: check.h:100
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:25
CCoinsView backed by another CCoinsView.
Definition: coins.h:338
CCoinsView * base
Definition: coins.h:340
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:358
void Uncache(const COutPoint &outpoint)
Removes the UTXO with the given outpoint from the cache, if it is not modified.
Definition: coins.cpp:338
Abstract view on the open txout dataset.
Definition: coins.h:304
virtual std::optional< Coin > GetCoin(const COutPoint &outpoint) const
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: coins.cpp:13
std::optional< Coin > GetCoin(const COutPoint &outpoint) const override
GetCoin, returning whether it exists and is not spent.
Definition: txmempool.cpp:782
void Reset()
Clear m_temp_added and m_non_base_coins.
Definition: txmempool.cpp:812
std::unordered_map< COutPoint, Coin, SaltedOutpointHasher > m_temp_added
Coins made available by transactions being validated.
Definition: txmempool.h:658
CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn)
Definition: txmempool.cpp:777
std::unordered_set< COutPoint, SaltedOutpointHasher > m_non_base_coins
Set of all coins that have been fetched from mempool or created using PackageAddTransaction (not base...
Definition: txmempool.h:666
void PackageAddTransaction(const CTransactionRef &tx)
Add the coins created by this transaction.
Definition: txmempool.cpp:805
const CTxMemPool & mempool
Definition: txmempool.h:669
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
std::string ToString() const
Definition: feerate.cpp:57
Amount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition: feerate.h:54
void TransactionRemovedFromMempool(const CTransactionRef &, MemPoolRemovalReason, uint64_t mempool_sequence)
void TransactionFinalized(const CTransactionRef &tx)
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
Definition: mempool_entry.h:65
std::set< std::reference_wrapper< const CTxMemPoolEntryRef >, CompareIteratorById > Children
Definition: mempool_entry.h:73
std::set< std::reference_wrapper< const CTxMemPoolEntryRef >, CompareIteratorById > Parents
Definition: mempool_entry.h:70
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:221
void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:303
CFeeRate estimateFee() const
Definition: txmempool.cpp:699
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:767
void ClearPrioritisation(const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:737
std::set< txiter, CompareIteratorById > setEntries
Definition: txmempool.h:321
void RemoveUnbroadcastTx(const TxId &txid, const bool unchecked=false)
Removes a transaction from the unbroadcast set.
Definition: txmempool.cpp:828
bool GetLoadTried() const
Definition: txmempool.cpp:1024
bool CalculateAncestors(setEntries &setAncestors, CTxMemPoolEntry::Parents &staged_ancestors) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Helper function to calculate all in-mempool ancestors of staged_ancestors param@[in] staged_ancestors...
Definition: txmempool.cpp:31
void updateFeeForBlock() EXCLUSIVE_LOCKS_REQUIRED(cs)
Called when a block is connected.
Definition: txmempool.cpp:324
CFeeRate GetMinFee() const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
Definition: txmempool.h:463
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:317
void trackPackageRemoved(const CFeeRate &rate) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:941
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:272
void UpdateForRemoveFromMempool(const setEntries &entriesToRemove) EXCLUSIVE_LOCKS_REQUIRED(cs)
For each transaction being removed, update ancestors and any direct children.
Definition: txmempool.cpp:103
const int m_check_ratio
Value n means that 1 times in n we check.
Definition: txmempool.h:224
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:949
const std::chrono::seconds m_expiry
Definition: txmempool.h:355
void AddTransactionsUpdated(unsigned int n)
Definition: txmempool.cpp:145
void UpdateChildrenForRemoval(txiter entry) EXCLUSIVE_LOCKS_REQUIRED(cs)
Sever link between specified transaction and direct children.
Definition: txmempool.cpp:93
bool CompareTopologically(const TxId &txida, const TxId &txidb) const
Definition: txmempool.cpp:506
TxMempoolInfo info(const TxId &txid) const
Definition: txmempool.cpp:689
const int64_t m_max_size_bytes
Definition: txmempool.h:354
void getAllTxIds(std::vector< TxId > &vtxid) const
Definition: txmempool.cpp:520
std::atomic< uint32_t > nTransactionsUpdated
Used by getblocktemplate to trigger CreateNewBlock() invocation.
Definition: txmempool.h:226
setEntries GetIterSet(const std::set< TxId > &txids) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Translate a set of txids into a set of pool iterators to avoid repeated lookups.
Definition: txmempool.cpp:756
size_t DynamicMemoryUsage() const
Definition: txmempool.cpp:817
bool setAvalancheFinalized(const CTxMemPoolEntryRef &tx, const Consensus::Params &params, const CBlockIndex &active_chain_tip, std::vector< TxId > &finalizedTxIds) EXCLUSIVE_LOCKS_REQUIRED(bool isAvalancheFinalizedPreConsensus(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:546
std::vector< TxMempoolInfo > infoAll() const
Definition: txmempool.cpp:538
void LimitSize(CCoinsViewCache &coins_cache) EXCLUSIVE_LOCKS_REQUIRED(cs
Reduce the size of the mempool by expiring and then trimming the mempool.
Definition: txmempool.cpp:882
void UpdateParent(txiter entry, txiter parent, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:908
CTransactionRef GetConflictTx(const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Get the transaction in the pool that spends the same prevout.
Definition: txmempool.cpp:742
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:200
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:851
bool isWorthPolling(const CTransactionRef &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs
Definition: txmempool.cpp:655
std::set< txiter, CompareIteratorByRevEntryId > setRevTopoEntries
Definition: txmempool.h:322
bool exists(const TxId &txid) const
Definition: txmempool.h:535
static const int ROLLING_FEE_HALFLIFE
Definition: txmempool.h:266
CTransactionRef get(const TxId &txid) const
Definition: txmempool.cpp:679
const CFeeRate m_min_relay_feerate
Definition: txmempool.h:356
void PrioritiseTransaction(const TxId &txid, const Amount nFeeDelta)
Affect CreateNewBlock prioritisation of transactions.
Definition: txmempool.cpp:709
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
Definition: txmempool.h:320
uint64_t GetAndIncrementSequence() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Guards this internal counter for external reporting.
Definition: txmempool.h:586
void UpdateChild(txiter entry, txiter child, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:898
void check(const CCoinsViewCache &active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(void addUnchecked(CTxMemPoolEntryRef entry) 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:382
RadixTree< CTxMemPoolEntry, MemPoolEntryRadixTreeAdapter > finalizedTxs
Definition: txmempool.h:324
void check(const CCoinsViewCache &active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(void cs_main
Definition: txmempool.h:383
bool CalculateMemPoolAncestors(const CTxMemPoolEntryRef &entry, setEntries &setAncestors, bool fSearchForParents=true) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Try to calculate all in-mempool ancestors of entry.
Definition: txmempool.cpp:58
void removeForFinalizedBlock(const std::unordered_set< TxId, SaltedTxIdHasher > &confirmedTxIdsInNonFinalizedBlocks) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:331
void clear(bool include_finalized_txs=false)
Definition: txmempool.cpp:382
Mutex cs_conflicting
Definition: txmempool.h:260
void CalculateDescendants(txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Populate setDescendants with all in-mempool descendants of hash.
Definition: txmempool.cpp:245
void RemoveStaged(const setEntries &stage, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Remove a set of transactions from the mempool.
Definition: txmempool.cpp:839
CTxMemPool(const Config &config, const Options &opts)
Create a new CTxMemPool.
Definition: txmempool.cpp:119
void UpdateParentsOf(bool add, txiter it) EXCLUSIVE_LOCKS_REQUIRED(cs)
Update parents of it to add/remove it as a child transaction.
Definition: txmempool.cpp:84
void ApplyDelta(const TxId &txid, Amount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:727
void SetLoadTried(bool load_tried)
Set whether or not an initial attempt to load the persisted mempool was made (regardless of whether t...
Definition: txmempool.cpp:1029
std::optional< txiter > GetIter(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns an iterator to the given txid, if found.
Definition: txmempool.cpp:747
bool isSpent(const COutPoint &outpoint) const
Definition: txmempool.cpp:136
unsigned int GetTransactionsUpdated() const
Definition: txmempool.cpp:141
void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:370
A UTXO entry.
Definition: coins.h:31
Definition: config.h:19
Fast randomness source.
Definition: random.h:411
Definition: rcu.h:85
T * get()
Get allows to access the undelying pointer.
Definition: rcu.h:170
std::string ToString() const
Definition: validation.h:125
std::string ToString() const
Definition: uint256.h:80
std::string GetHex() const
Definition: uint256.cpp:16
void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, bool check_for_overwrite)
Utility function to add all of a transaction's outputs to a cache.
Definition: coins.cpp:158
#define LogPrint(category,...)
Definition: logging.h:452
#define LogPrintf(...)
Definition: logging.h:424
std::string FormatMoney(const Amount amt)
Do not use these functions to represent or parse monetary amounts to or from JSON but use AmountFromV...
Definition: moneystr.cpp:13
@ AVALANCHE
Definition: logging.h:91
@ MEMPOOL
Definition: logging.h:71
bool CheckTxInputs(const CTransaction &tx, TxValidationState &state, const CCoinsViewCache &inputs, int nSpendHeight, Amount &txfee)
Check whether all inputs of this transaction are valid (no double spends and amounts).
Definition: tx_verify.cpp:194
static size_t DynamicUsage(const int8_t &v)
Dynamic memory usage for built-in types is zero.
Definition: memusage.h:28
static size_t IncrementalDynamicUsage(const std::set< X, Y > &s)
Definition: memusage.h:124
static size_t MallocUsage(size_t alloc)
Compute the total memory used by allocating alloc bytes.
Definition: memusage.h:74
Definition: messages.h:12
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition: rcu.h:259
static constexpr CFeeRate MEMPOOL_FULL_FEE_INCREMENT(1000 *SATOSHI)
Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or BIP...
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:315
Definition: amount.h:23
void SaturatingAdd(const Amount &other) noexcept
Amount addition with integer saturation.
Definition: amount.cpp:57
static constexpr Amount zero() noexcept
Definition: amount.h:36
Parameters that influence chain consensus.
Definition: params.h:34
RCUPtr< T > remove(const KeyType &key)
Remove an element from the tree.
Definition: radix.h:180
bool forEachLeaf(Callable &&func) const
Definition: radix.h:143
bool insert(const RCUPtr< T > &value)
Insert a value into the tree.
Definition: radix.h:111
A TxId is the identifier of a transaction.
Definition: txid.h:14
Information about a mempool transaction.
Definition: txmempool.h:137
Options struct containing options for constructing a CTxMemPool.
#define AssertLockNotHeld(cs)
Definition: sync.h:163
#define LOCK(cs)
Definition: sync.h:306
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:357
#define NO_THREAD_SAFETY_ANALYSIS
Definition: threadsafety.h:58
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
Definition: time.cpp:80
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1202
bilingual_str _(const char *psz)
Translation function.
Definition: translation.h:68
bool ContextualCheckTransactionForCurrentBlock(const CBlockIndex &active_chain_tip, const Consensus::Params &params, const CTransaction &tx, TxValidationState &state)
Definition: tx_verify.cpp:72
std::string RemovalReasonToString(const MemPoolRemovalReason &r) noexcept
Definition: txmempool.cpp:1034
static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it)
Definition: txmempool.cpp:532
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
Definition: txmempool.h:158
@ SIZELIMIT
Removed in size limiting.
@ BLOCK
Removed for block.
@ MANUAL
Manual removal via RPC.
@ EXPIRY
Expired from mempool.
@ AVALANCHE
Removed by avalanche vote.
@ CONFLICT
Removed for conflict with in-block transaction.
@ REORG
Removed for reorganization.
static const uint32_t MEMPOOL_HEIGHT
Fake height value used in Coins to signify they are only in the memory pool(since 0....
Definition: txmempool.h:55
AssertLockHeld(pool.cs)
assert(!tx.IsCoinBase())
CMainSignals & GetMainSignals()