Skip to content
Bitcoin Roots

v31.1-roots.1 · Commit 2: [PATCH 02/17] feat(policy): preserve Roots parsing and local transaction checks

src/policy/policy.h

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

File metadata
index 0bc7b32770833211913b82204f1b8fc4bdb4dfd0..69897f8d249e6e6201910ab8172b63889e0e711b 100644

Download original patch · Release notes

Diff rows 1–139 of 139. 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/policy/policy.h CHANGED
@@ -8,13 +8,18 @@
8
 
9
  #include <consensus/amount.h>
10
  #include <consensus/consensus.h>
 
 
11
  #include <primitives/transaction.h>
12
  #include <script/interpreter.h>
13
  #include <script/solver.h>
14
  #include <util/feefrac.h>
15
 
16
  #include <cstdint>
 
17
  #include <string>
 
 
18
 
19
  class CCoinsViewCache;
20
  class CFeeRate;
@@ -45,10 +50,32 @@ static constexpr unsigned int MAX_STANDARD_TX_SIGOPS_COST{MAX_BLOCK_SIGOPS_COST/
45
  static constexpr unsigned int MAX_TX_LEGACY_SIGOPS{2'500};
46
  /** Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or replacement **/
47
  static constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE{100};
48
- /** Default for -bytespersigop */
49
- static constexpr unsigned int DEFAULT_BYTES_PER_SIGOP{20};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  /** Default for -permitbaremultisig */
51
- static constexpr bool DEFAULT_PERMIT_BAREMULTISIG{true};
 
 
 
 
 
 
 
52
  /** The maximum number of witness stack items in a standard P2WSH script */
53
  static constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS{100};
54
  /** The maximum size in bytes of each witness stack item in a standard P2WSH script */
@@ -65,8 +92,11 @@ static constexpr unsigned int MAX_STANDARD_SCRIPTSIG_SIZE{1650};
65
  * only increase the dust limit after prior releases were already not creating
66
  * outputs below the new threshold */
67
  static constexpr unsigned int DUST_RELAY_TX_FEE{3000};
 
 
 
68
  /** Default for -minrelaytxfee, minimum relay fee for transactions */
69
- static constexpr unsigned int DEFAULT_MIN_RELAY_TX_FEE{100};
70
  /** Maximum number of transactions per cluster (default) */
71
  static constexpr unsigned int DEFAULT_CLUSTER_LIMIT{64};
72
  /** Maximum size of cluster in virtual kilobytes */
@@ -80,7 +110,7 @@ static const bool DEFAULT_ACCEPT_DATACARRIER = true;
80
  /**
81
  * Default setting for -datacarriersize in vbytes.
82
  */
83
- static const unsigned int MAX_OP_RETURN_RELAY = MAX_STANDARD_TX_WEIGHT / WITNESS_SCALE_FACTOR;
84
  /**
85
  * An extra transaction can be added to a package, as long as it only has one
86
  * ancestor and is no larger than this. Not really any reason to make this
@@ -136,6 +166,30 @@ static constexpr script_verify_flags STANDARD_NOT_MANDATORY_VERIFY_FLAGS{STANDAR
136
  /** Used as the flags parameter to sequence and nLocktime checks in non-consensus code. */
137
  static constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS{LOCKTIME_VERIFY_SEQUENCE};
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFee);
140
 
141
  bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFee);
@@ -155,13 +209,18 @@ static constexpr decltype(CTransaction::version) TX_MAX_STANDARD_VERSION{3};
155
  * Check for standard transaction types
156
  * @return True if all outputs (scriptPubKeys) use only standard transaction forms
157
  */
158
- bool IsStandardTx(const CTransaction& tx, const std::optional<unsigned>& max_datacarrier_bytes, bool permit_bare_multisig, const CFeeRate& dust_relay_fee, std::string& reason);
 
 
159
  /**
160
  * Check for standard transaction types
161
  * @param[in] mapInputs Map of previous transactions that have outputs we're spending
162
  * @return True if all inputs (scriptSigs) use only standard transaction forms
163
  */
164
- bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs);
 
 
 
165
  /**
166
  * Check if the transaction is over standard P2WSH resources limit:
167
  * 3600bytes witnessScript size, 80bytes per witness stack element, 100 witness stack elements
@@ -169,7 +228,8 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
169
  *
170
  * Also enforce a maximum stack item size limit and no annexes for tapscript spends.
171
  */
