Skip to content

Commit ea8533f

Browse files
committed
Remove unnecessary clones of the HTLC-HTLCSource table
1 parent 14f8107 commit ea8533f

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lightning/src/ln/channel.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -3762,7 +3762,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
37623762
}
37633763
bitcoin_tx.txid
37643764
};
3765-
let htlcs_cloned: Vec<_> = commitment_data.htlcs_included.iter().map(|htlc| (htlc.0.clone(), htlc.1.map(|h| h.clone()))).collect();
37663765

37673766
// If our counterparty updated the channel fee in this commitment transaction, check that
37683767
// they can actually afford the new fee now.
@@ -3800,8 +3799,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
38003799

38013800
let holder_keys = commitment_data.tx.trust().keys();
38023801
let mut nondust_htlc_sources = Vec::with_capacity(commitment_data.tx.nondust_htlcs().len());
3803-
let mut dust_htlcs = Vec::with_capacity(htlcs_cloned.len() - commitment_data.tx.nondust_htlcs().len());
3804-
for (idx, (htlc, mut source_opt)) in htlcs_cloned.into_iter().enumerate() {
3802+
let mut dust_htlcs = Vec::with_capacity(commitment_data.htlcs_included.len() - commitment_data.tx.nondust_htlcs().len());
3803+
for (idx, (htlc, mut source_opt)) in commitment_data.htlcs_included.into_iter().enumerate() {
38053804
if let Some(_) = htlc.transaction_output_index {
38063805
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, commitment_data.tx.feerate_per_kw(),
38073806
funding.get_counterparty_selected_contest_delay().unwrap(), &htlc, funding.get_channel_type(),
@@ -3818,13 +3817,13 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
38183817
}
38193818
if htlc.offered {
38203819
if let Some(source) = source_opt.take() {
3821-
nondust_htlc_sources.push(source);
3820+
nondust_htlc_sources.push(source.clone());
38223821
} else {
38233822
panic!("Missing outbound HTLC source");
38243823
}
38253824
}
38263825
} else {
3827-
dust_htlcs.push((htlc, None, source_opt.take()));
3826+
dust_htlcs.push((htlc, None, source_opt.take().cloned()));
38283827
}
38293828
debug_assert!(source_opt.is_none(), "HTLCSource should have been put somewhere");
38303829
}
@@ -9033,10 +9032,10 @@ impl<SP: Deref> FundedChannel<SP> where
90339032

90349033
let mut updates = Vec::with_capacity(self.pending_funding.len() + 1);
90359034
for funding in core::iter::once(&self.funding).chain(self.pending_funding.iter()) {
9036-
let (mut htlcs_ref, counterparty_commitment_tx) =
9035+
let (htlcs_ref, counterparty_commitment_tx) =
90379036
self.build_commitment_no_state_update(funding, logger);
90389037
let htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Box<HTLCSource>>)> =
9039-
htlcs_ref.drain(..).map(|(htlc, htlc_source)| (htlc, htlc_source.map(|source_ref| Box::new(source_ref.clone())))).collect();
9038+
htlcs_ref.into_iter().map(|(htlc, htlc_source)| (htlc, htlc_source.map(|source_ref| Box::new(source_ref.clone())))).collect();
90409039

90419040
if self.pending_funding.is_empty() {
90429041
// Soon, we will switch this to `LatestCounterpartyCommitmentTX`,

0 commit comments

Comments
 (0)