@@ -2333,47 +2333,38 @@ where L::Target: Logger {
2333
2333
}
2334
2334
}
2335
2335
2336
- let mut selected_paths = Vec :: < Vec < Result < RouteHop , LightningError > > > :: new ( ) ;
2336
+ let mut paths = Vec :: new ( ) ;
2337
2337
for payment_path in selected_route {
2338
- let mut path = payment_path. hops . iter ( ) . filter ( |( h, _) | h. candidate . short_channel_id ( ) . is_some ( ) )
2339
- . map ( |( payment_hop, node_features) | {
2340
- Ok ( RouteHop {
2341
- pubkey : PublicKey :: from_slice ( payment_hop. node_id . as_slice ( ) ) . map_err ( |_| LightningError { err : format ! ( "Public key {:?} is invalid" , & payment_hop. node_id) , action : ErrorAction :: IgnoreAndLog ( Level :: Trace ) } ) ?,
2342
- node_features : node_features. clone ( ) ,
2343
- short_channel_id : payment_hop. candidate . short_channel_id ( ) . unwrap ( ) ,
2344
- channel_features : payment_hop. candidate . features ( ) ,
2345
- fee_msat : payment_hop. fee_msat ,
2346
- cltv_expiry_delta : payment_hop. candidate . cltv_expiry_delta ( ) ,
2347
- } )
2348
- } ) . collect :: < Vec < _ > > ( ) ;
2338
+ let mut hops = Vec :: with_capacity ( payment_path. hops . len ( ) ) ;
2339
+ for ( hop, node_features) in payment_path. hops . iter ( )
2340
+ . filter ( |( h, _) | h. candidate . short_channel_id ( ) . is_some ( ) )
2341
+ {
2342
+ hops. push ( RouteHop {
2343
+ pubkey : PublicKey :: from_slice ( hop. node_id . as_slice ( ) ) . map_err ( |_| LightningError { err : format ! ( "Public key {:?} is invalid" , & hop. node_id) , action : ErrorAction :: IgnoreAndLog ( Level :: Trace ) } ) ?,
2344
+ node_features : node_features. clone ( ) ,
2345
+ short_channel_id : hop. candidate . short_channel_id ( ) . unwrap ( ) ,
2346
+ channel_features : hop. candidate . features ( ) ,
2347
+ fee_msat : hop. fee_msat ,
2348
+ cltv_expiry_delta : hop. candidate . cltv_expiry_delta ( ) ,
2349
+ } ) ;
2350
+ }
2349
2351
// Propagate the cltv_expiry_delta one hop backwards since the delta from the current hop is
2350
2352
// applicable for the previous hop.
2351
- path . iter_mut ( ) . rev ( ) . fold ( final_cltv_expiry_delta, |prev_cltv_expiry_delta, hop| {
2352
- core:: mem:: replace ( & mut hop. as_mut ( ) . unwrap ( ) . cltv_expiry_delta , prev_cltv_expiry_delta)
2353
+ hops . iter_mut ( ) . rev ( ) . fold ( final_cltv_expiry_delta, |prev_cltv_expiry_delta, hop| {
2354
+ core:: mem:: replace ( & mut hop. cltv_expiry_delta , prev_cltv_expiry_delta)
2353
2355
} ) ;
2354
- selected_paths . push ( path ) ;
2356
+ paths . push ( Path { hops , blinded_tail : None } ) ;
2355
2357
}
2356
2358
// Make sure we would never create a route with more paths than we allow.
2357
- debug_assert ! ( selected_paths . len( ) <= payment_params. max_path_count. into( ) ) ;
2359
+ debug_assert ! ( paths . len( ) <= payment_params. max_path_count. into( ) ) ;
2358
2360
2359
2361
if let Some ( node_features) = payment_params. payee . node_features ( ) {
2360
- for path in selected_paths. iter_mut ( ) {
2361
- if let Ok ( route_hop) = path. last_mut ( ) . unwrap ( ) {
2362
- route_hop. node_features = node_features. clone ( ) ;
2363
- }
2362
+ for path in paths. iter_mut ( ) {
2363
+ path. hops . last_mut ( ) . unwrap ( ) . node_features = node_features. clone ( ) ;
2364
2364
}
2365
2365
}
2366
2366
2367
- let mut paths: Vec < Path > = Vec :: new ( ) ;
2368
- for results_vec in selected_paths {
2369
- let mut hops = Vec :: with_capacity ( results_vec. len ( ) ) ;
2370
- for res in results_vec { hops. push ( res?) ; }
2371
- paths. push ( Path { hops, blinded_tail : None } ) ;
2372
- }
2373
- let route = Route {
2374
- paths,
2375
- payment_params : Some ( payment_params. clone ( ) ) ,
2376
- } ;
2367
+ let route = Route { paths, payment_params : Some ( payment_params. clone ( ) ) } ;
2377
2368
log_info ! ( logger, "Got route: {}" , log_route!( route) ) ;
2378
2369
Ok ( route)
2379
2370
}
0 commit comments