Skip to content

Commit cc798a8

Browse files
committed
Use one-hop blinded paths only for announced nodes
To avoid exposing a node's identity in a blinded path, only create one-hop blinded paths if the node has been announced, and thus has public channels. Otherwise, there is no way to route a payment to the node, exposing its identity needlessly.
1 parent 56f457c commit cc798a8

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lightning/src/onion_message/messenger.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -350,25 +350,29 @@ where
350350
const MIN_PEER_CHANNELS: usize = 3;
351351

352352
let network_graph = self.network_graph.deref().read_only();
353-
let paths = peers.into_iter()
353+
let paths = peers.iter()
354354
// Limit to peers with announced channels
355355
.filter(|pubkey|
356356
network_graph
357-
.node(&NodeId::from_pubkey(&pubkey))
357+
.node(&NodeId::from_pubkey(pubkey))
358358
.map(|info| &info.channels[..])
359359
.map(|channels| channels.len() >= MIN_PEER_CHANNELS)
360360
.unwrap_or(false)
361361
)
362-
.map(|pubkey| vec![pubkey, recipient])
362+
.map(|pubkey| vec![*pubkey, recipient])
363363
.map(|node_pks| BlindedPath::new_for_message(&node_pks, entropy_source, secp_ctx))
364364
.take(MAX_PATHS)
365365
.collect::<Result<Vec<_>, _>>();
366366

367367
match paths {
368368
Ok(paths) if !paths.is_empty() => Ok(paths),
369369
_ => {
370-
BlindedPath::one_hop_for_message(recipient, entropy_source, secp_ctx)
371-
.map(|path| vec![path])
370+
if network_graph.nodes().contains_key(&NodeId::from_pubkey(&recipient)) {
371+
BlindedPath::one_hop_for_message(recipient, entropy_source, secp_ctx)
372+
.map(|path| vec![path])
373+
} else {
374+
Err(())
375+
}
372376
},
373377
}
374378
}

lightning/src/routing/router.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,12 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, S: Deref, SP: Sized,
153153
match paths {
154154
Ok(paths) if !paths.is_empty() => Ok(paths),
155155
_ => {
156-
BlindedPath::one_hop_for_payment(recipient, tlvs, entropy_source, secp_ctx)
157-
.map(|path| vec![path])
156+
if network_graph.nodes().contains_key(&NodeId::from_pubkey(&recipient)) {
157+
BlindedPath::one_hop_for_payment(recipient, tlvs, entropy_source, secp_ctx)
158+
.map(|path| vec![path])
159+
} else {
160+
Err(())
161+
}
158162
},
159163
}
160164
}

0 commit comments

Comments
 (0)