Skip to content

Commit b005bf2

Browse files
committed
Introduce MAX_BIP125_RBF_SEQUENCE constant
1 parent 575cde4 commit b005bf2

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

src/bitcoin-tx.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "core_io.h"
1414
#include "keystore.h"
1515
#include "policy/policy.h"
16+
#include "policy/rbf.h"
1617
#include "primitives/transaction.h"
1718
#include "script/script.h"
1819
#include "script/sign.h"
@@ -215,7 +216,7 @@ static void MutateTxRBFOptIn(CMutableTransaction& tx, const std::string& strInId
215216
int cnt = 0;
216217
for (CTxIn& txin : tx.vin) {
217218
if (strInIdx == "" || cnt == inIdx) {
218-
txin.nSequence = std::numeric_limits<unsigned int>::max() - 2;
219+
txin.nSequence = MAX_BIP125_RBF_SEQUENCE;
219220
}
220221
++cnt;
221222
}

src/policy/rbf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "txmempool.h"
99

10+
static const uint32_t MAX_BIP125_RBF_SEQUENCE = 0xfffffffd;
11+
1012
enum RBFTransactionState {
1113
RBF_TRANSACTIONSTATE_UNKNOWN,
1214
RBF_TRANSACTIONSTATE_REPLACEABLE_BIP125,

src/rpc/rawtransaction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "merkleblock.h"
1515
#include "net.h"
1616
#include "policy/policy.h"
17+
#include "policy/rbf.h"
1718
#include "primitives/transaction.h"
1819
#include "rpc/server.h"
1920
#include "script/script.h"
@@ -359,7 +360,7 @@ UniValue createrawtransaction(const JSONRPCRequest& request)
359360

360361
uint32_t nSequence;
361362
if (rbfOptIn) {
362-
nSequence = std::numeric_limits<uint32_t>::max() - 2;
363+
nSequence = MAX_BIP125_RBF_SEQUENCE;
363364
} else if (rawTx.nLockTime) {
364365
nSequence = std::numeric_limits<uint32_t>::max() - 1;
365366
} else {
@@ -372,7 +373,7 @@ UniValue createrawtransaction(const JSONRPCRequest& request)
372373
int64_t seqNr64 = sequenceObj.get_int64();
373374
if (seqNr64 < 0 || seqNr64 > std::numeric_limits<uint32_t>::max()) {
374375
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, sequence number is out of range");
375-
} else if (seqNr64 <= std::numeric_limits<uint32_t>::max() - 2 && request.params.size() > 3 && request.params[3].isFalse()) {
376+
} else if (seqNr64 <= MAX_BIP125_RBF_SEQUENCE && request.params.size() > 3 && request.params[3].isFalse()) {
376377
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter combination: Sequence number contradicts optintorbf option");
377378
} else {
378379
nSequence = (uint32_t)seqNr64;

src/wallet/wallet.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2685,9 +2685,10 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
26852685
// and in the spirit of "smallest possible change from prior
26862686
// behavior."
26872687
bool rbf = coinControl ? coinControl->signalRbf : fWalletRbf;
2688+
const uint32_t nSequence = rbf ? MAX_BIP125_RBF_SEQUENCE : (std::numeric_limits<unsigned int>::max() - 1);
26882689
for (const auto& coin : setCoins)
26892690
txNew.vin.push_back(CTxIn(coin.outpoint,CScript(),
2690-
std::numeric_limits<unsigned int>::max() - (rbf ? 2 : 1)));
2691+
nSequence));
26912692

26922693
// Fill in dummy signatures for fee calculation.
26932694
if (!DummySignTx(txNew, setCoins)) {

0 commit comments

Comments
 (0)