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