Skip to content

Commit f7ff9c2

Browse files
f don't allow sending to blinded routes with 1 hop
1 parent cbaa448 commit f7ff9c2

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lightning/src/onion_message/functional_tests.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,21 @@ fn too_big_packet_error() {
122122

123123
#[test]
124124
fn invalid_blinded_route_error() {
125-
// Make sure we error as expected if a provided blinded route has 0 hops.
125+
// Make sure we error as expected if a provided blinded route has 0 or 1 hops.
126126
let mut nodes = create_nodes(3);
127127
let (node1, node2, node3) = (nodes.remove(0), nodes.remove(0), nodes.remove(0));
128128

129+
// 0 hops
129130
let secp_ctx = Secp256k1::new();
130131
let mut blinded_route = BlindedRoute::new::<EnforcingSigner, _, _>(&[node2.get_node_pk(), node3.get_node_pk()], &*node3.keys_manager, &secp_ctx).unwrap();
131132
blinded_route.blinded_hops.clear();
133+
let err = node1.messenger.send_onion_message(&[], Destination::BlindedRoute(blinded_route)).unwrap_err();
134+
assert_eq!(err, SendError::MissingBlindedHops);
132135

136+
// 1 hop
137+
let mut blinded_route = BlindedRoute::new::<EnforcingSigner, _, _>(&[node2.get_node_pk(), node3.get_node_pk()], &*node3.keys_manager, &secp_ctx).unwrap();
138+
blinded_route.blinded_hops.remove(0);
139+
assert_eq!(blinded_route.blinded_hops.len(), 1);
133140
let err = node1.messenger.send_onion_message(&[], Destination::BlindedRoute(blinded_route)).unwrap_err();
134141
assert_eq!(err, SendError::MissingBlindedHops);
135142
}

lightning/src/onion_message/messenger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl<Signer: Sign, K: Deref, L: Deref> OnionMessenger<Signer, K, L>
143143
/// See [`OnionMessenger`] for example usage.
144144
pub fn send_onion_message(&self, intermediate_nodes: &[PublicKey], destination: Destination) -> Result<(), SendError> {
145145
if let Destination::BlindedRoute(BlindedRoute { ref blinded_hops, .. }) = destination {
146-
if blinded_hops.is_empty() {
146+
if blinded_hops.len() < 2 {
147147
return Err(SendError::MissingBlindedHops);
148148
}
149149
}

0 commit comments

Comments
 (0)