Bitcoin ABC 0.30.12
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 <policy/packages.h>
18#include <radix.h>
19#include <sync.h>
20#include <txconflicting.h>
21#include <txorphanage.h>
22#include <uint256radixkey.h>
23#include <util/hasher.h>
24
25#include <boost/multi_index/hashed_index.hpp>
26#include <boost/multi_index/ordered_index.hpp>
27#include <boost/multi_index/sequenced_index.hpp>
28#include <boost/multi_index_container.hpp>
29
30#include <atomic>
31#include <map>
32#include <memory>
33#include <optional>
34#include <set>
35#include <string>
36#include <unordered_map>
37#include <utility>
38#include <vector>
39
40class CChain;
41class Chainstate;
43class Config;
44
49static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
50
51// extracts a transaction id from CTxMemPoolEntry or CTransactionRef
54
56 return entry->GetTx().GetId();
57 }
58
60 return tx->GetId();
61 }
62};
63
69 return entry.GetSharedTx()->GetId();
70 }
71};
72
73// used by the entry_time index
76 const CTxMemPoolEntryRef &b) const {
77 return a->GetTime() < b->GetTime();
78 }
79};
80
81// used by the entry_id index
84 const CTxMemPoolEntryRef &b) const {
85 return a->GetEntryId() < b->GetEntryId();
86 }
87};
88
96 // Used in tests
97 bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const {
98 const CFeeRate frA = a.GetModifiedFeeRate();
99 const CFeeRate frB = b.GetModifiedFeeRate();
100
101 // Sort by modified fee rate first
102 if (frA != frB) {
103 return frA > frB;
104 }
105
106 // Ties are broken by whichever is topologically earlier
107 // (this helps mining code avoid some backtracking).
108 if (a.GetEntryId() != b.GetEntryId()) {
109 return a.GetEntryId() < b.GetEntryId();
110 }
111
112 // If nothing else, sort by txid (this should never happen as entryID is
113 // expected to be unique).
114 return a.GetSharedTx()->GetId() < b.GetSharedTx()->GetId();
115 }
116
118 const CTxMemPoolEntryRef &b) const {
119 return operator()(*a, *b);
120 }
121};
122
123// Multi_index tag names
124struct entry_time {};
126struct entry_id {};
127
134
136 std::chrono::seconds m_time;
137
140
142 size_t vsize;
143
146};
147
154 EXPIRY,
156 SIZELIMIT,
158 REORG,
160 BLOCK,
162 CONFLICT,
164 AVALANCHE,
165};
166
167const std::string RemovalReasonToString(const MemPoolRemovalReason &r) noexcept;
168
214private:
216 const int m_check_ratio;
218 std::atomic<uint32_t> nTransactionsUpdated{0};
219
221 uint64_t totalTxSize GUARDED_BY(cs);
223 uint64_t totalFinalizedTxSize GUARDED_BY(cs){0};
225 uint64_t totalFinalizedTxSigchecks GUARDED_BY(cs){0};
227 Amount m_total_fee GUARDED_BY(cs);
230 uint64_t cachedInnerUsage GUARDED_BY(cs);
231
232 mutable int64_t lastRollingFeeUpdate GUARDED_BY(cs);
233 mutable bool blockSinceLastRollingFeeBump GUARDED_BY(cs);
235 mutable double rollingMinimumFeeRate GUARDED_BY(cs);
236
237 // In-memory counter for external mempool tracking purposes.
238 // This number is incremented once every time a transaction
239 // is added or removed from the mempool for any reason.
240 mutable uint64_t m_sequence_number GUARDED_BY(cs){1};
241
243
244 bool m_load_tried GUARDED_BY(cs){false};
245
248 uint64_t nextEntryId GUARDED_BY(cs) = 1;
249
252 std::unique_ptr<TxOrphanage> m_orphanage GUARDED_BY(cs_orphanage);
253
256 std::unique_ptr<TxConflicting> m_conflicting GUARDED_BY(cs_conflicting);
257
258public:
259 // public only for testing
260 static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12;
261
262 typedef boost::multi_index_container<
264 boost::multi_index::indexed_by<
265 // indexed by txid
266 boost::multi_index::hashed_unique<mempoolentry_txid,
268 // sorted by fee rate
269 boost::multi_index::ordered_non_unique<
270 boost::multi_index::tag<modified_feerate>,
271 boost::multi_index::identity<CTxMemPoolEntryRef>,
273 // sorted by entry time
274 boost::multi_index::ordered_non_unique<
275 boost::multi_index::tag<entry_time>,
276 boost::multi_index::identity<CTxMemPoolEntryRef>,
278 // sorted topologically (insertion order)
279 boost::multi_index::ordered_unique<
280 boost::multi_index::tag<entry_id>,
281 boost::multi_index::identity<CTxMemPoolEntryRef>,
284
314
315 using txiter = indexed_transaction_set::nth_index<0>::type::const_iterator;
316 typedef std::set<txiter, CompareIteratorById> setEntries;
317 typedef std::set<txiter, CompareIteratorByRevEntryId> setRevTopoEntries;
318
320
321private:
322 void UpdateParent(txiter entry, txiter parent, bool add)
324 void UpdateChild(txiter entry, txiter child, bool add)
326
331 std::set<TxId> m_unbroadcast_txids GUARDED_BY(cs);
332
339 bool CalculateAncestors(setEntries &setAncestors,
340 CTxMemPoolEntry::Parents &staged_ancestors) const
342
343public:
345 std::map<TxId, Amount> mapDeltas GUARDED_BY(cs);
346
348
349 const int64_t m_max_size_bytes;
350 const std::chrono::seconds m_expiry;
354 const std::optional<unsigned> m_max_datacarrier_bytes;
356
363 CTxMemPool(const Options &opts);
364 ~CTxMemPool();
365
372 void check(const CCoinsViewCache &active_coins_tip,
373 int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
374
375 // addUnchecked must update state for all parents of a given transaction,
376 // updating child links as necessary.
379
380 void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason)
382 void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs);
384 void removeForFinalizedBlock(const std::vector<CTransactionRef> &vtx)
386
387 void clear();
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 totalFinalizedTxSize;
506 }
507
510 return totalFinalizedTxSigchecks;
511 }
512
515 return m_total_fee;
516 }
517
518 bool exists(const TxId &txid) const {
519 LOCK(cs);
520 return mapTx.count(txid) != 0;
521 }
522
525 const bool ret = finalizedTxs.insert(tx);
526 if (ret) {
527 totalFinalizedTxSize += tx->GetTxSize();
528 totalFinalizedTxSigchecks += tx->GetSigChecks();
529 }
530
531 return ret;
532 }
533
534 bool isAvalancheFinalized(const TxId &txid) const {
535 LOCK(cs);
536 return finalizedTxs.get(txid) != nullptr;
537 }
538
539 CTransactionRef get(const TxId &txid) const;
540 TxMempoolInfo info(const TxId &txid) const;
541 std::vector<TxMempoolInfo> infoAll() const;
542
543 CFeeRate estimateFee() const;
544
545 size_t DynamicMemoryUsage() const;
546
548 void AddUnbroadcastTx(const TxId &txid) {
549 LOCK(cs);
550 // Sanity check the transaction is in the mempool & insert into
551 // unbroadcast set.
552 if (exists(txid)) {
553 m_unbroadcast_txids.insert(txid);
554 }
555 }
556
558 void RemoveUnbroadcastTx(const TxId &txid, const bool unchecked = false);
559
561 std::set<TxId> GetUnbroadcastTxs() const {
562 LOCK(cs);
563 return m_unbroadcast_txids;
564 }
565
569 return (m_unbroadcast_txids.count(txid) != 0);
570 }
571
574 return m_sequence_number++;
575 }
576
578 return m_sequence_number;
579 }
580
581 template <typename Callable>
582 auto withOrphanage(Callable &&func) const
585 assert(m_orphanage);
586 return func(*m_orphanage);
587 }
588
589 template <typename Callable>
590 auto withConflicting(Callable &&func) const
593 assert(m_conflicting);
594 return func(*m_conflicting);
595 }
596
597private:
599 void UpdateEntryForAncestors(txiter it, const setEntries *setAncestors)
609 void UpdateForRemoveFromMempool(const setEntries &entriesToRemove)
613
624};
625
645 std::unordered_map<COutPoint, Coin, SaltedOutpointHasher> m_temp_added;
646
652 mutable std::unordered_set<COutPoint, SaltedOutpointHasher>
654
655protected:
657
658public:
659 CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn);
664 bool GetCoin(const COutPoint &outpoint, Coin &coin) const override;
672 std::unordered_set<COutPoint, SaltedOutpointHasher>
674 return m_non_base_coins;
675 }
677 void Reset();
678};
679
680#endif // BITCOIN_TXMEMPOOL_H
An in-memory indexed chain of blocks.
Definition: chain.h:134
CCoinsView backed by another CCoinsView.
Definition: coins.h:201
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:221
Abstract view on the open txout dataset.
Definition: coins.h:163
CCoinsView that brings transactions from a mempool into view.
Definition: txmempool.h:639
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
GetCoin, returning whether it exists and is not spent.
Definition: txmempool.cpp:616
std::unordered_set< COutPoint, SaltedOutpointHasher > GetNonBaseCoins() const
Get all coins in m_non_base_coins.
Definition: txmempool.h:673
void Reset()
Clear m_temp_added and m_non_base_coins.
Definition: txmempool.cpp:647
std::unordered_map< COutPoint, Coin, SaltedOutpointHasher > m_temp_added
Coins made available by transactions being validated.
Definition: txmempool.h:645
CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn)
Definition: txmempool.cpp:612
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:653
void PackageAddTransaction(const CTransactionRef &tx)
Add the coins created by this transaction.
Definition: txmempool.cpp:640
const CTxMemPool & mempool
Definition: txmempool.h:656
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:213
void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:296
bool isAvalancheFinalized(const TxId &txid) const
Definition: txmempool.h:534
CFeeRate estimateFee() const
Definition: txmempool.cpp:534
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:602
void ClearPrioritisation(const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:572
std::set< txiter, CompareIteratorById > setEntries
Definition: txmempool.h:316
const bool m_require_standard
Definition: txmempool.h:355
void RemoveUnbroadcastTx(const TxId &txid, const bool unchecked=false)
Removes a transaction from the unbroadcast set.
Definition: txmempool.cpp:663
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)
uint64_t totalFinalizedTxSigchecks GUARDED_BY(cs)
sum of all mempool finalized tx's sigchecks
Definition: txmempool.h:225
bool GetLoadTried() const
Definition: txmempool.cpp:817
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:29
void updateFeeForBlock() EXCLUSIVE_LOCKS_REQUIRED(cs)
Called when a block is connected.
Definition: txmempool.cpp:314
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:312
void trackPackageRemoved(const CFeeRate &rate) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:764
Amount GetTotalFee() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:513
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:101
bool blockSinceLastRollingFeeBump GUARDED_BY(cs)
const int m_check_ratio
Value n means that 1 times in n we check.
Definition: txmempool.h:216
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:772
const std::chrono::seconds m_expiry
Definition: txmempool.h:350
const std::optional< unsigned > m_max_datacarrier_bytes
Definition: txmempool.h:354
void AddTransactionsUpdated(unsigned int n)
Definition: txmempool.cpp:142
void UpdateChildrenForRemoval(txiter entry) EXCLUSIVE_LOCKS_REQUIRED(cs)
Sever link between specified transaction and direct children.
Definition: txmempool.cpp:91
uint64_t GetTotalFinalizedTxSigchecks() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:508
bool CompareTopologically(const TxId &txida, const TxId &txidb) const
Definition: txmempool.cpp:468
TxMempoolInfo info(const TxId &txid) const
Definition: txmempool.cpp:524
std::map< TxId, Amount > mapDeltas GUARDED_BY(cs)
const int64_t m_max_size_bytes
Definition: txmempool.h:349
void getAllTxIds(std::vector< TxId > &vtxid) const
Definition: txmempool.cpp:482
std::atomic< uint32_t > nTransactionsUpdated
Used by getblocktemplate to trigger CreateNewBlock() invocation.
Definition: txmempool.h:218
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:591
std::unique_ptr< TxConflicting > m_conflicting GUARDED_BY(cs_conflicting)
Storage for conflicting txs information.
size_t DynamicMemoryUsage() const
Definition: txmempool.cpp:652
std::vector< TxMempoolInfo > infoAll() const
Definition: txmempool.cpp:500
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:705
bool setAvalancheFinalized(const CTxMemPoolEntryRef &tx) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:523
void UpdateParent(txiter entry, txiter parent, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:731
CTransactionRef GetConflictTx(const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Get the transaction in the pool that spends the same prevout.
Definition: txmempool.cpp:577
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:686
void clear()
Definition: txmempool.cpp:349
std::set< txiter, CompareIteratorByRevEntryId > setRevTopoEntries
Definition: txmempool.h:317
bool exists(const TxId &txid) const
Definition: txmempool.h:518
std::set< TxId > GetUnbroadcastTxs() const
Returns transactions in unbroadcast set.
Definition: txmempool.h:561
int64_t lastRollingFeeUpdate GUARDED_BY(cs)
const bool m_permit_bare_multisig
Definition: txmempool.h:353
bool m_load_tried GUARDED_BY(cs)
Definition: txmempool.h:244
static const int ROLLING_FEE_HALFLIFE
Definition: txmempool.h:260
auto withOrphanage(Callable &&func) const EXCLUSIVE_LOCKS_REQUIRED(!cs_orphanage)
Definition: txmempool.h:582
CTransactionRef get(const TxId &txid) const
Definition: txmempool.cpp:514
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:283
const CFeeRate m_min_relay_feerate
Definition: txmempool.h:351
void PrioritiseTransaction(const TxId &txid, const Amount nFeeDelta)
Affect CreateNewBlock prioritisation of transactions.
Definition: txmempool.cpp:544
uint64_t GetSequence() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:577
bool IsUnbroadcastTx(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns whether a txid is in the unbroadcast set.
Definition: txmempool.h:567
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
Definition: txmempool.h:315
uint64_t GetAndIncrementSequence() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Guards this internal counter for external reporting.
Definition: txmempool.h:573
void UpdateChild(txiter entry, txiter child, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:721
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:377
Mutex cs_orphanage
Definition: txmempool.h:250
RadixTree< CTxMemPoolEntry, MemPoolEntryRadixTreeAdapter > finalizedTxs
Definition: txmempool.h:319
void check(const CCoinsViewCache &active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(void cs_main
Definition: txmempool.h:378
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.
CTxMemPool(const Options &opts)
Create a new CTxMemPool.
Definition: txmempool.cpp:117
auto withConflicting(Callable &&func) const EXCLUSIVE_LOCKS_REQUIRED(!cs_conflicting)
Definition: txmempool.h:590
uint64_t totalFinalizedTxSize GUARDED_BY(cs)
sum of all mempool finalized tx's sizes
Definition: txmempool.h:223
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:56
void removeForFinalizedBlock(const std::vector< CTransactionRef > &vtx) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:321
Mutex cs_conflicting
Definition: txmempool.h:254
uint64_t GetTotalFinalizedTxSize() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:503
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:674
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:82
uint64_t m_sequence_number GUARDED_BY(cs)
Definition: txmempool.h:240
void ApplyDelta(const TxId &txid, Amount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:562
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:822
const CFeeRate m_dust_relay_feerate
Definition: txmempool.h:352
std::optional< txiter > GetIter(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns an iterator to the given txid, if found.
Definition: txmempool.cpp:582
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:133
void AddUnbroadcastTx(const TxId &txid)
Adds a transaction to the unbroadcast set.
Definition: txmempool.h:548
unsigned int GetTransactionsUpdated() const
Definition: txmempool.cpp:138
void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:337
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:699
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:1140
A UTXO entry.
Definition: coins.h:28
Definition: config.h:19
Definition: rcu.h:85
Map whose keys are pointers, but are compared by their dereferenced values.
Definition: indirectmap.h:26
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:82
bool operator()(const CTxMemPoolEntryRef &a, const CTxMemPoolEntryRef &b) const
Definition: txmempool.h:83
Definition: txmempool.h:74
bool operator()(const CTxMemPoolEntryRef &a, const CTxMemPoolEntryRef &b) const
Definition: txmempool.h:75
Sort by feerate of entry (modfee/vsize) in descending order.
Definition: txmempool.h:95
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:97
bool operator()(const CTxMemPoolEntryRef &a, const CTxMemPoolEntryRef &b) const
Definition: txmempool.h:117
Radix tree adapter for storing a CTxMemPoolEntry as a tree element.
Definition: txmempool.h:67
Uint256RadixKey getId(const CTxMemPoolEntry &entry) const
Definition: txmempool.h:68
RCUPtr< T > get(const KeyType &key)
Get the value corresponding to a key.
Definition: radix.h:118
bool insert(const RCUPtr< T > &value)
Insert a value into the tree.
Definition: radix.h:112
A TxId is the identifier of a transaction.
Definition: txid.h:14
Information about a mempool transaction.
Definition: txmempool.h:131
Amount fee
Fee of the transaction.
Definition: txmempool.h:139
Amount nFeeDelta
The fee delta.
Definition: txmempool.h:145
CTransactionRef tx
The transaction itself.
Definition: txmempool.h:133
std::chrono::seconds m_time
Time the transaction entered the mempool.
Definition: txmempool.h:136
size_t vsize
Virtual size of the transaction.
Definition: txmempool.h:142
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:55
result_type operator()(const CTransactionRef &tx) const
Definition: txmempool.h:59
#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:152
@ SIZELIMIT
Removed in size limiting.
@ EXPIRY
Expired from mempool.
@ 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:49
const std::string RemovalReasonToString(const MemPoolRemovalReason &r) noexcept
Definition: txmempool.cpp:828
AssertLockHeld(pool.cs)
assert(!tx.IsCoinBase())