Bitcoin ABC 0.30.7
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;
42class Config;
43
48static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
49
50// extracts a transaction id from CTxMemPoolEntry or CTransactionRef
53
55 return entry->GetTx().GetId();
56 }
57
59 return tx->GetId();
60 }
61};
62
68 return entry.GetSharedTx()->GetId();
69 }
70};
71
72// used by the entry_time index
75 const CTxMemPoolEntryRef &b) const {
76 return a->GetTime() < b->GetTime();
77 }
78};
79
80// used by the entry_id index
83 const CTxMemPoolEntryRef &b) const {
84 return a->GetEntryId() < b->GetEntryId();
85 }
86};
87
95 // Used in tests
96 bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const {
97 const CFeeRate frA = a.GetModifiedFeeRate();
98 const CFeeRate frB = b.GetModifiedFeeRate();
99
100 // Sort by modified fee rate first
101 if (frA != frB) {
102 return frA > frB;
103 }
104
105 // Ties are broken by whichever is topologically earlier
106 // (this helps mining code avoid some backtracking).
107 if (a.GetEntryId() != b.GetEntryId()) {
108 return a.GetEntryId() < b.GetEntryId();
109 }
110
111 // If nothing else, sort by txid (this should never happen as entryID is
112 // expected to be unique).
113 return a.GetSharedTx()->GetId() < b.GetSharedTx()->GetId();
114 }
115
117 const CTxMemPoolEntryRef &b) const {
118 return operator()(*a, *b);
119 }
120};
121
122// Multi_index tag names
123struct entry_time {};
125struct entry_id {};
126
133
135 std::chrono::seconds m_time;
136
139
141 size_t vsize;
142
145};
146
153 EXPIRY,
155 SIZELIMIT,
157 REORG,
159 BLOCK,
161 CONFLICT,
163 AVALANCHE,
164};
165
166const std::string RemovalReasonToString(const MemPoolRemovalReason &r) noexcept;
167
213private:
215 const int m_check_ratio;
217 std::atomic<uint32_t> nTransactionsUpdated{0};
218
220 uint64_t totalTxSize GUARDED_BY(cs);
222 Amount m_total_fee GUARDED_BY(cs);
225 uint64_t cachedInnerUsage GUARDED_BY(cs);
226
227 mutable int64_t lastRollingFeeUpdate GUARDED_BY(cs);
228 mutable bool blockSinceLastRollingFeeBump GUARDED_BY(cs);
230 mutable double rollingMinimumFeeRate GUARDED_BY(cs);
231
232 // In-memory counter for external mempool tracking purposes.
233 // This number is incremented once every time a transaction
234 // is added or removed from the mempool for any reason.
235 mutable uint64_t m_sequence_number GUARDED_BY(cs){1};
236
238
239 bool m_load_tried GUARDED_BY(cs){false};
240
243 uint64_t nextEntryId GUARDED_BY(cs) = 1;
244
247 std::unique_ptr<TxOrphanage> m_orphanage GUARDED_BY(cs_orphanage);
248
251 std::unique_ptr<TxConflicting> m_conflicting GUARDED_BY(cs_conflicting);
252
253public:
254 // public only for testing
255 static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12;
256
257 typedef boost::multi_index_container<
259 boost::multi_index::indexed_by<
260 // indexed by txid
261 boost::multi_index::hashed_unique<mempoolentry_txid,
263 // sorted by fee rate
264 boost::multi_index::ordered_non_unique<
265 boost::multi_index::tag<modified_feerate>,
266 boost::multi_index::identity<CTxMemPoolEntryRef>,
268 // sorted by entry time
269 boost::multi_index::ordered_non_unique<
270 boost::multi_index::tag<entry_time>,
271 boost::multi_index::identity<CTxMemPoolEntryRef>,
273 // sorted topologically (insertion order)
274 boost::multi_index::ordered_unique<
275 boost::multi_index::tag<entry_id>,
276 boost::multi_index::identity<CTxMemPoolEntryRef>,
279
309
310 using txiter = indexed_transaction_set::nth_index<0>::type::const_iterator;
311 typedef std::set<txiter, CompareIteratorById> setEntries;
312 typedef std::set<txiter, CompareIteratorByRevEntryId> setRevTopoEntries;
313
315
316private:
317 void UpdateParent(txiter entry, txiter parent, bool add)
319 void UpdateChild(txiter entry, txiter child, bool add)
321
326 std::set<TxId> m_unbroadcast_txids GUARDED_BY(cs);
327
334 bool CalculateAncestors(setEntries &setAncestors,
335 CTxMemPoolEntry::Parents &staged_ancestors) const
337
338public:
340 std::map<TxId, Amount> mapDeltas GUARDED_BY(cs);
341
343
344 const int64_t m_max_size_bytes;
345 const std::chrono::seconds m_expiry;
349 const std::optional<unsigned> m_max_datacarrier_bytes;
351
358 CTxMemPool(const Options &opts);
359 ~CTxMemPool();
360
367 void check(const CCoinsViewCache &active_coins_tip,
368 int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
369
370 // addUnchecked must update state for all parents of a given transaction,
371 // updating child links as necessary.
374
375 void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason)
377 void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs);
379 void removeForFinalizedBlock(const std::vector<CTransactionRef> &vtx)
381
382 void clear();
383 // lock free
385 bool CompareTopologically(const TxId &txida, const TxId &txidb) const;
386 void getAllTxIds(std::vector<TxId> &vtxid) const;
387 bool isSpent(const COutPoint &outpoint) const;
388 unsigned int GetTransactionsUpdated() const;
389 void AddTransactionsUpdated(unsigned int n);
395 bool HasNoInputsOf(const CTransaction &tx) const
397
399 void PrioritiseTransaction(const TxId &txid, const Amount nFeeDelta);
400 void ApplyDelta(const TxId &txid, Amount &nFeeDelta) const
403
405 CTransactionRef GetConflictTx(const COutPoint &prevout) const
407
409 std::optional<txiter> GetIter(const TxId &txid) const
411
416 setEntries GetIterSet(const std::set<TxId> &txids) const
418
424 void RemoveStaged(const setEntries &stage, MemPoolRemovalReason reason)
426
435 setEntries &setAncestors,
436 bool fSearchForParents = true) const
438
444 void CalculateDescendants(txiter it, setEntries &setDescendants) const
446
452 CFeeRate GetMinFee(size_t sizelimit) const;
453
460 void TrimToSize(size_t sizelimit,
461 std::vector<COutPoint> *pvNoSpendsRemaining = nullptr)
463
468 int Expire(std::chrono::seconds time) EXCLUSIVE_LOCKS_REQUIRED(cs);
469
473 void LimitSize(CCoinsViewCache &coins_cache)
475
480 bool GetLoadTried() const;
481
486 void SetLoadTried(bool load_tried);
487
488 unsigned long size() const {
489 LOCK(cs);
490 return mapTx.size();
491 }
492
495 return totalTxSize;
496 }
497
500 return m_total_fee;
501 }
502
503 bool exists(const TxId &txid) const {
504 LOCK(cs);
505 return mapTx.count(txid) != 0;
506 }
507
510 return finalizedTxs.insert(tx);
511 }
512
513 bool isAvalancheFinalized(const TxId &txid) const {
514 LOCK(cs);
515 return finalizedTxs.get(txid) != nullptr;
516 }
517
518 CTransactionRef get(const TxId &txid) const;
519 TxMempoolInfo info(const TxId &txid) const;
520 std::vector<TxMempoolInfo> infoAll() const;
521
522 CFeeRate estimateFee() const;
523
524 size_t DynamicMemoryUsage() const;
525
527 void AddUnbroadcastTx(const TxId &txid) {
528 LOCK(cs);
529 // Sanity check the transaction is in the mempool & insert into
530 // unbroadcast set.
531 if (exists(txid)) {
532 m_unbroadcast_txids.insert(txid);
533 }
534 }
535
537 void RemoveUnbroadcastTx(const TxId &txid, const bool unchecked = false);
538
540 std::set<TxId> GetUnbroadcastTxs() const {
541 LOCK(cs);
542 return m_unbroadcast_txids;
543 }
544
548 return (m_unbroadcast_txids.count(txid) != 0);
549 }
550
553 return m_sequence_number++;
554 }
555
557 return m_sequence_number;
558 }
559
560 template <typename Callable>
561 auto withOrphanage(Callable &&func) const
564 assert(m_orphanage);
565 return func(*m_orphanage);
566 }
567
568 template <typename Callable>
569 auto withConflicting(Callable &&func) const
572 assert(m_conflicting);
573 return func(*m_conflicting);
574 }
575
576private:
578 void UpdateEntryForAncestors(txiter it, const setEntries *setAncestors)
588 void UpdateForRemoveFromMempool(const setEntries &entriesToRemove)
592
603};
604
624 std::unordered_map<COutPoint, Coin, SaltedOutpointHasher> m_temp_added;
625
631 mutable std::unordered_set<COutPoint, SaltedOutpointHasher>
633
634protected:
636
637public:
638 CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn);
643 bool GetCoin(const COutPoint &outpoint, Coin &coin) const override;
651 std::unordered_set<COutPoint, SaltedOutpointHasher>
653 return m_non_base_coins;
654 }
656 void Reset();
657};
658
659#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:618
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
GetCoin, returning whether it exists and is not spent.
Definition: txmempool.cpp:610
std::unordered_set< COutPoint, SaltedOutpointHasher > GetNonBaseCoins() const
Get all coins in m_non_base_coins.
Definition: txmempool.h:652
void Reset()
Clear m_temp_added and m_non_base_coins.
Definition: txmempool.cpp:641
std::unordered_map< COutPoint, Coin, SaltedOutpointHasher > m_temp_added
Coins made available by transactions being validated.
Definition: txmempool.h:624
CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn)
Definition: txmempool.cpp:606
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:632
void PackageAddTransaction(const CTransactionRef &tx)
Add the coins created by this transaction.
Definition: txmempool.cpp:634
const CTxMemPool & mempool
Definition: txmempool.h:635
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:212
void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:293
bool isAvalancheFinalized(const TxId &txid) const
Definition: txmempool.h:513
CFeeRate estimateFee() const
Definition: txmempool.cpp:528
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:596
void ClearPrioritisation(const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:566
std::set< txiter, CompareIteratorById > setEntries
Definition: txmempool.h:311
const bool m_require_standard
Definition: txmempool.h:350
void RemoveUnbroadcastTx(const TxId &txid, const bool unchecked=false)
Removes a transaction from the unbroadcast set.
Definition: txmempool.cpp:657
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:811
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:311
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:451
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:307
void trackPackageRemoved(const CFeeRate &rate) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:758
Amount GetTotalFee() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:498
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:262
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:215
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:766
const std::chrono::seconds m_expiry
Definition: txmempool.h:345
const std::optional< unsigned > m_max_datacarrier_bytes
Definition: txmempool.h:349
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
bool CompareTopologically(const TxId &txida, const TxId &txidb) const
Definition: txmempool.cpp:462
TxMempoolInfo info(const TxId &txid) const
Definition: txmempool.cpp:518
std::map< TxId, Amount > mapDeltas GUARDED_BY(cs)
const int64_t m_max_size_bytes
Definition: txmempool.h:344
void getAllTxIds(std::vector< TxId > &vtxid) const
Definition: txmempool.cpp:476
std::atomic< uint32_t > nTransactionsUpdated
Used by getblocktemplate to trigger CreateNewBlock() invocation.
Definition: txmempool.h:217
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:585
std::unique_ptr< TxConflicting > m_conflicting GUARDED_BY(cs_conflicting)
Storage for conflicting txs information.
size_t DynamicMemoryUsage() const
Definition: txmempool.cpp:646
std::vector< TxMempoolInfo > infoAll() const
Definition: txmempool.cpp:494
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:699
bool setAvalancheFinalized(const CTxMemPoolEntryRef &tx) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:508
void UpdateParent(txiter entry, txiter parent, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:725
CTransactionRef GetConflictTx(const COutPoint &prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Get the transaction in the pool that spends the same prevout.
Definition: txmempool.cpp:571
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:680
void clear()
Definition: txmempool.cpp:343
std::set< txiter, CompareIteratorByRevEntryId > setRevTopoEntries
Definition: txmempool.h:312
bool exists(const TxId &txid) const
Definition: txmempool.h:503
std::set< TxId > GetUnbroadcastTxs() const
Returns transactions in unbroadcast set.
Definition: txmempool.h:540
int64_t lastRollingFeeUpdate GUARDED_BY(cs)
const bool m_permit_bare_multisig
Definition: txmempool.h:348
bool m_load_tried GUARDED_BY(cs)
Definition: txmempool.h:239
static const int ROLLING_FEE_HALFLIFE
Definition: txmempool.h:255
auto withOrphanage(Callable &&func) const EXCLUSIVE_LOCKS_REQUIRED(!cs_orphanage)
Definition: txmempool.h:561
CTransactionRef get(const TxId &txid) const
Definition: txmempool.cpp:508
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:278
const CFeeRate m_min_relay_feerate
Definition: txmempool.h:346
void PrioritiseTransaction(const TxId &txid, const Amount nFeeDelta)
Affect CreateNewBlock prioritisation of transactions.
Definition: txmempool.cpp:538
uint64_t GetSequence() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:556
bool IsUnbroadcastTx(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns whether a txid is in the unbroadcast set.
Definition: txmempool.h:546
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
Definition: txmempool.h:310
uint64_t GetAndIncrementSequence() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Guards this internal counter for external reporting.
Definition: txmempool.h:552
void UpdateChild(txiter entry, txiter child, bool add) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:715
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:372
Mutex cs_orphanage
Definition: txmempool.h:245
RadixTree< CTxMemPoolEntry, MemPoolEntryRadixTreeAdapter > finalizedTxs
Definition: txmempool.h:314
void check(const CCoinsViewCache &active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(void cs_main
Definition: txmempool.h:373
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:569
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:318
Mutex cs_conflicting
Definition: txmempool.h:249
void CalculateDescendants(txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Populate setDescendants with all in-mempool descendants of hash.
Definition: txmempool.cpp:235
void RemoveStaged(const setEntries &stage, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs)
Remove a set of transactions from the mempool.
Definition: txmempool.cpp:668
unsigned long size() const
Definition: txmempool.h:488
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:235
void ApplyDelta(const TxId &txid, Amount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:556
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:816
const CFeeRate m_dust_relay_feerate
Definition: txmempool.h:347
std::optional< txiter > GetIter(const TxId &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns an iterator to the given txid, if found.
Definition: txmempool.cpp:576
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:493
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:527
unsigned int GetTransactionsUpdated() const
Definition: txmempool.cpp:138
void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:331
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:699
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:81
bool operator()(const CTxMemPoolEntryRef &a, const CTxMemPoolEntryRef &b) const
Definition: txmempool.h:82
Definition: txmempool.h:73
bool operator()(const CTxMemPoolEntryRef &a, const CTxMemPoolEntryRef &b) const
Definition: txmempool.h:74
Sort by feerate of entry (modfee/vsize) in descending order.
Definition: txmempool.h:94
bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const
Definition: txmempool.h:96
bool operator()(const CTxMemPoolEntryRef &a, const CTxMemPoolEntryRef &b) const
Definition: txmempool.h:116
Radix tree adapter for storing a CTxMemPoolEntry as a tree element.
Definition: txmempool.h:66
Uint256RadixKey getId(const CTxMemPoolEntry &entry) const
Definition: txmempool.h:67
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:130
Amount fee
Fee of the transaction.
Definition: txmempool.h:138
Amount nFeeDelta
The fee delta.
Definition: txmempool.h:144
CTransactionRef tx
The transaction itself.
Definition: txmempool.h:132
std::chrono::seconds m_time
Time the transaction entered the mempool.
Definition: txmempool.h:135
size_t vsize
Virtual size of the transaction.
Definition: txmempool.h:141
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:54
result_type operator()(const CTransactionRef &tx) const
Definition: txmempool.h:58
#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:151
@ 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:48
const std::string RemovalReasonToString(const MemPoolRemovalReason &r) noexcept
Definition: txmempool.cpp:822
AssertLockHeld(pool.cs)
assert(!tx.IsCoinBase())