]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Store whether a forwarded HTLC is blinded in PendingHTLCRouting
authorValentine Wallace <vwallace@protonmail.com>
Thu, 26 Oct 2023 21:26:18 +0000 (17:26 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Wed, 29 Nov 2023 22:18:38 +0000 (17:18 -0500)
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
lightning/src/ln/onion_payment.rs

index 694d7734dba744af356d0b2eaa5466680316e2aa..9941ad6583c7f1cfb929009b7ed63f3311654e58 100644 (file)
@@ -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<u64> eventually when we bump MSRV
+               /// Set if this HTLC is being forwarded within a blinded path.
+               blinded: Option<BlindedForward>,
        },
        /// 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) => {
index ca7c0dff20c2fd986c55310dba19586ed27ace3f..c10cdc9ab10ea61e3dbd2d3063835553d57acf2b 100644 (file)
@@ -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"),