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. Before is on the left; after is on the right. Unified view fits narrow screens more easily.

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