Skip to content

Commit a6c6eac

Browse files
committed
Remove unnecessary clones of the HTLC-HTLCSource table
1 parent e638443 commit a6c6eac

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

lightning/src/ln/channel.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -3606,7 +3606,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
36063606
}
36073607
bitcoin_tx.txid
36083608
};
3609-
let mut htlcs_cloned: Vec<_> = commitment_data.htlcs_included.iter().map(|htlc| (htlc.0.clone(), htlc.1.map(|h| h.clone()))).collect();
36103609

36113610
// If our counterparty updated the channel fee in this commitment transaction, check that
36123611
// they can actually afford the new fee now.
@@ -3657,10 +3656,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
36573656
separate_nondust_htlc_sources = rand_val % 2 == 0;
36583657
}
36593658

3660-
let mut nondust_htlc_sources = Vec::with_capacity(htlcs_cloned.len());
3661-
let mut htlcs_and_sigs = Vec::with_capacity(htlcs_cloned.len());
3659+
let mut nondust_htlc_sources = Vec::with_capacity(commitment_data.htlcs_included.len());
3660+
let mut htlcs_and_sigs = Vec::with_capacity(commitment_data.htlcs_included.len());
36623661
let holder_keys = commitment_data.tx.trust().keys();
3663-
for (idx, (htlc, mut source_opt)) in htlcs_cloned.drain(..).enumerate() {
3662+
for (idx, (htlc, mut source_opt)) in commitment_data.htlcs_included.into_iter().enumerate() {
36643663
if let Some(_) = htlc.transaction_output_index {
36653664
let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, commitment_data.tx.feerate_per_kw(),
36663665
funding.get_counterparty_selected_contest_delay().unwrap(), &htlc, &self.channel_type,
@@ -3676,14 +3675,14 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
36763675
return Err(ChannelError::close("Invalid HTLC tx signature from peer".to_owned()));
36773676
}
36783677
if !separate_nondust_htlc_sources {
3679-
htlcs_and_sigs.push((htlc, Some(msg.htlc_signatures[idx]), source_opt.take()));
3678+
htlcs_and_sigs.push((htlc, Some(msg.htlc_signatures[idx]), source_opt.take().map(|source| source.clone())));
36803679
}
36813680
} else {
3682-
htlcs_and_sigs.push((htlc, None, source_opt.take()));
3681+
htlcs_and_sigs.push((htlc, None, source_opt.take().map(|source| source.clone())));
36833682
}
36843683
if separate_nondust_htlc_sources {
36853684
if let Some(source) = source_opt.take() {
3686-
nondust_htlc_sources.push(source);
3685+
nondust_htlc_sources.push(source.clone());
36873686
}
36883687
}
36893688
debug_assert!(source_opt.is_none(), "HTLCSource should have been put somewhere");
@@ -8810,11 +8809,11 @@ impl<SP: Deref> FundedChannel<SP> where
88108809
}
88118810
self.context.resend_order = RAACommitmentOrder::RevokeAndACKFirst;
88128811

8813-
let (mut htlcs_ref, counterparty_commitment_tx) =
8812+
let (htlcs_ref, counterparty_commitment_tx) =
88148813
self.build_commitment_no_state_update(logger);
88158814
let counterparty_commitment_txid = counterparty_commitment_tx.trust().txid();
8816-
let htlcs: Vec<(HTLCOutputInCommitment, Option<Box<HTLCSource>>)> =
8817-
htlcs_ref.drain(..).map(|(htlc, htlc_source)| (htlc, htlc_source.map(|source_ref| Box::new(source_ref.clone())))).collect();
8815+
let htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Box<HTLCSource>>)> =
8816+
htlcs_ref.into_iter().map(|(htlc, htlc_source)| (htlc, htlc_source.map(|source_ref| Box::new(source_ref.clone())))).collect();
88188817

88198818
if self.context.announcement_sigs_state == AnnouncementSigsState::MessageSent {
88208819
self.context.announcement_sigs_state = AnnouncementSigsState::Committed;
@@ -8827,7 +8826,7 @@ impl<SP: Deref> FundedChannel<SP> where
88278826
// and provide the full commit tx instead of the information needed to rebuild it.
88288827
updates: vec![ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo {
88298828
commitment_txid: counterparty_commitment_txid,
8830-
htlc_outputs: htlcs.clone(),
8829+
htlc_outputs,
88318830
commitment_number: self.context.cur_counterparty_commitment_transaction_number,
88328831
their_per_commitment_point: self.context.counterparty_cur_commitment_point.unwrap(),
88338832
feerate_per_kw: Some(counterparty_commitment_tx.feerate_per_kw()),

0 commit comments

Comments
 (0)