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