]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Allow create_blinded_paths Function to Take Recipient TLVs as a Field
authorshaavan <shaavan.github@gmail.com>
Sat, 15 Jun 2024 13:52:56 +0000 (19:22 +0530)
committershaavan <shaavan.github@gmail.com>
Tue, 25 Jun 2024 07:47:59 +0000 (13:17 +0530)
- Enabled `create_blinded_paths` to accept `RecipientData` TLVs as
  an input field.
- `RecipientData` is intended to be sent along with the `reply_path`
   to the counterparty.
- Added `RecipientData` in the `create_blinded_paths` flow, optionally
  appending it within the `reply_path`.
- Updated tests to verify the new feature.

13 files changed:
fuzz/src/chanmon_consistency.rs
fuzz/src/full_stack.rs
fuzz/src/invoice_request_deser.rs
fuzz/src/onion_message.rs
fuzz/src/refund_deser.rs
lightning/src/blinded_path/message.rs
lightning/src/blinded_path/mod.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/offers_tests.rs
lightning/src/onion_message/functional_tests.rs
lightning/src/onion_message/messenger.rs
lightning/src/routing/router.rs
lightning/src/util/test_utils.rs

index 423e69eb8f6f39ed94e61c8a565d366569724b2e..d020ffe02871bda395d8d5efa4fc250b5e5cf8ed 100644 (file)
@@ -33,6 +33,7 @@ use bitcoin::hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::hashes::Hash as TraitImport;
 use bitcoin::WPubkeyHash;
 
+use lightning::blinded_path::message::MessageContext;
 use lightning::blinded_path::payment::ReceiveTlvs;
 use lightning::blinded_path::BlindedPath;
 use lightning::chain;
@@ -138,7 +139,8 @@ impl MessageRouter for FuzzRouter {
        }
 
        fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
-               &self, _recipient: PublicKey, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>,
+               &self, _recipient: PublicKey, _recipient_data: Option<MessageContext>,
+               _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>,
        ) -> Result<Vec<BlindedPath>, ()> {
                unreachable!()
        }
index a2ae07a2149045e14742174f7df16f2888cfed61..d58f7746685e132289a7135f27acf83d5cfe59ea 100644 (file)
@@ -30,6 +30,7 @@ use bitcoin::hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::hashes::Hash as _;
 use bitcoin::WPubkeyHash;
 
+use lightning::blinded_path::message::MessageContext;
 use lightning::blinded_path::payment::ReceiveTlvs;
 use lightning::blinded_path::BlindedPath;
 use lightning::chain;
@@ -175,7 +176,8 @@ impl MessageRouter for FuzzRouter {
        }
 
        fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
-               &self, _recipient: PublicKey, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>,
+               &self, _recipient: PublicKey, _recipient_data: Option<MessageContext>,
+               _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>,
        ) -> Result<Vec<BlindedPath>, ()> {
                unreachable!()
        }
index 642da58236f6bc5fd51ad8cbc266ff2f3aa9676c..9c46651ffaec3b18e81c359c68c6f59c9c813e6e 100644 (file)
@@ -87,10 +87,22 @@ fn build_response<T: secp256k1::Signing + secp256k1::Verification>(
                ],
        ];
        let paths = vec![
-               BlindedPath::new_for_message(&intermediate_nodes[0], pubkey(42), &entropy_source, secp_ctx)
-                       .unwrap(),
-               BlindedPath::new_for_message(&intermediate_nodes[1], pubkey(42), &entropy_source, secp_ctx)
-                       .unwrap(),
+               BlindedPath::new_for_message(
+                       &intermediate_nodes[0],
+                       pubkey(42),
+                       None,
+                       &entropy_source,
+                       secp_ctx,
+               )
+               .unwrap(),
+               BlindedPath::new_for_message(
+                       &intermediate_nodes[1],
+                       pubkey(42),
+                       None,
+                       &entropy_source,
+                       secp_ctx,
+               )
+               .unwrap(),
        ];
 
        let payinfo = vec![
index b1c6312a93991082ce1ce432697d438113743b8c..004abbcbf5e459dd7e0fdfac088dae065ff4396e 100644 (file)
@@ -95,7 +95,8 @@ impl MessageRouter for TestMessageRouter {
        }
 
        fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
-               &self, _recipient: PublicKey, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>,
+               &self, _recipient: PublicKey, _recipient_data: Option<MessageContext>,
+               _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>,
        ) -> Result<Vec<BlindedPath>, ()> {
                unreachable!()
        }
