Skip to content

Commit 3fd9d67

Browse files
Update docs and method names for blinded payment paths
1 parent f31d29a commit 3fd9d67

File tree

5 files changed

+28
-27
lines changed

5 files changed

+28
-27
lines changed

fuzz/src/invoice_request_deser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ fn build_response<'a, T: secp256k1::Signing + secp256k1::Verification>(
7474
) -> Result<UnsignedInvoice<'a>, SemanticError> {
7575
let entropy_source = Randomness {};
7676
let paths = vec![
77-
BlindedPath::new(&[pubkey(43), pubkey(44), pubkey(42)], &entropy_source, secp_ctx).unwrap(),
78-
BlindedPath::new(&[pubkey(45), pubkey(46), pubkey(42)], &entropy_source, secp_ctx).unwrap(),
77+
BlindedPath::new_for_message(&[pubkey(43), pubkey(44), pubkey(42)], &entropy_source, secp_ctx).unwrap(),
78+
BlindedPath::new_for_message(&[pubkey(45), pubkey(46), pubkey(42)], &entropy_source, secp_ctx).unwrap(),
7979
];
8080

8181
let payinfo = vec![

fuzz/src/refund_deser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ fn build_response<'a, T: secp256k1::Signing + secp256k1::Verification>(
6363
) -> Result<UnsignedInvoice<'a>, SemanticError> {
6464
let entropy_source = Randomness {};
6565
let paths = vec![
66-
BlindedPath::new(&[pubkey(43), pubkey(44), pubkey(42)], &entropy_source, secp_ctx).unwrap(),
67-
BlindedPath::new(&[pubkey(45), pubkey(46), pubkey(42)], &entropy_source, secp_ctx).unwrap(),
66+
BlindedPath::new_for_message(&[pubkey(43), pubkey(44), pubkey(42)], &entropy_source, secp_ctx).unwrap(),
67+
BlindedPath::new_for_message(&[pubkey(45), pubkey(46), pubkey(42)], &entropy_source, secp_ctx).unwrap(),
6868
];
6969

