@@ -16777,6 +16777,33 @@ where
1677716777 }
1677816778}
1677916779
16780+ // If the HTLC corresponding to `prev_hop_data` is present in `decode_update_add_htlcs`, remove it
16781+ // from the map as it is already being stored and processed elsewhere.
16782+ fn dedup_decode_update_add_htlcs<L: Deref>(
16783+ decode_update_add_htlcs: &mut HashMap<u64, Vec<msgs::UpdateAddHTLC>>,
16784+ prev_hop_data: &HTLCPreviousHopData, removal_reason: &'static str, logger: &L,
16785+ ) where
16786+ L::Target: Logger,
16787+ {
16788+ decode_update_add_htlcs.retain(|src_outb_alias, update_add_htlcs| {
16789+ update_add_htlcs.retain(|update_add| {
16790+ let matches = *src_outb_alias == prev_hop_data.prev_outbound_scid_alias
16791+ && update_add.htlc_id == prev_hop_data.htlc_id;
16792+ if matches {
16793+ let logger = WithContext::from(
16794+ logger,
16795+ prev_hop_data.counterparty_node_id,
16796+ Some(update_add.channel_id),
16797+ Some(update_add.payment_hash),
16798+ );
16799+ log_info!(logger, "Removing pending to-decode HTLC: {}", removal_reason);
16800+ }
16801+ !matches
16802+ });
16803+ !update_add_htlcs.is_empty()
16804+ });
16805+ }
16806+
1678016807// Implement ReadableArgs for an Arc'd ChannelManager to make it a bit easier to work with the
1678116808// SipmleArcChannelManager type:
1678216809impl<
@@ -17644,19 +17671,11 @@ where
1764417671 // still have an entry for this HTLC in `forward_htlcs` or
1764517672 // `pending_intercepted_htlcs`, we were apparently not persisted after
1764617673 // the monitor was when forwarding the payment.
17647- decode_update_add_htlcs.retain(
17648- |src_outb_alias, update_add_htlcs| {
17649- update_add_htlcs.retain(|update_add_htlc| {
17650- let matches = *src_outb_alias
17651- == prev_hop_data.prev_outbound_scid_alias
17652- && update_add_htlc.htlc_id == prev_hop_data.htlc_id;
17653- if matches {
17654- log_info!(logger, "Removing pending to-decode HTLC as it was forwarded to the closed channel");
17655- }
17656- !matches
17657- });
17658- !update_add_htlcs.is_empty()
17659- },
17674+ dedup_decode_update_add_htlcs(
17675+ &mut decode_update_add_htlcs,
17676+ &prev_hop_data,
17677+ "HTLC was forwarded to the closed channel",
17678+ &args.logger,
1766017679 );
1766117680 forward_htlcs.retain(|_, forwards| {
1766217681 forwards.retain(|forward| {
0 commit comments