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