Merge pull request #5345 from str4d/nu5-standard-tx

Mark v5 transaction format as standard for NU5
This commit is contained in:
Daira Hopwood 2021-10-07 14:14:24 +01:00 committed by GitHub
commit ee8a8e67e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View File

@ -1787,7 +1787,7 @@ bool AcceptToMemoryPool(
if (tx.IsCoinBase()) if (tx.IsCoinBase())
return state.DoS(100, false, REJECT_INVALID, "coinbase"); return state.DoS(100, false, REJECT_INVALID, "coinbase");
// Rather not work on nonstandard transactions (unless -testnet/-regtest) // Rather not work on nonstandard transactions (unless -regtest)
string reason; string reason;
if (chainparams.RequireStandard() && !IsStandardTx(tx, reason, chainparams, nextBlockHeight)) if (chainparams.RequireStandard() && !IsStandardTx(tx, reason, chainparams, nextBlockHeight))
return state.DoS(0, false, REJECT_NONSTANDARD, reason); return state.DoS(0, false, REJECT_NONSTANDARD, reason);

View File

@ -59,8 +59,15 @@ bool IsStandardTx(const CTransaction& tx, std::string& reason, const CChainParam
{ {
bool overwinterActive = chainparams.GetConsensus().NetworkUpgradeActive(nHeight, Consensus::UPGRADE_OVERWINTER); bool overwinterActive = chainparams.GetConsensus().NetworkUpgradeActive(nHeight, Consensus::UPGRADE_OVERWINTER);
bool saplingActive = chainparams.GetConsensus().NetworkUpgradeActive(nHeight, Consensus::UPGRADE_SAPLING); bool saplingActive = chainparams.GetConsensus().NetworkUpgradeActive(nHeight, Consensus::UPGRADE_SAPLING);
bool nu5Active = chainparams.GetConsensus().NetworkUpgradeActive(nHeight, Consensus::UPGRADE_NU5);
if (saplingActive) { if (nu5Active) {
// NU5 standard rules apply
if (tx.nVersion > CTransaction::NU5_MAX_CURRENT_VERSION || tx.nVersion < CTransaction::NU5_MIN_CURRENT_VERSION) {
reason = "nu5-version";
return false;
}
} else if (saplingActive) {
// Sapling standard rules apply // Sapling standard rules apply
if (tx.nVersion > CTransaction::SAPLING_MAX_CURRENT_VERSION || tx.nVersion < CTransaction::SAPLING_MIN_CURRENT_VERSION) { if (tx.nVersion > CTransaction::SAPLING_MAX_CURRENT_VERSION || tx.nVersion < CTransaction::SAPLING_MIN_CURRENT_VERSION) {
reason = "sapling-version"; reason = "sapling-version";

View File

@ -719,6 +719,8 @@ public:
static const int32_t OVERWINTER_MAX_CURRENT_VERSION = 3; static const int32_t OVERWINTER_MAX_CURRENT_VERSION = 3;
static const int32_t SAPLING_MIN_CURRENT_VERSION = 4; static const int32_t SAPLING_MIN_CURRENT_VERSION = 4;
static const int32_t SAPLING_MAX_CURRENT_VERSION = 4; static const int32_t SAPLING_MAX_CURRENT_VERSION = 4;
static const int32_t NU5_MIN_CURRENT_VERSION = 4;
static const int32_t NU5_MAX_CURRENT_VERSION = 5;
static_assert(SPROUT_MIN_CURRENT_VERSION >= SPROUT_MIN_TX_VERSION, static_assert(SPROUT_MIN_CURRENT_VERSION >= SPROUT_MIN_TX_VERSION,
"standard rule for tx version should be consistent with network rule"); "standard rule for tx version should be consistent with network rule");
@ -737,6 +739,13 @@ public:
SAPLING_MAX_CURRENT_VERSION >= SAPLING_MIN_CURRENT_VERSION), SAPLING_MAX_CURRENT_VERSION >= SAPLING_MIN_CURRENT_VERSION),
"standard rule for tx version should be consistent with network rule"); "standard rule for tx version should be consistent with network rule");
static_assert(NU5_MIN_CURRENT_VERSION >= SAPLING_MIN_TX_VERSION,
"standard rule for tx version should be consistent with network rule");
static_assert( (NU5_MAX_CURRENT_VERSION <= ZIP225_MAX_TX_VERSION &&
NU5_MAX_CURRENT_VERSION >= NU5_MIN_CURRENT_VERSION),
"standard rule for tx version should be consistent with network rule");
// The local variables are made const to prevent unintended modification // The local variables are made const to prevent unintended modification
// without updating the cached hash value. However, CTransaction is not // without updating the cached hash value. However, CTransaction is not
// actually immutable; deserialization and assignment are implemented, // actually immutable; deserialization and assignment are implemented,