Skip to content

Commit fd4a5cc

Browse files
Extract method to dedup pre-decode update_add
We have an overarching goal of (mostly) getting rid of ChannelManager persistence and rebuilding the ChannelManager's state from existing ChannelMonitors, due to issues when the two structs are out-of-sync on restart. The main issue that can arise is channel force closure. We'll use this new util when reconstructing the ChannelManager::decode_update_add_htlcs map from Channel data in upcoming commits. While the Channel data is not included in the monitors yet, it will be in future work.
1 parent aeddf0f commit fd4a5cc

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16819,6 +16819,33 @@ where
1681916819
}
1682016820
}
1682116821

16822+
// If the HTLC corresponding to `prev_hop_data` is present in `decode_update_add_htlcs`, remove it
16823+
// from the map as it is already being stored and processed elsewhere.
16824+
fn dedup_decode_update_add_htlcs<L: Deref>(
16825+
decode_update_add_htlcs: &mut HashMap<u64, Vec<msgs::UpdateAddHTLC>>,
16826+
prev_hop_data: &HTLCPreviousHopData, removal_reason: &'static str, logger: &L,
16827+
) where
16828+
L::Target: Logger,
16829+
{
16830+
decode_update_add_htlcs.retain(|src_outb_alias, update_add_htlcs| {
16831+
update_add_htlcs.retain(|update_add| {
16832+
let matches = *src_outb_alias == prev_hop_data.prev_outbound_scid_alias
16833+
&& update_add.htlc_id == prev_hop_data.htlc_id;
16834+
if matches {
16835+
let logger = WithContext::from(
16836+
logger,
16837+
prev_hop_data.counterparty_node_id,
16838+
Some(update_add.channel_id),
16839+
Some(update_add.payment_hash),
16840+
);
16841+
log_info!(logger, "Removing pending to-decode HTLC: {}", removal_reason);
16842+
}
16843+
!matches
16844+
});
16845+
!update_add_htlcs.is_empty()
16846+
});
16847+
}
16848+
1682216849
// Implement ReadableArgs for an Arc'd ChannelManager to make it a bit easier to work with the
1682316850
// SipmleArcChannelManager type:
1682416851
impl<
@@ -17686,19 +17713,11 @@ where
1768617713
// still have an entry for this HTLC in `forward_htlcs` or
1768717714
// `pending_intercepted_htlcs`, we were apparently not persisted after
1768817715
// the monitor was when forwarding the payment.
17689-
decode_update_add_htlcs.retain(
17690-
|src_outb_alias, update_add_htlcs| {
17691-
update_add_htlcs.retain(|update_add_htlc| {
17692-
let matches = *src_outb_alias
17693-
== prev_hop_data.prev_outbound_scid_alias
17694-
&& update_add_htlc.htlc_id == prev_hop_data.htlc_id;
17695-
if matches {
17696-
log_info!(logger, "Removing pending to-decode HTLC as it was forwarded to the closed channel");
17697-
}
17698-
!matches
17699-
});
17700-
!update_add_htlcs.is_empty()
17701-
},
17716+
dedup_decode_update_add_htlcs(
17717+
&mut decode_update_add_htlcs,
17718+
&prev_hop_data,
17719+
"HTLC was forwarded to the closed channel",
17720+
&args.logger,
1770217721
);
1770317722
forward_htlcs.retain(|_, forwards| {
1770417723
forwards.retain(|forward| {

0 commit comments

Comments
 (0)