Skip to content

Commit fa07c1f

Browse files
committed
WIP: three-hop blinded paths
1 parent 37994bc commit fa07c1f

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

lightning/src/onion_message/messenger.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ where
342342
&self, recipient: PublicKey, peers: Vec<PublicKey>, entropy_source: &ES,
343343
secp_ctx: &Secp256k1<T>
344344
) -> Result<Vec<BlindedPath>, ()> {
345+
let recipient_node_id = NodeId::from_pubkey(&recipient);
346+
345347
// Limit the number of blinded paths that are computed.
346348
const MAX_PATHS: usize = 3;
347349

@@ -351,15 +353,35 @@ where
351353

352354
let network_graph = self.network_graph.deref().read_only();
353355
peers.into_iter()
356+
.map(|pubkey| (pubkey, NodeId::from_pubkey(&pubkey)))
354357
// Limit to peers with announced channels
355-
.filter(|pubkey|
358+
.filter_map(|(pubkey, node_id)|
356359
network_graph
357-
.node(&NodeId::from_pubkey(&pubkey))
360+
.node(&node_id)
358361
.map(|info| &info.channels[..])
359-
.map(|channels| channels.len() >= MIN_PEER_CHANNELS)
360-
.unwrap_or(false)
362+
.and_then(|channels| (channels.len() >= MIN_PEER_CHANNELS).then(|| channels))
363+
.map(|channels| (pubkey, node_id, channels))
364+
)
365+
// Pair peers with their other peers
366+
.flat_map(|(pubkey, node_id, channels)|
367+
channels
368+
.iter()
369+
.filter_map(|scid| network_graph.channels().get(scid))
370+
.filter_map(move |info| info
371+
.as_directed_to(&node_id)
372+
.map(|(_, source)| source)
373+
)
374+
.filter(|source| **source != recipient_node_id)
375+
.filter(|source| network_graph
376+
.node(source)
377+
.and_then(|info| info.announcement_info.as_ref())
378+
.map(|info| info.features.supports_onion_messages())
379+
.unwrap_or(false)
380+
)
381+
.filter_map(|source| source.as_pubkey().ok())
382+
.map(move |source_pubkey| (source_pubkey, pubkey))
361383
)
362-
.map(|pubkey| vec![pubkey, recipient])
384+
.map(|(source_pubkey, pubkey)| vec![source_pubkey, pubkey, recipient])
363385
.map(|node_pks| BlindedPath::new_for_message(&node_pks, entropy_source, secp_ctx))
364386
.take(MAX_PATHS)
365387
.collect()

0 commit comments

Comments
 (0)