Skip to content

Commit 7394bbe

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 1965df3 commit 7394bbe

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lightning/src/onion_message/messenger.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use bitcoin::hashes::sha256::Hash as Sha256;
1515
use bitcoin::hashes::{Hash, HashEngine};
1616
use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1, SecretKey};
1717

18+
use rand::Rng;
19+
1820
#[cfg(async_payments)]
1921
use super::async_payments::AsyncPaymentsMessage;
2022
use super::async_payments::AsyncPaymentsMessageHandler;
@@ -563,6 +565,10 @@ where
563565
// recipient's node_id.
564566
const MIN_PEER_CHANNELS: usize = 3;
565567

568+
// Add a random number (1 to 5) of dummy hops to each blinded path
569+
// to make it harder to infer the recipient's position.
570+
let dummy_hops_count = rand::thread_rng().gen_range(1..5);
571+
566572
let network_graph = network_graph.deref().read_only();
567573
let is_recipient_announced =
568574
network_graph.nodes().contains_key(&NodeId::from_pubkey(&recipient));
@@ -602,8 +608,15 @@ where
602608
Ok(paths) if !paths.is_empty() => Ok(paths),
603609
_ => {
604610
if is_recipient_announced {
605-
BlindedMessagePath::new(&[], recipient, context, &**entropy_source, secp_ctx)
606-
.map(|path| vec![path])
611+
BlindedMessagePath::new_with_dummy_hops(
612+
&[],
613+
dummy_hops_count,
614+
recipient,
615+
context,
616+
&**entropy_source,
617+
secp_ctx,
618+
)
619+
.map(|path| vec![path])
607620
} else {
608621
Err(())
609622
}

0 commit comments

Comments
 (0)