Bitcoin Core  31.0.0
P2P Digital Currency
txmempool.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-present 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 <indirectmap.h>
12 #include <kernel/cs_main.h>
13 #include <kernel/mempool_entry.h> // IWYU pragma: export
14 #include <kernel/mempool_limits.h> // IWYU pragma: export
15 #include <kernel/mempool_options.h> // IWYU pragma: export
16 #include <kernel/mempool_removal_reason.h> // IWYU pragma: export
17 #include <policy/feerate.h>
18 #include <policy/packages.h>
19 #include <primitives/transaction.h>
21 #include <sync.h>
22 #include <txgraph.h>
23 #include <util/feefrac.h>
24 #include <util/hasher.h>
25 #include <util/result.h>
26 
27 #include <boost/multi_index/hashed_index.hpp>
28 #include <boost/multi_index/identity.hpp>
29 #include <boost/multi_index/indexed_by.hpp>
30 #include <boost/multi_index/ordered_index.hpp>
31 #include <boost/multi_index/sequenced_index.hpp>
32 #include <boost/multi_index/tag.hpp>
33 #include <boost/multi_index_container.hpp>
34 
35 #include <atomic>
36 #include <map>
37 #include <optional>
38 #include <set>
39 #include <string>
40 #include <string_view>
41 #include <utility>
42 #include <vector>
43 
44 class CChain;
45 class ValidationSignals;
46 
47 struct bilingual_str;
48 
50 static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
51 
54 static constexpr uint64_t ACCEPTABLE_COST = 75'000;
55 
58 static constexpr uint64_t POST_CHANGE_COST = 5 * ACCEPTABLE_COST;
59 
63 bool TestLockPointValidity(CChain& active_chain, const LockPoints& lp) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
64 
65 // extracts a transaction hash from CTxMemPoolEntry or CTransactionRef
66 struct mempoolentry_txid
67 {
68  typedef Txid result_type;
69  result_type operator() (const CTxMemPoolEntry &entry) const
70  {
71  return entry.GetTx().GetHash();
72  }
73 
74  result_type operator() (const CTransactionRef& tx) const
75  {
76  return tx->GetHash();
77  }
78 };
79 
80 // extracts a transaction witness-hash from CTxMemPoolEntry or CTransactionRef
81 struct mempoolentry_wtxid
82 {
83  typedef Wtxid result_type;
84  result_type operator() (const CTxMemPoolEntry &entry) const
85  {
86  return entry.GetTx().GetWitnessHash();
87  }
88 
89  result_type operator() (const CTransactionRef& tx) const
90  {
91  return tx->GetWitnessHash();
92  }
93 };
94 
95 class CompareTxMemPoolEntryByEntryTime
96 {
97 public:
98  bool operator()(const CTxMemPoolEntry& a, const CTxMemPoolEntry& b) const
99  {
100  return a.GetTime() < b.GetTime();
101  }
102 };
103 
104 // Multi_index tag names
105 struct entry_time {};
106 struct index_by_wtxid {};
107 
111 struct TxMempoolInfo
112 {
114  CTransactionRef tx;
115 
117  std::chrono::seconds m_time;
118 
120  CAmount fee;
121 
123  int32_t vsize;
124 
126  int64_t nFeeDelta;
127 };
128 
186 class CTxMemPool
187 {
188 protected:
189  std::atomic<unsigned int> nTransactionsUpdated{0}; //!< Used by getblocktemplate to trigger CreateNewBlock() invocation
190 
191  uint64_t totalTxSize GUARDED_BY(cs){0}; //!< sum of all mempool tx's virtual sizes. Differs from serialized tx size since witness data is discounted. Defined in BIP 141.
192  CAmount m_total_fee GUARDED_BY(cs){0};
193  uint64_t cachedInnerUsage GUARDED_BY(cs){0};
194 
195  mutable int64_t lastRollingFeeUpdate GUARDED_BY(cs){GetTime()};
196  mutable bool blockSinceLastRollingFeeBump GUARDED_BY(cs){false};
197  mutable double rollingMinimumFeeRate GUARDED_BY(cs){0};
198 
199  // In-memory counter for external mempool tracking purposes.
200  // This number is incremented once every time a transaction
201  // is added or removed from the mempool for any reason.
202  mutable uint64_t m_sequence_number GUARDED_BY(cs){1};
203 
204  void trackPackageRemoved(const CFeeRate& rate) EXCLUSIVE_LOCKS_REQUIRED(cs);
205 
206  bool m_load_tried GUARDED_BY(cs){false};
207 
208  CFeeRate GetMinFee(size_t sizelimit) const;
209 
210 public:
211 
212  static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12; // public only for testing
213 
214  struct CTxMemPoolEntry_Indices final : boost::multi_index::indexed_by<
215  // sorted by txid
216  boost::multi_index::hashed_unique<mempoolentry_txid, SaltedTxidHasher>,
217  // sorted by wtxid
218  boost::multi_index::hashed_unique<
219  boost::multi_index::tag<index_by_wtxid>,
220  mempoolentry_wtxid,
221  SaltedWtxidHasher
222  >,
223  // sorted by entry time
224  boost::multi_index::ordered_non_unique<
225  boost::multi_index::tag<entry_time>,
226  boost::multi_index::identity<CTxMemPoolEntry>,
227  CompareTxMemPoolEntryByEntryTime
228  >
229  >
230  {};
231  typedef boost::multi_index_container<
235 
261  std::unique_ptr<TxGraph> m_txgraph GUARDED_BY(cs);
262  mutable std::unique_ptr<TxGraph::BlockBuilder> m_builder GUARDED_BY(cs);
264 
265  using txiter = indexed_transaction_set::nth_index<0>::type::const_iterator;
266  std::vector<std::pair<Wtxid, txiter>> txns_randomized GUARDED_BY(cs);
267 
268  typedef std::set<txiter, CompareIteratorByHash> setEntries;
269 
271 
272  std::tuple<size_t, size_t, CAmount> CalculateAncestorData(const CTxMemPoolEntry& entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
273  std::tuple<size_t, size_t, CAmount> CalculateDescendantData(const CTxMemPoolEntry& entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
274  int64_t GetDescendantCount(txiter it) const { LOCK(cs); return m_txgraph->GetDescendants(*it, TxGraph::Level::MAIN).size(); }
275  int64_t GetDescendantCount(const CTxMemPoolEntry &e) const { LOCK(cs); return m_txgraph->GetDescendants(e, TxGraph::Level::MAIN).size(); }
276  int64_t GetAncestorCount(const CTxMemPoolEntry &e) const { LOCK(cs); return m_txgraph->GetAncestors(e, TxGraph::Level::MAIN).size(); }
277  std::vector<CTxMemPoolEntry::CTxMemPoolEntryRef> GetChildren(const CTxMemPoolEntry &entry) const;
278  std::vector<CTxMemPoolEntry::CTxMemPoolEntryRef> GetParents(const CTxMemPoolEntry &entry) const;
279 
280 private:
281  std::vector<indexed_transaction_set::const_iterator> GetSortedScoreWithTopology() const EXCLUSIVE_LOCKS_REQUIRED(cs);
282 
286  std::set<Txid> m_unbroadcast_txids GUARDED_BY(cs);
287 
288  static TxMempoolInfo GetInfo(CTxMemPool::indexed_transaction_set::const_iterator it)
289  {
290  return TxMempoolInfo{it->GetSharedTx(), it->GetTime(), it->GetFee(), it->GetTxSize(), it->GetModifiedFee() - it->GetFee()};
291  }
292 
293  // Helper to remove all transactions that conflict with a given
294  // transaction (used for transactions appearing in a block).
295  void removeConflicts(const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(cs);
296 
297 public:
299  std::map<Txid, CAmount> mapDeltas GUARDED_BY(cs);
300 
302 
304 
310  explicit CTxMemPool(Options opts, bilingual_str& error);
311 
318  void check(const CCoinsViewCache& active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
319 
333  void removeForReorg(CChain& chain, std::function<bool(txiter)> filter_final_and_mature) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main);
334  void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight) EXCLUSIVE_LOCKS_REQUIRED(cs);
335 
336  bool CompareMiningScoreWithTopology(const Wtxid& hasha, const Wtxid& hashb) const;
337  bool isSpent(const COutPoint& outpoint) const;
338  unsigned int GetTransactionsUpdated() const;
339  void AddTransactionsUpdated(unsigned int n);
344  bool HasNoInputsOf(const CTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs);
345 
347  void PrioritiseTransaction(const Txid& hash, const CAmount& nFeeDelta);
348  void ApplyDelta(const Txid& hash, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs);
349  void ClearPrioritisation(const Txid& hash) EXCLUSIVE_LOCKS_REQUIRED(cs);
350 
351  struct delta_info {
353  const bool in_mempool;
355  const CAmount delta;
357  std::optional<CAmount> modified_fee;
359  const Txid txid;
360  };
362  std::vector<delta_info> GetPrioritisedTransactions() const EXCLUSIVE_LOCKS_REQUIRED(!cs);
363 
365  const CTransaction* GetConflictTx(const COutPoint& prevout) const EXCLUSIVE_LOCKS_REQUIRED(cs);
366 
368  std::optional<txiter> GetIter(const Txid& txid) const EXCLUSIVE_LOCKS_REQUIRED(cs);
369  std::optional<txiter> GetIter(const Wtxid& wtxid) const EXCLUSIVE_LOCKS_REQUIRED(cs);
370 
374  setEntries GetIterSet(const std::set<Txid>& hashes) const EXCLUSIVE_LOCKS_REQUIRED(cs);
375 
379  std::vector<txiter> GetIterVec(const std::vector<Txid>& txids) const EXCLUSIVE_LOCKS_REQUIRED(cs);
380 
394  void UpdateTransactionsFromBlock(const std::vector<Txid>& vHashesToUpdate) EXCLUSIVE_LOCKS_REQUIRED(cs, cs_main);
395 
396  std::vector<FeePerWeight> GetFeerateDiagram() const EXCLUSIVE_LOCKS_REQUIRED(cs);
397  FeePerWeight GetMainChunkFeerate(const CTxMemPoolEntry& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs) {
398  return m_txgraph->GetMainChunkFeerate(tx);
399  }
400  std::vector<const CTxMemPoolEntry*> GetCluster(Txid txid) const EXCLUSIVE_LOCKS_REQUIRED(cs) {
401  auto tx = GetIter(txid);
402  if (!tx) return {};
403  auto cluster = m_txgraph->GetCluster(**tx, TxGraph::Level::MAIN);
404  std::vector<const CTxMemPoolEntry*> ret;
405  ret.reserve(cluster.size());
406  for (const auto& tx : cluster) {
407  ret.emplace_back(static_cast<const CTxMemPoolEntry*>(tx));
408  }
409  return ret;
410  }
411 
412 
413  size_t GetUniqueClusterCount(const setEntries& iters_conflicting) const EXCLUSIVE_LOCKS_REQUIRED(cs) {
414  std::vector<const TxGraph::Ref *> entries;
415  entries.reserve(iters_conflicting.size());
416  for (auto it : iters_conflicting) {
417  entries.emplace_back(&*it);
418  }
419  Assume(!m_txgraph->IsOversized(TxGraph::Level::MAIN));
420  return m_txgraph->CountDistinctClusters(entries, TxGraph::Level::MAIN);
421  }
422 
430  setEntries CalculateMemPoolAncestors(const CTxMemPoolEntry& entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
431 
432  bool HasDescendants(const Txid& txid) const;
433 
438  std::vector<txiter> GatherClusters(const std::vector<Txid>& txids) const EXCLUSIVE_LOCKS_REQUIRED(cs);
439 
443  void CalculateDescendants(txiter it, setEntries& setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs);
444  CTxMemPool::txiter CalculateDescendants(const CTxMemPoolEntry& entry, setEntries& setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs);
445 
452  CFeeRate GetMinFee() const {
453  return GetMinFee(m_opts.max_size_bytes);
454  }
455 
460  void TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpendsRemaining = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs);
461 
463  int Expire(std::chrono::seconds time) EXCLUSIVE_LOCKS_REQUIRED(cs);
464 
471  void GetTransactionAncestry(const Txid& txid, size_t& ancestors, size_t& cluster_count, size_t* ancestorsize = nullptr, CAmount* ancestorfees = nullptr) const;
472 
477  bool GetLoadTried() const;
478 
483  void SetLoadTried(bool load_tried);
484 
485  unsigned long size() const
486  {
487  LOCK(cs);
488  return mapTx.size();
489  }
490 
492  {
494  return totalTxSize;
495  }
496 
498  {
500  return m_total_fee;
501  }
502 
503  bool exists(const Txid& txid) const
504  {
505  LOCK(cs);
506  return (mapTx.count(txid) != 0);
507  }
508 
509  bool exists(const Wtxid& wtxid) const
510  {
511  LOCK(cs);
512  return (mapTx.get<index_by_wtxid>().count(wtxid) != 0);
513  }
514 
515  const CTxMemPoolEntry* GetEntry(const Txid& txid) const LIFETIMEBOUND EXCLUSIVE_LOCKS_REQUIRED(cs);
516 
517  CTransactionRef get(const Txid& hash) const;
518 
519  template <TxidOrWtxid T>
520  TxMempoolInfo info(const T& id) const
521  {
522  LOCK(cs);
523  auto i{GetIter(id)};
524  return i.has_value() ? GetInfo(*i) : TxMempoolInfo{};
525  }
526 
528  template <TxidOrWtxid T>
529  TxMempoolInfo info_for_relay(const T& id, uint64_t last_sequence) const
530  {
531  LOCK(cs);
532  auto i{GetIter(id)};
533  return (i.has_value() && i.value()->GetSequence() < last_sequence) ? GetInfo(*i) : TxMempoolInfo{};
534  }
535 
536  std::vector<CTxMemPoolEntryRef> entryAll() const EXCLUSIVE_LOCKS_REQUIRED(cs);
537  std::vector<TxMempoolInfo> infoAll() const;
538 
539  size_t DynamicMemoryUsage() const;
540 
542  void AddUnbroadcastTx(const Txid& txid)
543  {
544  LOCK(cs);
545  // Sanity check the transaction is in the mempool & insert into
546  // unbroadcast set.
547  if (exists(txid)) m_unbroadcast_txids.insert(txid);
548  };
549 
550  bool CheckPolicyLimits(const CTransactionRef& tx);
551 
553  void RemoveUnbroadcastTx(const Txid& txid, bool unchecked = false);
554 
556  std::set<Txid> GetUnbroadcastTxs() const
557  {
558  LOCK(cs);
559  return m_unbroadcast_txids;
560  }
561 
564  {
566  return m_unbroadcast_txids.contains(txid);
567  }
568 
571  return m_sequence_number++;
572  }
573 
575  return m_sequence_number;
576  }
577 
578 private:
584  void RemoveStaged(setEntries& stage, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs);
585 
586  /* Helper for the public removeRecursive() */
587  void removeRecursive(txiter to_remove, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs);
588 
589  /* Removal from the mempool also triggers removal of the entry's Ref from txgraph. */
590  void removeUnchecked(txiter entry, MemPoolRemovalReason reason) EXCLUSIVE_LOCKS_REQUIRED(cs);
591 public:
592  /*
593  * CTxMemPool::ChangeSet:
594  *
595  * This class is used for all mempool additions and associated removals (eg
596  * due to rbf). Removals that don't need to be evaluated for acceptance,
597  * such as removing transactions that appear in a block, or due to reorg,
598  * or removals related to mempool limiting or expiry do not need to use
599  * this.
600  *
601  * Callers can interleave calls to StageAddition()/StageRemoval(), and
602  * removals may be invoked in any order, but additions must be done in a
603  * topological order in the case of transaction packages (ie, parents must
604  * be added before children).
605  *
606  * CalculateChunksForRBF() can be used to calculate the feerate diagram of
607  * the proposed set of new transactions and compare with the existing
608  * mempool.
609  *
610  * CalculateMemPoolAncestors() calculates the in-mempool (not including
611  * what is in the change set itself) ancestors of a given transaction.
612  *
613  * Apply() will apply the removals and additions that are staged into the
614  * mempool.
615  *
616  * Only one changeset may exist at a time. While a changeset is
617  * outstanding, no removals or additions may be made directly to the
618  * mempool.
619  */
620  class ChangeSet {
621  public:
622  explicit ChangeSet(CTxMemPool* pool) : m_pool(pool) { m_pool->m_txgraph->StartStaging(); }
624  AssertLockHeld(m_pool->cs);
625  if (m_pool->m_txgraph->HaveStaging()) {
626  m_pool->m_txgraph->AbortStaging();
627  }
628  m_pool->m_have_changeset = false;
629  }
630 
631  ChangeSet(const ChangeSet&) = delete;
632  ChangeSet& operator=(const ChangeSet&) = delete;
633 
635 
636  TxHandle StageAddition(const CTransactionRef& tx, CAmount fee, int64_t time, unsigned int entry_height, uint64_t entry_sequence, bool spends_coinbase, int64_t sigops_cost, LockPoints lp);
637 
638  void StageRemoval(CTxMemPool::txiter it);
639 
640  const CTxMemPool::setEntries& GetRemovals() const { return m_to_remove; }
641 
643  bool CheckMemPoolPolicyLimits();
644 
646  {
647  // Look up transaction in our cache first
648  auto it = m_ancestors.find(tx);
649  if (it != m_ancestors.end()) return it->second;
650 
651  // If not found, try to have the mempool calculate it, and cache
652  // for later.
653  LOCK(m_pool->cs);
654  auto ret = m_pool->CalculateMemPoolAncestors(*tx);
655  m_ancestors.try_emplace(tx, ret);
656  return ret;
657  }
658 
659  std::vector<CTransactionRef> GetAddedTxns() const {
660  std::vector<CTransactionRef> ret;
661  ret.reserve(m_entry_vec.size());
662  for (const auto& entry : m_entry_vec) {
663  ret.emplace_back(entry->GetSharedTx());
664  }
665  return ret;
666  }
667 
674  util::Result<std::pair<std::vector<FeeFrac>, std::vector<FeeFrac>>> CalculateChunksForRBF();
675 
676  size_t GetTxCount() const { return m_entry_vec.size(); }
677  const CTransaction& GetAddedTxn(size_t index) const { return m_entry_vec.at(index)->GetTx(); }
678 
679  void Apply() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
680 
681  private:
682  void ProcessDependencies();
683 
684  CTxMemPool* m_pool;
686  std::vector<CTxMemPool::txiter> m_entry_vec; // track the added transactions' insertion order
687  // map from the m_to_add index to the ancestors for the transaction
689  CTxMemPool::setEntries m_to_remove;
690  bool m_dependencies_processed{false};
691 
692  friend class CTxMemPool;
693  };
694 
695  std::unique_ptr<ChangeSet> GetChangeSet() EXCLUSIVE_LOCKS_REQUIRED(cs) {
696  Assume(!m_have_changeset);
697  m_have_changeset = true;
698  return std::make_unique<ChangeSet>(this);
699  }
700 
701  bool m_have_changeset GUARDED_BY(cs){false};
702 
703  friend class CTxMemPool::ChangeSet;
704 
705 private:
706  // Apply the given changeset to the mempool, by removing transactions in
707  // the to_remove set and adding transactions in the to_add set.
709 
710  // addNewTransaction must update state for all ancestors of a given transaction,
711  // to track size/count of descendant transactions. First version of
712  // addNewTransaction can be used to have it call CalculateMemPoolAncestors(), and
713  // then invoke the second version.
714  // Note that addNewTransaction is ONLY called (via Apply()) from ATMP
715  // outside of tests and any other callers may break wallet's in-mempool
716  // tracking (due to lack of CValidationInterface::TransactionAddedToMempool
717  // callbacks).
719 public:
720  void StartBlockBuilding() const EXCLUSIVE_LOCKS_REQUIRED(cs) { assert(!m_builder); m_builder = m_txgraph->GetBlockBuilder(); }
721  FeePerWeight GetBlockBuilderChunk(std::vector<CTxMemPoolEntry::CTxMemPoolEntryRef>& entries) const EXCLUSIVE_LOCKS_REQUIRED(cs)
722  {
723  if (!m_builder) { return {}; }
724 
725  auto res = m_builder->GetCurrentChunk();
726  if (!res) { return {}; }
727 
728  auto [chunk_entries, chunk_feerate] = *res;
729  for (TxGraph::Ref* ref : chunk_entries) {
730  entries.emplace_back(static_cast<const CTxMemPoolEntry&>(*ref));
731  }
732  return chunk_feerate;
733  }
734  void IncludeBuilderChunk() const EXCLUSIVE_LOCKS_REQUIRED(cs) { m_builder->Include(); }
735  void SkipBuilderChunk() const EXCLUSIVE_LOCKS_REQUIRED(cs) { m_builder->Skip(); }
736  void StopBlockBuilding() const EXCLUSIVE_LOCKS_REQUIRED(cs) { m_builder.reset(); }
737 };
738 
753 {
758  std::unordered_map<COutPoint, Coin, SaltedOutpointHasher> m_temp_added;
759 
764  mutable std::unordered_set<COutPoint, SaltedOutpointHasher> m_non_base_coins;
765 protected:
767 
768 public:
769  CCoinsViewMemPool(CCoinsView* baseIn, const CTxMemPool& mempoolIn);
772  std::optional<Coin> GetCoin(const COutPoint& outpoint) const override;
775  void PackageAddTransaction(const CTransactionRef& tx);
777  const std::unordered_set<COutPoint, SaltedOutpointHasher>& GetNonBaseCoins() const { return m_non_base_coins; }
779  void Reset();
780 };
781 #endif // BITCOIN_TXMEMPOOL_H
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:403
int64_t lastRollingFeeUpdate GUARDED_BY(cs)
sum of dynamic memory usage of all the map elements (NOT the maps themselves)
Definition: txmempool.h:195
const bool in_mempool
Whether this transaction is in the mempool.
Definition: txmempool.h:353
CTxMemPool::setEntries CalculateMemPoolAncestors(TxHandle tx)
Definition: txmempool.h:645
void IncludeBuilderChunk() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:734
Information about a mempool transaction.
Definition: txmempool.h:111
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:764
int ret
Always refers to the main graph, whether staging is present or not.
bool m_have_changeset GUARDED_BY(cs)
Definition: txmempool.h:701
AssertLockHeld(pool.cs)
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
Definition: txmempool.h:265
assert(!tx.IsCoinBase())
const CTransaction & GetAddedTxn(size_t index) const
Definition: txmempool.h:677
std::vector< const CTxMemPoolEntry * > GetCluster(Txid txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:400
Bilingual messages:
Definition: translation.h:24
T check(T ptr)
~ChangeSet() EXCLUSIVE_LOCKS_REQUIRED(m_pool -> cs)
Definition: txmempool.h:623
Options struct containing limit options for a CTxMemPool.
An in-memory indexed chain of blocks.
Definition: chain.h:379
int64_t GetAncestorCount(const CTxMemPoolEntry &e) const
Definition: txmempool.h:276
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
int64_t GetTime()
DEPRECATED, see GetTime.
Definition: time.cpp:81
TxMempoolInfo info(const T &id) const
Definition: txmempool.h:520
size_t GetTxCount() const
Definition: txmempool.h:676
ChangeSet(CTxMemPool *pool)
Definition: txmempool.h:622
uint64_t GetSequence() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:574
void StartBlockBuilding() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:720
std::unique_ptr< ChangeSet > GetChangeSet() EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:695
std::set< txiter, CompareIteratorByHash > setEntries
Definition: txmempool.h:268
Definition: common.h:29
void check(const CCoinsViewCache &active_coins_tip, int64_t spendheight) const EXCLUSIVE_LOCKS_REQUIRED(void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason) 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:325
CFeeRate GetMinFee() const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
Definition: txmempool.h:452
Tagged wrapper around FeeFrac to avoid unit confusion.
Definition: feefrac.h:238
std::optional< Coin > GetCoin(const COutPoint &outpoint) const override
GetCoin, returning whether it exists and is not spent.
Definition: txmempool.cpp:742
int64_t GetDescendantCount(txiter it) const
Definition: txmempool.h:274
void StopBlockBuilding() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:736
std::set< Txid > GetUnbroadcastTxs() const
Returns transactions in unbroadcast set.
Definition: txmempool.h:556
const CTxMemPool::setEntries & GetRemovals() const
Definition: txmempool.h:640
const CAmount delta
The fee delta added using PrioritiseTransaction().
Definition: txmempool.h:355
size_t GetUniqueClusterCount(const setEntries &iters_conflicting) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:413
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
Definition: mempool_entry.h:65
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
static const uint32_t MEMPOOL_HEIGHT
Fake height value used in Coin to signify they are only in the memory pool (since 0...
Definition: txmempool.h:50
bool blockSinceLastRollingFeeBump GUARDED_BY(cs)
Definition: txmempool.h:196
TxMempoolInfo info_for_relay(const T &id, uint64_t last_sequence) const
Returns info for a transaction if its entry_sequence < last_sequence.
Definition: txmempool.h:529
#define LIFETIMEBOUND
Definition: attributes.h:16
static constexpr uint64_t ACCEPTABLE_COST
How much linearization cost required for TxGraph clusters to have "acceptable" quality, if they cannot be optimally linearized with less cost.
Definition: txmempool.h:54
Abstract view on the open txout dataset.
Definition: coins.h:307
bool IsUnbroadcastTx(const Txid &txid) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Returns whether a txid is in the unbroadcast set.
Definition: txmempool.h:563
#define LOCK(cs)
Definition: sync.h:258
bool m_load_tried GUARDED_BY(cs)
Definition: txmempool.h:206
double rollingMinimumFeeRate GUARDED_BY(cs)
Definition: txmempool.h:197
uint64_t cachedInnerUsage GUARDED_BY(cs)
sum of all mempool tx&#39;s fees (NOT modified fee)
Definition: txmempool.h:193
CTxMemPool::txiter TxHandle
Definition: txmempool.h:634
uint64_t GetTotalTxSize() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:491
uint64_t m_sequence_number GUARDED_BY(cs)
minimum fee to get into the pool, decreases exponentially
Definition: txmempool.h:202
boost::multi_index_container< CTxMemPoolEntry, CTxMemPoolEntry_Indices > indexed_transaction_set
Definition: txmempool.h:234
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:28
const Txid txid
The prioritised transaction&#39;s txid.
Definition: txmempool.h:359
#define Assume(val)
Assume is the identity function.
Definition: check.h:125
bool exists(const Txid &txid) const
Definition: txmempool.h:503
std::vector< CTransactionRef > GetAddedTxns() const
Definition: txmempool.h:659
std::optional< CAmount > modified_fee
The modified fee (base fee + delta) of this entry.
Definition: txmempool.h:357
void Apply() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: txmempool.cpp:1037
uint64_t GetAndIncrementSequence() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Guards this internal counter for external reporting.
Definition: txmempool.h:570
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:51
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:186
void SkipBuilderChunk() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:735
FeePerWeight GetBlockBuilderChunk(std::vector< CTxMemPoolEntry::CTxMemPoolEntryRef > &entries) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:721
void Reset()
Clear m_temp_added and m_non_base_coins.
Definition: txmempool.cpp:772
const std::unordered_set< COutPoint, SaltedOutpointHasher > & GetNonBaseCoins() const
Get all coins in m_non_base_coins.
Definition: txmempool.h:777
CAmount GetTotalFee() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.h:497
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac...
Definition: feerate.h:31
static void pool cs
#define GUARDED_BY(x)
Definition: threadsafety.h:39
bool exists(const Wtxid &wtxid) const
Definition: txmempool.h:509
void PackageAddTransaction(const CTransactionRef &tx)
Add the coins created by this transaction.
Definition: txmempool.cpp:765
Definition: txmempool.h:214
CCoinsViewMemPool(CCoinsView *baseIn, const CTxMemPool &mempoolIn)
Definition: txmempool.cpp:740
Options struct containing options for constructing a CTxMemPool.
CAmount m_total_fee GUARDED_BY(cs)
sum of all mempool tx&#39;s virtual sizes. Differs from serialized tx size since witness data is discount...
Definition: txmempool.h:192
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:280
CCoinsView backed by another CCoinsView.
Definition: coins.h:347
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:367
const CTxMemPool & mempool
Definition: txmempool.h:766
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Definition: cs_main.cpp:8
void addNewTransaction(CTxMemPool::txiter it) EXCLUSIVE_LOCKS_REQUIRED(cs)
Definition: txmempool.cpp:229
CCoinsView that brings transactions from a mempool into view.
Definition: txmempool.h:752
int64_t GetDescendantCount(const CTxMemPoolEntry &e) const
Definition: txmempool.h:275
LockPoints lp
std::unordered_map< COutPoint, Coin, SaltedOutpointHasher > m_temp_added
Coins made available by transactions being validated.
Definition: txmempool.h:758
uint64_t fee
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it...
Definition: txmempool.h:260
const Options m_opts
Definition: txmempool.h:303