Skip to content

Commit fade619

Browse files
author
MarcoFalke
committed
Move TX_MAX_STANDARD_VERSION to policy
Also remove extraneous whitespace, should be reviewed with --ignore-all-space
1 parent 38176dc commit fade619

File tree

4 files changed

+28
-25
lines changed

4 files changed

+28
-25
lines changed

src/bitcoin-tx.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <consensus/consensus.h>
1212
#include <core_io.h>
1313
#include <key_io.h>
14+
#include <policy/policy.h>
1415
#include <policy/rbf.h>
1516
#include <primitives/transaction.h>
1617
#include <script/script.h>
@@ -196,8 +197,9 @@ static CAmount ExtractAndValidateValue(const std::string& strValue)
196197
static void MutateTxVersion(CMutableTransaction& tx, const std::string& cmdVal)
197198
{
198199
int64_t newVersion;
199-
if (!ParseInt64(cmdVal, &newVersion) || newVersion < 1 || newVersion > CTransaction::MAX_STANDARD_VERSION)
200+
if (!ParseInt64(cmdVal, &newVersion) || newVersion < 1 || newVersion > TX_MAX_STANDARD_VERSION) {
200201
throw std::runtime_error("Invalid TX version requested: '" + cmdVal + "'");
202+
}
201203

202204
tx.nVersion = (int) newVersion;
203205
}

src/policy/policy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ bool IsStandard(const CScript& scriptPubKey, TxoutType& whichType)
7575

7676
bool IsStandardTx(const CTransaction& tx, bool permit_bare_multisig, const CFeeRate& dust_relay_fee, std::string& reason)
7777
{
78-
if (tx.nVersion > CTransaction::MAX_STANDARD_VERSION || tx.nVersion < 1) {
78+
if (tx.nVersion > TX_MAX_STANDARD_VERSION || tx.nVersion < 1) {
7979
reason = "version";
8080
return false;
8181
}

src/policy/policy.h

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,32 @@ CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFee);
9090
bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFee);
9191

9292
bool IsStandard(const CScript& scriptPubKey, TxoutType& whichType);
93-
/**
94-
* Check for standard transaction types
95-
* @return True if all outputs (scriptPubKeys) use only standard transaction forms
96-
*/
93+
94+
95+
// Changing the default transaction version requires a two step process: first
96+
// adapting relay policy by bumping TX_MAX_STANDARD_VERSION, and then later
97+
// allowing the new transaction version in the wallet/RPC.
98+
static constexpr decltype(CTransaction::nVersion) TX_MAX_STANDARD_VERSION{2};
99+
100+
/**
101+
* Check for standard transaction types
102+
* @return True if all outputs (scriptPubKeys) use only standard transaction forms
103+
*/
97104
bool IsStandardTx(const CTransaction& tx, bool permit_bare_multisig, const CFeeRate& dust_relay_fee, std::string& reason);
98-
/**
99-
* Check for standard transaction types
100-
* @param[in] mapInputs Map of previous transactions that have outputs we're spending
101-
* @param[in] taproot_active Whether or taproot consensus rules are active (used to decide whether spends of them are permitted)
102-
* @return True if all inputs (scriptSigs) use only standard transaction forms
103-
*/
105+
/**
106+
* Check for standard transaction types
107+
* @param[in] mapInputs Map of previous transactions that have outputs we're spending
108+
* @param[in] taproot_active Whether or taproot consensus rules are active (used to decide whether spends of them are permitted)
109+
* @return True if all inputs (scriptSigs) use only standard transaction forms
110+
*/
104111
bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, bool taproot_active);
105-
/**
106-
* Check if the transaction is over standard P2WSH resources limit:
107-
* 3600bytes witnessScript size, 80bytes per witness stack element, 100 witness stack elements
108-
* These limits are adequate for multisignatures up to n-of-100 using OP_CHECKSIG, OP_ADD, and OP_EQUAL.
109-
*
110-
* Also enforce a maximum stack item size limit and no annexes for tapscript spends.
111-
*/
112+
/**
113+
* Check if the transaction is over standard P2WSH resources limit:
114+
* 3600bytes witnessScript size, 80bytes per witness stack element, 100 witness stack elements
115+
* These limits are adequate for multisignatures up to n-of-100 using OP_CHECKSIG, OP_ADD, and OP_EQUAL.
116+
*
117+
* Also enforce a maximum stack item size limit and no annexes for tapscript spends.
118+
*/
112119
bool IsWitnessStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs);
113120

114121
/** Compute the virtual transaction size (weight reinterpreted as bytes). */

src/primitives/transaction.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,6 @@ class CTransaction
262262
// Default transaction version.
263263
static const int32_t CURRENT_VERSION=2;
264264

265-
// Changing the default transaction version requires a two step process: first
266-
// adapting relay policy by bumping MAX_STANDARD_VERSION, and then later date
267-
// bumping the default CURRENT_VERSION at which point both CURRENT_VERSION and
268-
// MAX_STANDARD_VERSION will be equal.
269-
static const int32_t MAX_STANDARD_VERSION=2;
270-
271265
// The local variables are made const to prevent unintended modification
272266
// without updating the cached hash value. However, CTransaction is not
273267
// actually immutable; deserialization and assignment are implemented,

0 commit comments

Comments
 (0)