Skip to content

Commit 8daa399

Browse files
Extract util for HTLCIntercepted event creation
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. As part of rebuilding ChannelManager forward HTLCs maps, we will also add a fix that will regenerate HTLCIntercepted events for HTLC intercepts that are present but have no corresponding event in the queue. That fix will use this new method.
1 parent ca9e050 commit 8daa399

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3911,6 +3911,25 @@ macro_rules! process_events_body {
39113911
}
39123912
}
39133913

3914+
/// Creates an [`Event::HTLCIntercepted`] from a [`PendingAddHTLCInfo`]. We generate this event in a
3915+
/// few places so this DRYs the code.
3916+
fn create_htlc_intercepted_event(
3917+
intercept_id: InterceptId, pending_add: &PendingAddHTLCInfo,
3918+
) -> Result<Event, ()> {
3919+
let inbound_amount_msat = pending_add.forward_info.incoming_amt_msat.ok_or(())?;
3920+
let requested_next_hop_scid = match pending_add.forward_info.routing {
3921+
PendingHTLCRouting::Forward { short_channel_id, .. } => short_channel_id,
3922+
_ => return Err(()),
3923+
};
3924+
Ok(Event::HTLCIntercepted {
3925+
requested_next_hop_scid,
3926+
payment_hash: pending_add.forward_info.payment_hash,
3927+
inbound_amount_msat,
3928+
expected_outbound_amount_msat: pending_add.forward_info.outgoing_amt_msat,
3929+
intercept_id,
3930+
})
3931+
}
3932+
39143933
impl<
39153934
M: Deref,
39163935
T: Deref,
@@ -11486,22 +11505,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1148611505
let mut pending_intercepts = self.pending_intercepted_htlcs.lock().unwrap();
1148711506
match pending_intercepts.entry(intercept_id) {
1148811507
hash_map::Entry::Vacant(entry) => {
11489-
new_intercept_events.push_back((
11490-
events::Event::HTLCIntercepted {
11491-
requested_next_hop_scid: scid,
11492-
payment_hash,
11493-
inbound_amount_msat: pending_add
11494-
.forward_info
11495-
.incoming_amt_msat
11496-
.unwrap(),
11497-
expected_outbound_amount_msat: pending_add
11498-
.forward_info
11499-
.outgoing_amt_msat,
11500-
intercept_id,
11501-
},
11502-
None,
11503-
));
11504-
entry.insert(pending_add);
11508+
if let Ok(intercept_ev) =
11509+
create_htlc_intercepted_event(intercept_id, &pending_add)
11510+
{
11511+
new_intercept_events.push_back((intercept_ev, None));
11512+
entry.insert(pending_add);
11513+
} else {
11514+
debug_assert!(false);
11515+
fail_intercepted_htlc(pending_add);
11516+
}
1150511517
},
1150611518
hash_map::Entry::Occupied(_) => {
1150711519
log_info!(

0 commit comments

Comments
 (0)