@@ -350,6 +350,8 @@ where
350
350
& self , recipient : PublicKey , peers : Vec < PublicKey > , entropy_source : & ES ,
351
351
secp_ctx : & Secp256k1 < T >
352
352
) -> Result < Vec < BlindedPath > , ( ) > {
353
+ let recipient_node_id = NodeId :: from_pubkey ( & recipient) ;
354
+
353
355
// Limit the number of blinded paths that are computed.
354
356
const MAX_PATHS : usize = 3 ;
355
357
@@ -359,15 +361,35 @@ where
359
361
360
362
let network_graph = self . network_graph . deref ( ) . read_only ( ) ;
361
363
let paths = peers. iter ( )
364
+ . map ( |pubkey| ( pubkey, NodeId :: from_pubkey ( & pubkey) ) )
362
365
// Limit to peers with announced channels
363
- . filter ( | pubkey|
366
+ . filter_map ( | ( pubkey, node_id ) |
364
367
network_graph
365
- . node ( & NodeId :: from_pubkey ( pubkey ) )
368
+ . node ( & node_id )
366
369
. map ( |info| & info. channels [ ..] )
367
- . map ( |channels| channels. len ( ) >= MIN_PEER_CHANNELS )
368
- . unwrap_or ( false )
370
+ . and_then ( |channels| ( channels. len ( ) >= MIN_PEER_CHANNELS ) . then ( || channels) )
371
+ . map ( |channels| ( pubkey, node_id, channels) )
372
+ )
373
+ // Pair peers with their other peers
374
+ . flat_map ( |( pubkey, node_id, channels) |
375
+ channels
376
+ . iter ( )
377
+ . filter_map ( |scid| network_graph. channels ( ) . get ( scid) )
378
+ . filter_map ( move |info| info
379
+ . as_directed_to ( & node_id)
380
+ . map ( |( _, source) | source)
381
+ )
382
+ . filter ( |source| * * source != recipient_node_id)
383
+ . filter ( |source| network_graph
384
+ . node ( source)
385
+ . and_then ( |info| info. announcement_info . as_ref ( ) )
386
+ . map ( |info| info. features . supports_onion_messages ( ) )
387
+ . unwrap_or ( false )
388
+ )
389
+ . filter_map ( |source| source. as_pubkey ( ) . ok ( ) )
390
+ . map ( move |source_pubkey| ( source_pubkey, * pubkey) )
369
391
)
370
- . map ( |pubkey| vec ! [ * pubkey, recipient] )
392
+ . map ( |( source_pubkey , pubkey) | vec ! [ source_pubkey , pubkey, recipient] )
371
393
. map ( |node_pks| BlindedPath :: new_for_message ( & node_pks, entropy_source, secp_ctx) )
372
394
. take ( MAX_PATHS )
373
395
. collect :: < Result < Vec < _ > , _ > > ( ) ;
0 commit comments