]> Git Repo - VerusCoin.git/commitdiff
Expire Overwinter transactions before the Sapling activation height
authorJack Grigg <[email protected]>
Thu, 3 May 2018 11:27:56 +0000 (12:27 +0100)
committerJack Grigg <[email protected]>
Thu, 3 May 2018 11:27:56 +0000 (12:27 +0100)
src/main.cpp
src/rpcrawtransaction.cpp
src/wallet/rpcwallet.cpp
src/wallet/wallet.cpp

index fff319b663259ebf3accf8d4ecec88b514f4f513..1f80e3b2921329ae871aaf59eff7ac6b243377b6 100644 (file)
@@ -31,6 +31,7 @@
 #include "wallet/asyncrpcoperation_sendmany.h"
 #include "wallet/asyncrpcoperation_shieldcoinbase.h"
 
+#include <algorithm>
 #include <sstream>
 
 #include <boost/algorithm/string/replace.hpp>
@@ -6078,17 +6079,18 @@ CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Para
     bool isOverwintered = NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_OVERWINTER);
     if (isOverwintered) {
         mtx.fOverwintered = true;
+        mtx.nExpiryHeight = nHeight + expiryDelta;
+
         if (NetworkUpgradeActive(nHeight, consensusParams, Consensus::UPGRADE_SAPLING)) {
             mtx.nVersionGroupId = SAPLING_VERSION_GROUP_ID;
             mtx.nVersion = SAPLING_TX_VERSION;
         } else {
             mtx.nVersionGroupId = OVERWINTER_VERSION_GROUP_ID;
             mtx.nVersion = OVERWINTER_TX_VERSION;
+            mtx.nExpiryHeight = std::min(
+                mtx.nExpiryHeight,
+                static_cast<uint32_t>(consensusParams.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight - 1));
         }
-        // Expiry height is not set. Only fields required for a parser to treat as a valid Overwinter V3 tx.
-
-        // TODO: In future, when moving from Overwinter to Sapling, it will be useful
-        // to set the expiry height to: min(activation_height - 1, default_expiry_height)
     }
     return mtx;
 }
index 7e03df07a6853a6c3f8537cd3d8740f1b3dc2652..62f3e6e0a0eba854feeb836ca7036ec78a28d572 100644 (file)
@@ -454,7 +454,6 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp)
         Params().GetConsensus(), nextBlockHeight);
     
     if (NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER)) {
-        rawTx.nExpiryHeight = nextBlockHeight + expiryDelta;
         if (rawTx.nExpiryHeight >= TX_EXPIRY_HEIGHT_THRESHOLD){
             throw JSONRPCError(RPC_INVALID_PARAMETER, "nExpiryHeight must be less than TX_EXPIRY_HEIGHT_THRESHOLD.");
         }
index 8cdc3a092c1f079bb6d83ab02e8928b3ce88ab75..be5868af4666190bc7dc87d90a290ddbdcc13306 100644 (file)
@@ -3674,9 +3674,6 @@ UniValue z_sendmany(const UniValue& params, bool fHelp)
     if (contextualTx.nVersion == 1 && isShielded) {
         contextualTx.nVersion = 2; // Tx format should support vjoinsplits 
     }
-    if (NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER)) {
-        contextualTx.nExpiryHeight = nextBlockHeight + expiryDelta;
-    }
 
     // Create operation and add to global queue
     std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue();
@@ -3872,9 +3869,6 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp)
     if (contextualTx.nVersion == 1) {
         contextualTx.nVersion = 2; // Tx format should support vjoinsplits 
     }
-    if (overwinterActive) {
-        contextualTx.nExpiryHeight = nextBlockHeight + expiryDelta;
-    }
 
     // Create operation and add to global queue
     std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue();
@@ -4211,9 +4205,6 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
     if (contextualTx.nVersion == 1 && isShielded) {
         contextualTx.nVersion = 2; // Tx format should support vjoinsplit
     }
-    if (overwinterActive) {
-        contextualTx.nExpiryHeight = nextBlockHeight + expiryDelta;
-    }
 
     // Create operation and add to global queue
     std::shared_ptr<AsyncRPCQueue> q = getAsyncRPCQueue();
index 448dd50e71a60763bb177ed6b142519292afe475..cab1b55f47d1673e3627299d4b5c6eebeee628cb 100644 (file)
@@ -2580,13 +2580,10 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
         Params().GetConsensus(), nextBlockHeight);
 
     // Activates after Overwinter network upgrade
-    // Set nExpiryHeight to expiryDelta (default 20) blocks past current block height
     if (NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER)) {
-        if (nextBlockHeight + expiryDelta >= TX_EXPIRY_HEIGHT_THRESHOLD){
+        if (txNew.nExpiryHeight >= TX_EXPIRY_HEIGHT_THRESHOLD){
             strFailReason = _("nExpiryHeight must be less than TX_EXPIRY_HEIGHT_THRESHOLD.");
             return false;
-        } else {
-            txNew.nExpiryHeight = nextBlockHeight + expiryDelta;
         }
     }
     
This page took 0.04581 seconds and 4 git commands to generate.