Implement transaction expiry for Overwinter

This commit is contained in:
Jay Graber
2018-02-21 20:21:06 -08:00
parent c5904fb2a4
commit 9bb37bf0d5
11 changed files with 99 additions and 10 deletions

View File

@@ -10,6 +10,7 @@
#include "coincontrol.h"
#include "consensus/upgrades.h"
#include "consensus/validation.h"
#include "consensus/consensus.h"
#include "init.h"
#include "main.h"
#include "net.h"
@@ -2523,6 +2524,7 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount &nFeeRet, int& nC
CReserveKey reservekey(this);
CWalletTx wtx;
if (!CreateTransaction(vecSend, wtx, reservekey, nFeeRet, nChangePosRet, strFailReason, &coinControl, false))
return false;
@@ -2573,9 +2575,20 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
wtxNew.fTimeReceivedIsTxTime = true;
wtxNew.BindWallet(this);
int nextBlockHeight = chainActive.Height() + 1;
CMutableTransaction txNew = CreateNewContextualCMutableTransaction(
Params().GetConsensus(), chainActive.Height() + 1);
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){
strFailReason = _("nExpiryHeight must be less than TX_EXPIRY_HEIGHT_THRESHOLD.");
} else {
txNew.nExpiryHeight = nextBlockHeight + expiryDelta;
}
}
// Discourage fee sniping.
//
// However because of a off-by-one-error in previous versions we need to