7070
let payinfo = vec![

lightning/src/blinded_path/mod.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ use core::ops::Deref;
2727
use crate::io::{self, Cursor};
2828
use crate::prelude::*;
2929

30-
/// Onion messages can be sent and received to blinded paths, which serve to hide the identity of
31-
/// the recipient.
30+
/// Onion messages and payments can be sent and received to blinded paths, which serve to hide the
31+
/// identity of the recipient.
3232
#[derive(Clone, Debug, PartialEq)]
3333
pub struct BlindedPath {
3434
/// To send to a blinded path, the sender first finds a route to the unblinded
3535
/// `introduction_node_id`, which can unblind its [`encrypted_payload`] to find out the onion
36-
/// message's next hop and forward it along.
36+
/// message or payment's next hop and forward it along.
3737
///
3838
/// [`encrypted_payload`]: BlindedHop::encrypted_payload
3939
pub(crate) introduction_node_id: PublicKey,
4040
/// Used by the introduction node to decrypt its [`encrypted_payload`] to forward the onion
41-
/// message.
41+
/// message or payment.
4242
///
4343
/// [`encrypted_payload`]: BlindedHop::encrypted_payload
4444
pub(crate) blinding_point: PublicKey,
@@ -59,12 +59,12 @@ pub struct BlindedHop {
5959
}
6060

6161
impl BlindedPath {
62-
/// Create a blinded path to be forwarded along `node_pks`. The last node pubkey in `node_pks`
63-
/// will be the destination node.
62+
/// Create a blinded path for an onion message, to be forwarded along `node_pks`. The last node
63+
/// pubkey in `node_pks` will be the destination node.
6464
///
6565
/// Errors if less than two hops are provided or if `node_pk`(s) are invalid.
6666
// TODO: make all payloads the same size with padding + add dummy hops
67-
pub fn new<ES: EntropySource, T: secp256k1::Signing + secp256k1::Verification>
67+
pub fn new_for_message<ES: EntropySource, T: secp256k1::Signing + secp256k1::Verification>
6868
(node_pks: &[PublicKey], entropy_source: &ES, secp_ctx: &Secp256k1<T>) -> Result<Self, ()>
6969
{
7070
if node_pks.len() < 2 { return Err(()) }
@@ -75,12 +75,13 @@ impl BlindedPath {
7575
Ok(BlindedPath {
7676
introduction_node_id,
7777
blinding_point: PublicKey::from_secret_key(secp_ctx, &blinding_secret),
78-
blinded_hops: blinded_hops(secp_ctx, node_pks, &blinding_secret).map_err(|_| ())?,
78+
blinded_hops: blinded_message_hops(secp_ctx, node_pks, &blinding_secret).map_err(|_| ())?,
7979
})
8080
}
8181

82-
// Advance the blinded path by one hop, so make the second hop into the new introduction node.
83-
pub(super) fn advance_by_one<NS: Deref, T: secp256k1::Signing + secp256k1::Verification>
82+
// Advance the blinded onion message path by one hop, so make the second hop into the new
83+
// introduction node.
84+
pub(super) fn advance_message_path_by_one<NS: Deref, T: secp256k1::Signing + secp256k1::Verification>
8485
(&mut self, node_signer: &NS, secp_ctx: &Secp256k1<T>) -> Result<(), ()>
8586
where NS::Target: NodeSigner
8687
{
@@ -115,8 +116,8 @@ impl BlindedPath {
115116
}
116117
}
117118

118-
/// Construct blinded hops for the given `unblinded_path`.
119-
fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
119+
/// Construct blinded onion message hops for the given `unblinded_path`.
120+
fn blinded_message_hops<T: secp256k1::Signing + secp256k1::Verification>(
120121
secp_ctx: &Secp256k1<T>, unblinded_path: &[PublicKey], session_priv: &SecretKey
121122
) -> Result<Vec<BlindedHop>, secp256k1::Error> {
122123
let mut blinded_hops = Vec::with_capacity(unblinded_path.len());

lightning/src/onion_message/functional_tests.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn two_unblinded_two_blinded() {
136136
let test_msg = OnionMessageContents::Custom(TestCustomMessage {});
137137

138138
let secp_ctx = Secp256k1::new();
139-
let blinded_path = BlindedPath::new(&[nodes[3].get_node_pk(), nodes[4].get_node_pk()], &*nodes[4].keys_manager, &secp_ctx).unwrap();
139+
let blinded_path = BlindedPath::new_for_message(&[nodes[3].get_node_pk(), nodes[4].get_node_pk()], &*nodes[4].keys_manager, &secp_ctx).unwrap();
140140

141141
nodes[0].messenger.send_onion_message(&[nodes[1].get_node_pk(), nodes[2].get_node_pk()], Destination::BlindedPath(blinded_path), test_msg, None).unwrap();
142142
pass_along_path(&nodes, None);
@@ -148,7 +148,7 @@ fn three_blinded_hops() {
148148
let test_msg = OnionMessageContents::Custom(TestCustomMessage {});
149149

150150
let secp_ctx = Secp256k1::new();
151-
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();
151+
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();
152152

153153
nodes[0].messenger.send_onion_message(&[], Destination::BlindedPath(blinded_path), test_msg, None).unwrap();
154154
pass_along_path(&nodes, None);
@@ -174,13 +174,13 @@ fn we_are_intro_node() {
174174
let test_msg = TestCustomMessage {};
175175

176176
let secp_ctx = Secp256k1::new();
177-
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();
177+
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();
178178

179179
nodes[0].messenger.send_onion_message(&[], Destination::BlindedPath(blinded_path), OnionMessageContents::Custom(test_msg.clone()), None).unwrap();
180180
pass_along_path(&nodes, None);
181181

182182
// Try with a two-hop blinded path where we are the introduction node.
183-
let blinded_path = BlindedPath::new(&[nodes[0].get_node_pk(), nodes[1].get_node_pk()], &*nodes[1].keys_manager, &secp_ctx).unwrap();
183+
let blinded_path = BlindedPath::new_for_message(&[nodes[0].get_node_pk(), nodes[1].get_node_pk()], &*nodes[1].keys_manager, &secp_ctx).unwrap();
184184
nodes[0].messenger.send_onion_message(&[], Destination::BlindedPath(blinded_path), OnionMessageContents::Custom(test_msg), None).unwrap();
185185
nodes.remove(2);
186186
pass_along_path(&nodes, None);
@@ -194,13 +194,13 @@ fn invalid_blinded_path_error() {
194194

195195
// 0 hops
196196
let secp_ctx = Secp256k1::new();
197-
let mut blinded_path = BlindedPath::new(&[nodes[1].get_node_pk(), nodes[2].get_node_pk()], &*nodes[2].keys_manager, &secp_ctx).unwrap();
197+
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();
198198
blinded_path.blinded_hops.clear();
199199
let err = nodes[0].messenger.send_onion_message(&[], Destination::BlindedPath(blinded_path), OnionMessageContents::Custom(test_msg.clone()), None).unwrap_err();
200200
assert_eq!(err, SendError::TooFewBlindedHops);
201201

202202
// 1 hop
203-
let mut blinded_path = BlindedPath::new(&[nodes[1].get_node_pk(), nodes[2].get_node_pk()], &*nodes[2].keys_manager, &secp_ctx).unwrap();
203+
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();
204204
blinded_path.blinded_hops.remove(0);
205205
assert_eq!(blinded_path.blinded_hops.len(), 1);
206206
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() {
214214
let secp_ctx = Secp256k1::new();
215215

216216
// Destination::Node
217-
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();
217+
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();
218218
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();
219219
pass_along_path(&nodes, None);
220220
// Make sure the last node successfully decoded the reply path.
@@ -223,8 +223,8 @@ fn reply_path() {
223223
&format!("Received an onion message with path_id None and a reply_path"), 1);
224224

225225
// Destination::BlindedPath
226-
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();
227-
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();
226+
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();
227+
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();
228228

229229
nodes[0].messenger.send_onion_message(&[], Destination::BlindedPath(blinded_path), OnionMessageContents::Custom(test_msg), Some(reply_path)).unwrap();
230230
pass_along_path(&nodes, None);

lightning/src/onion_message/messenger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ use crate::prelude::*;
9191
/// // Create a blinded path to yourself, for someone to send an onion message to.
9292
/// # let your_node_id = hop_node_id1;
9393
/// let hops = [hop_node_id3, hop_node_id4, your_node_id];
94-
/// let blinded_path = BlindedPath::new(&hops, &keys_manager, &secp_ctx).unwrap();
94+
/// let blinded_path = BlindedPath::new_for_message(&hops, &keys_manager, &secp_ctx).unwrap();
9595
///
9696
/// // Send a custom onion message to a blinded path.
9797
/// # let intermediate_hops = [hop_node_id1, hop_node_id2];
@@ -226,7 +226,7 @@ impl<ES: Deref, NS: Deref, L: Deref, CMH: Deref> OnionMessenger<ES, NS, L, CMH>
226226
let our_node_id = self.node_signer.get_node_id(Recipient::Node)
227227
.map_err(|()| SendError::GetNodeIdFailed)?;
228228
if blinded_path.introduction_node_id == our_node_id {
229-
blinded_path.advance_by_one(&self.node_signer, &self.secp_ctx)
229+
blinded_path.advance_message_path_by_one(&self.node_signer, &self.secp_ctx)
230230
.map_err(|()| SendError::BlindedPathAdvanceFailed)?;
231231
}
232232
}

0 commit comments

Comments
 (0)