@@ -1095,44 +1095,39 @@ where
1095
1095
}
1096
1096
}
1097
1097
1098
- let ( num_blinded_hops, num_trampoline_hops) =
1099
- path. blinded_tail . as_ref ( ) . map_or ( ( 0 , 0 ) , |bt| ( bt. hops . len ( ) , bt. trampoline_hops . len ( ) ) ) ;
1100
-
1101
- // We are first collecting all the unblinded `RouteHop`s inside `onion_keys`. Then, if applicable,
1102
- // we will add all the `TrampolineHop`s, and finally, the blinded hops.
1103
- let mut onion_keys =
1104
- Vec :: with_capacity ( path. hops . len ( ) + num_trampoline_hops + num_blinded_hops) ;
1098
+ let num_blinded_hops = path. blinded_tail . as_ref ( ) . map_or ( 0 , |bt| bt. hops . len ( ) ) ;
1105
1099
1106
1100
// if we have Trampoline hops, the blinded hops are part of the inner Trampoline onion
1107
- let nontrampoline_bp =
1101
+ let nontrampoline_bt =
1108
1102
if path. has_trampoline_hops ( ) { None } else { path. blinded_tail . as_ref ( ) } ;
1109
- let nontrampoline_hops =
1110
- construct_onion_keys_generic ( secp_ctx, & path. hops , nontrampoline_bp , outer_session_priv) ;
1111
- for ( shared_secret, _, _, route_hop_option, _) in nontrampoline_hops {
1112
- onion_keys . push ( ( route_hop_option. map ( |rh| ErrorHop :: RouteHop ( rh) ) , shared_secret) ) ;
1113
- }
1103
+ let nontrampolines =
1104
+ construct_onion_keys_generic ( secp_ctx, & path. hops , nontrampoline_bt , outer_session_priv)
1105
+ . map ( | ( shared_secret, _, _, route_hop_option, _) | {
1106
+ ( route_hop_option. map ( |rh| ErrorHop :: RouteHop ( rh) ) , shared_secret)
1107
+ } ) ;
1114
1108
1115
- if path. has_trampoline_hops ( ) {
1109
+ let trampolines = if path. has_trampoline_hops ( ) {
1116
1110
// Trampoline hops are part of the blinded tail, so this can never panic
1117
1111
let blinded_tail = path. blinded_tail . as_ref ( ) ;
1118
1112
let hops = & blinded_tail. unwrap ( ) . trampoline_hops ;
1119
1113
let inner_session_priv =
1120
1114
inner_session_priv. expect ( "Trampoline hops always have an inner session priv" ) ;
1121
- let trampoline_hops =
1122
- construct_onion_keys_generic ( secp_ctx, hops, blinded_tail, inner_session_priv) ;
1123
- for ( shared_secret, _, _, trampoline_hop_option, _) in trampoline_hops {
1124
- onion_keys
1125
- . push ( ( trampoline_hop_option. map ( |th| ErrorHop :: TrampolineHop ( th) ) , shared_secret) ) ;
1126
- }
1127
- }
1115
+ Some ( construct_onion_keys_generic ( secp_ctx, hops, blinded_tail, inner_session_priv) . map (
1116
+ |( shared_secret, _, _, route_hop_option, _) | {
1117
+ ( route_hop_option. map ( |tram_hop| ErrorHop :: TrampolineHop ( tram_hop) ) , shared_secret)
1118
+ } ,
1119
+ ) )
1120
+ } else {
1121
+ None
1122
+ } ;
1128
1123
1129
1124
// In the best case, paths can be up to 27 hops. But attribution data can only be conveyed back to the sender from
1130
1125
// the first 20 hops. Determine the number of hops to be used for attribution data.
1131
1126
let attributable_hop_count = usize:: min ( path. hops . len ( ) , MAX_HOPS ) ;
1132
1127
1133
1128
// Handle packed channel/node updates for passing back for the route handler
1134
- let mut iterator = onion_keys . into_iter ( ) . enumerate ( ) . peekable ( ) ;
1135
- while let Some ( ( route_hop_idx, ( route_hop_option, shared_secret) ) ) = iterator . next ( ) {
1129
+ let mut iter = nontrampolines . chain ( trampolines . into_iter ( ) . flatten ( ) ) . enumerate ( ) . peekable ( ) ;
1130
+ while let Some ( ( route_hop_idx, ( route_hop_option, shared_secret) ) ) = iter . next ( ) {
1136
1131
let route_hop = match route_hop_option. as_ref ( ) {
1137
1132
Some ( hop) => hop,
1138
1133
None => {
0 commit comments