From 72540cee4ac19539480e0e4c90236b5421c52b24 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 19 Apr 2018 16:25:04 +0100 Subject: [PATCH] Add Sapling v4 transactions to IsStandard --- src/main.cpp | 11 +++++++++-- src/primitives/transaction.h | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9db267be6..07ed8c592 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -645,9 +645,16 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) EXCLUSIVE_LOCKS_REQUIRE bool IsStandardTx(const CTransaction& tx, string& reason, const int nHeight) { - bool isOverwinter = NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER); + bool overwinterActive = NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER); + bool saplingActive = NetworkUpgradeActive(nHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING); - if (isOverwinter) { + if (saplingActive) { + // Sapling standard rules apply + if (tx.nVersion > CTransaction::SAPLING_MAX_CURRENT_VERSION || tx.nVersion < CTransaction::SAPLING_MIN_CURRENT_VERSION) { + reason = "sapling-version"; + return false; + } + } else if (overwinterActive) { // Overwinter standard rules apply if (tx.nVersion > CTransaction::OVERWINTER_MAX_CURRENT_VERSION || tx.nVersion < CTransaction::OVERWINTER_MIN_CURRENT_VERSION) { reason = "overwinter-version"; diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 4c8aaa4ac..fb15ffeeb 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -426,6 +426,8 @@ public: static const int32_t SPROUT_MAX_CURRENT_VERSION = 2; static const int32_t OVERWINTER_MIN_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_MAX_CURRENT_VERSION = 4; static_assert(SPROUT_MIN_CURRENT_VERSION >= SPROUT_MIN_TX_VERSION, "standard rule for tx version should be consistent with network rule"); @@ -437,6 +439,13 @@ public: OVERWINTER_MAX_CURRENT_VERSION >= OVERWINTER_MIN_CURRENT_VERSION), "standard rule for tx version should be consistent with network rule"); + static_assert(SAPLING_MIN_CURRENT_VERSION >= SAPLING_MIN_TX_VERSION, + "standard rule for tx version should be consistent with network rule"); + + static_assert( (SAPLING_MAX_CURRENT_VERSION <= SAPLING_MAX_TX_VERSION && + SAPLING_MAX_CURRENT_VERSION >= SAPLING_MIN_CURRENT_VERSION), + "standard rule for tx version should be consistent with network rule"); + // The local variables are made const to prevent unintended modification // without updating the cached hash value. However, CTransaction is not // actually immutable; deserialization and assignment are implemented,