From b64523780b2f08f8cea7f29b660841310dba7a70 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Thu, 26 Oct 2023 17:26:18 -0400 Subject: [PATCH] Store whether a forwarded HTLC is blinded in PendingHTLCRouting We need to store the inbound blinding point in PendingHTLCRouting in order to calculate the outbound blinding point. The new BlindedForward struct will be augmented when we add support for forwarding as a non-intro node. --- lightning/src/ln/channelmanager.rs | 23 +++++++++++++++++++++-- lightning/src/ln/onion_payment.rs | 3 ++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 694d7734d..9941ad658 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -119,6 +119,8 @@ pub enum PendingHTLCRouting { /// The SCID from the onion that we should forward to. This could be a real SCID or a fake one /// generated using `get_fake_scid` from the scid_utils::fake_scid module. short_channel_id: u64, // This should be NonZero eventually when we bump MSRV + /// Set if this HTLC is being forwarded within a blinded path. + blinded: Option, }, /// An HTLC paid to an invoice (supposedly) generated by us. /// At this point, we have not checked that the invoice being paid was actually generated by us, @@ -155,6 +157,16 @@ pub enum PendingHTLCRouting { }, } +/// Information used to forward or fail this HTLC that is being forwarded within a blinded path. +#[derive(Clone, Copy, Hash, PartialEq, Eq)] +pub struct BlindedForward { + /// The `blinding_point` that was set in the inbound [`msgs::UpdateAddHTLC`], or in the inbound + /// onion payload if we're the introduction node. Useful for calculating the next hop's + /// [`msgs::UpdateAddHTLC::blinding_point`]. + pub inbound_blinding_point: PublicKey, + // Another field will be added here when we support forwarding as a non-intro node. +} + /// Full details of an incoming HTLC, including routing info. #[derive(Clone)] // See Channel::revoke_and_ack for why, tl;dr: Rust bug pub struct PendingHTLCInfo { @@ -4013,8 +4025,10 @@ where })?; let routing = match payment.forward_info.routing { - PendingHTLCRouting::Forward { onion_packet, .. } => { - PendingHTLCRouting::Forward { onion_packet, short_channel_id: next_hop_scid } + PendingHTLCRouting::Forward { onion_packet, blinded, .. } => { + PendingHTLCRouting::Forward { + onion_packet, blinded, short_channel_id: next_hop_scid + } }, _ => unreachable!() // Only `PendingHTLCRouting::Forward`s are intercepted }; @@ -9143,9 +9157,14 @@ impl_writeable_tlv_based!(PhantomRouteHints, { (6, real_node_pubkey, required), }); +impl_writeable_tlv_based!(BlindedForward, { + (0, inbound_blinding_point, required), +}); + impl_writeable_tlv_based_enum!(PendingHTLCRouting, (0, Forward) => { (0, onion_packet, required), + (1, blinded, option), (2, short_channel_id, required), }, (1, Receive) => { diff --git a/lightning/src/ln/onion_payment.rs b/lightning/src/ln/onion_payment.rs index ca7c0dff2..c10cdc9ab 100644 --- a/lightning/src/ln/onion_payment.rs +++ b/lightning/src/ln/onion_payment.rs @@ -56,6 +56,7 @@ pub(super) fn create_fwd_pending_htlc_info( routing: PendingHTLCRouting::Forward { onion_packet: outgoing_packet, short_channel_id, + blinded: None, }, payment_hash: msg.payment_hash, incoming_shared_secret: shared_secret, @@ -414,7 +415,7 @@ mod tests { .map_err(|e| e.msg).unwrap(); let next_onion = match peeled.routing { - PendingHTLCRouting::Forward { onion_packet, short_channel_id: _ } => { + PendingHTLCRouting::Forward { onion_packet, .. } => { onion_packet }, _ => panic!("expected a forwarded onion"), -- 2.39.5