index 11907b6d6965c121be2c6d612453d9169893b8d8..5e55b18eb8bba973323273c2422e353a7d6d7c40 100644 (file)
@@ -76,10 +76,22 @@ fn build_response<T: secp256k1::Signing + secp256k1::Verification>(
                ],
        ];
        let paths = vec![
-               BlindedPath::new_for_message(&intermediate_nodes[0], pubkey(42), &entropy_source, secp_ctx)
-                       .unwrap(),
-               BlindedPath::new_for_message(&intermediate_nodes[1], pubkey(42), &entropy_source, secp_ctx)
-                       .unwrap(),
+               BlindedPath::new_for_message(
+                       &intermediate_nodes[0],
+                       pubkey(42),
+                       None,
+                       &entropy_source,
+                       secp_ctx,
+               )
+               .unwrap(),
+               BlindedPath::new_for_message(
+                       &intermediate_nodes[1],
+                       pubkey(42),
+                       None,
+                       &entropy_source,
+                       secp_ctx,
+               )
+               .unwrap(),
        ];
 
        let payinfo = vec![
index f299fbfd9f5bd28f6fa36e22dd2c461b6f1d526b..9a30d91bd8009cf81dca0da511af9bb207549d69 100644 (file)
@@ -12,6 +12,7 @@
 //! [`BlindedPath`]: crate::blinded_path::BlindedPath
 
 use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
+
 #[allow(unused_imports)]
 use crate::prelude::*;
 
@@ -139,7 +140,7 @@ impl_writeable_tlv_based_enum!(OffersContext,
 /// Construct blinded onion message hops for the given `intermediate_nodes` and `recipient_node_id`.
 pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
        secp_ctx: &Secp256k1<T>, intermediate_nodes: &[ForwardNode], recipient_node_id: PublicKey,
-       session_priv: &SecretKey
+       context: Option<MessageContext>, session_priv: &SecretKey
 ) -> Result<Vec<BlindedHop>, secp256k1::Error> {
        let pks = intermediate_nodes.iter().map(|node| &node.node_id)
                .chain(core::iter::once(&recipient_node_id));
@@ -151,7 +152,7 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
                        None => NextMessageHop::NodeId(*pubkey),
                })
                .map(|next_hop| ControlTlvs::Forward(ForwardTlvs { next_hop, next_blinding_override: None }))
-               .chain(core::iter::once(ControlTlvs::Receive(ReceiveTlvs { path_id: None })));
+               .chain(core::iter::once(ControlTlvs::Receive(ReceiveTlvs{ path_id: context })));
 
        utils::construct_blinded_hops(secp_ctx, pks, tlvs, session_priv)
 }
index 2d3d085bddf35d51a5276c5c9c048506527ac45b..0c65f0b56a8a35b50d97686569fdee7c97768550 100644 (file)
@@ -14,6 +14,7 @@ pub mod message;
 pub(crate) mod utils;
 
 use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
+use message::MessageContext;
 use core::ops::Deref;
 
 use crate::ln::msgs::DecodeError;
