Skip to content

Commit bb5a5a3

Browse files
Extract method to dedup pre-decode update_add
XXX
1 parent 61eb844 commit bb5a5a3

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16658,6 +16658,33 @@ where
1665816658
}
1665916659
}
1666016660

16661+
// If the HTLC corresponding to `prev_hop_data` is present in `decode_update_add_htlcs`, remove it
16662+
// from the map as it is already being stored and processed elsewhere.
16663+
fn dedup_decode_update_add_htlcs<L: Deref>(
16664+
decode_update_add_htlcs: &mut HashMap<u64, Vec<msgs::UpdateAddHTLC>>,
16665+
prev_hop_data: &HTLCPreviousHopData, removal_reason: &'static str, logger: &L,
16666+
) where
16667+
L::Target: Logger,
16668+
{
16669+
decode_update_add_htlcs.retain(|src_outb_alias, update_add_htlcs| {
16670+
update_add_htlcs.retain(|update_add| {
16671+
let matches = *src_outb_alias == prev_hop_data.prev_outbound_scid_alias
16672+
&& update_add.htlc_id == prev_hop_data.htlc_id;
16673+
if matches {
16674+
let logger = WithContext::from(
16675+
logger,
16676+
prev_hop_data.counterparty_node_id,
16677+
Some(update_add.channel_id),
16678+
Some(update_add.payment_hash),
16679+
);
16680+
log_info!(logger, "Removing pending to-decode HTLC: {}", removal_reason);
16681+
}
16682+
!matches
16683+
});
16684+
!update_add_htlcs.is_empty()
16685+
});
16686+
}
16687+
1666116688
// Implement ReadableArgs for an Arc'd ChannelManager to make it a bit easier to work with the
1666216689
// SipmleArcChannelManager type:
1666316690
impl<
@@ -17526,18 +17553,12 @@ where
1752617553
// still have an entry for this HTLC in `forward_htlcs` or
1752717554
// `pending_intercepted_htlcs`, we were apparently not persisted after
1752817555
// the monitor was when forwarding the payment.
17529-
decode_update_add_htlcs.retain(|src_outb_alias, update_add_htlcs| {
17530-
update_add_htlcs.retain(|update_add_htlc| {
17531-
let matches = *src_outb_alias == prev_hop_data.prev_outbound_scid_alias &&
17532-
update_add_htlc.htlc_id == prev_hop_data.htlc_id;
17533-
if matches {
17534-
log_info!(logger, "Removing pending to-decode HTLC with hash {} as it was forwarded to the closed channel",
17535-
&htlc.payment_hash);
17536-
}
17537-
!matches
17538-
});
17539-
!update_add_htlcs.is_empty()
17540-
});
17556+
dedup_decode_update_add_htlcs(
17557+
&mut decode_update_add_htlcs,
17558+
&prev_hop_data,
17559+
"HTLC was forwarded to the closed channel",
17560+
&args.logger,
17561+
);
1754117562
forward_htlcs.retain(|_, forwards| {
1754217563
forwards.retain(|forward| {
1754317564
if let HTLCForwardInfo::AddHTLC(htlc_info) = forward {

0 commit comments

Comments
 (0)