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/policy/policy.h

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

File metadata
index 23993dd705e5fd637ead7d1a9330bd8383d326fd..1c7bab2f8964dc3ad1f5d48ea4133f801680cd93 100644

Download original patch · Release notes

Diff rows 1–147 of 147. 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
@@ -14,13 +14,26 @@
14
 
15
  #include <cstdint>
16
  #include <string>
 
 
17
 
18
  class CCoinsViewCache;
19
  class CFeeRate;
20
  class CScript;
21
-
 
 
 
 
 
 
 
 
 
22
  /** Default for -blockmaxweight, which controls the range of block weights the mining code will create **/
23
- static constexpr unsigned int DEFAULT_BLOCK_MAX_WEIGHT{MAX_BLOCK_WEIGHT};
 
 
24
  /** Default for -blockreservedweight **/
25
  static constexpr unsigned int DEFAULT_BLOCK_RESERVED_WEIGHT{8000};
26
  /** This accounts for the block header, var_int encoding of the transaction count and a minimally viable
@@ -29,7 +42,7 @@ static constexpr unsigned int DEFAULT_BLOCK_RESERVED_WEIGHT{8000};
29
  * Setting a lower value is prevented at startup. */
30
  static constexpr unsigned int MINIMUM_BLOCK_RESERVED_WEIGHT{2000};
31
  /** Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by mining code **/
32
- static constexpr unsigned int DEFAULT_BLOCK_MIN_TX_FEE{1};
33
  /** The maximum weight for transactions we're willing to relay/mine */
34
  static constexpr int32_t MAX_STANDARD_TX_WEIGHT{400000};
35
  /** The minimum non-witness size for transactions we're willing to relay/mine: one larger than 64 */
@@ -41,11 +54,37 @@ static constexpr unsigned int MAX_STANDARD_TX_SIGOPS_COST{MAX_BLOCK_SIGOPS_COST/
41
  /** The maximum number of potentially executed legacy signature operations in a single standard tx */
42
  static constexpr unsigned int MAX_TX_LEGACY_SIGOPS{2'500};
43
  /** Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or replacement **/
44
- static constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE{100};
 
 
 
45
  /** Default for -bytespersigop */
46
  static constexpr unsigned int DEFAULT_BYTES_PER_SIGOP{20};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  /** Default for -permitbaremultisig */
48
- static constexpr bool DEFAULT_PERMIT_BAREMULTISIG{true};
 
 
49
  /** The maximum number of witness stack items in a standard P2WSH script */
50
  static constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS{100};
51
  /** The maximum size in bytes of each witness stack item in a standard P2WSH script */
@@ -62,8 +101,11 @@ static constexpr unsigned int MAX_STANDARD_SCRIPTSIG_SIZE{1650};
62
  * only increase the dust limit after prior releases were already not creating
63
  * outputs below the new threshold */
64
  static constexpr unsigned int DUST_RELAY_TX_FEE{3000};
 
 
 
65
  /** Default for -minrelaytxfee, minimum relay fee for transactions */
66
- static constexpr unsigned int DEFAULT_MIN_RELAY_TX_FEE{100};
67
  /** Default for -limitancestorcount, max number of in-mempool ancestors */
68
  static constexpr unsigned int DEFAULT_ANCESTOR_LIMIT{25};
69
  /** Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors */
@@ -77,7 +119,11 @@ static const bool DEFAULT_ACCEPT_DATACARRIER = true;
77
  /**
78
  * Default setting for -datacarriersize in vbytes.
79
  */
80
- static const unsigned int MAX_OP_RETURN_RELAY = MAX_STANDARD_TX_WEIGHT / WITNESS_SCALE_FACTOR;
 
 
 
 
81
  /**
82
  * An extra transaction can be added to a package, as long as it only has one
83
  * ancestor and is no larger than this. Not really any reason to make this
@@ -133,6 +179,9 @@ static constexpr unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS{STANDARD_SCRIP
133
  /** Used as the flags parameter to sequence and nLocktime checks in non-consensus code. */
134
  static constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS{LOCKTIME_VERIFY_SEQUENCE};
135
 
 
 
 
136
  CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFee);
137
 
138
  bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFee);
@@ -152,13 +201,19 @@ static constexpr decltype(CTransaction::version) TX_MAX_STANDARD_VERSION{3};
152
  * Check for standard transaction types
153
  * @return True if all outputs (scriptPubKeys) use only standard transaction forms
154
  */
155
- bool IsStandardTx(const CTransaction& tx, const std::optional<unsigned>& max_datacarrier_bytes, bool permit_bare_multisig, const CFeeRate& dust_relay_fee, std::string& reason);
 
 
 
