From 711204b517006c3f9c82b16611ecfabfc61ac644 Mon Sep 17 00:00:00 2001 From: jp1ac4 <121959000+jp1ac4@users.noreply.github.com> Date: Fri, 24 Nov 2023 16:40:33 +0000 Subject: [PATCH] rbf: pass change_address to create_spend_internal --- src/commands/mod.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 1d794a2bb..a474bde07 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1059,25 +1059,26 @@ impl DaemonControl { .collect(); // Set the change index we'll use for the replacement transaction, if any, to that of // the change output with the largest value and then largest index. - let change_index = prev_derivs + let change_address = prev_derivs .iter() - .filter_map(|(_, amt, deriv)| { + .filter_map(|(addr, amt, deriv)| { if let Some((ind, true)) = &deriv { - Some((*ind, amt)) + Some((addr, amt, ind)) } else { None } }) - .max_by(|(ind_1, amt_1), (ind_2, amt_2)| amt_1.cmp(amt_2).then(ind_1.cmp(ind_2))) - .map(|(ind, _)| ind); + .max_by(|(_, amt_1, ind_1), (_, amt_2, ind_2)| amt_1.cmp(amt_2).then(ind_1.cmp(ind_2))) + .map(|(addr, _, _)| addr); // Use all previous outputs as destinations, except for the output corresponding to the change index we found above. let destinations: HashMap = prev_derivs .iter() - .filter_map(|(addr, amt, deriv)| match deriv { - Some((ind, true)) if *ind == change_index.expect("change_index is some here") => { + .filter_map(|(addr, amt, _)| { + if change_address != Some(addr) { + Some((addr.clone(), *amt)) + } else { None } - _ => Some((addr.clone(), *amt)), }) .collect(); @@ -1127,12 +1128,12 @@ impl DaemonControl { // will ensure that the PSBT meets the required replacement fee and the loop will exit. let min_fee = mempool_entry.fees.descendant.to_sat() + rbf_vsize; println!("trying min_fee of {}", min_fee); - let rbf_psbt = match self.create_rbf_spend( + let rbf_psbt = match self.create_spend_internal( &destinations, &candidate_coins, feerate_vb, min_fee, - change_index, + change_address.cloned(), ) { Ok(psbt) => psbt, // If we get a coin selection error due to insufficient funds and we want to cancel the