@@ -123,9 +124,9 @@ pub struct BlindedHop {
 impl BlindedPath {
        /// Create a one-hop blinded path for a message.
        pub fn one_hop_for_message<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
-               recipient_node_id: PublicKey, entropy_source: ES, secp_ctx: &Secp256k1<T>
+               recipient_node_id: PublicKey, context: Option<MessageContext>, entropy_source: ES, secp_ctx: &Secp256k1<T>
        ) -> Result<Self, ()> where ES::Target: EntropySource {
-               Self::new_for_message(&[], recipient_node_id, entropy_source, secp_ctx)
+               Self::new_for_message(&[], recipient_node_id, context, entropy_source, secp_ctx)
        }
 
        /// Create a blinded path for an onion message, to be forwarded along `node_pks`. The last node
@@ -135,7 +136,7 @@ impl BlindedPath {
        //  TODO: make all payloads the same size with padding + add dummy hops
        pub fn new_for_message<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
                intermediate_nodes: &[message::ForwardNode], recipient_node_id: PublicKey,
-               entropy_source: ES, secp_ctx: &Secp256k1<T>
+               context: Option<MessageContext>, entropy_source: ES, secp_ctx: &Secp256k1<T>
        ) -> Result<Self, ()> where ES::Target: EntropySource {
                let introduction_node = IntroductionNode::NodeId(
                        intermediate_nodes.first().map_or(recipient_node_id, |n| n.node_id)
@@ -147,7 +148,8 @@ impl BlindedPath {
                        introduction_node,
                        blinding_point: PublicKey::from_secret_key(secp_ctx, &blinding_secret),
                        blinded_hops: message::blinded_hops(
-                               secp_ctx, intermediate_nodes, recipient_node_id, &blinding_secret,
+                               secp_ctx, intermediate_nodes, recipient_node_id,
+                               context, &blinding_secret,
                        ).map_err(|_| ())?,
                })
        }
index 2fb741deeac8dbd36b9d9a37e227523b51f47878..fd08c055cfd6a4d72519b633afcf63f29c50f980 100644 (file)
@@ -31,7 +31,7 @@ use bitcoin::secp256k1::{SecretKey,PublicKey};
 use bitcoin::secp256k1::Secp256k1;
 use bitcoin::{secp256k1, Sequence};
 
-use crate::blinded_path::message::OffersContext;
+use crate::blinded_path::message::{MessageContext, OffersContext};
 use crate::blinded_path::{BlindedPath, NodeIdLookUp};
 use crate::blinded_path::message::ForwardNode;
 use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, PaymentConstraints, PaymentContext, ReceiveTlvs};
@@ -8375,7 +8375,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
                let entropy = &*$self.entropy_source;
                let secp_ctx = &$self.secp_ctx;
 
-               let path = $self.create_blinded_path_using_absolute_expiry(absolute_expiry)
+               let path = $self.create_blinded_path_using_absolute_expiry(absolute_expiry, None)
                        .map_err(|_| Bolt12SemanticError::MissingPaths)?;
                let builder = OfferBuilder::deriving_signing_pubkey(
                        node_id, expanded_key, entropy, secp_ctx
@@ -8447,7 +8447,10 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
                let entropy = &*$self.entropy_source;
                let secp_ctx = &$self.secp_ctx;
 
-               let path = $self.create_blinded_path_using_absolute_expiry(Some(absolute_expiry))
+               let context = MessageContext::Offers(
+                       OffersContext::OutboundPayment { payment_id }
+               );
+               let path = $self.create_blinded_path_using_absolute_expiry(Some(absolute_expiry), Some(context))
                        .map_err(|_| Bolt12SemanticError::MissingPaths)?;
                let builder = RefundBuilder::deriving_payer_id(
                        node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
@@ -8570,7 +8573,10 @@ where
                        Some(payer_note) => builder.payer_note(payer_note),
                };
                let invoice_request = builder.build_and_sign()?;
-               let reply_path = self.create_blinded_path().map_err(|_| Bolt12SemanticError::MissingPaths)?;
+               let context = MessageContext::Offers(
+                       OffersContext::OutboundPayment { payment_id }
+               );
+               let reply_path = self.create_blinded_path(Some(context)).map_err(|_| Bolt12SemanticError::MissingPaths)?;
 
                let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
 
@@ -8670,7 +8676,7 @@ where
                                )?;
                                let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
                                let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
-                               let reply_path = self.create_blinded_path()
+                               let reply_path = self.create_blinded_path(None)
                                        .map_err(|_| Bolt12SemanticError::MissingPaths)?;
 
                                let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
@@ -8803,15 +8809,15 @@ where
        /// respectively, based on the given `absolute_expiry` as seconds since the Unix epoch. See
        /// [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`].
        fn create_blinded_path_using_absolute_expiry(
-               &self, absolute_expiry: Option<Duration>
+               &self, absolute_expiry: Option<Duration>, context: Option<MessageContext>
        ) -> Result<BlindedPath, ()> {
                let now = self.duration_since_epoch();
                let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
 
                if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
-                       self.create_compact_blinded_path()
+                       self.create_compact_blinded_path(context)
                } else {
-                       self.create_blinded_path()
+                       self.create_blinded_path(context)
                }
        }
 
