Skip to content

Commit 40b78ea

Browse files
authored
Merge pull request #1918 from TheBlueMatt/2022-12-one-blinded-path
Unify blinding nomenclature to call them "paths" not "routes".
2 parents d4dc05b + 8dbf6db commit 40b78ea

File tree

6 files changed

+83
-83
lines changed

6 files changed

+83
-83
lines changed

lightning/src/onion_message/blinded_route.rs renamed to lightning/src/onion_message/blinded_path.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// You may not use this file except in accordance with one or both of these
88
// licenses.
99

10-
//! Creating blinded routes and related utilities live here.
10+
//! Creating blinded paths and related utilities live here.
1111
1212
use bitcoin::hashes::{Hash, HashEngine};
1313
use bitcoin::hashes::sha256::Hash as Sha256;
@@ -26,11 +26,11 @@ use core::ops::Deref;
2626
use crate::io::{self, Cursor};
2727
use crate::prelude::*;
2828

29-
/// Onion messages can be sent and received to blinded routes, which serve to hide the identity of
29+
/// Onion messages can be sent and received to blinded paths, which serve to hide the identity of
3030
/// the recipient.
3131
#[derive(Clone, Debug, PartialEq)]
32-
pub struct BlindedRoute {
33-
/// To send to a blinded route, the sender first finds a route to the unblinded
32+
pub struct BlindedPath {
33+
/// To send to a blinded path, the sender first finds a route to the unblinded
3434
/// `introduction_node_id`, which can unblind its [`encrypted_payload`] to find out the onion
3535
/// message's next hop and forward it along.
3636
///
@@ -41,24 +41,24 @@ pub struct BlindedRoute {
4141
///
4242
/// [`encrypted_payload`]: BlindedHop::encrypted_payload
4343
pub(crate) blinding_point: PublicKey,
44-
/// The hops composing the blinded route.
44+
/// The hops composing the blinded path.
4545
pub(crate) blinded_hops: Vec<BlindedHop>,
4646
}
4747

48-
/// Used to construct the blinded hops portion of a blinded route. These hops cannot be identified
48+
/// Used to construct the blinded hops portion of a blinded path. These hops cannot be identified
4949
/// by outside observers and thus can be used to hide the identity of the recipient.
5050
#[derive(Clone, Debug, PartialEq)]
5151
pub struct BlindedHop {
52-
/// The blinded node id of this hop in a blinded route.
52+
/// The blinded node id of this hop in a blinded path.
5353
pub(crate) blinded_node_id: PublicKey,
54-
/// The encrypted payload intended for this hop in a blinded route.
55-
// The node sending to this blinded route will later encode this payload into the onion packet for
54+
/// The encrypted payload intended for this hop in a blinded path.
55+
// The node sending to this blinded path will later encode this payload into the onion packet for
5656
// this hop.
5757
pub(crate) encrypted_payload: Vec<u8>,
5858
}
5959

60-
impl BlindedRoute {
61-
/// Create a blinded route to be forwarded along `node_pks`. The last node pubkey in `node_pks`
60+
impl BlindedPath {
61+
/// Create a blinded path to be forwarded along `node_pks`. The last node pubkey in `node_pks`
6262
/// will be the destination node.
6363
///
6464
/// Errors if less than two hops are provided or if `node_pk`(s) are invalid.
@@ -71,14 +71,14 @@ impl BlindedRoute {
7171
let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");
7272
let introduction_node_id = node_pks[0];
7373

74-
Ok(BlindedRoute {
74+
Ok(BlindedPath {
7575
introduction_node_id,
7676
blinding_point: PublicKey::from_secret_key(secp_ctx, &blinding_secret),
7777
blinded_hops: blinded_hops(secp_ctx, node_pks, &blinding_secret).map_err(|_| ())?,
7878
})
7979
}
8080

81-
// Advance the blinded route by one hop, so make the second hop into the new introduction node.
81+
// Advance the blinded path by one hop, so make the second hop into the new introduction node.
8282
pub(super) fn advance_by_one<K: Deref, T: secp256k1::Signing + secp256k1::Verification>
8383
(&mut self, keys_manager: &K, secp_ctx: &Secp256k1<T>) -> Result<(), ()>
8484
where K::Target: KeysInterface
@@ -156,7 +156,7 @@ fn encrypt_payload<P: Writeable>(payload: P, encrypted_tlvs_ss: [u8; 32]) -> Vec
156156
writer.0
157157
}
158158

159-
impl Writeable for BlindedRoute {
159+
impl Writeable for BlindedPath {
160160
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
161161
self.introduction_node_id.write(w)?;
162162
self.blinding_point.write(w)?;
@@ -168,7 +168,7 @@ impl Writeable for BlindedRoute {
168168
}
169169
}
170170

171-
impl Readable for BlindedRoute {
171+
impl Readable for BlindedPath {
172172
fn read<R: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
173173
let introduction_node_id = Readable::read(r)?;
174174
let blinding_point = Readable::read(r)?;
@@ -178,7 +178,7 @@ impl Readable for BlindedRoute {
178178
for _ in 0..num_hops {
179179
blinded_hops.push(Readable::read(r)?);
180180
}
181-
Ok(BlindedRoute {
181+
Ok(BlindedPath {
182182
introduction_node_id,
183183
blinding_point,
184184
blinded_hops,
@@ -196,15 +196,15 @@ impl_writeable!(BlindedHop, {
196196
pub(crate) struct ForwardTlvs {
197197
/// The node id of the next hop in the onion message's path.
198198
pub(super) next_node_id: PublicKey,
199-
/// Senders to a blinded route use this value to concatenate the route they find to the
200-
/// introduction node with the blinded route.
199+
/// Senders to a blinded path use this value to concatenate the route they find to the
200+
/// introduction node with the blinded path.
201201
pub(super) next_blinding_override: Option<PublicKey>,
202202
}
203203

204204
/// Similar to [`ForwardTlvs`], but these TLVs are for the final node.
205205
pub(crate) struct ReceiveTlvs {
206-
/// If `path_id` is `Some`, it is used to identify the blinded route that this onion message is
207-
/// sending to. This is useful for receivers to check that said blinded route is being used in
206+
/// If `path_id` is `Some`, it is used to identify the blinded path that this onion message is
207+
/// sending to. This is useful for receivers to check that said blinded path is being used in
208208
/// the right context.
209209
pub(super) path_id: Option<[u8; 32]>,
210210
}

lightning/src/onion_message/functional_tests.rs

+26-26
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use crate::chain::keysinterface::{KeysInterface, Recipient};
1313
use crate::ln::features::InitFeatures;
1414
use crate::ln::msgs::{self, DecodeError, OnionMessageHandler};
15-
use super::{BlindedRoute, CustomOnionMessageContents, CustomOnionMessageHandler, Destination, OnionMessageContents, OnionMessenger, SendError};
15+
use super::{BlindedPath, CustomOnionMessageContents, CustomOnionMessageHandler, Destination, OnionMessageContents, OnionMessenger, SendError};
1616
use crate::util::ser::{Writeable, Writer};
1717
use crate::util::test_utils;
1818

@@ -136,9 +136,9 @@ fn two_unblinded_two_blinded() {
136136
let test_msg = OnionMessageContents::Custom(TestCustomMessage {});
137137

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

141-
nodes[0].messenger.send_onion_message(&[nodes[1].get_node_pk(), nodes[2].get_node_pk()], Destination::BlindedRoute(blinded_route), test_msg, None).unwrap();
141+
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);
143143
}
144144

@@ -148,9 +148,9 @@ fn three_blinded_hops() {
148148
let test_msg = OnionMessageContents::Custom(TestCustomMessage {});
149149

150150
let secp_ctx = Secp256k1::new();
151-
let blinded_route = BlindedRoute::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(&[nodes[1].get_node_pk(), nodes[2].get_node_pk(), nodes[3].get_node_pk()], &*nodes[3].keys_manager, &secp_ctx).unwrap();
152152

153-
nodes[0].messenger.send_onion_message(&[], Destination::BlindedRoute(blinded_route), test_msg, None).unwrap();
153+
nodes[0].messenger.send_onion_message(&[], Destination::BlindedPath(blinded_path), test_msg, None).unwrap();
154154
pass_along_path(&nodes, None);
155155
}
156156

@@ -168,42 +168,42 @@ fn too_big_packet_error() {
168168

169169
#[test]
170170
fn we_are_intro_node() {
171-
// If we are sending straight to a blinded route and we are the introduction node, we need to
172-
// advance the blinded route by 1 hop so the second hop is the new introduction node.
171+
// If we are sending straight to a blinded path and we are the introduction node, we need to
172+
// advance the blinded path by 1 hop so the second hop is the new introduction node.
173173
let mut nodes = create_nodes(3);
174174
let test_msg = TestCustomMessage {};
175175

176176
let secp_ctx = Secp256k1::new();
177-
let blinded_route = BlindedRoute::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(&[nodes[0].get_node_pk(), nodes[1].get_node_pk(), nodes[2].get_node_pk()], &*nodes[2].keys_manager, &secp_ctx).unwrap();
178178

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

182-
// Try with a two-hop blinded route where we are the introduction node.
183-
let blinded_route = BlindedRoute::new(&[nodes[0].get_node_pk(), nodes[1].get_node_pk()], &*nodes[1].keys_manager, &secp_ctx).unwrap();
184-
nodes[0].messenger.send_onion_message(&[], Destination::BlindedRoute(blinded_route), OnionMessageContents::Custom(test_msg), None).unwrap();
182+
// 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();
184+
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);
187187
}
188188

189189
#[test]
190-
fn invalid_blinded_route_error() {
191-
// Make sure we error as expected if a provided blinded route has 0 or 1 hops.
190+
fn invalid_blinded_path_error() {
191+
// Make sure we error as expected if a provided blinded path has 0 or 1 hops.
192192
let nodes = create_nodes(3);
193193
let test_msg = TestCustomMessage {};
194194

195195
// 0 hops
196196
let secp_ctx = Secp256k1::new();
197-
let mut blinded_route = BlindedRoute::new(&[nodes[1].get_node_pk(), nodes[2].get_node_pk()], &*nodes[2].keys_manager, &secp_ctx).unwrap();
198-
blinded_route.blinded_hops.clear();
199-
let err = nodes[0].messenger.send_onion_message(&[], Destination::BlindedRoute(blinded_route), OnionMessageContents::Custom(test_msg.clone()), None).unwrap_err();
197+
let mut blinded_path = BlindedPath::new(&[nodes[1].get_node_pk(), nodes[2].get_node_pk()], &*nodes[2].keys_manager, &secp_ctx).unwrap();
198+
blinded_path.blinded_hops.clear();
199+
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_route = BlindedRoute::new(&[nodes[1].get_node_pk(), nodes[2].get_node_pk()], &*nodes[2].keys_manager, &secp_ctx).unwrap();
204-
blinded_route.blinded_hops.remove(0);
205-
assert_eq!(blinded_route.blinded_hops.len(), 1);
206-
let err = nodes[0].messenger.send_onion_message(&[], Destination::BlindedRoute(blinded_route), OnionMessageContents::Custom(test_msg), None).unwrap_err();
203+
let mut blinded_path = BlindedPath::new(&[nodes[1].get_node_pk(), nodes[2].get_node_pk()], &*nodes[2].keys_manager, &secp_ctx).unwrap();
204+
blinded_path.blinded_hops.remove(0);
205+
assert_eq!(blinded_path.blinded_hops.len(), 1);
206+
let err = nodes[0].messenger.send_onion_message(&[], Destination::BlindedPath(blinded_path), OnionMessageContents::Custom(test_msg), None).unwrap_err();
207207
assert_eq!(err, SendError::TooFewBlindedHops);
208208
}
209209

@@ -214,19 +214,19 @@ fn reply_path() {
214214
let secp_ctx = Secp256k1::new();
215215

216216
// Destination::Node
217-
let reply_path = BlindedRoute::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(&[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.
221221
nodes[3].logger.assert_log_contains(
222222
"lightning::onion_message::messenger".to_string(),
223223
format!("Received an onion message with path_id None and a reply_path").to_string(), 1);
224224

225-
// Destination::BlindedRoute
226-
let blinded_route = BlindedRoute::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 = BlindedRoute::new(&[nodes[2].get_node_pk(), nodes[1].get_node_pk(), nodes[0].get_node_pk()], &*nodes[0].keys_manager, &secp_ctx).unwrap();
225+
// 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();
228228

229-
nodes[0].messenger.send_onion_message(&[], Destination::BlindedRoute(blinded_route), OnionMessageContents::Custom(test_msg), Some(reply_path)).unwrap();
229+
nodes[0].messenger.send_onion_message(&[], Destination::BlindedPath(blinded_path), OnionMessageContents::Custom(test_msg), Some(reply_path)).unwrap();
230230
pass_along_path(&nodes, None);
231231
nodes[3].logger.assert_log_contains(
232232
"lightning::onion_message::messenger".to_string(),

0 commit comments

Comments
 (0)