Skip to content

Commit 4506256

Browse files
committed
Update Default Blinded Path constructor to use Dummy Hops
Applies dummy hops by default when constructing blinded paths via `DefaultMessageRouter`, enhancing privacy by obscuring the true path length. Uses a predefined `DUMMY_HOPS_COUNT` to apply dummy hops consistently without requiring explicit user input.
1 parent 58a0c13 commit 4506256

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lightning/src/onion_message/messenger.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,13 @@ where
563563
// recipient's node_id.
564564
const MIN_PEER_CHANNELS: usize = 3;
565565

566+
// Add a random number (1 to 5) of dummy hops to each non-compact blinded path
567+
// to make it harder to infer the recipient's position.
568+
let dummy_hops_count = compact_paths.then_some(0).unwrap_or_else(|| {
569+
let random_byte = entropy_source.get_secure_random_bytes()[0];
570+
(random_byte % 5) + 1
571+
});
572+
566573
let network_graph = network_graph.deref().read_only();
567574
let is_recipient_announced =
568575
network_graph.nodes().contains_key(&NodeId::from_pubkey(&recipient));
@@ -602,8 +609,15 @@ where
602609
Ok(paths) if !paths.is_empty() => Ok(paths),
603610
_ => {
604611
if is_recipient_announced {
605-
BlindedMessagePath::new(&[], recipient, context, &**entropy_source, secp_ctx)
606-
.map(|path| vec![path])
612+
BlindedMessagePath::new_with_dummy_hops(
613+
&[],
614+
dummy_hops_count,
615+
recipient,
616+
context,
617+
&**entropy_source,
618+
secp_ctx,
619+
)
620+
.map(|path| vec![path])
607621
} else {
608622
Err(())
609623
}

0 commit comments

Comments
 (0)