Skip to content

Commit c7da01a

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 8daa399 commit c7da01a

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16819,6 +16819,38 @@ 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!(
16842+
logger,
16843+
"Removing pending to-decode HTLC with id {}: {}",
16844+
update_add.htlc_id,
16845+
removal_reason
16846+
);
16847+
}
16848+
!matches
16849+
});
16850+
!update_add_htlcs.is_empty()
16851+
});
16852+
}
16853+
1682216854
// Implement ReadableArgs for an Arc'd ChannelManager to make it a bit easier to work with the
1682316855
// SipmleArcChannelManager type:
1682416856
impl<
@@ -17686,19 +17718,11 @@ where
1768617718
// still have an entry for this HTLC in `forward_htlcs` or
1768717719
// `pending_intercepted_htlcs`, we were apparently not persisted after
1768817720
// 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-
},
17721+
dedup_decode_update_add_htlcs(
17722+
&mut decode_update_add_htlcs,
17723+
&prev_hop_data,
17724+
"HTLC was forwarded to the closed channel",
17725+
&args.logger,
1770217726
);
1770317727
forward_htlcs.retain(|_, forwards| {
1770417728
forwards.retain(|forward| {

0 commit comments

Comments
 (0)