Skip to content

Commit 5b39bec

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 2255665 commit 5b39bec

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

lightning/src/onion_message/messenger.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,25 @@ where
571571
// recipient's node_id.
572572
const MIN_PEER_CHANNELS: usize = 3;
573573

574+
// Add a random number (0 to `MAX_DUMMY_HOPS`) of dummy hops to each non-compact blinded path
575+
// to make it harder to infer the recipient's position.
576+
//
577+
// # Note on compact paths:
578+
//
579+
// Compact paths are optimized for minimal size. Adding dummy hops to them
580+
// would increase their size and undermine their primary advantage.
581+
// Therefore, we avoid adding dummy hops to compact paths.
582+
const MAX_DUMMY_HOPS: usize = 3;
583+
584+
let dummy_hops_count = if compact_paths {
585+
0
586+
} else {
587+
{
588+
let random_byte: usize = entropy_source.get_secure_random_bytes()[0].into();
589+
random_byte % (MAX_DUMMY_HOPS + 1)
590+
}
591+
};
592+
574593
let network_graph = network_graph.deref().read_only();
575594
let is_recipient_announced =
576595
network_graph.nodes().contains_key(&NodeId::from_pubkey(&recipient));
@@ -605,9 +624,10 @@ where
605624
let paths = peer_info
606625
.into_iter()
607626
.map(|(peer, _, _)| {
608-
BlindedMessagePath::new(
627+
BlindedMessagePath::new_with_dummy_hops(
609628
&[peer],
610629
recipient,
630+
dummy_hops_count,
611631
local_node_receive_key,
612632
context.clone(),
613633
entropy,
@@ -621,9 +641,10 @@ where
621641
Ok(paths) if !paths.is_empty() => Ok(paths),
622642
_ => {
623643
if is_recipient_announced {
624-
BlindedMessagePath::new(
644+
BlindedMessagePath::new_with_dummy_hops(
625645
&[],
626646
recipient,
647+
dummy_hops_count,
627648
local_node_receive_key,
628649
context,
629650
&**entropy_source,

0 commit comments

Comments
 (0)