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. The two line-number columns refer to before and after.

src/txmempool.h CHANGED
@@ -18,6 +18,7 @@
18
18
  #include <policy/packages.h>
19
19
  #include <primitives/transaction.h>
20
20
  #include <primitives/transaction_identifier.h>
21
+ #include <script/script.h>
21
22
  #include <sync.h>
22
23
  #include <util/epochguard.h>
23
24
  #include <util/feefrac.h>
@@ -42,13 +43,23 @@
42
43
  #include <vector>
43
44
 
44
45
  class CChain;
46
+ class CScript;
45
47
  class ValidationSignals;
46
48
 
47
49
  struct bilingual_str;
48
50
 
51
+ static constexpr std::chrono::minutes DYNAMIC_DUST_FEERATE_UPDATE_INTERVAL{15};
52
+
49
53
  /** Fake height value used in Coin to signify they are only in the memory pool (since 0.8) */
50
54
  static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
51
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
+
52
63
  /**
53
64
  * Test whether the LockPoints height and time are still valid on the current chain
54
65
  */
@@ -177,12 +188,16 @@ public:
177
188
  }
178
189
  };
179
190
 
191
+ uint160 ScriptHashkey(const CScript& script);
192
+
180
193
  // Multi_index tag names
181
194
  struct descendant_score {};
182
195
  struct entry_time {};
183
196
  struct ancestor_score {};
184
197
  struct index_by_wtxid {};
185
198
 
199
+ class CBlockPolicyEstimator;
200
+
186
201
  /**
187
202
  * Information about a mempool transaction.
188
203
  */
@@ -373,6 +388,9 @@ public:
373
388
  using Limits = kernel::MemPoolLimits;
374
389
 
375
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
+
376
394
  private:
377
395
  typedef std::map<txiter, setEntries, CompareIteratorByHash> cacheMap;
378
396
 
@@ -412,11 +430,11 @@ private:
412
430
 
413
431
  public:
414
432
  indirectmap<COutPoint, const CTransaction*> mapNextTx GUARDED_BY(cs);
415
- std::map<Txid, CAmount> mapDeltas GUARDED_BY(cs);
433
+ std::map<Txid, std::pair<double, CAmount>> mapDeltas GUARDED_BY(cs);
416
434
 
417
435
  using Options = kernel::MemPoolOptions;
418
436
 
419
- const Options m_opts;
437
+ Options m_opts;
420
438
 
421
439
  /** Create a new CTxMemPool.
422
440
  * Sanity checks will be off by default for performance, because otherwise
@@ -455,10 +473,20 @@ public:
455
473
  * the tx is not dependent on other mempool transactions to be included in a block.
456
474
  */
457
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();
458
484
 
459
485
  /** 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);
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); }
462
490
  void ClearPrioritisation(const Txid& hash) EXCLUSIVE_LOCKS_REQUIRED(cs);
463
491
 
464
492
  struct delta_info {
@@ -466,6 +494,7 @@ public:
466
494
  const bool in_mempool;
467
495
  /** The fee delta added using PrioritiseTransaction(). */
468
496
  const CAmount delta;
497
+ const double priority_delta;
469
498
  /** The modified fee (base fee + delta) of this entry. Only present if in_mempool=true. */
470
499
  std::optional<CAmount> modified_fee;
471
500
  /** The prioritised transaction's txid. */
@@ -661,6 +690,8 @@ public:
661
690
  std::vector<CTxMemPoolEntryRef> entryAll() const EXCLUSIVE_LOCKS_REQUIRED(cs);
662
691
  std::vector<TxMempoolInfo> infoAll() const;
663
692
 
693
+ void FindScriptPubKey(const std::set<CScript>& needles, std::map<COutPoint, Coin>& out_results);
694
+
664
695
  size_t DynamicMemoryUsage() const;
665
696
 
666
697
  /** Adds a transaction to the unbroadcast set */
@@ -821,7 +852,12 @@ public:
821
852
 
822
853
  using TxHandle = CTxMemPool::txiter;
823
854
 
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);
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
+ }
825
861
  void StageRemoval(CTxMemPool::txiter it) { m_to_remove.insert(it); }
826
862
 
827
863
  const CTxMemPool::setEntries& GetRemovals() const { return m_to_remove; }
@@ -862,9 +898,9 @@ public:
862
898
 
863
899
  void Apply() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
864
900
 
865
- private:
866
901
  CTxMemPool* m_pool;
867
902
  CTxMemPool::indexed_transaction_set m_to_add;
903
+ private:
868
904
  std::vector<CTxMemPool::txiter> m_entry_vec; // track the added transactions' insertion order
869
905
  // map from the m_to_add index to the ancestors for the transaction
870
906
  std::map<CTxMemPool::txiter, CTxMemPool::setEntries, CompareIteratorByHash> m_ancestors;
@@ -912,6 +948,9 @@ private:
912
948
  * It also allows you to sign a double-spend directly in
913
949
  * signrawtransactionwithkey and signrawtransactionwithwallet,
914
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.
915
954
  */
916
955
  class CCoinsViewMemPool : public CCoinsViewBacked
917
956
  {