@@ -8831,7 +8837,7 @@ where
        /// Creates a blinded path by delegating to [`MessageRouter::create_blinded_paths`].
        ///
        /// Errors if the `MessageRouter` errors or returns an empty `Vec`.
-       fn create_blinded_path(&self) -> Result<BlindedPath, ()> {
+       fn create_blinded_path(&self, context: Option<MessageContext>) -> Result<BlindedPath, ()> {
                let recipient = self.get_our_node_id();
                let secp_ctx = &self.secp_ctx;
 
@@ -8844,14 +8850,14 @@ where
                        .collect::<Vec<_>>();
 
                self.router
-                       .create_blinded_paths(recipient, peers, secp_ctx)
+                       .create_blinded_paths(recipient, context, peers, secp_ctx)
                        .and_then(|paths| paths.into_iter().next().ok_or(()))
        }
 
        /// Creates a blinded path by delegating to [`MessageRouter::create_compact_blinded_paths`].
        ///
        /// Errors if the `MessageRouter` errors or returns an empty `Vec`.
-       fn create_compact_blinded_path(&self) -> Result<BlindedPath, ()> {
+       fn create_compact_blinded_path(&self, context: Option<MessageContext>) -> Result<BlindedPath, ()> {
                let recipient = self.get_our_node_id();
                let secp_ctx = &self.secp_ctx;
 
@@ -8871,7 +8877,7 @@ where
                        .collect::<Vec<_>>();
 
                self.router
-                       .create_compact_blinded_paths(recipient, peers, secp_ctx)
+                       .create_compact_blinded_paths(recipient, context, peers, secp_ctx)
                        .and_then(|paths| paths.into_iter().next().ok_or(()))
        }
 
index 405ab87be3f11fb25c99a13960d854e6253f2cbe..83ff8ce6d5c9516ea38d499c5f6b25ec046f7672 100644 (file)
@@ -1412,6 +1412,14 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
 
        let invoice_error = extract_invoice_error(david, &onion_message);
        assert_eq!(invoice_error, InvoiceError::from(Bolt12SemanticError::MissingPaths));
+
+       // Confirm that david drops this failed payment from his pending outbound payments.
+       match get_event!(david, Event::InvoiceRequestFailed) {
+               Event::InvoiceRequestFailed { payment_id: pay_id } => {
+                       assert_eq!(pay_id, payment_id)
+               },
+               _ => panic!("No Event::InvoiceRequestFailed"),
+       }
 }
 
 #[test]
index 390a22e91c0e4b02cee50b5a9c8fa11d11196baa..112e35ee08b5a550b53b78d475aac19d9d75e81c 100644 (file)
@@ -372,7 +372,7 @@ fn one_blinded_hop() {
        let test_msg = TestCustomMessage::Pong;
 
        let secp_ctx = Secp256k1::new();
-       let blinded_path = BlindedPath::new_for_message(&[], nodes[1].node_id, &*nodes[1].entropy_source, &secp_ctx).unwrap();
+       let blinded_path = BlindedPath::new_for_message(&[], nodes[1].node_id, None, &*nodes[1].entropy_source, &secp_ctx).unwrap();
        let destination = Destination::BlindedPath(blinded_path);
        nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap();
        nodes[1].custom_message_handler.expect_message(TestCustomMessage::Pong);
@@ -386,7 +386,7 @@ fn two_unblinded_two_blinded() {
 
        let secp_ctx = Secp256k1::new();
        let intermediate_nodes = [ForwardNode { node_id: nodes[3].node_id, short_channel_id: None }];
-       let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[4].node_id, &*nodes[4].entropy_source, &secp_ctx).unwrap();
+       let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[4].node_id, None, &*nodes[4].entropy_source, &secp_ctx).unwrap();
        let path = OnionMessagePath {
                intermediate_nodes: vec![nodes[1].node_id, nodes[2].node_id],
                destination: Destination::BlindedPath(blinded_path),
@@ -408,7 +408,7 @@ fn three_blinded_hops() {
                ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
                ForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
        ];
-       let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[3].node_id, &*nodes[3].entropy_source, &secp_ctx).unwrap();
+       let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[3].node_id, None, &*nodes[3].entropy_source, &secp_ctx).unwrap();
        let destination = Destination::BlindedPath(blinded_path);
 
        nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap();
