From 0fefcbb776063b7fcc03c28e544d830a2f540250 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Wed, 1 Jun 2022 12:35:00 -0400 Subject: wallet: Explicitly preserve transaction locktime in CreateTransaction We provide the preset nLockTime to CCoinControl so that CreateTransactionInternal can be aware of it and set it in the produced transaction. --- src/wallet/coincontrol.h | 2 ++ src/wallet/spend.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/src/wallet/coincontrol.h b/src/wallet/coincontrol.h index 32595955f0..c99a3bfd0f 100644 --- a/src/wallet/coincontrol.h +++ b/src/wallet/coincontrol.h @@ -91,6 +91,8 @@ public: 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 m_locktime; CCoinControl(); diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 7ec2775fb1..9dfc8c2879 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -1160,6 +1160,11 @@ static util::Result 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()); } @@ -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); -- cgit v1.2.3