Skip to content

Commit 28dc94a

Browse files
committed
Remove unnecessary clones of the HTLC-HTLCSource table
1 parent 48fd1db commit 28dc94a

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
@@ -3764,7 +3764,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
37643764
}
37653765
bitcoin_tx.txid
37663766
};
3767-
let htlcs_cloned: Vec<_> = commitment_data.htlcs_included.iter().map(|htlc| (htlc.0.clone(), htlc.1.map(|h| h.clone()))).collect();
37683767

37693768
// If our counterparty updated the channel fee in this commitment transaction, check that
37703769
// they can actually afford the new fee now.
@@ -3802,8 +3801,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
38023801

38033802
let holder_keys = commitment_data.tx.trust().keys();
38043803
let mut nondust_htlc_sources = Vec::with_capacity(commitment_data.tx.nondust_htlcs().len());
3805-
let mut dust_htlcs = Vec::with_capacity(htlcs_cloned.len() - commitment_data.tx.nondust_htlcs().len());
3806-
for (idx, (htlc, mut source_opt)) in htlcs_cloned.into_iter().enumerate() {
3804+
let mut dust_htlcs = Vec::with_capacity(commitment_data.htlcs_included.len() - commitment_data.tx.nondust_htlcs().len());
3805+
for (idx, (htlc, mut source_opt)) in commitment_data.htlcs_included.into_iter().enumerate() {
38073806
if let Some(_) = htlc.transaction_output_index {
38083807
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, commitment_data.tx.feerate_per_kw(),
38093808
funding.get_counterparty_selected_contest_delay().unwrap(), &htlc, funding.get_channel_type(),
@@ -3820,13 +3819,13 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
38203819
}
38213820
if htlc.offered {
38223821
if let Some(source) = source_opt.take() {
3823-
nondust_htlc_sources.push(source);
3822+
nondust_htlc_sources.push(source.clone());
38243823
} else {
38253824
panic!("Missing outbound HTLC source");
38263825
}
38273826
}
38283827
} else {
3829-
dust_htlcs.push((htlc, None, source_opt.take()));
3828+
dust_htlcs.push((htlc, None, source_opt.take().cloned()));
38303829
}
38313830
debug_assert!(source_opt.is_none(), "HTLCSource should have been put somewhere");
38323831
}
@@ -9032,10 +9031,10 @@ impl<SP: Deref> FundedChannel<SP> where
90329031

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

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

0 commit comments

Comments
 (0)