Skip to content

Commit 8f3eea5

Browse files
committed
Rewrite closure
Async closures are complicated. Preparatory commit.
1 parent a86d72a commit 8f3eea5

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

lightning/src/events/bump_transaction.rs

+17-11
Original file line numberDiff line numberDiff line change
@@ -525,11 +525,17 @@ where
525525
((BASE_TX_SIZE + total_output_size) * WITNESS_SCALE_FACTOR as u64);
526526
let input_amount_sat = must_spend.iter().map(|input| input.previous_utxo.value).sum();
527527
let target_amount_sat = must_pay_to.iter().map(|output| output.value).sum();
528-
let do_coin_selection = |force_conflicting_utxo_spend: bool,
529-
tolerate_high_network_feerates: bool| {
530-
log_debug!(self.logger, "Attempting coin selection targeting {} sat/kW (force_conflicting_utxo_spend = {}, tolerate_high_network_feerates = {})",
531-
target_feerate_sat_per_1000_weight, force_conflicting_utxo_spend, tolerate_high_network_feerates);
532-
self.select_confirmed_utxos_internal(
528+
529+
let configs = [(false, false), (false, true), (true, false), (true, true)];
530+
for (force_conflicting_utxo_spend, tolerate_high_network_feerates) in configs {
531+
log_debug!(
532+
self.logger,
533+
"Attempting coin selection targeting {} sat/kW (force_conflicting_utxo_spend = {}, tolerate_high_network_feerates = {})",
534+
target_feerate_sat_per_1000_weight,
535+
force_conflicting_utxo_spend,
536+
tolerate_high_network_feerates
537+
);
538+
let attempt = self.select_confirmed_utxos_internal(
533539
&utxos,
534540
claim_id,
535541
force_conflicting_utxo_spend,
@@ -538,12 +544,12 @@ where
538544
preexisting_tx_weight,
539545
input_amount_sat,
540546
target_amount_sat,
541-
)
542-
};
543-
do_coin_selection(false, false)
544-
.or_else(|_| do_coin_selection(false, true))
545-
.or_else(|_| do_coin_selection(true, false))
546-
.or_else(|_| do_coin_selection(true, true))
547+
);
548+
if attempt.is_ok() {
549+
return attempt;
550+
}
551+
}
552+
Err(())
547553
}
548554

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

0 commit comments

Comments
 (0)