Skip to content

Commit c4ba79f

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 fcd8a11 commit c4ba79f

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
@@ -154,8 +154,12 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, S: Deref, SP: Sized,
154154
match paths {
155155
Ok(paths) if !paths.is_empty() => Ok(paths),
156156
_ => {
157-
BlindedPath::one_hop_for_payment(recipient, tlvs, entropy_source, secp_ctx)
158-
.map(|path| vec![path])
157+
if network_graph.nodes().contains_key(&NodeId::from_pubkey(&recipient)) {
158+
BlindedPath::one_hop_for_payment(recipient, tlvs, entropy_source, secp_ctx)
159+
.map(|path| vec![path])
160+
} else {
161+
Err(())
162+
}
159163
},
160164
}
161165
}

0 commit comments

Comments
 (0)