Skip to content
Bitcoin Roots

v31.1-roots.1 · Commit 3: [PATCH 03/17] feat(policy): preserve cluster accounting and repair dynamic dust

src/kernel/mempool_entry.h

Before: src/kernel/mempool_entry.h · After: src/kernel/mempool_entry.h

File metadata
index dd0c23a2cdecd42ae45922c0962d89d2f66c396c..84d5161a1d5af3414a400601508bb68c65c879f7 100644

Download original patch · Release notes

Diff rows 1–71 of 71. 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/kernel/mempool_entry.h CHANGED
@@ -18,6 +18,7 @@
18
18
  #include <cstddef>
19
19
  #include <cstdint>
20
20
  #include <functional>
21
+ #include <map>
21
22
  #include <memory>
22
23
  #include <set>
23
24
 
@@ -73,6 +74,7 @@ private:
73
74
  const CTransactionRef tx;
74
75
  const CAmount nFee; //!< Cached to avoid expensive parent-transaction lookups
75
76
  const int32_t nTxWeight; //!< ... and avoid recomputing tx weight (also used for GetTxSize())
77
+ const int32_t m_extra_weight; //!< Additional local policy weight; actual weight is unchanged
76
78
  const size_t nUsageSize; //!< ... and total memory usage
77
79
  const int64_t nTime; //!< Local time when entering the mempool
78
80
  const uint64_t entry_sequence; //!< Sequence number used to determine whether this transaction is too recent for relay
@@ -87,10 +89,11 @@ public:
87
89
  CTxMemPoolEntry(const CTransactionRef& tx, CAmount fee,
88
90
  int64_t time, unsigned int entry_height, uint64_t entry_sequence,
89
91
  bool spends_coinbase,
90
- int64_t sigops_cost, LockPoints lp)
92
+ int64_t sigops_cost, LockPoints lp, int32_t extra_weight = 0, CAmount dust_penalty = 0, std::map<CScript, unsigned> script_claims = {})
91
93
  : tx{tx},
92
94
  nFee{fee},
93
95
  nTxWeight{GetTransactionWeight(*tx)},
96
+ m_extra_weight{extra_weight},
94
97
  nUsageSize{RecursiveDynamicUsage(tx)},
95
98
  nTime{time},
96
99
  entry_sequence{entry_sequence},
@@ -98,7 +101,9 @@ public:
98
101
  spendsCoinbase{spends_coinbase},
99
102
  sigOpCost{sigops_cost},
100
103
  m_modified_fee{nFee},
101
- lockPoints{lp} {}
104
+ lockPoints{lp},
105
+ m_dust_penalty{dust_penalty},
106
+ m_script_claims{std::move(script_claims)} {}
102
107
 
103
108
  CTxMemPoolEntry& operator=(const CTxMemPoolEntry&) = delete;
104
109
  CTxMemPoolEntry(CTxMemPoolEntry&&) = default;
@@ -109,16 +114,22 @@ public:
109
114
  const CAmount& GetFee() const { return nFee; }
110
115
  int32_t GetTxSize() const
111
116
  {
112
- return GetVirtualTransactionSize(nTxWeight, sigOpCost, ::nBytesPerSigOp);
117
+ return GetVirtualTransactionSize(int64_t{nTxWeight} + m_extra_weight, sigOpCost, ::nBytesPerSigOp);
113
118
  }
114
- int32_t GetAdjustedWeight() const { return GetSigOpsAdjustedWeight(nTxWeight, sigOpCost, ::nBytesPerSigOp); }
119
+ int64_t GetAdjustedWeight() const { return GetSigOpsAdjustedWeight(int64_t{nTxWeight} + m_extra_weight, sigOpCost, ::nBytesPerSigOp); }
120
+ int32_t GetExtraWeight() const { return m_extra_weight; }
115
121
  int32_t GetTxWeight() const { return nTxWeight; }
116
122
  std::chrono::seconds GetTime() const { return std::chrono::seconds{nTime}; }
117
123
  unsigned int GetHeight() const { return entryHeight; }
118
124
  uint64_t GetSequence() const { return entry_sequence; }
119
125
  int64_t GetSigOpCost() const { return sigOpCost; }
120
126
  CAmount GetModifiedFee() const { return m_modified_fee; }
121
- size_t DynamicMemoryUsage() const { return nUsageSize; }
127
+ size_t DynamicMemoryUsage() const
128
+ {
129
+ size_t usage{nUsageSize + memusage::DynamicUsage(m_script_claims)};
130
+ for (const auto& [script, claims] : m_script_claims) usage += RecursiveDynamicUsage(script);
131
+ return usage;
132
+ }
122
133
  const LockPoints& GetLockPoints() const { return lockPoints; }
123
134
 
124
135
  // Updates the modified fees with descendants/ancestors.
@@ -135,6 +146,10 @@ public:
135
146
 
136
147
  bool GetSpendsCoinbase() const { return spendsCoinbase; }
137
148
 
149
+ const CAmount m_dust_penalty; //!< Admission-time deficit; dynamic changes do not reprice entries
150
+ // Bit 1: spent; bit 2: created. Full scripts avoid hash collisions.
151
+ const std::map<CScript, unsigned> m_script_claims;
152
+
138
153
  mutable size_t idx_randomized; //!< Index in mempool's txns_randomized
139
154
  };
140
155