Skip to content
50 changes: 37 additions & 13 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16819,6 +16819,38 @@ where
}
}

// If the HTLC corresponding to `prev_hop_data` is present in `decode_update_add_htlcs`, remove it
// from the map as it is already being stored and processed elsewhere.
fn dedup_decode_update_add_htlcs<L: Deref>(
decode_update_add_htlcs: &mut HashMap<u64, Vec<msgs::UpdateAddHTLC>>,
Comment on lines +16822 to +16825
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this be used outside of the channel manager's read? If not, feels this could be a closure as it seems very specific to the filtering that needs to happen there.

prev_hop_data: &HTLCPreviousHopData, removal_reason: &'static str, logger: &L,
) where
L::Target: Logger,
{
decode_update_add_htlcs.retain(|src_outb_alias, update_add_htlcs| {
update_add_htlcs.retain(|update_add| {
let matches = *src_outb_alias == prev_hop_data.prev_outbound_scid_alias
&& update_add.htlc_id == prev_hop_data.htlc_id;
if matches {
let logger = WithContext::from(
logger,
prev_hop_data.counterparty_node_id,
Some(update_add.channel_id),
Some(update_add.payment_hash),
);
log_info!(
logger,
"Removing pending to-decode HTLC with id {}: {}",
update_add.htlc_id,
removal_reason
);
}
!matches
});
!update_add_htlcs.is_empty()
});
}

// Implement ReadableArgs for an Arc'd ChannelManager to make it a bit easier to work with the
// SipmleArcChannelManager type:
impl<
Expand Down Expand Up @@ -17686,19 +17718,11 @@ where
// still have an entry for this HTLC in `forward_htlcs` or
// `pending_intercepted_htlcs`, we were apparently not persisted after
// the monitor was when forwarding the payment.
decode_update_add_htlcs.retain(
|src_outb_alias, update_add_htlcs| {
update_add_htlcs.retain(|update_add_htlc| {
let matches = *src_outb_alias
== prev_hop_data.prev_outbound_scid_alias
&& update_add_htlc.htlc_id == prev_hop_data.htlc_id;
if matches {
log_info!(logger, "Removing pending to-decode HTLC as it was forwarded to the closed channel");
}
!matches
});
!update_add_htlcs.is_empty()
},
dedup_decode_update_add_htlcs(
&mut decode_update_add_htlcs,
&prev_hop_data,
"HTLC was forwarded to the closed channel",
&args.logger,
);
forward_htlcs.retain(|_, forwards| {
forwards.retain(|forward| {
Expand Down