@@ -1025,39 +1025,34 @@ where
1025
1025
}
1026
1026
}
1027
1027
1028
- let ( num_blinded_hops, num_trampoline_hops) =
1029
- path. blinded_tail . as_ref ( ) . map_or ( ( 0 , 0 ) , |bt| ( bt. hops . len ( ) , bt. trampoline_hops . len ( ) ) ) ;
1030
-
1031
- // We are first collecting all the unblinded `RouteHop`s inside `onion_keys`. Then, if applicable,
1032
- // we will add all the `TrampolineHop`s, and finally, the blinded hops.
1033
- let mut onion_keys =
1034
- Vec :: with_capacity ( path. hops . len ( ) + num_trampoline_hops + num_blinded_hops) ;
1028
+ let num_blinded_hops = path. blinded_tail . as_ref ( ) . map_or ( 0 , |bt| bt. hops . len ( ) ) ;
1035
1029
1036
1030
// if we have Trampoline hops, the blinded hops are part of the inner Trampoline onion
1037
1031
let nontrampoline_bp =
1038
1032
if path. has_trampoline_hops ( ) { None } else { path. blinded_tail . as_ref ( ) } ;
1039
1033
let nontrampoline_hops =
1040
- construct_onion_keys_generic ( secp_ctx, & path. hops , nontrampoline_bp, outer_session_priv) ;
1041
- for ( shared_secret, _, _, route_hop_option, _) in nontrampoline_hops {
1042
- onion_keys . push ( ( route_hop_option. map ( |rh| ErrorHop :: RouteHop ( rh) ) , shared_secret) ) ;
1043
- }
1034
+ construct_onion_keys_generic ( secp_ctx, & path. hops , nontrampoline_bp, outer_session_priv)
1035
+ . map ( | ( shared_secret, _, _, route_hop_option, _) | {
1036
+ ( route_hop_option. map ( |rh| ErrorHop :: RouteHop ( rh) ) , shared_secret)
1037
+ } ) ;
1044
1038
1045
- if path. has_trampoline_hops ( ) {
1039
+ let trampoline_hops = if path. has_trampoline_hops ( ) {
1046
1040
// Trampoline hops are part of the blinded tail, so this can never panic
1047
1041
let blinded_tail = path. blinded_tail . as_ref ( ) ;
1048
1042
let hops = & blinded_tail. unwrap ( ) . trampoline_hops ;
1049
1043
let inner_session_priv =
1050
1044
inner_session_priv. expect ( "Trampoline hops always have an inner session priv" ) ;
1051
- let trampoline_hops =
1052
- construct_onion_keys_generic ( secp_ctx, hops, blinded_tail, inner_session_priv) ;
1053
- for ( shared_secret, _, _, trampoline_hop_option, _) in trampoline_hops {
1054
- onion_keys
1055
- . push ( ( trampoline_hop_option. map ( |th| ErrorHop :: TrampolineHop ( th) ) , shared_secret) ) ;
1056
- }
1057
- }
1045
+ Some ( construct_onion_keys_generic ( secp_ctx, hops, blinded_tail, inner_session_priv) . map (
1046
+ |( shared_secret, _, _, route_hop_option, _) | {
1047
+ ( route_hop_option. map ( |th| ErrorHop :: TrampolineHop ( th) ) , shared_secret)
1048
+ } ,
1049
+ ) )
1050
+ } else {
1051
+ None
1052
+ } ;
1058
1053
1059
1054
// Handle packed channel/node updates for passing back for the route handler
1060
- let mut iterator = onion_keys . into_iter ( ) . peekable ( ) ;
1055
+ let mut iterator = nontrampoline_hops . chain ( trampoline_hops . into_iter ( ) . flatten ( ) ) . peekable ( ) ;
1061
1056
while let Some ( ( route_hop_option, shared_secret) ) = iterator. next ( ) {
1062
1057
let route_hop = match route_hop_option. as_ref ( ) {
1063
1058
Some ( hop) => hop,
0 commit comments