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