Skip to content

Commit 37ac678

Browse files
committed
Merge #8601: Add option to opt into full-RBF when sending funds (rebase, original by petertodd)
86726d8 Rename `-optintofullrbf` option to `-walletrbf` (Wladimir J. van der Laan) 05fa823 wallet: Add BIP125 comment for MAXINT-1/-2 behavior (Wladimir J. van der Laan) 152f45b Add option to opt into full-RBF when sending funds (Peter Todd)
2 parents 39ac1ec + 86726d8 commit 37ac678

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/wallet/wallet.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ CFeeRate payTxFee(DEFAULT_TRANSACTION_FEE);
4040
unsigned int nTxConfirmTarget = DEFAULT_TX_CONFIRM_TARGET;
4141
bool bSpendZeroConfChange = DEFAULT_SPEND_ZEROCONF_CHANGE;
4242
bool fSendFreeTransactions = DEFAULT_SEND_FREE_TRANSACTIONS;
43+
bool fWalletRbf = DEFAULT_WALLET_RBF;
4344

4445
const char * DEFAULT_WALLET_DAT = "wallet.dat";
4546
const uint32_t BIP32_HARDENED_KEY_LIMIT = 0x80000000;
@@ -2362,11 +2363,17 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
23622363

23632364
// Fill vin
23642365
//
2365-
// Note how the sequence number is set to max()-1 so that the
2366-
// nLockTime set above actually works.
2366+
// Note how the sequence number is set to non-maxint so that
2367+
// the nLockTime set above actually works.
2368+
//
2369+
// BIP125 defines opt-in RBF as any nSequence < maxint-1, so
2370+
// we use the highest possible value in that range (maxint-2)
2371+
// to avoid conflicting with other possible uses of nSequence,
2372+
// and in the spirit of "smallest posible change from prior
2373+
// behavior."
23672374
BOOST_FOREACH(const PAIRTYPE(const CWalletTx*,unsigned int)& coin, setCoins)
23682375
txNew.vin.push_back(CTxIn(coin.first->GetHash(),coin.second,CScript(),
2369-
std::numeric_limits<unsigned int>::max()-1));
2376+
std::numeric_limits<unsigned int>::max() - (fWalletRbf ? 2 : 1)));
23702377

23712378
// Sign
23722379
int nIn = 0;
@@ -3246,6 +3253,7 @@ std::string CWallet::GetWalletHelpString(bool showDebug)
32463253
strUsage += HelpMessageOpt("-spendzeroconfchange", strprintf(_("Spend unconfirmed change when sending transactions (default: %u)"), DEFAULT_SPEND_ZEROCONF_CHANGE));
32473254
strUsage += HelpMessageOpt("-txconfirmtarget=<n>", strprintf(_("If paytxfee is not set, include enough fee so transactions begin confirmation on average within n blocks (default: %u)"), DEFAULT_TX_CONFIRM_TARGET));
32483255
strUsage += HelpMessageOpt("-usehd", _("Use hierarchical deterministic key generation (HD) after BIP32. Only has effect during wallet creation/first start") + " " + strprintf(_("(default: %u)"), DEFAULT_USE_HD_WALLET));
3256+
strUsage += HelpMessageOpt("-walletrbf", strprintf(_("Send transactions with full-RBF opt-in enabled (default: %u)"), DEFAULT_WALLET_RBF));
32493257
strUsage += HelpMessageOpt("-upgradewallet", _("Upgrade wallet to latest format on startup"));
32503258
strUsage += HelpMessageOpt("-wallet=<file>", _("Specify wallet file (within data directory)") + " " + strprintf(_("(default: %s)"), DEFAULT_WALLET_DAT));
32513259
strUsage += HelpMessageOpt("-walletbroadcast", _("Make the wallet broadcast transactions") + " " + strprintf(_("(default: %u)"), DEFAULT_WALLETBROADCAST));
@@ -3486,6 +3494,7 @@ bool CWallet::ParameterInteraction()
34863494
nTxConfirmTarget = GetArg("-txconfirmtarget", DEFAULT_TX_CONFIRM_TARGET);
34873495
bSpendZeroConfChange = GetBoolArg("-spendzeroconfchange", DEFAULT_SPEND_ZEROCONF_CHANGE);
34883496
fSendFreeTransactions = GetBoolArg("-sendfreetransactions", DEFAULT_SEND_FREE_TRANSACTIONS);
3497+
fWalletRbf = GetBoolArg("-walletrbf", DEFAULT_WALLET_RBF);
34893498

34903499
return true;
34913500
}

src/wallet/wallet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extern CFeeRate payTxFee;
3737
extern unsigned int nTxConfirmTarget;
3838
extern bool bSpendZeroConfChange;
3939
extern bool fSendFreeTransactions;
40+
extern bool fWalletRbf;
4041

4142
static const unsigned int DEFAULT_KEYPOOL_SIZE = 100;
4243
//! -paytxfee default
@@ -53,6 +54,8 @@ static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
5354
static const bool DEFAULT_SEND_FREE_TRANSACTIONS = false;
5455
//! -txconfirmtarget default
5556
static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 2;
57+
//! -walletrbf default
58+
static const bool DEFAULT_WALLET_RBF = false;
5659
//! Largest (in bytes) free transaction we're willing to create
5760
static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000;
5861
static const bool DEFAULT_WALLETBROADCAST = true;

0 commit comments

Comments
 (0)