@@ -430,7 +430,7 @@ fn async_response_over_one_blinded_hop() {
 
        // 3. Simulate the creation of a Blinded Reply path provided by Bob.
        let secp_ctx = Secp256k1::new();
-       let reply_path = BlindedPath::new_for_message(&[], nodes[1].node_id, &*nodes[1].entropy_source, &secp_ctx).unwrap();
+       let reply_path = BlindedPath::new_for_message(&[], nodes[1].node_id, None, &*nodes[1].entropy_source, &secp_ctx).unwrap();
 
        // 4. Create a responder using the reply path for Alice.
        let responder = Some(Responder::new(reply_path));
@@ -465,7 +465,7 @@ fn async_response_with_reply_path_succeeds() {
 
        // Alice receives a message from Bob with an added reply_path for responding back.
        let message = TestCustomMessage::Ping;
-       let reply_path = BlindedPath::new_for_message(&[], bob.node_id, &*bob.entropy_source, &secp_ctx).unwrap();
+       let reply_path = BlindedPath::new_for_message(&[], bob.node_id, None, &*bob.entropy_source, &secp_ctx).unwrap();
 
        // Alice asynchronously responds to Bob, expecting a response back from him.
        let responder = Responder::new(reply_path);
@@ -501,7 +501,7 @@ fn async_response_with_reply_path_fails() {
 
        // Alice receives a message from Bob with an added reply_path for responding back.
        let message = TestCustomMessage::Ping;
-       let reply_path = BlindedPath::new_for_message(&[], bob.node_id, &*bob.entropy_source, &secp_ctx).unwrap();
+       let reply_path = BlindedPath::new_for_message(&[], bob.node_id, None, &*bob.entropy_source, &secp_ctx).unwrap();
 
        // Alice tries to asynchronously respond to Bob, but fails because the nodes are unannounced and
        // disconnected. Thus, a reply path could no be created for the response.
@@ -545,7 +545,7 @@ fn we_are_intro_node() {
                ForwardNode { node_id: nodes[0].node_id, short_channel_id: None },
                ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
        ];
-       let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[2].node_id, &*nodes[2].entropy_source, &secp_ctx).unwrap();
+       let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[2].node_id, None, &*nodes[2].entropy_source, &secp_ctx).unwrap();
        let destination = Destination::BlindedPath(blinded_path);
 
        nodes[0].messenger.send_onion_message(test_msg.clone(), destination, None).unwrap();
@@ -554,7 +554,7 @@ fn we_are_intro_node() {
 
        // Try with a two-hop blinded path where we are the introduction node.
        let intermediate_nodes = [ForwardNode { node_id: nodes[0].node_id, short_channel_id: None }];
-       let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[1].node_id, &*nodes[1].entropy_source, &secp_ctx).unwrap();
+       let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[1].node_id, None, &*nodes[1].entropy_source, &secp_ctx).unwrap();
        let destination = Destination::BlindedPath(blinded_path);
        nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap();
        nodes[1].custom_message_handler.expect_message(TestCustomMessage::Pong);
@@ -570,7 +570,7 @@ fn invalid_blinded_path_error() {
 
        let secp_ctx = Secp256k1::new();
        let intermediate_nodes = [ForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
-       let mut blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[2].node_id, &*nodes[2].entropy_source, &secp_ctx).unwrap();
+       let mut blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[2].node_id, None, &*nodes[2].entropy_source, &secp_ctx).unwrap();
        blinded_path.blinded_hops.clear();
        let destination = Destination::BlindedPath(blinded_path);
        let err = nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap_err();
@@ -593,7 +593,7 @@ fn reply_path() {
                ForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
                ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
        ];
-       let reply_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[0].node_id, &*nodes[0].entropy_source, &secp_ctx).unwrap();
+       let reply_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[0].node_id, None, &*nodes[0].entropy_source, &secp_ctx).unwrap();
        nodes[0].messenger.send_onion_message_using_path(path, test_msg.clone(), Some(reply_path)).unwrap();
        nodes[3].custom_message_handler.expect_message(TestCustomMessage::Ping);
        pass_along_path(&nodes);
@@ -607,13 +607,13 @@ fn reply_path() {
                ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
                ForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
        ];
-       let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[3].node_id, &*nodes[3].entropy_source, &secp_ctx).unwrap();
+       let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[3].node_id, None, &*nodes[3].entropy_source, &secp_ctx).unwrap();
        let destination = Destination::BlindedPath(blinded_path);
        let intermediate_nodes = [
                ForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
                ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
        ];
