diff options
author | Andrew Chow <achow101-github@achow101.com> | 2022-06-01 12:35:00 -0400 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2023-12-08 14:55:14 -0500 |
commit | 0fefcbb776063b7fcc03c28e544d830a2f540250 (patch) | |
tree | e044f7aeb276eb6e3cfddc187d21094d45442269 | |
parent | 4d335bb1e00a414a4740007d5a192a73179b2262 (diff) |
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.
-rw-r--r-- | src/wallet/coincontrol.h | 2 | ||||
-rw-r--r-- | src/wallet/spend.cpp | 8 |
2 files changed, 10 insertions, 0 deletions
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<uint32_t> 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<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()); } @@ -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); |