172
- bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs);
 
173
  /**
174
  * Check whether this transaction spends any witness program but P2A, including not-yet-defined ones.
175
  * May return `false` early for consensus-invalid transactions.
@@ -195,4 +255,7 @@ int64_t GetSigOpsAdjustedWeight(int64_t weight, int64_t sigop_cost, unsigned int
195
 
196
  static inline FeePerVSize ToFeePerVSize(FeePerWeight feerate) { return {feerate.fee, (feerate.size + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR}; }
197
 
 
 
 
198
  #endif // BITCOIN_POLICY_POLICY_H
 
8
 
9
  #include <consensus/amount.h>
10
  #include <consensus/consensus.h>
11
+ #include <policy/feerate.h>
12
+ #include <policy/settings.h>
13
  #include <primitives/transaction.h>
14
  #include <script/interpreter.h>
15
  #include <script/solver.h>
16
  #include <util/feefrac.h>
17
 
18
  #include <cstdint>
19
+ #include <optional>
20
  #include <string>
21
+ #include <unordered_set>
22
+ #include <utility>
23
 
24
  class CCoinsViewCache;
25
  class CFeeRate;
 
50
  static constexpr unsigned int MAX_TX_LEGACY_SIGOPS{2'500};
51
  /** Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or replacement **/
52
  static constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE{100};
53
+ /** Default for -rejecttokens */
54
+ static constexpr bool DEFAULT_REJECT_TOKENS{false};
55
+ /** Default for -subdustfeepenalty */
56
+ static constexpr bool DEFAULT_SUBDUSTFEEPENALTY{true};
57
+
58
+ // NOTE: Changes to these three require manually adjusting doc in init.cpp
59
+ /** Default for -permitephemeral=send */
60
+ static constexpr bool DEFAULT_PERMITEPHEMERAL_SEND{false};
61
+ /** Default for -permitephemeral=dust */
62
+ static constexpr bool DEFAULT_PERMITEPHEMERAL_DUST{false};
63
+ /** Default for -permitephemeral=anchor */
64
+ static constexpr bool DEFAULT_PERMITEPHEMERAL_ANCHOR{true};
65
+
66
+ /** Default for -permitbareanchor */
67
+ static constexpr bool DEFAULT_PERMITBAREANCHOR{true};
68
+ /** Default for -permitbarepubkey */
69
+ static constexpr bool DEFAULT_PERMIT_BAREPUBKEY{false};
70
  /** Default for -permitbaremultisig */
71
+ static constexpr bool DEFAULT_PERMIT_BAREMULTISIG{false};
72
+ /** Default for -rejectparasites */
73
+ static constexpr bool DEFAULT_REJECT_PARASITES{true};
74
+ /** Locktime marker used by the CAT21 parasitic overlay protocol. */
75
+ static constexpr uint32_t PARASITE_CAT21_LOCKTIME{21};
76
+ /** Default for -acceptunknownwitness */
77
+ static constexpr bool DEFAULT_ACCEPTUNKNOWNWITNESS{true};
78
+
79
  /** The maximum number of witness stack items in a standard P2WSH script */
80
  static constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS{100};
81
  /** The maximum size in bytes of each witness stack item in a standard P2WSH script */
 
92
  * only increase the dust limit after prior releases were already not creating
93
  * outputs below the new threshold */
94
  static constexpr unsigned int DUST_RELAY_TX_FEE{3000};
