From b005bf21a7cabe827ef62f266c22adf2ee745b61 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Fri, 3 Feb 2017 19:13:28 +0000 Subject: [PATCH] Introduce MAX_BIP125_RBF_SEQUENCE constant --- src/bitcoin-tx.cpp | 3 ++- src/policy/rbf.h | 2 ++ src/rpc/rawtransaction.cpp | 5 +++-- src/wallet/wallet.cpp | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 87d847594..a67c42ec5 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -13,6 +13,7 @@ #include "core_io.h" #include "keystore.h" #include "policy/policy.h" +#include "policy/rbf.h" #include "primitives/transaction.h" #include "script/script.h" #include "script/sign.h" @@ -215,7 +216,7 @@ static void MutateTxRBFOptIn(CMutableTransaction& tx, const std::string& strInId int cnt = 0; for (CTxIn& txin : tx.vin) { if (strInIdx == "" || cnt == inIdx) { - txin.nSequence = std::numeric_limits::max() - 2; + txin.nSequence = MAX_BIP125_RBF_SEQUENCE; } ++cnt; } diff --git a/src/policy/rbf.h b/src/policy/rbf.h index 139aec576..22c73f331 100644 --- a/src/policy/rbf.h +++ b/src/policy/rbf.h @@ -7,6 +7,8 @@ #include "txmempool.h" +static const uint32_t MAX_BIP125_RBF_SEQUENCE = 0xfffffffd; + enum RBFTransactionState { RBF_TRANSACTIONSTATE_UNKNOWN, RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125, diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 07a7ef34e..332dbc08a 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -14,6 +14,7 @@ #include "merkleblock.h" #include "net.h" #include "policy/policy.h" +#include "policy/rbf.h" #include "primitives/transaction.h" #include "rpc/server.h" #include "script/script.h" @@ -359,7 +360,7 @@ UniValue createrawtransaction(const JSONRPCRequest& request) uint32_t nSequence; if (rbfOptIn) { - nSequence = std::numeric_limits::max() - 2; + nSequence = MAX_BIP125_RBF_SEQUENCE; } else if (rawTx.nLockTime) { nSequence = std::numeric_limits::max() - 1; } else { @@ -372,7 +373,7 @@ UniValue createrawtransaction(const JSONRPCRequest& request) int64_t seqNr64 = sequenceObj.get_int64(); if (seqNr64 < 0 || seqNr64 > std::numeric_limits::max()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, sequence number is out of range"); - } else if (seqNr64 <= std::numeric_limits::max() - 2 && request.params.size() > 3 && request.params[3].isFalse()) { + } else if (seqNr64 <= MAX_BIP125_RBF_SEQUENCE && request.params.size() > 3 && request.params[3].isFalse()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter combination: Sequence number contradicts optintorbf option"); } else { nSequence = (uint32_t)seqNr64; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c00f52282..b2706d09f 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2685,9 +2685,10 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CWalletT // and in the spirit of "smallest possible change from prior // behavior." bool rbf = coinControl ? coinControl->signalRbf : fWalletRbf; + const uint32_t nSequence = rbf ? MAX_BIP125_RBF_SEQUENCE : (std::numeric_limits::max() - 1); for (const auto& coin : setCoins) txNew.vin.push_back(CTxIn(coin.outpoint,CScript(), - std::numeric_limits::max() - (rbf ? 2 : 1))); + nSequence)); // Fill in dummy signatures for fee calculation. if (!DummySignTx(txNew, setCoins)) {