From: Valentine Wallace Date: Thu, 16 Mar 2023 02:30:41 +0000 (-0400) Subject: Update docs and method names for blinded payment paths X-Git-Tag: v0.0.115~5^2~15 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=e691e5077dd4d770c948962af177d49819b51be3;p=rust-lightning Update docs and method names for blinded payment paths --- diff --git a/fuzz/src/invoice_request_deser.rs b/fuzz/src/invoice_request_deser.rs index 5239c1e79..e88588489 100644 --- a/fuzz/src/invoice_request_deser.rs +++ b/fuzz/src/invoice_request_deser.rs @@ -74,8 +74,8 @@ fn build_response<'a, T: secp256k1::Signing + secp256k1::Verification>( ) -> Result, SemanticError> { let entropy_source = Randomness {}; let paths = vec![ - BlindedPath::new(&[pubkey(43), pubkey(44), pubkey(42)], &entropy_source, secp_ctx).unwrap(), - BlindedPath::new(&[pubkey(45), pubkey(46), pubkey(42)], &entropy_source, secp_ctx).unwrap(), + BlindedPath::new_for_message(&[pubkey(43), pubkey(44), pubkey(42)], &entropy_source, secp_ctx).unwrap(), + BlindedPath::new_for_message(&[pubkey(45), pubkey(46), pubkey(42)], &entropy_source, secp_ctx).unwrap(), ]; let payinfo = vec![ diff --git a/fuzz/src/refund_deser.rs b/fuzz/src/refund_deser.rs index fab303050..d76607c03 100644 --- a/fuzz/src/refund_deser.rs +++ b/fuzz/src/refund_deser.rs @@ -63,8 +63,8 @@ fn build_response<'a, T: secp256k1::Signing + secp256k1::Verification>( ) -> Result, SemanticError> { let entropy_source = Randomness {}; let paths = vec![ - BlindedPath::new(&[pubkey(43), pubkey(44), pubkey(42)], &entropy_source, secp_ctx).unwrap(), - BlindedPath::new(&[pubkey(45), pubkey(46), pubkey(42)], &entropy_source, secp_ctx).unwrap(), + BlindedPath::new_for_message(&[pubkey(43), pubkey(44), pubkey(42)], &entropy_source, secp_ctx).unwrap(), + BlindedPath::new_for_message(&[pubkey(45), pubkey(46), pubkey(42)], &entropy_source, secp_ctx).unwrap(), ]; let payinfo = vec![ diff --git a/lightning/src/blinded_path/mod.rs b/lightning/src/blinded_path/mod.rs index a4128d6a3..3a4c2ae72 100644 --- a/lightning/src/blinded_path/mod.rs +++ b/lightning/src/blinded_path/mod.rs @@ -27,18 +27,18 @@ use core::ops::Deref; use crate::io::{self, Cursor}; use crate::prelude::*; -/// Onion messages can be sent and received to blinded paths, which serve to hide the identity of -/// the recipient. +/// Onion messages and payments can be sent and received to blinded paths, which serve to hide the +/// identity of the recipient. #[derive(Clone, Debug, PartialEq)] pub struct BlindedPath { /// To send to a blinded path, the sender first finds a route to the unblinded /// `introduction_node_id`, which can unblind its [`encrypted_payload`] to find out the onion - /// message's next hop and forward it along. + /// message or payment's next hop and forward it along. /// /// [`encrypted_payload`]: BlindedHop::encrypted_payload pub(crate) introduction_node_id: PublicKey, /// Used by the introduction node to decrypt its [`encrypted_payload`] to forward the onion - /// message. + /// message or payment. /// /// [`encrypted_payload`]: BlindedHop::encrypted_payload pub(crate) blinding_point: PublicKey, @@ -59,12 +59,12 @@ pub struct BlindedHop { } impl BlindedPath { - /// Create a blinded path to be forwarded along `node_pks`. The last node pubkey in `node_pks` - /// will be the destination node. + /// Create a blinded path for an onion message, to be forwarded along `node_pks`. The last node + /// pubkey in `node_pks` will be the destination node. /// /// Errors if less than two hops are provided or if `node_pk`(s) are invalid. // TODO: make all payloads the same size with padding + add dummy hops - pub fn new + pub fn new_for_message (node_pks: &[PublicKey], entropy_source: &ES, secp_ctx: &Secp256k1) -> Result { if node_pks.len() < 2 { return Err(()) } @@ -75,12 +75,13 @@ impl BlindedPath { Ok(BlindedPath { introduction_node_id, blinding_point: PublicKey::from_secret_key(secp_ctx, &blinding_secret), - blinded_hops: blinded_hops(secp_ctx, node_pks, &blinding_secret).map_err(|_| ())?, + blinded_hops: blinded_message_hops(secp_ctx, node_pks, &blinding_secret).map_err(|_| ())?, }) } - // Advance the blinded path by one hop, so make the second hop into the new introduction node. - pub(super) fn advance_by_one + // Advance the blinded onion message path by one hop, so make the second hop into the new + // introduction node. + pub(super) fn advance_message_path_by_one (&mut self, node_signer: &NS, secp_ctx: &Secp256k1) -> Result<(), ()> where NS::Target: NodeSigner { @@ -115,8 +116,8 @@ impl BlindedPath { } } -/// Construct blinded hops for the given `unblinded_path`. -fn blinded_hops( +/// Construct blinded onion message hops for the given `unblinded_path`. +fn blinded_message_hops( secp_ctx: &Secp256k1, unblinded_path: &[PublicKey], session_priv: &SecretKey ) -> Result, secp256k1::Error> { let mut blinded_hops = Vec::with_capacity(unblinded_path.len()); diff --git a/lightning/src/onion_message/functional_tests.rs b/lightning/src/onion_message/functional_tests.rs index df13aa2cb..991b4e9e7 100644 --- a/lightning/src/onion_message/functional_tests.rs +++ b/lightning/src/onion_message/functional_tests.rs @@ -136,7 +136,7 @@ fn two_unblinded_two_blinded() { let test_msg = OnionMessageContents::Custom(TestCustomMessage {}); let secp_ctx = Secp256k1::new(); - let blinded_path = BlindedPath::new(&[nodes[3].get_node_pk(), nodes[4].get_node_pk()], &*nodes[4].keys_manager, &secp_ctx).unwrap(); + let blinded_path = BlindedPath::new_for_message(&[nodes[3].get_node_pk(), nodes[4].get_node_pk()], &*nodes[4].keys_manager, &secp_ctx).unwrap(); nodes[0].messenger.send_onion_message(&[nodes[1].get_node_pk(), nodes[2].get_node_pk()], Destination::BlindedPath(blinded_path), test_msg, None).unwrap(); pass_along_path(&nodes, None); @@ -148,7 +148,7 @@ fn three_blinded_hops() { let test_msg = OnionMessageContents::Custom(TestCustomMessage {}); let secp_ctx = Secp256k1::new(); - let blinded_path = BlindedPath::new(&[nodes[1].get_node_pk(), nodes[2].get_node_pk(), nodes[3].get_node_pk()], &*nodes[3].keys_manager, &secp_ctx).unwrap(); + let blinded_path = BlindedPath::new_for_message(&[nodes[1].get_node_pk(), nodes[2].get_node_pk(), nodes[3].get_node_pk()], &*nodes[3].keys_manager, &secp_ctx).unwrap(); nodes[0].messenger.send_onion_message(&[], Destination::BlindedPath(blinded_path), test_msg, None).unwrap(); pass_along_path(&nodes, None); @@ -174,13 +174,13 @@ fn we_are_intro_node() { let test_msg = TestCustomMessage {}; let secp_ctx = Secp256k1::new(); - let blinded_path = BlindedPath::new(&[nodes[0].get_node_pk(), nodes[1].get_node_pk(), nodes[2].get_node_pk()], &*nodes[2].keys_manager, &secp_ctx).unwrap(); + let blinded_path = BlindedPath::new_for_message(&[nodes[0].get_node_pk(), nodes[1].get_node_pk(), nodes[2].get_node_pk()], &*nodes[2].keys_manager, &secp_ctx).unwrap(); nodes[0].messenger.send_onion_message(&[], Destination::BlindedPath(blinded_path), OnionMessageContents::Custom(test_msg.clone()), None).unwrap(); pass_along_path(&nodes, None); // Try with a two-hop blinded path where we are the introduction node. - let blinded_path = BlindedPath::new(&[nodes[0].get_node_pk(), nodes[1].get_node_pk()], &*nodes[1].keys_manager, &secp_ctx).unwrap(); + let blinded_path = BlindedPath::new_for_message(&[nodes[0].get_node_pk(), nodes[1].get_node_pk()], &*nodes[1].keys_manager, &secp_ctx).unwrap(); nodes[0].messenger.send_onion_message(&[], Destination::BlindedPath(blinded_path), OnionMessageContents::Custom(test_msg), None).unwrap(); nodes.remove(2); pass_along_path(&nodes, None); @@ -194,13 +194,13 @@ fn invalid_blinded_path_error() { // 0 hops let secp_ctx = Secp256k1::new(); - let mut blinded_path = BlindedPath::new(&[nodes[1].get_node_pk(), nodes[2].get_node_pk()], &*nodes[2].keys_manager, &secp_ctx).unwrap(); + let mut blinded_path = BlindedPath::new_for_message(&[nodes[1].get_node_pk(), nodes[2].get_node_pk()], &*nodes[2].keys_manager, &secp_ctx).unwrap(); blinded_path.blinded_hops.clear(); let err = nodes[0].messenger.send_onion_message(&[], Destination::BlindedPath(blinded_path), OnionMessageContents::Custom(test_msg.clone()), None).unwrap_err(); assert_eq!(err, SendError::TooFewBlindedHops); // 1 hop - let mut blinded_path = BlindedPath::new(&[nodes[1].get_node_pk(), nodes[2].get_node_pk()], &*nodes[2].keys_manager, &secp_ctx).unwrap(); + let mut blinded_path = BlindedPath::new_for_message(&[nodes[1].get_node_pk(), nodes[2].get_node_pk()], &*nodes[2].keys_manager, &secp_ctx).unwrap(); blinded_path.blinded_hops.remove(0); assert_eq!(blinded_path.blinded_hops.len(), 1); let err = nodes[0].messenger.send_onion_message(&[], Destination::BlindedPath(blinded_path), OnionMessageContents::Custom(test_msg), None).unwrap_err(); @@ -214,7 +214,7 @@ fn reply_path() { let secp_ctx = Secp256k1::new(); // Destination::Node - let reply_path = BlindedPath::new(&[nodes[2].get_node_pk(), nodes[1].get_node_pk(), nodes[0].get_node_pk()], &*nodes[0].keys_manager, &secp_ctx).unwrap(); + let reply_path = BlindedPath::new_for_message(&[nodes[2].get_node_pk(), nodes[1].get_node_pk(), nodes[0].get_node_pk()], &*nodes[0].keys_manager, &secp_ctx).unwrap(); nodes[0].messenger.send_onion_message(&[nodes[1].get_node_pk(), nodes[2].get_node_pk()], Destination::Node(nodes[3].get_node_pk()), OnionMessageContents::Custom(test_msg.clone()), Some(reply_path)).unwrap(); pass_along_path(&nodes, None); // Make sure the last node successfully decoded the reply path. @@ -223,8 +223,8 @@ fn reply_path() { &format!("Received an onion message with path_id None and a reply_path"), 1); // Destination::BlindedPath - let blinded_path = BlindedPath::new(&[nodes[1].get_node_pk(), nodes[2].get_node_pk(), nodes[3].get_node_pk()], &*nodes[3].keys_manager, &secp_ctx).unwrap(); - let reply_path = BlindedPath::new(&[nodes[2].get_node_pk(), nodes[1].get_node_pk(), nodes[0].get_node_pk()], &*nodes[0].keys_manager, &secp_ctx).unwrap(); + let blinded_path = BlindedPath::new_for_message(&[nodes[1].get_node_pk(), nodes[2].get_node_pk(), nodes[3].get_node_pk()], &*nodes[3].keys_manager, &secp_ctx).unwrap(); + let reply_path = BlindedPath::new_for_message(&[nodes[2].get_node_pk(), nodes[1].get_node_pk(), nodes[0].get_node_pk()], &*nodes[0].keys_manager, &secp_ctx).unwrap(); nodes[0].messenger.send_onion_message(&[], Destination::BlindedPath(blinded_path), OnionMessageContents::Custom(test_msg), Some(reply_path)).unwrap(); pass_along_path(&nodes, None); diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index 72b67dc92..b50282433 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -91,7 +91,7 @@ use crate::prelude::*; /// // Create a blinded path to yourself, for someone to send an onion message to. /// # let your_node_id = hop_node_id1; /// let hops = [hop_node_id3, hop_node_id4, your_node_id]; -/// let blinded_path = BlindedPath::new(&hops, &keys_manager, &secp_ctx).unwrap(); +/// let blinded_path = BlindedPath::new_for_message(&hops, &keys_manager, &secp_ctx).unwrap(); /// /// // Send a custom onion message to a blinded path. /// # let intermediate_hops = [hop_node_id1, hop_node_id2]; @@ -226,7 +226,7 @@ impl OnionMessenger let our_node_id = self.node_signer.get_node_id(Recipient::Node) .map_err(|()| SendError::GetNodeIdFailed)?; if blinded_path.introduction_node_id == our_node_id { - blinded_path.advance_by_one(&self.node_signer, &self.secp_ctx) + blinded_path.advance_message_path_by_one(&self.node_signer, &self.secp_ctx) .map_err(|()| SendError::BlindedPathAdvanceFailed)?; } }