Skip to content

Commit

Permalink
wallet: Explicitly preserve transaction locktime in CreateTransaction
Browse files Browse the repository at this point in the history
We provide the preset nLockTime to CCoinControl so that
CreateTransactionInternal can be aware of it and set it in the produced
transaction.
  • Loading branch information
achow101 committed Dec 8, 2023
1 parent 4d335bb commit 0fefcbb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/wallet/coincontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class CCoinControl
int m_max_depth = DEFAULT_MAX_DEPTH;
//! SigningProvider that has pubkeys and scripts to do spend size estimation for external inputs
FlatSigningProvider m_external_provider;
//! Locktime
std::optional<uint32_t> m_locktime;

CCoinControl();

Expand Down
8 changes: 8 additions & 0 deletions src/wallet/spend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,11 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
}
txNew.vin.emplace_back(coin->outpoint, CScript(), sequence.value_or(default_sequence));
}
if (coin_control.m_locktime) {
txNew.nLockTime = coin_control.m_locktime.value();
// If we have a locktime set, we can't use anti-fee-sniping
use_anti_fee_sniping = false;
}
if (use_anti_fee_sniping) {
DiscourageFeeSniping(txNew, rng_fast, wallet.chain(), wallet.GetLastBlockHash(), wallet.GetLastBlockHeight());
}
Expand Down Expand Up @@ -1341,6 +1346,9 @@ bool FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& nFeeRet,
vecSend.push_back(recipient);
}

// Set the user desired locktime
coinControl.m_locktime = tx.nLockTime;

// Acquire the locks to prevent races to the new locked unspents between the
// CreateTransaction call and LockCoin calls (when lockUnspents is true).
LOCK(wallet.cs_wallet);
Expand Down

0 comments on commit 0fefcbb

Please sign in to comment.