Bitcoin ABC 0.32.4
P2P Digital Currency
txmempool.h
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-2016 The Bitcoin Core developers
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef BITCOIN_TXMEMPOOL_H
7#define BITCOIN_TXMEMPOOL_H
8
9#include <coins.h>
10#include <consensus/amount.h>
11#include <core_memusage.h>
12#include <indirectmap.h>
13#include <kernel/cs_main.h>
16#include <node/blockfitter.h>
17#include <policy/packages.h>
19#include <radix.h>
20#include <sync.h>
21#include <txconflicting.h>
22#include <txorphanage.h>
23#include <uint256radixkey.h>
24#include <util/hasher.h>
25
26#include <boost/multi_index/hashed_index.hpp>
27#include <boost/multi_index/ordered_index.hpp>
28#include <boost/multi_index/sequenced_index.hpp>
29#include <boost/multi_index_container.hpp>
30
31#include <atomic>
32#include <map>
33#include <memory>
34#include <optional>
35#include <set>
36#include <string>
37#include <unordered_map>
38#include <utility>
39#include <vector>
40
41class CBlockIndex;
42class CChain;
43class Chainstate;
45class Config;
46
47namespace Consensus {
48struct Params;
49} // namespace Consensus
50
55static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
56
57// extracts a transaction id from CTxMemPoolEntry or CTransactionRef
60
62 return entry->GetTx().GetId();
63 }
64
66 return tx->GetId();
67 }
68};
69
75 return entry.GetSharedTx()->GetId();
76 }
77};
78
79// used by the entry_time index
82 const CTxMemPoolEntryRef &b) const {
83 return a->GetTime() < b->GetTime();
84 }
85};
86
87// used by the entry_id index
90 const CTxMemPoolEntryRef &b) const {
91 return a->GetEntryId() < b->GetEntryId();
92 }
93};
94
102 // Used in tests
103 bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const {
104 const CFeeRate frA = a.GetModifiedFeeRate();
105 const CFeeRate frB = b.GetModifiedFeeRate();
106
107 // Sort by modified fee rate first
108 if (frA != frB) {
109 return frA > frB;
110 }
111
112 // Ties are broken by whichever is topologically earlier
113 // (this helps mining code avoid some backtracking).
114 if (a.GetEntryId() != b.GetEntryId()) {
115 return a.GetEntryId() < b.GetEntryId();
116 }
117
118 // If nothing else, sort by txid (this should never happen as entryID is
119 // expected to be unique).
120 return a.GetSharedTx()->GetId() < b.GetSharedTx()->GetId();
121 }
122
124 const CTxMemPoolEntryRef &b) const {
125 return operator()(*a, *b);
126 }
127};
128
129// Multi_index tag names
130struct entry_time {};
132struct entry_id {};
133
140
142 std::chrono::seconds m_time;
143
146
148 size_t vsize;
149
152};
153
160 EXPIRY,
162 SIZELIMIT,
164 REORG,
166 BLOCK,
168 CONFLICT,
170 AVALANCHE,
172 MANUAL,
173};
174
175std::string RemovalReasonToString(const MemPoolRemovalReason &r) noexcept;
176
222private:
224 const int m_check_ratio;
226 std::atomic<uint32_t> nTransactionsUpdated{0};
227
229 uint64_t totalTxSize GUARDED_BY(cs);
231 node::BlockFitter m_finalizedTxsFitter GUARDED_BY(cs);
233 Amount m_total_fee GUARDED_BY(cs);
236 uint64_t cachedInnerUsage GUARDED_BY(cs);
237
238 mutable int64_t lastRollingFeeUpdate GUARDED_BY(cs);
239 mutable bool blockSinceLastRollingFeeBump GUARDED_BY(cs);
241 mutable double rollingMinimumFeeRate GUARDED_BY(cs);
242
243 // In-memory counter for external mempool tracking purposes.
244 // This number is incremented once every time a transaction
245 // is added or removed from the mempool for any reason.
246 mutable uint64_t m_sequence_number GUARDED_BY(cs){1};
247
249
250 bool m_load_tried GUARDED_BY(cs){false};
251
254 uint64_t nextEntryId GUARDED_BY(cs) = 1;
255
258 std::unique_ptr<TxOrphanage> m_orphanage GUARDED_BY(cs_orphanage);
259
262 std::unique_ptr<TxConflicting> m_conflicting GUARDED_BY(cs_conflicting);
263
264public:
265 // public only for testing
266 static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12;
267
268 typedef boost::multi_index_container<
270 boost::multi_index::indexed_by<
271 // indexed by txid
272 boost::multi_index::hashed_unique<mempoolentry_txid,
274 // sorted by fee rate
275 boost::multi_index::ordered_non_unique<
276 boost::multi_index::tag<modified_feerate>,
277 boost::multi_index::identity<CTxMemPoolEntryRef>,
279 // sorted by entry time
280 boost::multi_index::ordered_non_unique<
281 boost::multi_index::tag<entry_time>,
282 boost::multi_index::identity<CTxMemPoolEntryRef>,
284 // sorted topologically (insertion order)
285 boost::multi_index::ordered_unique<
286 boost::multi_index::tag<entry_id>,
287 boost::multi_index::identity<CTxMemPoolEntryRef>,
290
319
320 using txiter = indexed_transaction_set::nth_index<0>::type::const_iterator;
321 typedef std::set<txiter, CompareIteratorById> setEntries;
322 typedef std::set<txiter, CompareIteratorByRevEntryId> setRevTopoEntries;
323
325
326private:
327 void UpdateParent(txiter entry, txiter parent, bool add)
329 void UpdateChild(txiter entry, txiter child, bool add)
331
336 std::set<TxId> m_unbroadcast_txids GUARDED_BY(cs);
337
344 bool CalculateAncestors(setEntries &setAncestors,
345 CTxMemPoolEntry::Parents &staged_ancestors) const
347
348public:
350 std::map<TxId, Amount> mapDeltas GUARDED_BY(cs);
351
353
354 const int64_t m_max_size_bytes;
355 const std::chrono::seconds m_expiry;
359 const std::optional<unsigned> m_max_datacarrier_bytes;
361
368 CTxMemPool(const Config &config, const Options &opts);
369 ~CTxMemPool();
370
377 void check(const CCoinsViewCache &active_coins_tip,
378 int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
379
380 // addUnchecked must update state for all parents of a given transaction,
381 // updating child links as necessary.
384
385 void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason)
387 void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs);
389 void
390 removeForFinalizedBlock(const std::unordered_set<TxId, SaltedTxIdHasher>
391 &confirmedTxIdsInNonFinalizedBlocks)
393
394 void clear(bool include_finalized_txs = false);
395 // lock free
397 bool CompareTopologically(const TxId &txida, const TxId &txidb) const;
398 void getAllTxIds(std::vector<TxId> &vtxid) const;
399 bool isSpent(const COutPoint &outpoint) const;
400 unsigned int GetTransactionsUpdated() const;
401 void AddTransactionsUpdated(unsigned int n);
407 bool HasNoInputsOf(const CTransaction &tx) const
409
411 void PrioritiseTransaction(const TxId &txid, const Amount nFeeDelta);
412 void ApplyDelta(const TxId &txid, Amount &nFeeDelta) const
415
417 CTransactionRef GetConflictTx(const COutPoint &prevout) const
419
421 std::optional<txiter> GetIter(const TxId &txid) const
423
428 setEntries GetIterSet(const std::set<TxId> &txids) const
430
436 void RemoveStaged(const setEntries &stage, MemPoolRemovalReason reason)
438
447 setEntries &setAncestors,
448 bool fSearchForParents = true) const
450
456 void CalculateDescendants(txiter it, setEntries &setDescendants) const
458
464 CFeeRate GetMinFee(size_t sizelimit) const;
465
472 void TrimToSize(size_t sizelimit,
473 std::vector<COutPoint> *pvNoSpendsRemaining = nullptr)
475
480 int Expire(std::chrono::seconds time) EXCLUSIVE_LOCKS_REQUIRED(cs);
481
485 void LimitSize(CCoinsViewCache &coins_cache)
487
492 bool GetLoadTried() const;
493
498 void SetLoadTried(bool load_tried);
499
500 unsigned long size() const {
501 LOCK(cs);
502 return mapTx.size();
503 }
504
507 return totalTxSize;
508 }
509
512 return m_finalizedTxsFitter.nBlockSize -
514 }
515
518 return m_finalizedTxsFitter.nBlockSigChecks -
520 }
521
522 bool isWorthPolling(const CTransactionRef &tx) const
524
527 return m_total_fee;
528 }
529
530 bool exists(const TxId &txid) const {
531 LOCK(cs);
532 return mapTx.count(txid) != 0;
533 }
534
535 bool setAvalancheFinalized(const CTxMemPoolEntryRef &tx,
536 const Consensus::Params &params,
537 const CBlockIndex &active_chain_tip,
538 std::vector<TxId> &finalizedTxIds)
540
544 return finalizedTxs.get(txid) != nullptr;
545 }
546
547 CTransactionRef get(const TxId &txid) const;
548 TxMempoolInfo info(const TxId &txid) const;
549 std::vector<TxMempoolInfo> infoAll() const;
550
551 CFeeRate estimateFee() const;
552
553 size_t DynamicMemoryUsage() const;
554
556 void AddUnbroadcastTx(const TxId &txid) {
557 LOCK(cs);
558 // Sanity check the transaction is in the mempool & insert into
559 // unbroadcast set.
560 if (exists(txid)) {
561 m_unbroadcast_txids.insert(txid);
562 }
563 }
564
566 void RemoveUnbroadcastTx(const TxId &txid, const bool unchecked = false);
567
569 std::set<TxId> GetUnbroadcastTxs() const {
570 LOCK(cs);
571 return m_unbroadcast_txids;
572 }
573
577 return (m_unbroadcast_txids.count(txid) != 0);
578 }
579
582 return m_sequence_number++;
583 }
584
586 return m_sequence_number;
587 }
588
589 template <typename Callable>
590 auto withOrphanage(Callable &&func) const
593 assert(m_orphanage);
594 return func(*m_orphanage);
595 }
596
597 template <typename Callable>
598 auto withConflicting(Callable &&func) const
601 assert(m_conflicting);
602 return func(*m_conflicting);
603 }
604
605private:
607 void UpdateEntryForAncestors(txiter it, const setEntries *setAncestors)
617 void UpdateForRemoveFromMempool(const setEntries &entriesToRemove)
621
632};
633
653 std::unordered_map<COutPoint, Coin, SaltedOutpointHasher> m_temp_added;
654
660 mutable std::unordered_set<COutPoint, SaltedOutpointHasher>
662
663protected:
665
666public:
667 CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn);
672 bool GetCoin(const COutPoint &outpoint, Coin &coin) const override;
680 std::unordered_set<COutPoint, SaltedOutpointHasher>
682 return m_non_base_coins;
683 }
685 void Reset();
686};
687
688#endif // BITCOIN_TXMEMPOOL_H
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:21
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:25
An in-memory indexed chain of blocks.
Definition: chain.h:134
CCoinsView backed by another CCoinsView.
Definition: coins.h:343
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:363
Abstract view on the open txout dataset.
Definition: coins.h:305
CCoinsView that brings transactions from a mempool into view.
Definition: txmempool.h:647
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
GetCoin, returning whether it exists and is not spent.
Definition: txmempool.cpp:779
std::unordered_set< COutPoint, SaltedOutpointHasher > GetNonBaseCoins() const
Get all coins in m_non_base_coins.
Definition: txmempool.h:681
void Reset()
Clear m_temp_added and m_non_base_coins.
Definition: txmempool.cpp:810
std::unordered_map< COutPoint, Coin, SaltedOutpointHasher > m_temp_added
Coins made available by transactions being validated.
Definition: txmempool.h:653
CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn)
Definition: txmempool.cpp:775
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:661
void PackageAddTransaction(const CTransactionRef &tx)
Add the coins created by this transaction.
Definition: txmempool.cpp:803
const CTxMemPool & mempool
Definition: txmempool.h:664
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
Definition: mempool_entry.h:65
uint64_t GetEntryId() const
CTransactionRef GetSharedTx() const
CFeeRate GetModifiedFeeRate() const
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:301
CFeeRate estimateFee() const
Definition: txmempool.cpp:697
uint64_t nextEntryId GUARDED_BY(cs)
Used by addUnchecked to generate ever-increasing CTxMemPoolEntry::entryId's.
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:765
void ClearPrioritisation(const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:735
std::set< txiter, CompareIteratorById > setEntries
Definition: txmempool.h:321
const bool m_require_standard
Definition: txmempool.h:360
void RemoveUnbroadcastTx(const TxId &txid, const bool unchecked=false)
Removes a transaction from the unbroadcast set.
Definition: txmempool.cpp:826
uint64_t cachedInnerUsage GUARDED_BY(cs)
sum of dynamic memory usage of all the map elements (NOT the maps themselves)
Amount m_total_fee GUARDED_BY(cs)
sum of all mempool tx's fees (NOT modified fee)
bool GetLoadTried() const
Definition: txmempool.cpp:1022
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:32
void updateFeeForBlock() EXCLUSIVE_LOCKS_REQUIRED(cs)
Called when a block is connected.
Definition: txmempool.cpp:322
void UpdateEntryForAncestors(txiter it, const setEntries *setAncestors) EXCLUSIVE_LOCKS_REQUIRED(cs)
Set ancestor state for an entry.
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:939
Amount GetTotalFee() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:525
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:270
void UpdateForRemoveFromMempool(const setEntries &entriesToRemove) EXCLUSIVE_LOCKS_REQUIRED(cs)
For each transaction being removed, update ancestors and any direct children.
Definition: txmempool.cpp:104
bool blockSinceLastRollingFeeBump GUARDED_BY(cs)
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:947
const std::chrono::seconds m_expiry
Definition: txmempool.h:355
const std::optional< unsigned > m_max_datacarrier_bytes
Definition: txmempool.h:359
void AddTransactionsUpdated(unsigned int n)
Definition: txmempool.cpp:146
void UpdateChildrenForRemoval(txiter entry) EXCLUSIVE_LOCKS_REQUIRED(cs)
Sever link between specified transaction and direct children.
Definition: txmempool.cpp:94
uint64_t GetTotalFinalizedTxSigchecks() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:516
bool CompareTopologically(const TxId &txida, const TxId &txidb) const
Definition: txmempool.cpp:504
TxMempoolInfo info(const TxId &txid) const
Definition: txmempool.cpp:687
std::map< TxId, Amount > mapDeltas GUARDED_BY(cs)
const int64_t m_max_size_bytes
Definition: txmempool.h:354
void getAllTxIds(std::vector< TxId > &vtxid) const
Definition: txmempool.cpp:518
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:754
std::unique_ptr< TxConflicting > m_conflicting GUARDED_BY(cs_conflicting)
Storage for conflicting txs information.
size_t DynamicMemoryUsage() const
Definition: txmempool.cpp:815
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:541
std::vector< TxMempoolInfo > infoAll() const
Definition: txmempool.cpp:536
indexed_transaction_set mapTx GUARDED_BY(cs)
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:880
void UpdateParent(txiter entry, txiter parent, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:906
CTransactionRef GetConflictTx(const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Get the transaction in the pool that spends the same prevout.
Definition: txmempool.cpp:740
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:198
uint64_t totalTxSize GUARDED_BY(cs)
sum of all mempool tx's sizes.
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:849
bool isWorthPolling(const CTransactionRef &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs
Definition: txmempool.cpp:653
std::set< txiter, CompareIteratorByRevEntryId > setRevTopoEntries
Definition: txmempool.h:322
bool exists(const TxId &txid) const
Definition: txmempool.h:530
std::set< TxId > GetUnbroadcastTxs() const
Returns transactions in unbroadcast set.
Definition: txmempool.h:569
node::BlockFitter m_finalizedTxsFitter GUARDED_BY(cs)
Check whether the finalized txs would fit a block.
int64_t lastRollingFeeUpdate GUARDED_BY(cs)
const bool m_permit_bare_multisig
Definition: txmempool.h:358
bool m_load_tried GUARDED_BY(cs)
Definition: txmempool.h:250
static const int ROLLING_FEE_HALFLIFE
Definition: txmempool.h:266
auto withOrphanage(Callable &&func) const EXCLUSIVE_LOCKS_REQUIRED(!cs_orphanage)
Definition: txmempool.h:590
CTransactionRef get(const TxId &txid) const
Definition: txmempool.cpp:677
boost::multi_index_container< CTxMemPoolEntryRef, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< mempoolentry_txid, SaltedTxIdHasher >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< modified_feerate >, boost::multi_index::identity< CTxMemPoolEntryRef >, CompareTxMemPoolEntryByModifiedFeeRate >, boost::multi_index::ordered_non_unique< boost::multi_index::tag< entry_time >, boost::multi_index::identity< CTxMemPoolEntryRef >, CompareTxMemPoolEntryByEntryTime >, boost::multi_index::ordered_unique< boost::multi_index::tag< entry_id >, boost::multi_index::identity< CTxMemPoolEntryRef >, CompareTxMemPoolEntryByEntryId > > > indexed_transaction_set
Definition: txmempool.h:289
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:707
uint64_t GetSequence() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:585
bool IsUnbroadcastTx(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns whether a txid is in the unbroadcast set.
Definition: txmempool.h:575
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:581
void UpdateChild(txiter entry, txiter child, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:896
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
Mutex cs_orphanage
Definition: txmempool.h:256
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
double rollingMinimumFeeRate GUARDED_BY(cs)
minimum fee to get into the pool, decreases exponentially
std::unique_ptr< TxOrphanage > m_orphanage GUARDED_BY(cs_orphanage)
Storage for orphan information.
auto withConflicting(Callable &&func) const EXCLUSIVE_LOCKS_REQUIRED(!cs_conflicting)
Definition: txmempool.h:598
indirectmap< COutPoint, CTransactionRef > mapNextTx GUARDED_BY(cs)
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:59
void removeForFinalizedBlock(const std::unordered_set< TxId, SaltedTxIdHasher > &confirmedTxIdsInNonFinalizedBlocks) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:329
void clear(bool include_finalized_txs=false)
Definition: txmempool.cpp:380
Mutex cs_conflicting
Definition: txmempool.h:260
uint64_t GetTotalFinalizedTxSize() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:510
void CalculateDescendants(txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Populate setDescendants with all in-mempool descendants of hash.
Definition: txmempool.cpp:243
void RemoveStaged(const setEntries &stage, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Remove a set of transactions from the mempool.
Definition: txmempool.cpp:837
unsigned long size() const
Definition: txmempool.h:500
CTxMemPool(const Config &config, const Options &opts)
Create a new CTxMemPool.
Definition: txmempool.cpp:120
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:85
uint64_t m_sequence_number GUARDED_BY(cs)
Definition: txmempool.h:246
void ApplyDelta(const TxId &txid, Amount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:725
void SetLoadTried(bool load_tried)
Set whether or not we've made an attempt to load the mempool (regardless of whether the attempt was s...
Definition: txmempool.cpp:1027
const CFeeRate m_dust_relay_feerate
Definition: txmempool.h:357
std::optional< txiter > GetIter(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns an iterator to the given txid, if found.
Definition: txmempool.cpp:745
std::set< TxId > m_unbroadcast_txids GUARDED_BY(cs)
Track locally submitted transactions to periodically retry initial broadcast.
uint64_t GetTotalTxSize() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:505
bool isSpent(const COutPoint &outpoint) const
Definition: txmempool.cpp:137
void AddUnbroadcastTx(const TxId &txid)
Adds a transaction to the unbroadcast set.
Definition: txmempool.h:556
unsigned int GetTransactionsUpdated() const
Definition: txmempool.cpp:142
void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:368
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:734
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:1186
A UTXO entry.
Definition: coins.h:29
Definition: config.h:19
Definition: rcu.h:85
Map whose keys are pointers, but are compared by their dereferenced values.
Definition: indirectmap.h:26
Check for block limits when adding transactions.
Definition: blockfitter.h:18
static constexpr uint64_t COINBASE_RESERVED_SIGCHECKS
Definition: blockfitter.h:26
static constexpr uint64_t COINBASE_RESERVED_SIZE
Definition: blockfitter.h:25
@ MANUAL
We open manual connections to addresses that users explicitly inputted via the addnode RPC,...
RCUPtr< CTxMemPoolEntry > CTxMemPoolEntryRef
Definition: mempool_entry.h:56
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition: rcu.h:259
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:315
Definition: amount.h:19
Definition: txmempool.h:88
bool operator()(const CTxMemPoolEntryRef &a, const CTxMemPoolEntryRef &b) const
Definition: txmempool.h:89
Definition: txmempool.h:80
bool operator()(const CTxMemPoolEntryRef &a, const CTxMemPoolEntryRef &b) const
Definition: txmempool.h:81
Sort by feerate of entry (modfee/vsize) in descending order.
Definition: txmempool.h:101
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:103
bool operator()(const CTxMemPoolEntryRef &a, const CTxMemPoolEntryRef &b) const
Definition: txmempool.h:123
Parameters that influence chain consensus.
Definition: params.h:34
Radix tree adapter for storing a CTxMemPoolEntry as a tree element.
Definition: txmempool.h:73
Uint256RadixKey getId(const CTxMemPoolEntry &entry) const
Definition: txmempool.h:74
RCUPtr< T > get(const KeyType &key)
Get the value corresponding to a key.
Definition: radix.h:118
A TxId is the identifier of a transaction.
Definition: txid.h:14
Information about a mempool transaction.
Definition: txmempool.h:137
Amount fee
Fee of the transaction.
Definition: txmempool.h:145
Amount nFeeDelta
The fee delta.
Definition: txmempool.h:151
CTransactionRef tx
The transaction itself.
Definition: txmempool.h:139
std::chrono::seconds m_time
Time the transaction entered the mempool.
Definition: txmempool.h:142
size_t vsize
Virtual size of the transaction.
Definition: txmempool.h:148
Facility for using an uint256 as a radix tree key.
Options struct containing options for constructing a CTxMemPool.
result_type operator()(const CTxMemPoolEntryRef &entry) const
Definition: txmempool.h:61
result_type operator()(const CTransactionRef &tx) const
Definition: txmempool.h:65
#define LOCK(cs)
Definition: sync.h:306
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
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.
@ EXPIRY
Expired from mempool.
@ CONFLICT
Removed for conflict with in-block transaction.
@ REORG
Removed for reorganization.
std::string RemovalReasonToString(const MemPoolRemovalReason &r) noexcept
Definition: txmempool.cpp:1032
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())