156
  /**
157
  * Check for standard transaction types
158
  * @param[in] mapInputs Map of previous transactions that have outputs we're spending
159
  * @return True if all inputs (scriptSigs) use only standard transaction forms
160
  */
161
- bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs);
 
 
 
162
  /**
163
  * Check if the transaction is over standard P2WSH resources limit:
164
  * 3600bytes witnessScript size, 80bytes per witness stack element, 100 witness stack elements
@@ -166,7 +221,7 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
166
  *
167
  * Also enforce a maximum stack item size limit and no annexes for tapscript spends.
168
  */
169
- bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs);
170
  /**
171
  * Check whether this transaction spends any witness program but P2A, including not-yet-defined ones.
172
  * May return `false` early for consensus-invalid transactions.
@@ -188,4 +243,10 @@ static inline int64_t GetVirtualTransactionInputSize(const CTxIn& tx)
188
  return GetVirtualTransactionInputSize(tx, 0, 0);
189
  }
190
 
 
 
 
 
 
 
191
  #endif // BITCOIN_POLICY_POLICY_H
 
14
 
15
  #include <cstdint>
16
  #include <string>
17
+ #include <unordered_set>
18
+ #include <utility>
19
 
20
  class CCoinsViewCache;
21
  class CFeeRate;
22
  class CScript;
23
+ namespace kernel {
24
+ struct MemPoolOptions;
25
+ };
26
+
27
+ /** Default for -blockmaxsize, which controls the maximum size of block the mining code will create **/
28
+ static const unsigned int DEFAULT_BLOCK_MAX_SIZE = 300000;
29
+ /** Default for -blockprioritysize, maximum space for zero/low-fee transactions **/
30
+ static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE = 100000;
31
+ /** Minimum priority for transactions to be accepted into the priority area **/
32
+ static const double MINIMUM_TX_PRIORITY = COIN * 144 / 250;
33
  /** Default for -blockmaxweight, which controls the range of block weights the mining code will create **/
34
+ static constexpr unsigned int DEFAULT_BLOCK_MAX_WEIGHT{DEFAULT_BLOCK_MAX_SIZE * WITNESS_SCALE_FACTOR};
35
+ /** Default for BlockCreateOptions.block_reserved_size **/
36
+ static constexpr unsigned int DEFAULT_BLOCK_RESERVED_SIZE{1000};
37
  /** Default for -blockreservedweight **/
38
  static constexpr unsigned int DEFAULT_BLOCK_RESERVED_WEIGHT{8000};
39
  /** This accounts for the block header, var_int encoding of the transaction count and a minimally viable
 
42
  * Setting a lower value is prevented at startup. */
43
  static constexpr unsigned int MINIMUM_BLOCK_RESERVED_WEIGHT{2000};
44
  /** Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by mining code **/
45
+ static constexpr unsigned int DEFAULT_BLOCK_MIN_TX_FEE{1000};
46
  /** The maximum weight for transactions we're willing to relay/mine */
47
  static constexpr int32_t MAX_STANDARD_TX_WEIGHT{400000};
48
  /** The minimum non-witness size for transactions we're willing to relay/mine: one larger than 64 */
 
54
  /** The maximum number of potentially executed legacy signature operations in a single standard tx */
