@@ -342,6 +342,8 @@ where
342
342
& self , recipient : PublicKey , peers : Vec < PublicKey > , entropy_source : & ES ,
343
343
secp_ctx : & Secp256k1 < T >
344
344
) -> Result < Vec < BlindedPath > , ( ) > {
345
+ let recipient_node_id = NodeId :: from_pubkey ( & recipient) ;
346
+
345
347
// Limit the number of blinded paths that are computed.
346
348
const MAX_PATHS : usize = 3 ;
347
349
@@ -351,15 +353,35 @@ where
351
353
352
354
let network_graph = self . network_graph . deref ( ) . read_only ( ) ;
353
355
peers. into_iter ( )
356
+ . map ( |pubkey| ( pubkey, NodeId :: from_pubkey ( & pubkey) ) )
354
357
// Limit to peers with announced channels
355
- . filter ( | pubkey|
358
+ . filter_map ( | ( pubkey, node_id ) |
356
359
network_graph
357
- . node ( & NodeId :: from_pubkey ( & pubkey ) )
360
+ . node ( & node_id )
358
361
. 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) )
361
383
)
362
- . map ( |pubkey| vec ! [ pubkey, recipient] )
384
+ . map ( |( source_pubkey , pubkey) | vec ! [ source_pubkey , pubkey, recipient] )
363
385
. map ( |node_pks| BlindedPath :: new_for_message ( & node_pks, entropy_source, secp_ctx) )
364
386
. take ( MAX_PATHS )
365
387
. collect ( )
0 commit comments