Skip to content
Bitcoin Roots

v30.3-roots.1 · Commit 3: [PATCH 03/68] feat(policy): preserve Roots relay and network controls on Core 30.3

src/txmempool.h

Before: src/txmempool.h · After: src/txmempool.h

File metadata
index befaf4e59fd10bfca1cbca0311230aab620096fc..40ae4fcc5218dca5bd377879546012af4d2d0e52 100644

Download original patch · Release notes

Diff rows 1–137 of 137. Line numbers refer to the original before/after files.

+ Added− RemovedUnmarked lines are context.

Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.

src/txmempool.h CHANGED
@@ -18,6 +18,7 @@
18
  #include <policy/packages.h>
19
  #include <primitives/transaction.h>
20
  #include <primitives/transaction_identifier.h>
 
21
  #include <sync.h>
22
  #include <util/epochguard.h>
23
  #include <util/feefrac.h>
@@ -42,13 +43,23 @@
42
  #include <vector>
43
 
44
  class CChain;
 
45
  class ValidationSignals;
46
 
47
  struct bilingual_str;
48
 
 
 
49
  /** Fake height value used in Coin to signify they are only in the memory pool (since 0.8) */
50
  static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
51
 
 
 
 
 
 
 
 
52
  /**
53
  * Test whether the LockPoints height and time are still valid on the current chain
54
  */
@@ -177,12 +188,16 @@ public:
177
  }
178
  };
179
 
 
 
180
  // Multi_index tag names
181
  struct descendant_score {};
182
  struct entry_time {};
183
  struct ancestor_score {};
184
  struct index_by_wtxid {};
185
 
 
 
186
  /**
187
  * Information about a mempool transaction.
188
  */
@@ -373,6 +388,9 @@ public:
373
  using Limits = kernel::MemPoolLimits;
374
 