-       let reply_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[0].node_id, &*nodes[0].entropy_source, &secp_ctx).unwrap();
+       let reply_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[0].node_id, None, &*nodes[0].entropy_source, &secp_ctx).unwrap();
 
        nodes[0].messenger.send_onion_message(test_msg, destination, Some(reply_path)).unwrap();
        nodes[3].custom_message_handler.expect_message(TestCustomMessage::Ping);
@@ -695,7 +695,7 @@ fn requests_peer_connection_for_buffered_messages() {
 
        let intermediate_nodes = [ForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
        let blinded_path = BlindedPath::new_for_message(
-               &intermediate_nodes, nodes[2].node_id, &*nodes[0].entropy_source, &secp_ctx
+               &intermediate_nodes, nodes[2].node_id, None, &*nodes[0].entropy_source, &secp_ctx
        ).unwrap();
        let destination = Destination::BlindedPath(blinded_path);
 
@@ -733,7 +733,7 @@ fn drops_buffered_messages_waiting_for_peer_connection() {
 
        let intermediate_nodes = [ForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
        let blinded_path = BlindedPath::new_for_message(
-               &intermediate_nodes, nodes[2].node_id, &*nodes[0].entropy_source, &secp_ctx
+               &intermediate_nodes, nodes[2].node_id, None, &*nodes[0].entropy_source, &secp_ctx
        ).unwrap();
        let destination = Destination::BlindedPath(blinded_path);
 
@@ -783,7 +783,7 @@ fn intercept_offline_peer_oms() {
        let secp_ctx = Secp256k1::new();
        let intermediate_nodes = [ForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
        let blinded_path = BlindedPath::new_for_message(
-               &intermediate_nodes, nodes[2].node_id, &*nodes[2].entropy_source, &secp_ctx
+               &intermediate_nodes, nodes[2].node_id, None, &*nodes[2].entropy_source, &secp_ctx
        ).unwrap();
        let destination = Destination::BlindedPath(blinded_path);
 
index 2158ef3ff03b9647fb4a892d9857f5e542807273..421edb803526942af3dc14b321a9ccfb4bce4237 100644 (file)
@@ -145,7 +145,7 @@ for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH> where
 /// # use bitcoin::hashes::hex::FromHex;
 /// # use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey, self};
 /// # use lightning::blinded_path::{BlindedPath, EmptyNodeIdLookUp};
-/// # use lightning::blinded_path::message::ForwardNode;
+/// # use lightning::blinded_path::message::{ForwardNode, MessageContext};
 /// # use lightning::sign::{EntropySource, KeysManager};
 /// # use lightning::ln::peer_handler::IgnoringMessageHandler;
 /// # use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath, OnionMessenger};
@@ -172,7 +172,7 @@ for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH> where
 /// #         })
 /// #     }
 /// #     fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
-/// #         &self, _recipient: PublicKey, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>
+/// #         &self, _recipient: PublicKey, _recipient_data: Option<MessageContext>, _peers: Vec<PublicKey>, _secp_ctx: &Secp256k1<T>
 /// #     ) -> Result<Vec<BlindedPath>, ()> {
 /// #         unreachable!()
 /// #     }
@@ -225,7 +225,8 @@ for OnionMessenger<ES, NS, L, NL, MR, OMH, APH, CMH> where
 ///    ForwardNode { node_id: hop_node_id3, short_channel_id: None },
 ///    ForwardNode { node_id: hop_node_id4, short_channel_id: None },
 /// ];
-/// let blinded_path = BlindedPath::new_for_message(&hops, your_node_id, &keys_manager, &secp_ctx).unwrap();
+/// let context = Some(MessageContext::Custom(Vec::new()));
+/// let blinded_path = BlindedPath::new_for_message(&hops, your_node_id, context, &keys_manager, &secp_ctx).unwrap();
 ///
 /// // Send a custom onion message to a blinded path.
 /// let destination = Destination::BlindedPath(blinded_path);
@@ -441,7 +442,7 @@ pub trait MessageRouter {
        fn create_blinded_paths<
                T: secp256k1::Signing + secp256k1::Verification
        >(
-               &self, recipient: PublicKey, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
+               &self, recipient: PublicKey, context: Option<MessageContext>, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
        ) -> Result<Vec<BlindedPath>, ()>;
 
        /// Creates compact [`BlindedPath`]s to the `recipient` node. The nodes in `peers` are assumed
@@ -460,13 +461,14 @@ pub trait MessageRouter {
        fn create_compact_blinded_paths<
                T: secp256k1::Signing + secp256k1::Verification
        >(
-               &self, recipient: PublicKey, peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
+               &self, recipient: PublicKey, context: Option<MessageContext>,
+               peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
        ) -> Result<Vec<BlindedPath>, ()> {
                let peers = peers
                        .into_iter()
                        .map(|ForwardNode { node_id, short_channel_id: _ }| node_id)
                        .collect();
-               self.create_blinded_paths(recipient, peers, secp_ctx)
+               self.create_blinded_paths(recipient, context, peers, secp_ctx)
        }
 }
 
@@ -501,7 +503,8 @@ where
                I: ExactSizeIterator<Item = ForwardNode>,
                T: secp256k1::Signing + secp256k1::Verification
        >(
-               &self, recipient: PublicKey, peers: I, secp_ctx: &Secp256k1<T>, compact_paths: bool
+               &self, recipient: PublicKey, context: Option<MessageContext>, peers: I,
+               secp_ctx: &Secp256k1<T>, compact_paths: bool
        ) -> Result<Vec<BlindedPath>, ()> {
                // Limit the number of blinded paths that are computed.
                const MAX_PATHS: usize = 3;
@@ -540,7 +543,7 @@ where
 
                let paths = peer_info.into_iter()
                        .map(|(peer, _, _)| {
-                               BlindedPath::new_for_message(&[peer], recipient, &*self.entropy_source, secp_ctx)
+                               BlindedPath::new_for_message(&[peer], recipient, context.clone(), &*self.entropy_source, secp_ctx)
                        })
                        .take(MAX_PATHS)
                        .collect::<Result<Vec<_>, _>>();
@@ -549,7 +552,7 @@ where
                        Ok(paths) if !paths.is_empty() => Ok(paths),
                        _ => {
                                if is_recipient_announced {
-                                       BlindedPath::one_hop_for_message(recipient, &*self.entropy_source, secp_ctx)
+                                       BlindedPath::one_hop_for_message(recipient, context, &*self.entropy_source, secp_ctx)
                                                .map(|path| vec![path])
                                } else {
                                        Err(())
@@ -608,20 +611,22 @@ where
        fn create_blinded_paths<
                T: secp256k1::Signing + secp256k1::Verification
        >(
-               &self, recipient: PublicKey, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
+               &self, recipient: PublicKey, context: Option<MessageContext>,
+               peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
        ) -> Result<Vec<BlindedPath>, ()> {
                let peers = peers
                        .into_iter()
                        .map(|node_id| ForwardNode { node_id, short_channel_id: None });
-               self.create_blinded_paths_from_iter(recipient, peers, secp_ctx, false)
+               self.create_blinded_paths_from_iter(recipient, context, peers, secp_ctx, false)
        }
 
        fn create_compact_blinded_paths<
                T: secp256k1::Signing + secp256k1::Verification
        >(
-               &self, recipient: PublicKey, peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
+               &self, recipient: PublicKey, context: Option<MessageContext>,
+               peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
        ) -> Result<Vec<BlindedPath>, ()> {
-               self.create_blinded_paths_from_iter(recipient, peers.into_iter(), secp_ctx, true)
+               self.create_blinded_paths_from_iter(recipient, context, peers.into_iter(), secp_ctx, true)
        }
 }
 
@@ -1178,7 +1183,7 @@ where
                        .collect::<Vec<_>>();
 
                self.message_router
-                       .create_blinded_paths(recipient, peers, secp_ctx)
+                       .create_blinded_paths(recipient, None, peers, secp_ctx)
                        .and_then(|paths| paths.into_iter().next().ok_or(()))
                        .map_err(|_| SendError::PathNotFound)
        }
index 28aaba0513fb45de1e9ba9b24d42b463bd548ba4..25476f16f5d6698e0ff311dfd6c9caf989a162d2 100644 (file)
@@ -12,7 +12,7 @@
 use bitcoin::secp256k1::{PublicKey, Secp256k1, self};
 
 use crate::blinded_path::{BlindedHop, BlindedPath, Direction, IntroductionNode};
-use crate::blinded_path::message;
+use crate::blinded_path::message::{self, MessageContext};
 use crate::blinded_path::payment::{ForwardTlvs, PaymentConstraints, PaymentRelay, ReceiveTlvs, self};
 use crate::ln::{PaymentHash, PaymentPreimage};
 use crate::ln::channel_state::ChannelDetails;
@@ -193,17 +193,17 @@ impl< G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, ES: Deref, S: Deref,
        fn create_blinded_paths<
                T: secp256k1::Signing + secp256k1::Verification
        > (
-               &self, recipient: PublicKey, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
+               &self, recipient: PublicKey, context: Option<MessageContext>, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
        ) -> Result<Vec<BlindedPath>, ()> {
-               self.message_router.create_blinded_paths(recipient, peers, secp_ctx)
+               self.message_router.create_blinded_paths(recipient, context, peers, secp_ctx)
        }
 
        fn create_compact_blinded_paths<
                T: secp256k1::Signing + secp256k1::Verification
        > (
-               &self, recipient: PublicKey, peers: Vec<message::ForwardNode>, secp_ctx: &Secp256k1<T>,
+               &self, recipient: PublicKey, context: Option<MessageContext>, peers: Vec<message::ForwardNode>, secp_ctx: &Secp256k1<T>,
        ) -> Result<Vec<BlindedPath>, ()> {
-               self.message_router.create_compact_blinded_paths(recipient, peers, secp_ctx)
+               self.message_router.create_compact_blinded_paths(recipient, context, peers, secp_ctx)
        }
 }
 
index 4d17f8fd17ddcd9a919acb4a4abddd9aac673c17..b730f1a54fd77218571e2b8086aa30ff2d29aab0 100644 (file)
@@ -7,6 +7,7 @@
 // You may not use this file except in accordance with one or both of these
 // licenses.
 
+use crate::blinded_path::message::MessageContext;
 use crate::blinded_path::BlindedPath;
 use crate::blinded_path::message::ForwardNode;
 use crate::blinded_path::payment::ReceiveTlvs;
@@ -252,17 +253,19 @@ impl<'a> MessageRouter for TestRouter<'a> {
        fn create_blinded_paths<
                T: secp256k1::Signing + secp256k1::Verification
        >(
-               &self, recipient: PublicKey, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
+               &self, recipient: PublicKey, context: Option<MessageContext>,
+               peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
        ) -> Result<Vec<BlindedPath>, ()> {
-               self.router.create_blinded_paths(recipient, peers, secp_ctx)
+               self.router.create_blinded_paths(recipient, context, peers, secp_ctx)
        }
 
        fn create_compact_blinded_paths<
                T: secp256k1::Signing + secp256k1::Verification
        >(
-               &self, recipient: PublicKey, peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
+               &self, recipient: PublicKey, context: Option<MessageContext>,
+               peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
        ) -> Result<Vec<BlindedPath>, ()> {
-               self.router.create_compact_blinded_paths(recipient, peers, secp_ctx)
+               self.router.create_compact_blinded_paths(recipient, context, peers, secp_ctx)
        }
 }
 
@@ -295,15 +298,17 @@ impl<'a> MessageRouter for TestMessageRouter<'a> {
        }
 
        fn create_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
-               &self, recipient: PublicKey, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
+               &self, recipient: PublicKey, context: Option<MessageContext>,
+               peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
        ) -> Result<Vec<BlindedPath>, ()> {
-               self.inner.create_blinded_paths(recipient, peers, secp_ctx)
+               self.inner.create_blinded_paths(recipient, context, peers, secp_ctx)
        }
 
        fn create_compact_blinded_paths<T: secp256k1::Signing + secp256k1::Verification>(
-               &self, recipient: PublicKey, peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
+               &self, recipient: PublicKey, context: Option<MessageContext>,
+               peers: Vec<ForwardNode>, secp_ctx: &Secp256k1<T>,
        ) -> Result<Vec<BlindedPath>, ()> {
-               self.inner.create_compact_blinded_paths(recipient, peers, secp_ctx)
+               self.inner.create_compact_blinded_paths(recipient, context, peers, secp_ctx)
        }
 }