Skip to content

Commit 0c76ed8

Browse files
committed
Rewrite closure
Async closures are complicated. Preparatory commit.
1 parent f305413 commit 0c76ed8

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

lightning/src/events/bump_transaction.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -504,18 +504,33 @@ where
504504
((BASE_TX_SIZE + total_output_size) * WITNESS_SCALE_FACTOR as u64);
505505
let input_amount_sat = must_spend.iter().map(|input| input.previous_utxo.value).sum();
506506
let target_amount_sat = must_pay_to.iter().map(|output| output.value).sum();
507-
let do_coin_selection = |force_conflicting_utxo_spend: bool, tolerate_high_network_feerates: bool| {
508-
log_debug!(self.logger, "Attempting coin selection targeting {} sat/kW (force_conflicting_utxo_spend = {}, tolerate_high_network_feerates = {})",
509-
target_feerate_sat_per_1000_weight, force_conflicting_utxo_spend, tolerate_high_network_feerates);
510-
self.select_confirmed_utxos_internal(
511-
&utxos, claim_id, force_conflicting_utxo_spend, tolerate_high_network_feerates,
512-
target_feerate_sat_per_1000_weight, preexisting_tx_weight, input_amount_sat, target_amount_sat,
513-
)
514-
};
515-
do_coin_selection(false, false)
516-
.or_else(|_| do_coin_selection(false, true))
517-
.or_else(|_| do_coin_selection(true, false))
518-
.or_else(|_| do_coin_selection(true, true))
507+
508+
let configs = [(false, false), (false, true), (true, false), (true, true)];
509+
let mut last_err = None;
510+
for (force_conflicting_utxo_spend, tolerate_high_network_feerates) in configs {
511+
log_debug!(
512+
self.logger,
513+
"Attempting coin selection targeting {} sat/kW (force_conflicting_utxo_spend = {}, tolerate_high_network_feerates = {})",
514+
target_feerate_sat_per_1000_weight,
515+
force_conflicting_utxo_spend,
516+
tolerate_high_network_feerates
517+
);
518+
let attempt = self.select_confirmed_utxos_internal(
519+
&utxos,
520+
claim_id,
521+
force_conflicting_utxo_spend,
522+
tolerate_high_network_feerates,
523+
target_feerate_sat_per_1000_weight,
524+
preexisting_tx_weight,
525+
input_amount_sat,
526+
target_amount_sat,
527+
);
528+
if attempt.is_ok() {
529+
return attempt;
530+
}
531+
last_err = Some(attempt);
532+
}
533+
last_err.unwrap()
519534
}
520535

521536
fn sign_psbt(&self, psbt: Psbt) -> Result<Transaction, ()> {

0 commit comments

Comments
 (0)