375
  uint64_t CalculateDescendantMaximum(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
 
 
 
376
  private:
377
  typedef std::map<txiter, setEntries, CompareIteratorByHash> cacheMap;
378
 
@@ -412,11 +430,11 @@ private:
412
 
413
  public:
414
  indirectmap<COutPoint, const CTransaction*> mapNextTx GUARDED_BY(cs);
415
- std::map<Txid, CAmount> mapDeltas GUARDED_BY(cs);
416
 
417
  using Options = kernel::MemPoolOptions;
418
 
419
- const Options m_opts;
420
 
421
  /** Create a new CTxMemPool.
422
  * Sanity checks will be off by default for performance, because otherwise
@@ -455,10 +473,20 @@ public:
455
  * the tx is not dependent on other mempool transactions to be included in a block.
456
  */
457
  bool HasNoInputsOf(const CTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs);
 
 
 
 
 
 
 
 
458
 
459
  /** Affect CreateNewBlock prioritisation of transactions */
460
- void PrioritiseTransaction(const Txid& hash, const CAmount& nFeeDelta);
461
- void ApplyDelta(const Txid& hash, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs);
 
 
462
  void ClearPrioritisation(const Txid& hash) EXCLUSIVE_LOCKS_REQUIRED(cs);
463
 
464
  struct delta_info {
@@ -466,6 +494,7 @@ public:
466
  const bool in_mempool;
467
  /** The fee delta added using PrioritiseTransaction(). */
468
  const CAmount delta;
 
469
  /** The modified fee (base fee + delta) of this entry. Only present if in_mempool=true. */
470
  std::optional<CAmount> modified_fee;
471
  /** The prioritised transaction's txid. */
@@ -661,6 +690,8 @@ public:
661
  std::vector<CTxMemPoolEntryRef> entryAll() const EXCLUSIVE_LOCKS_REQUIRED(cs);
662
  std::vector<TxMempoolInfo> infoAll() const;
663
 
 
 
664
  size_t DynamicMemoryUsage() const;
665
 
666
  /** Adds a transaction to the unbroadcast set */
@@ -821,7 +852,12 @@ public:
821
 
822
  using TxHandle = CTxMemPool::txiter;
823
 
824
- TxHandle StageAddition(const CTransactionRef& tx, const CAmount fee, int64_t time, unsigned int entry_height, uint64_t entry_sequence, bool spends_coinbase, int64_t sigops_cost, LockPoints lp);
 
 
 
 
 
825
  void StageRemoval(CTxMemPool::txiter it) { m_to_remove.insert(it); }
826
 
827
  const CTxMemPool::setEntries& GetRemovals() const { return m_to_remove; }
@@ -862,9 +898,9 @@ public:
862
 
863
  void Apply() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
864
 
865
- private:
866
  CTxMemPool* m_pool;
867
  CTxMemPool::indexed_transaction_set m_to_add;
 
868
  std::vector<CTxMemPool::txiter> m_entry_vec; // track the added transactions' insertion order
869
  // map from the m_to_add index to the ancestors for the transaction
870
  std::map<CTxMemPool::txiter, CTxMemPool::setEntries, CompareIteratorByHash> m_ancestors;
@@ -912,6 +948,9 @@ private:
912
  * It also allows you to sign a double-spend directly in
913
  * signrawtransactionwithkey and signrawtransactionwithwallet,
914
  * as long as the conflicting transaction is not yet confirmed.
 
 
 
915
  */
916
  class CCoinsViewMemPool : public CCoinsViewBacked
917
  {
 
18
  #include <policy/packages.h>
19
  #include <primitives/transaction.h>
20
  #include <primitives/transaction_identifier.h>
21
+ #include <script/script.h>
22
  #include <sync.h>
23
  #include <util/epochguard.h>
24
  #include <util/feefrac.h>
 
43
  #include <vector>
44
 
45
  class CChain;
46
+ class CScript;
47
  class ValidationSignals;
48
 
49
  struct bilingual_str;
50
 
51
+ static constexpr std::chrono::minutes DYNAMIC_DUST_FEERATE_UPDATE_INTERVAL{15};
52
+
53
  /** Fake height value used in Coin to signify they are only in the memory pool (since 0.8) */
54
  static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
55
 
56
+ inline int64_t maxmempoolMinimumBytes(const int64_t descendant_size_vbytes) {
57
+ return descendant_size_vbytes * 40;
58
+ }
59
+ inline int64_t limitdescendantsizeMaximumVBytes(const int64_t maxmempool) {
60
+ return maxmempool / 40;
61
+ }
62
+
63
  /**
64
  * Test whether the LockPoints height and time are still valid on the current chain
65
  */
 
188
  }
189
  };
190
 
191
+ uint160 ScriptHashkey(const CScript& script);
192
+
193
  // Multi_index tag names
194
  struct descendant_score {};
195
  struct entry_time {};
196
  struct ancestor_score {};
197
  struct index_by_wtxid {};
198
 
199
+ class CBlockPolicyEstimator;
200
+
201
  /**
202
  * Information about a mempool transaction.
203
  */
 
388
  using Limits = kernel::MemPoolLimits;
389
 
390
  uint64_t CalculateDescendantMaximum(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
391
+
392
+ std::map<uint160, std::pair<const CTransaction *, const CTransaction *>> mapUsedSPK GUARDED_BY(cs);
393
+
394
  private:
395
  typedef std::map<txiter, setEntries, CompareIteratorByHash> cacheMap;
396
 
 
430
 
431
  public:
432
  indirectmap<COutPoint, const CTransaction*> mapNextTx GUARDED_BY(cs);
433
+ std::map<Txid, std::pair<double, CAmount>> mapDeltas GUARDED_BY(cs);
434
 
435
  using Options = kernel::MemPoolOptions;
436
 
437
+ Options m_opts;
438
 
439
  /** Create a new CTxMemPool.
440
  * Sanity checks will be off by default for performance, because otherwise
 
473
  * the tx is not dependent on other mempool transactions to be included in a block.
474
  */
475
  bool HasNoInputsOf(const CTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs);
476
+ /**
477
+ * Update all transactions in the mempool which depend on tx to recalculate their priority
478
+ * and adjust the input value that will age to reflect that the inputs from this transaction have
479
+ * either just been added to the chain or just been removed.
480
+ */
481
+ void UpdateDependentPriorities(const CTransaction &tx, unsigned int nBlockHeight, bool addToChain);
482
+
483
+ void UpdateDynamicDustFeerate();
484
 
485
  /** Affect CreateNewBlock prioritisation of transactions */
486
+ void PrioritiseTransaction(const Txid& hash, double dPriorityDelta, const CAmount& nFeeDelta);
487
+ void PrioritiseTransaction(const Txid& hash, const CAmount& nFeeDelta) { PrioritiseTransaction(hash, 0., nFeeDelta); }
488
+ void ApplyDeltas(const Txid& hash, double &dPriorityDelta, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs);
489
+ void ApplyDelta(const Txid& hash, CAmount& fee_delta) const EXCLUSIVE_LOCKS_REQUIRED(cs) { double priority_delta{0}; ApplyDeltas(hash, priority_delta, fee_delta); }
490
  void ClearPrioritisation(const Txid& hash) EXCLUSIVE_LOCKS_REQUIRED(cs);
491
 
492
  struct delta_info {
 
494
  const bool in_mempool;
495
  /** The fee delta added using PrioritiseTransaction(). */
496
  const CAmount delta;
497
+ const double priority_delta;
498
  /** The modified fee (base fee + delta) of this entry. Only present if in_mempool=true. */
499
  std::optional<CAmount> modified_fee;
500
  /** The prioritised transaction's txid. */
 
690
  std::vector<CTxMemPoolEntryRef> entryAll() const EXCLUSIVE_LOCKS_REQUIRED(cs);
691
  std::vector<TxMempoolInfo> infoAll() const;
692
 
693
+ void FindScriptPubKey(const std::set<CScript>& needles, std::map<COutPoint, Coin>& out_results);
694
+
695
  size_t DynamicMemoryUsage() const;
696
 
697
  /** Adds a transaction to the unbroadcast set */
 
852
 
853
  using TxHandle = CTxMemPool::txiter;
854
 
855
+ TxHandle StageAddition(const CTransactionRef& tx, const CAmount fee, int64_t time, unsigned int entry_height, uint64_t entry_sequence, CoinAgeCache coin_age_cache, bool spends_coinbase, int32_t extra_weight, int64_t sigops_cost, LockPoints lp);
856
+ TxHandle StageAddition(const CTransactionRef& tx, const CAmount fee, int64_t time, unsigned int entry_height, uint64_t entry_sequence, bool spends_coinbase, int64_t sigops_cost, LockPoints lp)
857
+ {
858
+ return StageAddition(tx, fee, time, entry_height, entry_sequence, COIN_AGE_CACHE_ZERO,
859
+ spends_coinbase, /*extra_weight=*/0, sigops_cost, lp);
860
+ }
861
  void StageRemoval(CTxMemPool::txiter it) { m_to_remove.insert(it); }
862
 
863
  const CTxMemPool::setEntries& GetRemovals() const { return m_to_remove; }
 
898
 
899
  void Apply() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
900
 
 
901
  CTxMemPool* m_pool;
902
  CTxMemPool::indexed_transaction_set m_to_add;
903
+ private:
904
  std::vector<CTxMemPool::txiter> m_entry_vec; // track the added transactions' insertion order
905
  // map from the m_to_add index to the ancestors for the transaction
906
  std::map<CTxMemPool::txiter, CTxMemPool::setEntries, CompareIteratorByHash> m_ancestors;
 
948
  * It also allows you to sign a double-spend directly in
949
  * signrawtransactionwithkey and signrawtransactionwithwallet,
950
  * as long as the conflicting transaction is not yet confirmed.
951
+ *
952
+ * Its Cursor also doesn't work. In general, it is broken as a CCoinsView
953
+ * implementation outside of a few use cases.
954
  */
955
  class CCoinsViewMemPool : public CCoinsViewBacked
956
  {