Skip to content
Bitcoin Roots

v29.4-roots.3 · Commit 3: [PATCH 03/30] policy: restore conservative relay and network controls

src/txmempool.h

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

File metadata
index acc52aef1d9543f1e582aecaca049612dbd155dc..4acb5f626fc7e1611caf8c44bb2c44f05986d24b 100644

Download original patch · Release notes

Diff rows 1–136 of 136. 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
@@ -17,6 +17,7 @@
17
17
  #include <policy/feerate.h>
18
18
  #include <policy/packages.h>
19
19
  #include <primitives/transaction.h>
20
+ #include <script/script.h>
20
21
  #include <sync.h>
21
22
  #include <util/epochguard.h>
22
23
  #include <util/hasher.h>
@@ -41,13 +42,23 @@
41
42
  #include <vector>
42
43
 
43
44
  class CChain;
45
+ class CScript;
44
46
  class ValidationSignals;
45
47
 
46
48
  struct bilingual_str;
47
49
 
50
+ static constexpr std::chrono::minutes DYNAMIC_DUST_FEERATE_UPDATE_INTERVAL{15};
51
+
48
52
  /** Fake height value used in Coin to signify they are only in the memory pool (since 0.8) */
49
53
  static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
50
54
 
55
+ inline int64_t maxmempoolMinimumBytes(const int64_t descendant_size_vbytes) {
56
+ return descendant_size_vbytes * 40;
57
+ }
58
+ inline int64_t limitdescendantsizeMaximumVBytes(const int64_t maxmempool) {
59
+ return maxmempool / 40;
60
+ }
61
+
51
62
  /**
52
63
  * Test whether the LockPoints height and time are still valid on the current chain
53
64
  */
@@ -200,12 +211,16 @@ public:
200
211
  }
201
212
  };
202
213
 
214
+ uint160 ScriptHashkey(const CScript& script);
215
+
203
216
  // Multi_index tag names
204
217
  struct descendant_score {};
205
218
  struct entry_time {};
206
219
  struct ancestor_score {};
207
220
  struct index_by_wtxid {};
208
221
 
222
+ class CBlockPolicyEstimator;
223
+
209
224
  /**
210
225
  * Information about a mempool transaction.
211
226
  */
@@ -396,6 +411,9 @@ public:
396
411
  using Limits = kernel::MemPoolLimits;
397
412
 
398
413
  uint64_t CalculateDescendantMaximum(txiter entry) const EXCLUSIVE_LOCKS_REQUIRED(cs);
414
+
415
+ std::map<uint160, std::pair<const CTransaction *, const CTransaction *>> mapUsedSPK;
416
+
399
417
  private:
400
418
  typedef std::map<txiter, setEntries, CompareIteratorByHash> cacheMap;
401
419
 
@@ -430,11 +448,11 @@ private:
430
448
 
431
449
  public:
432
450
  indirectmap<COutPoint, const CTransaction*> mapNextTx GUARDED_BY(cs);
433
- std::map<uint256, CAmount> mapDeltas GUARDED_BY(cs);
451
+ std::map<uint256, std::pair<double, CAmount> > mapDeltas GUARDED_BY(cs);
434
452
 
435
453
  using Options = kernel::MemPoolOptions;
436
454
 
437
- const Options m_opts;
455
+ Options m_opts;
438
456
 
439
457
  /** Create a new CTxMemPool.
440
458
  * Sanity checks will be off by default for performance, because otherwise
@@ -473,10 +491,19 @@ public:
473
491
  * the tx is not dependent on other mempool transactions to be included in a block.
474
492
  */
475
493
  bool HasNoInputsOf(const CTransaction& tx) const EXCLUSIVE_LOCKS_REQUIRED(cs);
494
+ /**
495
+ * Update all transactions in the mempool which depend on tx to recalculate their priority
496
+ * and adjust the input value that will age to reflect that the inputs from this transaction have
497
+ * either just been added to the chain or just been removed.
498
+ */
499
+ void UpdateDependentPriorities(const CTransaction &tx, unsigned int nBlockHeight, bool addToChain);
500
+
501
+ void UpdateDynamicDustFeerate();
476
502
 
477
503
  /** Affect CreateNewBlock prioritisation of transactions */
478
- void PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta);
479
- void ApplyDelta(const uint256& hash, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs);
504
+ void PrioritiseTransaction(const uint256& hash, double dPriorityDelta, const CAmount& nFeeDelta);
505
+ void PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta) { PrioritiseTransaction(hash, 0., nFeeDelta); }
506
+ void ApplyDeltas(const uint256& hash, double &dPriorityDelta, CAmount &nFeeDelta) const EXCLUSIVE_LOCKS_REQUIRED(cs);
480
507
  void ClearPrioritisation(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs);
481
508
 
482
509
  struct delta_info {
@@ -484,6 +511,7 @@ public:
484
511
  const bool in_mempool;
485
512
  /** The fee delta added using PrioritiseTransaction(). */
486
513
  const CAmount delta;
514
+ const double priority_delta;
487
515
  /** The modified fee (base fee + delta) of this entry. Only present if in_mempool=true. */
488
516
  std::optional<CAmount> modified_fee;
489
517
  /** The prioritised transaction's txid. */
@@ -667,6 +695,8 @@ public:
667
695
  std::vector<CTxMemPoolEntryRef> entryAll() const EXCLUSIVE_LOCKS_REQUIRED(cs);
668
696
  std::vector<TxMempoolInfo> infoAll() const;
669
697
 
698
+ void FindScriptPubKey(const std::set<CScript>& needles, std::map<COutPoint, Coin>& out_results);
699
+
670
700
  size_t DynamicMemoryUsage() const;
671
701
 
672
702
  /** Adds a transaction to the unbroadcast set */
@@ -827,7 +857,12 @@ public:
827
857
 
828
858
  using TxHandle = CTxMemPool::txiter;
829
859
 
830
- 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);
860
+ 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);
861
+ 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)
862
+ {
863
+ return StageAddition(tx, fee, time, entry_height, entry_sequence, COIN_AGE_CACHE_ZERO,
864
+ spends_coinbase, /*extra_weight=*/0, sigops_cost, lp);
865
+ }
831
866
  void StageRemoval(CTxMemPool::txiter it) { m_to_remove.insert(it); }
832
867
 
833
868
  const CTxMemPool::setEntries& GetRemovals() const { return m_to_remove; }
@@ -868,9 +903,9 @@ public:
868
903
 
869
904
  void Apply() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
870
905
 
871
- private:
872
906
  CTxMemPool* m_pool;
873
907
  CTxMemPool::indexed_transaction_set m_to_add;
908
+ private:
874
909
  std::vector<CTxMemPool::txiter> m_entry_vec; // track the added transactions' insertion order
875
910
  // map from the m_to_add index to the ancestors for the transaction
876
911
  std::map<CTxMemPool::txiter, CTxMemPool::setEntries, CompareIteratorByHash> m_ancestors;
@@ -918,6 +953,9 @@ private:
918
953
  * It also allows you to sign a double-spend directly in
919
954
  * signrawtransactionwithkey and signrawtransactionwithwallet,
920
955
  * as long as the conflicting transaction is not yet confirmed.
956
+ *
957
+ * Its Cursor also doesn't work. In general, it is broken as a CCoinsView
958
+ * implementation outside of a few use cases.
921
959
  */
922
960
  class CCoinsViewMemPool : public CCoinsViewBacked
923
961
  {