95
+ static const std::string DEFAULT_DUST_DYNAMIC{"off"};
96
+ static const int DEFAULT_DUST_RELAY_MULTIPLIER{3'000};
97
+ static const std::string DEFAULT_SPKREUSE{"allow"};
98
  /** Default for -minrelaytxfee, minimum relay fee for transactions */
99
+ static constexpr unsigned int DEFAULT_MIN_RELAY_TX_FEE{1000};
100
  /** Maximum number of transactions per cluster (default) */
101
  static constexpr unsigned int DEFAULT_CLUSTER_LIMIT{64};
102
  /** Maximum size of cluster in virtual kilobytes */
 
110
  /**
111
  * Default setting for -datacarriersize in vbytes.
112
  */
113
+ static const unsigned int MAX_OP_RETURN_RELAY = 83;
114
  /**
115
  * An extra transaction can be added to a package, as long as it only has one
116
  * ancestor and is no larger than this. Not really any reason to make this
 
166
  /** Used as the flags parameter to sequence and nLocktime checks in non-consensus code. */
167
  static constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS{LOCKTIME_VERIFY_SEQUENCE};
168
 
169
+ static constexpr bool DEFAULT_DATACARRIER_FULLCOUNT{true};
170
+
171
+ static const bool DEFAULT_PERMITBAREDATACARRIER{false};
172
+
173
+ typedef std::unordered_set<std::string> ignore_rejects_type;
174
+ static const ignore_rejects_type empty_ignore_rejects{};
175
+
176
+ /** Local transaction-standardness settings shared by admission and policy checks. */
177
+ struct StandardnessOptions {
178
+ CFeeRate dust_relay_feerate{DUST_RELAY_TX_FEE};
179
+ unsigned int maxtxlegacysigops{MAX_TX_LEGACY_SIGOPS};
180
+ std::optional<unsigned> max_datacarrier_bytes{DEFAULT_ACCEPT_DATACARRIER ? std::optional{MAX_OP_RETURN_RELAY} : std::nullopt};
181
+ bool permitbaredatacarrier{DEFAULT_PERMITBAREDATACARRIER};
182
+ bool permitbareanchor{DEFAULT_PERMITBAREANCHOR};
183
+ bool permit_bare_pubkey{DEFAULT_PERMIT_BAREPUBKEY};
184
+ bool permit_bare_multisig{DEFAULT_PERMIT_BAREMULTISIG};
185
+ bool reject_parasites{DEFAULT_REJECT_PARASITES};
186
+ bool reject_tokens{DEFAULT_REJECT_TOKENS};
187
+ bool acceptunknownwitness{DEFAULT_ACCEPTUNKNOWNWITNESS};
188
+ bool permitephemeral_anchor{DEFAULT_PERMITEPHEMERAL_ANCHOR};
189
+ bool permitephemeral_send{DEFAULT_PERMITEPHEMERAL_SEND};
190
+ bool permitephemeral_dust{DEFAULT_PERMITEPHEMERAL_DUST};
191
+ };
192
+
193
  CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFee);
194
 
195
  bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFee);
 
209
  * Check for standard transaction types
210
  * @return True if all outputs (scriptPubKeys) use only standard transaction forms
211
  */
212
+ bool IsStandardTx(const CTransaction& tx, const StandardnessOptions& opts, std::string& out_reason, const ignore_rejects_type& ignore_rejects=empty_ignore_rejects);
213
+ // Retain the native entry point for callers using individual policy values.
214
+ bool IsStandardTx(const CTransaction& tx, const std::optional<unsigned>& max_datacarrier_bytes, bool permit_bare_multisig, const CFeeRate& dust_relay_feerate, std::string& out_reason);
215
  /**
216
  * Check for standard transaction types
217
  * @param[in] mapInputs Map of previous transactions that have outputs we're spending
218
  * @return True if all inputs (scriptSigs) use only standard transaction forms
219
  */
220
+ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, const StandardnessOptions& opts, const std::string& reason_prefix, std::string& out_reason, const ignore_rejects_type& ignore_rejects=empty_ignore_rejects);
221
+
222
+ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& map_inputs);
223
+
224
  /**
225
  * Check if the transaction is over standard P2WSH resources limit:
226
  * 3600bytes witnessScript size, 80bytes per witness stack element, 100 witness stack elements
 
228
  *
229
  * Also enforce a maximum stack item size limit and no annexes for tapscript spends.
230
  */
231
+ bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, const std::string& reason_prefix, std::string& out_reason, const ignore_rejects_type& ignore_rejects=empty_ignore_rejects);
232
+ bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& map_inputs);
233
  /**
234
  * Check whether this transaction spends any witness program but P2A, including not-yet-defined ones.
235
  * May return `false` early for consensus-invalid transactions.
 
255
 
256
  static inline FeePerVSize ToFeePerVSize(FeePerWeight feerate) { return {feerate.fee, (feerate.size + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR}; }
257
 
258
+ std::pair<CScript, unsigned int> GetScriptForTransactionInput(CScript prev_script, const CTxIn& input);
259
+ std::pair<size_t, size_t> DatacarrierBytes(const CTransaction& tx, const CCoinsViewCache& view);
260
+
261
  #endif // BITCOIN_POLICY_POLICY_H