aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorMatthew Zipkin <pinheadmz@gmail.com>2023-02-06 15:27:57 -0500
committerfanquake <fanquake@gmail.com>2023-02-22 09:12:50 +0000
commita62c541ae8a579d19b8fc55bbb922f0939ab6110 (patch)
treeb378660fcc6bc476a358ad64171174e55ead72c8 /src/wallet
parent64e7db6f4f256656f4d78a96b07e51f7d5c6d526 (diff)
downloadbitcoin-a62c541ae8a579d19b8fc55bbb922f0939ab6110.tar.xz
wallet: reuse change dest when recreating TX with avoidpartialspends
Github-Pull: #27053 Rebased-From: 14b4921a91920df25b19ff420bfe2bff8c56f71e
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/spend.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp
index f534e10799..1807a98db1 100644
--- a/src/wallet/spend.cpp
+++ b/src/wallet/spend.cpp
@@ -1074,6 +1074,13 @@ util::Result<CreatedTransactionResult> CreateTransaction(
TRACE1(coin_selection, attempting_aps_create_tx, wallet.GetName().c_str());
CCoinControl tmp_cc = coin_control;
tmp_cc.m_avoid_partial_spends = true;
+
+ // Re-use the change destination from the first creation attempt to avoid skipping BIP44 indexes
+ const int ungrouped_change_pos = txr_ungrouped.change_pos;
+ if (ungrouped_change_pos != -1) {
+ ExtractDestination(txr_ungrouped.tx->vout[ungrouped_change_pos].scriptPubKey, tmp_cc.destChange);
+ }
+
auto txr_grouped = CreateTransactionInternal(wallet, vecSend, change_pos, tmp_cc, sign);
// if fee of this alternative one is within the range of the max fee, we use this one
const bool use_aps{txr_grouped.has_value() ? (txr_grouped->fee <= txr_ungrouped.fee + wallet.m_max_aps_fee) : false};