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. The two line-number columns refer to before and after.
src/policy/policy.h
CHANGED
|
@@ -8,13 +8,18 @@
|
|
|
8
8
|
|
|
9
9
|
#include <consensus/amount.h>
|
|
10
10
|
#include <consensus/consensus.h>
|
|
11
|
+
#include <policy/feerate.h>
|
|
12
|
+
#include <policy/settings.h>
|
|
11
13
|
#include <primitives/transaction.h>
|
|
12
14
|
#include <script/interpreter.h>
|
|
13
15
|
#include <script/solver.h>
|
|
14
16
|
#include <util/feefrac.h>
|
|
15
17
|
|
|
16
18
|
#include <cstdint>
|
|
19
|
+
#include <optional>
|
|
17
20
|
#include <string>
|
|
21
|
+
#include <unordered_set>
|
|
22
|
+
#include <utility>
|
|
18
23
|
|
|
19
24
|
class CCoinsViewCache;
|
|
20
25
|
class CFeeRate;
|
|
@@ -45,10 +50,32 @@ static constexpr unsigned int MAX_STANDARD_TX_SIGOPS_COST{MAX_BLOCK_SIGOPS_COST/
|
|
|
45
50
|
static constexpr unsigned int MAX_TX_LEGACY_SIGOPS{2'500};
|
|
46
51
|
/** Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or replacement **/
|
|
47
52
|
static constexpr unsigned int DEFAULT_INCREMENTAL_RELAY_FEE{100};
|
|
48
|
-
/** Default for -bytespersigop */
|
|
49
|
-
static constexpr unsigned int DEFAULT_BYTES_PER_SIGOP{20};
|
|
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};
|
|
50
70
|
/** Default for -permitbaremultisig */
|
|
51
|
-
static constexpr bool DEFAULT_PERMIT_BAREMULTISIG{true};
|
|
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
|
+
|
|
52
79
|
/** The maximum number of witness stack items in a standard P2WSH script */
|
|
53
80
|
static constexpr unsigned int MAX_STANDARD_P2WSH_STACK_ITEMS{100};
|
|
54
81
|
/** 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
92
|
* only increase the dust limit after prior releases were already not creating
|
|
66
93
|
* outputs below the new threshold */
|
|
67
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"};
|
|
68
98
|
/** Default for -minrelaytxfee, minimum relay fee for transactions */
|
|
69
|
-
static constexpr unsigned int DEFAULT_MIN_RELAY_TX_FEE{100};
|
|
99
|
+
static constexpr unsigned int DEFAULT_MIN_RELAY_TX_FEE{1000};
|
|
70
100
|
/** Maximum number of transactions per cluster (default) */
|
|
71
101
|
static constexpr unsigned int DEFAULT_CLUSTER_LIMIT{64};
|
|
72
102
|
/** Maximum size of cluster in virtual kilobytes */
|
|
@@ -80,7 +110,7 @@ static const bool DEFAULT_ACCEPT_DATACARRIER = true;
|
|
|
80
110
|
/**
|
|
81
111
|
* Default setting for -datacarriersize in vbytes.
|
|
82
112
|
*/
|
|
83
|
-
static const unsigned int MAX_OP_RETURN_RELAY = MAX_STANDARD_TX_WEIGHT / WITNESS_SCALE_FACTOR;
|
|
113
|
+
static const unsigned int MAX_OP_RETURN_RELAY = 83;
|
|
84
114
|
/**
|
|
85
115
|
* An extra transaction can be added to a package, as long as it only has one
|
|
86
116
|
* 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
166
|
/** Used as the flags parameter to sequence and nLocktime checks in non-consensus code. */
|
|
137
167
|
static constexpr unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS{LOCKTIME_VERIFY_SEQUENCE};
|
|
138
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
|
+
|
|
139
193
|
CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFee);
|
|
140
194
|
|
|
141
195
|
bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFee);
|
|
@@ -155,13 +209,18 @@ static constexpr decltype(CTransaction::version) TX_MAX_STANDARD_VERSION{3};
|
|
|
155
209
|
* Check for standard transaction types
|
|
156
210
|
* @return True if all outputs (scriptPubKeys) use only standard transaction forms
|
|
157
211
|
*/
|
|
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);
|
|
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);
|
|
159
215
|
/**
|
|
160
216
|
* Check for standard transaction types
|
|
161
217
|
* @param[in] mapInputs Map of previous transactions that have outputs we're spending
|
|
162
218
|
* @return True if all inputs (scriptSigs) use only standard transaction forms
|
|
163
219
|
*/
|
|
164
|
-
bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs);
|
|
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
|
+
|
|
165
224
|
/**
|
|
166
225
|
* Check if the transaction is over standard P2WSH resources limit:
|
|
167
226
|
* 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
228
|
*
|
|
170
229
|
* Also enforce a maximum stack item size limit and no annexes for tapscript spends.
|
|
171
230
|
*/
|
|
172
|
-
bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs);
|
|
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);
|
|
173
233
|
/**
|
|
174
234
|
* Check whether this transaction spends any witness program but P2A, including not-yet-defined ones.
|
|
175
235
|
* 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
255
|
|
|
196
256
|
static inline FeePerVSize ToFeePerVSize(FeePerWeight feerate) { return {feerate.fee, (feerate.size + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR}; }
|
|
197
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
|
+
|
|
198
261
|
#endif // BITCOIN_POLICY_POLICY_H
|