Bitcoin ABC 0.33.11
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
343 bool CalculateAncestors(setEntries &setAncestors,
344 CTxMemPoolEntry::Parents &staged_ancestors) const
346
347public:
349 std::map<TxId, Amount> mapDeltas GUARDED_BY(cs);
350
352
354
361 CTxMemPool(const Config &config, Options opts);
362 ~CTxMemPool();
363
370 void check(const CCoinsViewCache &active_coins_tip,
371 int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
372
373 // addUnchecked must update state for all parents of a given transaction,
374 // updating child links as necessary.
377
378 void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason)
380 void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs);
382 void
383 removeForFinalizedBlock(const std::unordered_set<TxId, SaltedTxIdHasher>
384 &confirmedTxIdsInNonFinalizedBlocks)
386
387 void clear(bool include_finalized_txs = false);
388 // lock free
390 bool CompareTopologically(const TxId &txida, const TxId &txidb) const;
391 void getAllTxIds(std::vector<TxId> &vtxid) const;
392 bool isSpent(const COutPoint &outpoint) const;
393 unsigned int GetTransactionsUpdated() const;
394 void AddTransactionsUpdated(unsigned int n);
400 bool HasNoInputsOf(const CTransaction &tx) const
402
404 void PrioritiseTransaction(const TxId &txid, const Amount nFeeDelta);
405 void ApplyDelta(const TxId &txid, Amount &nFeeDelta) const
408
410 CTransactionRef GetConflictTx(const COutPoint &prevout) const
412
414 std::optional<txiter> GetIter(const TxId &txid) const
416
421 setEntries GetIterSet(const std::set<TxId> &txids) const
423
429 void RemoveStaged(const setEntries &stage, MemPoolRemovalReason reason)
431
440 setEntries &setAncestors,
441 bool fSearchForParents = true) const
443
449 void CalculateDescendants(txiter it, setEntries &setDescendants) const
451
457 CFeeRate GetMinFee(size_t sizelimit) const;
458
465 void TrimToSize(size_t sizelimit,
466 std::vector<COutPoint> *pvNoSpendsRemaining = nullptr)
468
473 int Expire(std::chrono::seconds time) EXCLUSIVE_LOCKS_REQUIRED(cs);
474
478 void LimitSize(CCoinsViewCache &coins_cache)
480
485 bool GetLoadTried() const;
486
491 void SetLoadTried(bool load_tried);
492
493 unsigned long size() const {
494 LOCK(cs);
495 return mapTx.size();
496 }
497
500 return totalTxSize;
501 }
502
505 return m_finalizedTxsFitter.nBlockTx;
506 }
507
510 return m_finalizedTxsFitter.nBlockSize -
512 }
513
516 return m_finalizedTxsFitter.nBlockSigChecks -
518 }
519
520 bool isWorthPolling(const CTransactionRef &tx) const
522
525 return m_total_fee;
526 }
527
528 bool exists(const TxId &txid) const {
529 LOCK(cs);
530 return mapTx.count(txid) != 0;
531 }
532
533 bool setAvalancheFinalized(const CTxMemPoolEntryRef &tx,
534 const Consensus::Params &params,
535 const CBlockIndex &active_chain_tip,
536 std::vector<TxId> &finalizedTxIds)
538
542 return finalizedTxs.get(txid) != nullptr;
543 }
544
545 CTransactionRef get(const TxId &txid) const;
546 TxMempoolInfo info(const TxId &txid) const;
547 std::vector<TxMempoolInfo> infoAll() const;
548
549 CFeeRate estimateFee() const;
550
551 size_t DynamicMemoryUsage() const;
552
554 void AddUnbroadcastTx(const TxId &txid) {
555 LOCK(cs);
556 // Sanity check the transaction is in the mempool & insert into
557 // unbroadcast set.
558 if (exists(txid)) {
559 m_unbroadcast_txids.insert(txid);
560 }
561 }
562
564 void RemoveUnbroadcastTx(const TxId &txid, const bool unchecked = false);
565
567 std::set<TxId> GetUnbroadcastTxs() const {
568 LOCK(cs);
569 return m_unbroadcast_txids;
570 }
571
575 return (m_unbroadcast_txids.count(txid) != 0);
576 }
577
580 return m_sequence_number++;
581 }
582
584 return m_sequence_number;
585 }
586
587 template <typename Callable>
588 auto withOrphanage(Callable &&func) const
591 assert(m_orphanage);
592 return func(*m_orphanage);
593 }
594
595 template <typename Callable>
596 auto withConflicting(Callable &&func) const
599 assert(m_conflicting);
600 return func(*m_conflicting);
601 }
602
603private:
605 void UpdateEntryForAncestors(txiter it, const setEntries *setAncestors)
615 void UpdateForRemoveFromMempool(const setEntries &entriesToRemove)
619
630};
631
651 std::unordered_map<COutPoint, Coin, SaltedOutpointHasher> m_temp_added;
652
658 mutable std::unordered_set<COutPoint, SaltedOutpointHasher>
660
661protected:
663
664public:
665 CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn);
670 std::optional<Coin> GetCoin(const COutPoint &outpoint) const override;
678 std::unordered_set<COutPoint, SaltedOutpointHasher>
680 return m_non_base_coins;
681 }
683 void Reset();
684};
685
686#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:338
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:358
Abstract view on the open txout dataset.
Definition: coins.h:304
CCoinsView that brings transactions from a mempool into view.
Definition: txmempool.h:645
std::unordered_set< COutPoint, SaltedOutpointHasher > GetNonBaseCoins() const
Get all coins in m_non_base_coins.
Definition: txmempool.h:679
std::optional< Coin > GetCoin(const COutPoint &outpoint) const override
GetCoin, returning whether it exists and is not spent.
Definition: txmempool.cpp:779
void Reset()
Clear m_temp_added and m_non_base_coins.
Definition: txmempool.cpp:809
std::unordered_map< COutPoint, Coin, SaltedOutpointHasher > m_temp_added
Coins made available by transactions being validated.
Definition: txmempool.h:651
CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn)
Definition: txmempool.cpp:774
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:659
void PackageAddTransaction(const CTransactionRef &tx)
Add the coins created by this transaction.
Definition: txmempool.cpp:802
const CTxMemPool & mempool
Definition: txmempool.h:662
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:222
void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:299
CFeeRate estimateFee() const
Definition: txmempool.cpp:696
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:764
void ClearPrioritisation(const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:734
std::set< txiter, CompareIteratorById > setEntries
Definition: txmempool.h:320
void RemoveUnbroadcastTx(const TxId &txid, const bool unchecked=false)
Removes a transaction from the unbroadcast set.
Definition: txmempool.cpp:825
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:1021
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:320
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:456
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:938
Amount GetTotalFee() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:523
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:268
void UpdateForRemoveFromMempool(const setEntries &entriesToRemove) EXCLUSIVE_LOCKS_REQUIRED(cs)
For each transaction being removed, update ancestors and any direct children.
Definition: txmempool.cpp:103
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:946
void AddTransactionsUpdated(unsigned int n)
Definition: txmempool.cpp:139
void UpdateChildrenForRemoval(txiter entry) EXCLUSIVE_LOCKS_REQUIRED(cs)
Sever link between specified transaction and direct children.
Definition: txmempool.cpp:93
uint64_t GetTotalFinalizedTxSigchecks() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:514
bool CompareTopologically(const TxId &txida, const TxId &txidb) const
Definition: txmempool.cpp:501
TxMempoolInfo info(const TxId &txid) const
Definition: txmempool.cpp:686
std::map< TxId, Amount > mapDeltas GUARDED_BY(cs)
void getAllTxIds(std::vector< TxId > &vtxid) const
Definition: txmempool.cpp:515
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:753
std::unique_ptr< TxConflicting > m_conflicting GUARDED_BY(cs_conflicting)
Storage for conflicting txs information.
size_t DynamicMemoryUsage() const
Definition: txmempool.cpp:814
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:539
const Options m_opts
Definition: txmempool.h:353
std::vector< TxMempoolInfo > infoAll() const
Definition: txmempool.cpp:533
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:879
void UpdateParent(txiter entry, txiter parent, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:905
CTransactionRef GetConflictTx(const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Get the transaction in the pool that spends the same prevout.
Definition: txmempool.cpp:739
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:194
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:848
bool isWorthPolling(const CTransactionRef &tx) const EXCLUSIVE_LOCKS_REQUIRED(cs
Definition: txmempool.cpp:652
std::set< txiter, CompareIteratorByRevEntryId > setRevTopoEntries
Definition: txmempool.h:321
bool exists(const TxId &txid) const
Definition: txmempool.h:528
std::set< TxId > GetUnbroadcastTxs() const
Returns transactions in unbroadcast set.
Definition: txmempool.h:567
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:588
CTransactionRef get(const TxId &txid) const
Definition: txmempool.cpp:676
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:706
CTxMemPool(const Config &config, Options opts)
Create a new CTxMemPool.
Definition: txmempool.cpp:119
uint64_t GetSequence() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:583
bool IsUnbroadcastTx(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns whether a txid is in the unbroadcast set.
Definition: txmempool.h:573
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:579
void UpdateChild(txiter entry, txiter child, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:895
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:375
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:503
void check(const CCoinsViewCache &active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(void cs_main
Definition: txmempool.h:376
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:596
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:58
void removeForFinalizedBlock(const std::unordered_set< TxId, SaltedTxIdHasher > &confirmedTxIdsInNonFinalizedBlocks) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:326
void clear(bool include_finalized_txs=false)
Definition: txmempool.cpp:377
Mutex cs_conflicting
Definition: txmempool.h:259
uint64_t GetTotalFinalizedTxSize() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:508
void CalculateDescendants(txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Populate setDescendants with all in-mempool descendants of hash.
Definition: txmempool.cpp:241
void RemoveStaged(const setEntries &stage, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Remove a set of transactions from the mempool.
Definition: txmempool.cpp:836
unsigned long size() const
Definition: txmempool.h:493
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
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:724
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:1026
std::optional< txiter > GetIter(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns an iterator to the given txid, if found.
Definition: txmempool.cpp:744
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:498
bool isSpent(const COutPoint &outpoint) const
Definition: txmempool.cpp:130
void AddUnbroadcastTx(const TxId &txid)
Adds a transaction to the unbroadcast set.
Definition: txmempool.h:554
unsigned int GetTransactionsUpdated() const
Definition: txmempool.cpp:135
void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:365
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:725
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:1174
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: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: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: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:1031
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())