55
  static constexpr unsigned int MAX_TX_LEGACY_SIGOPS{2'500};
56
  /** Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or replacement **/
57
+ static constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE{1000};
58
+ static constexpr CAmount CORE_INCREMENTAL_RELAY_FEE{100};
59
+ /** Default for -maxscriptsize */
60
+ static constexpr unsigned int DEFAULT_SCRIPT_SIZE_POLICY_LIMIT{1650};
61
  /** Default for -bytespersigop */
62
  static constexpr unsigned int DEFAULT_BYTES_PER_SIGOP{20};
63
+ /** Default for -bytespersigopstrict */
64
+ static constexpr unsigned int DEFAULT_BYTES_PER_SIGOP_STRICT{20};
65
+ /** Default for -datacarriercost (multiplied by WITNESS_SCALE_FACTOR) */
66
+ static constexpr unsigned int DEFAULT_WEIGHT_PER_DATA_BYTE{4};
67
+ /** Default for -rejecttokens */
68
+ static constexpr bool DEFAULT_REJECT_TOKENS{false};
69
+ /** Default for -subdustfeepenalty */
70
+ static constexpr bool DEFAULT_SUBDUSTFEEPENALTY{true};
71
+
72
+ // NOTE: Changes to these three require manually adjusting doc in init.cpp
73
+ /** Default for -permitephemeral=send */
74
+ static constexpr bool DEFAULT_PERMITEPHEMERAL_SEND{false};
75
+ /** Default for -permitephemeral=dust */
76
+ static constexpr bool DEFAULT_PERMITEPHEMERAL_DUST{false};
77
+ /** Default for -permitephemeral=anchor */
78
+ static constexpr bool DEFAULT_PERMITEPHEMERAL_ANCHOR{true};
79
+
80
+ /** Default for -permitbareanchor */
81
+ static constexpr bool DEFAULT_PERMITBAREANCHOR{true};
82
+ /** Default for -permitbarepubkey */
83
+ static constexpr bool DEFAULT_PERMIT_BAREPUBKEY{false};
84
  /** Default for -permitbaremultisig */
85
+ static constexpr bool DEFAULT_PERMIT_BAREMULTISIG{false};
86
+ /** Default for -rejectparasites */
87
+ static constexpr bool DEFAULT_REJECT_PARASITES{true};
88
  /** The maximum number of witness stack items in a standard P2WSH script */
89
  static constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS{100};
90
  /** The maximum size in bytes of each witness stack item in a standard P2WSH script */
 
101
  * only increase the dust limit after prior releases were already not creating
102
  * outputs below the new threshold */
103
  static constexpr unsigned int DUST_RELAY_TX_FEE{3000};
104
+ static const std::string DEFAULT_DUST_DYNAMIC{"off"};
105
+ static const int DEFAULT_DUST_RELAY_MULTIPLIER{3'000};
106
+ static const std::string DEFAULT_SPKREUSE{"allow"};
107
  /** Default for -minrelaytxfee, minimum relay fee for transactions */
108
+ static constexpr unsigned int DEFAULT_MIN_RELAY_TX_FEE{1000};
109
  /** Default for -limitancestorcount, max number of in-mempool ancestors */
110
  static constexpr unsigned int DEFAULT_ANCESTOR_LIMIT{25};
111
  /** Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors */
 
119
  /**
120
  * Default setting for -datacarriersize in vbytes.
121
  */
122
+ /** Default for -permitbaredatacarrier */
123
+ static const bool DEFAULT_PERMITBAREDATACARRIER{false};
124
+ static const unsigned int MAX_OP_RETURN_RELAY = 83;
125
+ /** Default for -datacarrierfullcount */
126
+ static constexpr bool DEFAULT_DATACARRIER_FULLCOUNT{true};
127
  /**
128
  * An extra transaction can be added to a package, as long as it only has one
129
  * ancestor and is no larger than this. Not really any reason to make this
 
179
  /** Used as the flags parameter to sequence and nLocktime checks in non-consensus code. */
180
  static constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS{LOCKTIME_VERIFY_SEQUENCE};
181
 
182
+ typedef std::unordered_set<std::string> ignore_rejects_type;
183
+ static const ignore_rejects_type empty_ignore_rejects{};
184
+
185
  CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFee);
186
 
187
  bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFee);
 
201
  * Check for standard transaction types
202
  * @return True if all outputs (scriptPubKeys) use only standard transaction forms
203
  */
204
+ bool IsStandardTx(const CTransaction& tx, const kernel::MemPoolOptions& opts, std::string& out_reason, const ignore_rejects_type& ignore_rejects=empty_ignore_rejects);
205
+ // Compatibility entry point for existing unit tests. Production admission uses
206
+ // the MemPoolOptions overload above so every policy setting is explicit.
207
+ 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);
208
  /**
209
  * Check for standard transaction types
210
  * @param[in] mapInputs Map of previous transactions that have outputs we're spending
211
  * @return True if all inputs (scriptSigs) use only standard transaction forms
212
  */
213
+ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, const kernel::MemPoolOptions& opts, const std::string& reason_prefix, std::string& out_reason, const ignore_rejects_type& ignore_rejects=empty_ignore_rejects);
214
+
215
+ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& map_inputs);
216
+
217
  /**
218
  * Check if the transaction is over standard P2WSH resources limit:
219
  * 3600bytes witnessScript size, 80bytes per witness stack element, 100 witness stack elements
 
221
  *
222
  * Also enforce a maximum stack item size limit and no annexes for tapscript spends.
223
  */
224
+ 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);
225
  /**
226
  * Check whether this transaction spends any witness program but P2A, including not-yet-defined ones.
227
  * May return `false` early for consensus-invalid transactions.
 
243
  return GetVirtualTransactionInputSize(tx, 0, 0);
244
  }
245
 
246
+ std::pair<CScript, unsigned int> GetScriptForTransactionInput(CScript prevScript, const CTxIn&);
247
+
248
+ std::pair<size_t, size_t> DatacarrierBytes(const CTransaction& tx, const CCoinsViewCache& view);
249
+
250
+ int32_t CalculateExtraTxWeight(const CTransaction& tx, const CCoinsViewCache& view, const unsigned int weight_per_data_byte);
251
+
252
  #endif // BITCOIN_POLICY_POLICY_H