Skip to content

Commit f14f502

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 fac2c9f commit f14f502

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
#[cfg(not(c_bindings))]
@@ -611,7 +611,7 @@ where
611611
L::Target: Logger
612612
{
613613
fn select_confirmed_utxos(
614-
&self, claim_id: ClaimId, must_spend: &[Input], must_pay_to: &[TxOut],
614+
&self, claim_id: ClaimId, must_spend: Vec<Input>, must_pay_to: &[TxOut],
615615
target_feerate_sat_per_1000_weight: u32,
616616
) -> Result<CoinSelection, ()> {
617617
let utxos = self.source.list_confirmed_utxos()?;
@@ -743,7 +743,7 @@ where
743743
satisfaction_weight: commitment_tx.weight() as u64 + ANCHOR_INPUT_WITNESS_WEIGHT + EMPTY_SCRIPT_SIG_WEIGHT,
744744
}];
745745
let coin_selection = self.utxo_source.select_confirmed_utxos(
746-
claim_id, &must_spend, &[], anchor_target_feerate_sat_per_1000_weight,
746+
claim_id, must_spend, &[], anchor_target_feerate_sat_per_1000_weight,
747747
)?;
748748

749749
let mut anchor_tx = Transaction {
@@ -822,13 +822,16 @@ where
822822

823823
log_debug!(self.logger, "Peforming coin selection for HTLC transaction targeting {} sat/kW",
824824
target_feerate_sat_per_1000_weight);
825+
#[cfg(debug_assertions)]
826+
let must_spend_satisfaction_weight =
827+
must_spend.iter().map(|input| input.satisfaction_weight).sum::<u64>();
825828
let coin_selection = self.utxo_source.select_confirmed_utxos(
826-
claim_id, &must_spend, &htlc_tx.output, target_feerate_sat_per_1000_weight,
829+
claim_id, must_spend, &htlc_tx.output, target_feerate_sat_per_1000_weight,
827830
)?;
828831
#[cfg(debug_assertions)]
829832
let total_satisfaction_weight =
830833
coin_selection.confirmed_utxos.iter().map(|utxo| utxo.satisfaction_weight).sum::<u64>() +
831-
must_spend.iter().map(|input| input.satisfaction_weight).sum::<u64>();
834+
must_spend_satisfaction_weight;
832835
self.process_coin_selection(&mut htlc_tx, coin_selection);
833836

834837
#[cfg(debug_assertions)]

0 commit comments

Comments
 (0)