Skip to content

Commit 30d4406

Browse files
committed
f - only use three-hop for compact paths
1 parent a0bbec3 commit 30d4406

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lightning/src/onion_message/messenger.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@ pub trait MessageRouter {
459459

460460
/// A [`MessageRouter`] that can only route to a directly connected [`Destination`].
461461
///
462+
/// When creating [`BlindedPath`]s, prefers three-hop paths over two-hops paths for the compact
463+
/// representation. For the non-compact representation, three-hop paths are not considered.
464+
///
462465
/// # Privacy
463466
///
464467
/// Creating [`BlindedPath`]s may affect privacy since, if a suitable path cannot be found, it will
@@ -550,8 +553,10 @@ where
550553
.map(|(_, peer, _, _)| BlindedPath::new_for_message(&[peer.clone()], recipient, entropy_source, secp_ctx))
551554
.take(MAX_PATHS);
552555

553-
let mut paths = three_hop_paths
554-
.collect::<Result<Vec<_>, _>>().ok()
556+
// Prefer three-hop paths over two-hop paths for compact paths. Fallback to a one-hop path
557+
// if none were found and the recipient node is announced.
558+
let mut paths = (!compact_paths).then(|| vec![])
559+
.or_else(|| three_hop_paths.collect::<Result<Vec<_>, _>>().ok())
555560
.and_then(|paths| (!paths.is_empty()).then(|| paths))
556561
.or_else(|| two_hop_paths.collect::<Result<Vec<_>, _>>().ok())
557562
.and_then(|paths| (!paths.is_empty()).then(|| paths))

0 commit comments

Comments
 (0)