@@ -308,6 +308,32 @@ impl InboundHTLCState {
308308 }
309309}
310310
311+ /// Information about the outbound hop for a forwarded HTLC. Useful for generating an accurate
312+ /// [`Event::PaymentForwarded`] if we need to claim this HTLC post-restart.
313+ ///
314+ /// [`Event::PaymentForwarded`]: crate::events::Event::PaymentForwarded
315+ #[derive(Debug, Copy, Clone)]
316+ pub(super) struct OutboundHop {
317+ /// The amount forwarded outbound.
318+ pub(super) amt_msat: u64,
319+ /// The outbound channel this HTLC was forwarded over.
320+ pub(super) channel_id: ChannelId,
321+ /// The next-hop recipient of this HTLC.
322+ pub(super) node_id: PublicKey,
323+ /// The outbound channel's funding outpoint.
324+ pub(super) funding_txo: OutPoint,
325+ /// The outbound channel's user channel ID.
326+ pub(super) user_channel_id: u128,
327+ }
328+
329+ impl_writeable_tlv_based!(OutboundHop, {
330+ (0, amt_msat, required),
331+ (2, channel_id, required),
332+ (4, node_id, required),
333+ (6, funding_txo, required),
334+ (8, user_channel_id, required),
335+ });
336+
311337/// A field of `InboundHTLCState::Committed` containing the HTLC's `update_add_htlc` message. If
312338/// the HTLC is a forward and gets irrevocably committed to the outbound edge, we convert to
313339/// `InboundUpdateAdd::Forwarded`, thus pruning the onion and not persisting it on every
@@ -328,11 +354,7 @@ enum InboundUpdateAdd {
328354 phantom_shared_secret: Option<[u8; 32]>,
329355 trampoline_shared_secret: Option<[u8; 32]>,
330356 blinded_failure: Option<BlindedFailure>,
331- /// Useful for generating an accurate [`Event::PaymentForwarded`], if we need to claim this
332- /// HTLC post-restart.
333- ///
334- /// [`Event::PaymentForwarded`]: crate::events::Event::PaymentForwarded
335- outbound_amt_msat: u64,
357+ outbound_hop: OutboundHop,
336358 },
337359 /// This HTLC was received pre-LDK 0.3, before we started persisting the onion for inbound
338360 /// committed HTLCs.
@@ -346,7 +368,7 @@ impl_writeable_tlv_based_enum_upgradable!(InboundUpdateAdd,
346368 (2, Legacy) => {},
347369 (4, Forwarded) => {
348370 (0, incoming_packet_shared_secret, required),
349- (2, outbound_amt_msat , required),
371+ (2, outbound_hop , required),
350372 (4, phantom_shared_secret, option),
351373 (6, trampoline_shared_secret, option),
352374 (8, blinded_failure, option),
@@ -7948,15 +7970,15 @@ where
79487970 phantom_shared_secret,
79497971 trampoline_shared_secret,
79507972 blinded_failure,
7951- outbound_amt_msat ,
7973+ outbound_hop: OutboundHop { amt_msat, .. } ,
79527974 },
79537975 } => {
79547976 if htlc_resolution_in_holding_cell(htlc.htlc_id) {
79557977 return None;
79567978 }
79577979 // The reconstructed `HTLCPreviousHopData` is used to fail or claim the HTLC backwards
79587980 // post-restart, if it is missing in the outbound edge.
7959- let hop_data = HTLCPreviousHopData {
7981+ let prev_hop_data = HTLCPreviousHopData {
79607982 prev_outbound_scid_alias,
79617983 user_channel_id: Some(user_channel_id),
79627984 htlc_id: htlc.htlc_id,
@@ -7969,7 +7991,7 @@ where
79697991 counterparty_node_id: Some(counterparty_node_id),
79707992 cltv_expiry: Some(htlc.cltv_expiry),
79717993 };
7972- Some((htlc.payment_hash, hop_data , *outbound_amt_msat ))
7994+ Some((htlc.payment_hash, prev_hop_data , *amt_msat ))
79737995 },
79747996 _ => None,
79757997 })
@@ -8019,17 +8041,18 @@ where
80198041 /// This inbound HTLC was irrevocably forwarded to the outbound edge, so we no longer need to
80208042 /// persist its onion.
80218043 pub(super) fn prune_inbound_htlc_onion(
8022- &mut self, htlc_id: u64, hop_data: &HTLCPreviousHopData, outbound_amt_msat: u64,
8044+ &mut self, htlc_id: u64, prev_hop_data: &HTLCPreviousHopData,
8045+ outbound_hop_data: OutboundHop,
80238046 ) {
80248047 for htlc in self.context.pending_inbound_htlcs.iter_mut() {
80258048 if htlc.htlc_id == htlc_id {
80268049 if let InboundHTLCState::Committed { ref mut update_add_htlc } = htlc.state {
80278050 *update_add_htlc = InboundUpdateAdd::Forwarded {
8028- incoming_packet_shared_secret: hop_data .incoming_packet_shared_secret,
8029- phantom_shared_secret: hop_data .phantom_shared_secret,
8030- trampoline_shared_secret: hop_data .trampoline_shared_secret,
8031- blinded_failure: hop_data .blinded_failure,
8032- outbound_amt_msat ,
8051+ incoming_packet_shared_secret: prev_hop_data .incoming_packet_shared_secret,
8052+ phantom_shared_secret: prev_hop_data .phantom_shared_secret,
8053+ trampoline_shared_secret: prev_hop_data .trampoline_shared_secret,
8054+ blinded_failure: prev_hop_data .blinded_failure,
8055+ outbound_hop: outbound_hop_data ,
80338056 };
80348057 return;
80358058 }
0 commit comments