Skip to content

Commit 0c629ff

Browse files
committed
Pass must-spend inputs to users by ownership
We already hold them in a vec, so there's no cost to passing them by ownership vs making it a slice. Further, this helps bindings as we can't represent slices to non-pointers in a sensible way.
1 parent be08b4f commit 0c629ff

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lightning/src/events/bump_transaction.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ pub trait CoinSelectionSource {
464464
/// which UTXOs to double spend is left to the implementation, but it must strive to keep the
465465
/// set of other claims being double spent to a minimum.
466466
fn select_confirmed_utxos(
467-
&self, claim_id: ClaimId, must_spend: &[Input], must_pay_to: &[TxOut],
467+
&self, claim_id: ClaimId, must_spend: Vec<Input>, must_pay_to: &[TxOut],
468468
target_feerate_sat_per_1000_weight: u32,
469469
) -> Result<CoinSelection, ()>;
470470
/// Signs and provides the full witness for all inputs within the transaction known to the
@@ -600,7 +600,7 @@ where
600600
L::Target: Logger
601601
{
602602
fn select_confirmed_utxos(
603-
&self, claim_id: ClaimId, must_spend: &[Input], must_pay_to: &[TxOut],
603+
&self, claim_id: ClaimId, must_spend: Vec<Input>, must_pay_to: &[TxOut],
604604
target_feerate_sat_per_1000_weight: u32,
605605
) -> Result<CoinSelection, ()> {
606606
let utxos = self.source.list_confirmed_utxos()?;
@@ -726,7 +726,7 @@ where
726726
satisfaction_weight: commitment_tx.weight() as u64 + ANCHOR_INPUT_WITNESS_WEIGHT + EMPTY_SCRIPT_SIG_WEIGHT,
727727
}];
728728
let coin_selection = self.utxo_source.select_confirmed_utxos(
729-
claim_id, &must_spend, &[], anchor_target_feerate_sat_per_1000_weight,
729+
claim_id, must_spend, &[], anchor_target_feerate_sat_per_1000_weight,
730730
)?;
731731

732732
let mut anchor_tx = Transaction {
@@ -800,13 +800,16 @@ where
800800

801801
log_debug!(self.logger, "Peforming coin selection for HTLC transaction targeting {} sat/kW",
802802
target_feerate_sat_per_1000_weight);
803+
#[cfg(debug_assertions)]
804+
let must_spend_satisfaction_weight =
805+
must_spend.iter().map(|input| input.satisfaction_weight).sum::<u64>();
803806
let coin_selection = self.utxo_source.select_confirmed_utxos(
804-
claim_id, &must_spend, &htlc_tx.output, target_feerate_sat_per_1000_weight,
807+
claim_id, must_spend, &htlc_tx.output, target_feerate_sat_per_1000_weight,
805808
)?;
806809
#[cfg(debug_assertions)]
807810
let total_satisfaction_weight =
808811
coin_selection.confirmed_utxos.iter().map(|utxo| utxo.satisfaction_weight).sum::<u64>() +
809-
must_spend.iter().map(|input| input.satisfaction_weight).sum::<u64>();
812+
must_spend_satisfaction_weight;
810813
self.process_coin_selection(&mut htlc_tx, coin_selection);
811814

812815
#[cfg(debug_assertions)]

0 commit comments

Comments
 (0)