Bitcoin ABC 0.34.3
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;
46class Config;
47
48namespace Consensus {
49struct Params;
50} // namespace Consensus
51
56static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
57
58// extracts a transaction id from CTxMemPoolEntry or CTransactionRef
61
63 return entry->GetTx().GetId();
64 }
65
67 return tx->GetId();
68 }
69};
70
76 return entry.GetSharedTx()->GetId();
77 }
78};
79
80// used by the entry_time index
83 const CTxMemPoolEntryRef &b) const {
84 return a->GetTime() < b->GetTime();
85 }
86};
87
88// used by the entry_id index
91 const CTxMemPoolEntryRef &b) const {
92 return a->GetEntryId() < b->GetEntryId();
93 }
94};
95
103 // Used in tests
104 bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const {
105 const CFeeRate frA = a.GetModifiedFeeRate();
106 const CFeeRate frB = b.GetModifiedFeeRate();
107
108 // Sort by modified fee rate first
109 if (frA != frB) {
110 return frA > frB;
111 }
112
113 // Ties are broken by whichever is topologically earlier
114 // (this helps mining code avoid some backtracking).
115 if (a.GetEntryId() != b.GetEntryId()) {
116 return a.GetEntryId() < b.GetEntryId();
117 }
118
119 // If nothing else, sort by txid (this should never happen as entryID is
120 // expected to be unique).
121 return a.GetSharedTx()->GetId() < b.GetSharedTx()->GetId();
122 }
123
125 const CTxMemPoolEntryRef &b) const {
126 return operator()(*a, *b);
127 }
128};
129
130// Multi_index tag names
131struct entry_time {};
133struct entry_id {};
134
141
143 std::chrono::seconds m_time;
144
147
149 size_t vsize;
150
153};
154
161 EXPIRY,
163 SIZELIMIT,
165 REORG,
167 BLOCK,
169 CONFLICT,
171 AVALANCHE,
173 MANUAL,
174};
175
176std::string RemovalReasonToString(const MemPoolRemovalReason &r) noexcept;
177
223private:
225 std::atomic<uint32_t> nTransactionsUpdated{0};
226
228 uint64_t totalTxSize GUARDED_BY(cs);
230 node::BlockFitter m_finalizedTxsFitter GUARDED_BY(cs);
232 Amount m_total_fee GUARDED_BY(cs);
235 uint64_t cachedInnerUsage GUARDED_BY(cs);
236
237 mutable int64_t lastRollingFeeUpdate GUARDED_BY(cs);
238 mutable bool blockSinceLastRollingFeeBump GUARDED_BY(cs);
240 mutable double rollingMinimumFeeRate GUARDED_BY(cs);
241
242 // In-memory counter for external mempool tracking purposes.
243 // This number is incremented once every time a transaction
244 // is added or removed from the mempool for any reason.
245 mutable uint64_t m_sequence_number GUARDED_BY(cs){1};
246
248
249 bool m_load_tried GUARDED_BY(cs){false};
250
253 uint64_t nextEntryId GUARDED_BY(cs) = 1;
254
257 std::unique_ptr<TxOrphanage> m_orphanage GUARDED_BY(cs_orphanage);
258
261 std::unique_ptr<TxConflicting> m_conflicting GUARDED_BY(cs_conflicting);
262
263public:
264 // public only for testing
265 static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12;
266
267 typedef boost::multi_index_container<
269 boost::multi_index::indexed_by<
270 // indexed by txid
271 boost::multi_index::hashed_unique<mempoolentry_txid,
273 // sorted by fee rate
274 boost::multi_index::ordered_non_unique<
275 boost::multi_index::tag<modified_feerate>,
276 boost::multi_index::identity<CTxMemPoolEntryRef>,
278 // sorted by entry time
279 boost::multi_index::ordered_non_unique<
280 boost::multi_index::tag<entry_time>,
281 boost::multi_index::identity<CTxMemPoolEntryRef>,
283 // sorted topologically (insertion order)
284 boost::multi_index::ordered_unique<
285 boost::multi_index::tag<entry_id>,
286 boost::multi_index::identity<CTxMemPoolEntryRef>,
289
318
319 using txiter = indexed_transaction_set::nth_index<0>::type::const_iterator;
320 typedef std::set<txiter, CompareIteratorById> setEntries;
321 typedef std::set<txiter, CompareIteratorByRevEntryId> setRevTopoEntries;
322
324
325private:
326 void UpdateParent(txiter entry, txiter parent, bool add)
328 void UpdateChild(txiter entry, txiter child, bool add)
330
335 std::set<TxId> m_unbroadcast_txids GUARDED_BY(cs);
336
345 void CalculateAncestors(setEntries &setAncestors,
346 CTxMemPoolEntry::Parents &staged_ancestors,
347 bool unfinalizedOnly = false) const
349
350public:
351 indirectmap<COutPoint, CTransactionRef> mapNextTx GUARDED_BY(cs);
352 std::map<TxId, Amount> mapDeltas GUARDED_BY(cs);
353
354 using Options = kernel::MemPoolOptions;
355
357
364 CTxMemPool(const Config &config, Options opts);
366
373 void check(const CCoinsViewCache &active_coins_tip,
374 int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
375
376 // addUnchecked must update state for all parents of a given transaction,
377 // updating child links as necessary.
380
381 void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason)
383 void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs);
385 void
386 removeForFinalizedBlock(const std::unordered_set<TxId, SaltedTxIdHasher>
387 &confirmedTxIdsInNonFinalizedBlocks)
389
390 void clear(bool include_finalized_txs = false);
391 // lock free
393 bool CompareTopologically(const TxId &txida, const TxId &txidb) const;
394 void getAllTxIds(std::vector<TxId> &vtxid) const;
395 bool isSpent(const COutPoint &outpoint) const;
396 unsigned int GetTransactionsUpdated() const;
397 void AddTransactionsUpdated(unsigned int n);
403 bool HasNoInputsOf(const CTransaction &tx) const
405
407 void PrioritiseTransaction(const TxId &txid, const Amount nFeeDelta);
408 void ApplyDelta(const TxId &txid, Amount &nFeeDelta) const
411
413 CTransactionRef GetConflictTx(const COutPoint &prevout) const
415
417 std::optional<txiter> GetIter(const TxId &txid) const
419
424 setEntries GetIterSet(const std::set<TxId> &txids) const
426
432 void RemoveStaged(const setEntries &stage, MemPoolRemovalReason reason)
434
444 setEntries &setAncestors,
445 bool unfinalizedOnly = false) const
447
453 void CalculateDescendants(txiter it, setEntries &setDescendants) const
455
461 CFeeRate GetMinFee(size_t sizelimit) const;
462
469 void TrimToSize(size_t sizelimit,
470 std::vector<COutPoint> *pvNoSpendsRemaining = nullptr)
472
477 int Expire(std::chrono::seconds time) EXCLUSIVE_LOCKS_REQUIRED(cs);
478
482 void LimitSize(CCoinsViewCache &coins_cache)
484
489 bool GetLoadTried() const;
490
495 void SetLoadTried(bool load_tried);
496
497 unsigned long size() const {
498 LOCK(cs);
499 return mapTx.size();
500 }
501
504 return totalTxSize;
505 }
506
509 return m_finalizedTxsFitter.nBlockTx;
510 }
511
514 return m_finalizedTxsFitter.nBlockSize -
516 }
517
520 return m_finalizedTxsFitter.nBlockSigChecks -
522 }
523
524 bool isWorthPolling(const CTransactionRef &tx) const
526
529 return m_total_fee;
530 }
531
532 bool exists(const TxId &txid) const {
533 LOCK(cs);
534 return mapTx.count(txid) != 0;
535 }
536
537 bool setAvalancheFinalized(const CTxMemPoolEntryRef &tx,
538 const Consensus::Params &params,
539 const CBlockIndex &active_chain_tip,
540 Chainstate &active_chainstate,
541 std::vector<TxId> &finalizedTxIds)
543
547 return finalizedTxs.get(txid) != nullptr;
548 }
549
550 CTransactionRef get(const TxId &txid) const;
551 TxMempoolInfo info(const TxId &txid) const;
552 std::vector<TxMempoolInfo> infoAll() const;
553
554 CFeeRate estimateFee() const;
555
556 size_t DynamicMemoryUsage() const;
557
559 void AddUnbroadcastTx(const TxId &txid) {
560 LOCK(cs);
561 // Sanity check the transaction is in the mempool & insert into
562 // unbroadcast set.
563 if (exists(txid)) {
564 m_unbroadcast_txids.insert(txid);
565 }
566 }
567
569 void RemoveUnbroadcastTx(const TxId &txid, const bool unchecked = false);
570
572 std::set<TxId> GetUnbroadcastTxs() const {
573 LOCK(cs);
574 return m_unbroadcast_txids;
575 }
576
580 return (m_unbroadcast_txids.count(txid) != 0);
581 }
582
585 return m_sequence_number++;
586 }
587
589 return m_sequence_number;
590 }
591
592 template <typename Callable>
593 auto withOrphanage(Callable &&func) const
596 assert(m_orphanage);
597 return func(*m_orphanage);
598 }
599
600 template <typename Callable>
601 auto withConflicting(Callable &&func) const
604 assert(m_conflicting);
605 return func(*m_conflicting);
606 }
607
608private:
610 void UpdateEntryForAncestors(txiter it, const setEntries *setAncestors)
620 void UpdateForRemoveFromMempool(const setEntries &entriesToRemove)
624
635};
636
656 std::unordered_map<COutPoint, Coin, SaltedOutpointHasher> m_temp_added;
657
663 mutable std::unordered_set<COutPoint, SaltedOutpointHasher>
665
666protected:
668
669public:
670 CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn);
675 std::optional<Coin> GetCoin(const COutPoint &outpoint) const override;
683 std::unordered_set<COutPoint, SaltedOutpointHasher>
685 return m_non_base_coins;
686 }
688 void Reset();
689};
690
691#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:138
CCoinsView backed by another CCoinsView.
Definition: coins.h:337
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:357
Abstract view on the open txout dataset.
Definition: coins.h:303
CCoinsView that brings transactions from a mempool into view.
Definition: txmempool.h:650
std::unordered_set< COutPoint, SaltedOutpointHasher > GetNonBaseCoins() const
Get all coins in m_non_base_coins.
Definition: txmempool.h:684
std::optional< Coin > GetCoin(const COutPoint &outpoint) const override
GetCoin, returning whether it exists and is not spent.
Definition: txmempool.cpp:796
void Reset()
Clear m_temp_added and m_non_base_coins.
Definition: txmempool.cpp:826
std::unordered_map< COutPoint, Coin, SaltedOutpointHasher > m_temp_added
Coins made available by transactions being validated.
Definition: txmempool.h:656
CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn)
Definition: txmempool.cpp:791
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:664
void PackageAddTransaction(const CTransactionRef &tx)
Add the coins created by this transaction.
Definition: txmempool.cpp:819
const CTxMemPool & mempool
Definition: txmempool.h:667
Fee rate in satoshis per virtualbyte: Amount / vB the feerate is represented internally as FeeFrac.
Definition: feerate.h:24
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:222
void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:296
CFeeRate estimateFee() const
Definition: txmempool.cpp:713
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:781
void ClearPrioritisation(const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:751
std::set< txiter, CompareIteratorById > setEntries
Definition: txmempool.h:320
void CalculateAncestors(setEntries &setAncestors, CTxMemPoolEntry::Parents &staged_ancestors, bool unfinalizedOnly=false) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Helper function to calculate all in-mempool ancestors of staged_ancestors.
Definition: txmempool.cpp:32
void RemoveUnbroadcastTx(const TxId &txid, const bool unchecked=false)
Removes a transaction from the unbroadcast set.
Definition: txmempool.cpp:842
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:1038
void updateFeeForBlock() EXCLUSIVE_LOCKS_REQUIRED(cs)
Called when a block is connected.
Definition: txmempool.cpp:317
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:460
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:316
void trackPackageRemoved(const CFeeRate &rate) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:955
Amount GetTotalFee() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:527
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:265
void UpdateForRemoveFromMempool(const setEntries &entriesToRemove) EXCLUSIVE_LOCKS_REQUIRED(cs)
For each transaction being removed, update ancestors and any direct children.
Definition: txmempool.cpp:100
bool blockSinceLastRollingFeeBump GUARDED_BY(cs)
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:963
void AddTransactionsUpdated(unsigned int n)
Definition: txmempool.cpp:136
void UpdateChildrenForRemoval(txiter entry) EXCLUSIVE_LOCKS_REQUIRED(cs)
Sever link between specified transaction and direct children.
Definition: txmempool.cpp:90
uint64_t GetTotalFinalizedTxSigchecks() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:518
bool setAvalancheFinalized(const CTxMemPoolEntryRef &tx, const Consensus::Params &params, const CBlockIndex &active_chain_tip, Chainstate &active_chainstate, std::vector< TxId > &finalizedTxIds) EXCLUSIVE_LOCKS_REQUIRED(bool isAvalancheFinalizedPreConsensus(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:544
bool CompareTopologically(const TxId &txida, const TxId &txidb) const
Definition: txmempool.cpp:495
TxMempoolInfo info(const TxId &txid) const
Definition: txmempool.cpp:703
void getAllTxIds(std::vector< TxId > &vtxid) const
Definition: txmempool.cpp:509
std::atomic< uint32_t > nTransactionsUpdated
Used by getblocktemplate to trigger CreateNewBlock() invocation.
Definition: txmempool.h:225
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:770
std::unique_ptr< TxConflicting > m_conflicting GUARDED_BY(cs_conflicting)
Storage for conflicting txs information.
size_t DynamicMemoryUsage() const
Definition: txmempool.cpp:831
const Options m_opts
Definition: txmempool.h:356
std::vector< TxMempoolInfo > infoAll() const
Definition: txmempool.cpp:527
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:896
void UpdateParent(txiter entry, txiter parent, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:922
CTransactionRef GetConflictTx(const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Get the transaction in the pool that spends the same prevout.
Definition: txmempool.cpp:756
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:191
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:865
bool isWorthPolling(const CTransactionRef &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs
Definition: txmempool.cpp:669
std::set< txiter, CompareIteratorByRevEntryId > setRevTopoEntries
Definition: txmempool.h:321
bool exists(const TxId &txid) const
Definition: txmempool.h:532
std::set< TxId > GetUnbroadcastTxs() const
Returns transactions in unbroadcast set.
Definition: txmempool.h:572
node::BlockFitter m_finalizedTxsFitter GUARDED_BY(cs)
Check whether the finalized txs would fit a block.
int64_t lastRollingFeeUpdate GUARDED_BY(cs)
bool m_load_tried GUARDED_BY(cs)
Definition: txmempool.h:249
static const int ROLLING_FEE_HALFLIFE
Definition: txmempool.h:265
auto withOrphanage(Callable &&func) const EXCLUSIVE_LOCKS_REQUIRED(!cs_orphanage)
Definition: txmempool.h:593
CTransactionRef get(const TxId &txid) const
Definition: txmempool.cpp:693
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:288
void PrioritiseTransaction(const TxId &txid, const Amount nFeeDelta)
Affect CreateNewBlock prioritisation of transactions.
Definition: txmempool.cpp:723
uint64_t GetSequence() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:588
bool IsUnbroadcastTx(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns whether a txid is in the unbroadcast set.
Definition: txmempool.h:578
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
Definition: txmempool.h:319
uint64_t GetAndIncrementSequence() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Guards this internal counter for external reporting.
Definition: txmempool.h:584
void UpdateChild(txiter entry, txiter child, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:912
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:378
Mutex cs_orphanage
Definition: txmempool.h:255
RadixTree< CTxMemPoolEntry, MemPoolEntryRadixTreeAdapter > finalizedTxs
Definition: txmempool.h:323
uint64_t GetFinalizedTxCount() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:507
void check(const CCoinsViewCache &active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(void cs_main
Definition: txmempool.h:379
void CalculateMemPoolAncestors(const CTxMemPoolEntryRef &entry, setEntries &setAncestors, bool unfinalizedOnly=false) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Calculate all in-mempool ancestors of entry.
Definition: txmempool.cpp:61
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:601
void removeForFinalizedBlock(const std::unordered_set< TxId, SaltedTxIdHasher > &confirmedTxIdsInNonFinalizedBlocks) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:323
void clear(bool include_finalized_txs=false)
Definition: txmempool.cpp:374
Mutex cs_conflicting
Definition: txmempool.h:259
uint64_t GetTotalFinalizedTxSize() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:512
void CalculateDescendants(txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Populate setDescendants with all in-mempool descendants of hash.
Definition: txmempool.cpp:238
void RemoveStaged(const setEntries &stage, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Remove a set of transactions from the mempool.
Definition: txmempool.cpp:853
unsigned long size() const
Definition: txmempool.h:497
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:81
uint64_t m_sequence_number GUARDED_BY(cs)
Definition: txmempool.h:245
void ApplyDelta(const TxId &txid, Amount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:741
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:1043
std::optional< txiter > GetIter(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns an iterator to the given txid, if found.
Definition: txmempool.cpp:761
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:502
bool isSpent(const COutPoint &outpoint) const
Definition: txmempool.cpp:127
void AddUnbroadcastTx(const TxId &txid)
Adds a transaction to the unbroadcast set.
Definition: txmempool.h:559
unsigned int GetTransactionsUpdated() const
Definition: txmempool.cpp:132
void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:362
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:727
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:1176
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
Definition: init.h:28
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:23
Definition: txmempool.h:89
bool operator()(const CTxMemPoolEntryRef &a, const CTxMemPoolEntryRef &b) const
Definition: txmempool.h:90
Definition: txmempool.h:81
bool operator()(const CTxMemPoolEntryRef &a, const CTxMemPoolEntryRef &b) const
Definition: txmempool.h:82
Sort by feerate of entry (modfee/vsize) in descending order.
Definition: txmempool.h:102
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:104
bool operator()(const CTxMemPoolEntryRef &a, const CTxMemPoolEntryRef &b) const
Definition: txmempool.h:124
Parameters that influence chain consensus.
Definition: params.h:34
Radix tree adapter for storing a CTxMemPoolEntry as a tree element.
Definition: txmempool.h:74
Uint256RadixKey getId(const CTxMemPoolEntry &entry) const
Definition: txmempool.h:75
RCUPtr< T > get(const KeyType &key)
Get the value corresponding to a key.
Definition: radix.h:117
A TxId is the identifier of a transaction.
Definition: txid.h:14
Information about a mempool transaction.
Definition: txmempool.h:138
Amount fee
Fee of the transaction.
Definition: txmempool.h:146
Amount nFeeDelta
The fee delta.
Definition: txmempool.h:152
CTransactionRef tx
The transaction itself.
Definition: txmempool.h:140
std::chrono::seconds m_time
Time the transaction entered the mempool.
Definition: txmempool.h:143
size_t vsize
Virtual size of the transaction.
Definition: txmempool.h:149
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:62
result_type operator()(const CTransactionRef &tx) const
Definition: txmempool.h:66
#define LOCK(cs)
Definition: sync.h:295
#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:159
@ 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:1048
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:56
AssertLockHeld(pool.cs)
assert(!tx.IsCoinBase())