@@ -965,44 +965,48 @@ where
965
965
}
966
966
let mut res: Option < FailureLearnings > = None ;
967
967
let mut htlc_msat = * first_hop_htlc_msat;
968
- let mut error_code_ret = None ;
969
- let mut error_packet_ret = None ;
968
+ let mut _error_code_ret = None ;
969
+ let mut _error_packet_ret = None ;
970
970
let mut is_from_final_node = false ;
971
971
972
972
const BADONION : u16 = 0x8000 ;
973
973
const PERM : u16 = 0x4000 ;
974
974
const NODE : u16 = 0x2000 ;
975
975
const UPDATE : u16 = 0x1000 ;
976
976
977
- // Handle packed channel/node updates for passing back for the route handler
978
- let callback = |shared_secret : SharedSecret ,
979
- _,
980
- _,
981
- route_hop_opt : Option < & RouteHop > ,
982
- route_hop_idx| {
983
- if res. is_some ( ) {
984
- return ;
985
- }
977
+ let num_blinded_hops = path. blinded_tail . as_ref ( ) . map_or ( 0 , |bt| bt. hops . len ( ) ) ;
978
+ let mut onion_keys = Vec :: with_capacity ( path. hops . len ( ) + num_blinded_hops) ;
979
+ construct_onion_keys_generic_callback (
980
+ secp_ctx,
981
+ & path. hops ,
982
+ path. blinded_tail . as_ref ( ) ,
983
+ session_priv,
984
+ |shared_secret, _, _, route_hop_option : Option < & RouteHop > , _| {
985
+ onion_keys. push ( ( route_hop_option. cloned ( ) , shared_secret) )
986
+ } ,
987
+ )
988
+ . expect ( "Route we used spontaneously grew invalid keys in the middle of it?" ) ;
986
989
987
- let route_hop = match route_hop_opt {
990
+ // Handle packed channel/node updates for passing back for the route handler
991
+ for ( route_hop_idx, ( route_hop_option, shared_secret) ) in onion_keys. into_iter ( ) . enumerate ( ) {
992
+ let route_hop = match route_hop_option. as_ref ( ) {
988
993
Some ( hop) => hop,
989
994
None => {
990
995
// Got an error from within a blinded route.
991
- error_code_ret = Some ( BADONION | PERM | 24 ) ; // invalid_onion_blinding
992
- error_packet_ret = Some ( vec ! [ 0 ; 32 ] ) ;
996
+ _error_code_ret = Some ( BADONION | PERM | 24 ) ; // invalid_onion_blinding
997
+ _error_packet_ret = Some ( vec ! [ 0 ; 32 ] ) ;
993
998
res = Some ( FailureLearnings {
994
999
network_update : None ,
995
1000
short_channel_id : None ,
996
1001
payment_failed_permanently : false ,
997
1002
failed_within_blinded_path : true ,
998
1003
} ) ;
999
- return ;
1004
+ break ;
1000
1005
} ,
1001
1006
} ;
1002
1007
1003
1008
// The failing hop includes either the inbound channel to the recipient or the outbound channel
1004
1009
// from the current hop (i.e., the next hop's inbound channel).
1005
- let num_blinded_hops = path. blinded_tail . as_ref ( ) . map_or ( 0 , |bt| bt. hops . len ( ) ) ;
1006
1010
// For 1-hop blinded paths, the final `path.hops` entry is the recipient.
1007
1011
is_from_final_node = route_hop_idx + 1 == path. hops . len ( ) && num_blinded_hops <= 1 ;
1008
1012
let failing_route_hop = if is_from_final_node {
@@ -1014,8 +1018,8 @@ where
1014
1018
// The failing hop is within a multi-hop blinded path.
1015
1019
#[ cfg( not( test) ) ]
1016
1020
{
1017
- error_code_ret = Some ( BADONION | PERM | 24 ) ; // invalid_onion_blinding
1018
- error_packet_ret = Some ( vec ! [ 0 ; 32 ] ) ;
1021
+ _error_code_ret = Some ( BADONION | PERM | 24 ) ; // invalid_onion_blinding
1022
+ _error_packet_ret = Some ( vec ! [ 0 ; 32 ] ) ;
1019
1023
}
1020
1024
#[ cfg( test) ]
1021
1025
{
@@ -1026,10 +1030,10 @@ where
1026
1030
& encrypted_packet. data ,
1027
1031
) )
1028
1032
. unwrap ( ) ;
1029
- error_code_ret = Some ( u16:: from_be_bytes (
1033
+ _error_code_ret = Some ( u16:: from_be_bytes (
1030
1034
err_packet. failuremsg . get ( 0 ..2 ) . unwrap ( ) . try_into ( ) . unwrap ( ) ,
1031
1035
) ) ;
1032
- error_packet_ret = Some ( err_packet. failuremsg [ 2 ..] . to_vec ( ) ) ;
1036
+ _error_packet_ret = Some ( err_packet. failuremsg [ 2 ..] . to_vec ( ) ) ;
1033
1037
}
1034
1038
1035
1039
res = Some ( FailureLearnings {
@@ -1038,7 +1042,7 @@ where
1038
1042
payment_failed_permanently : false ,
1039
1043
failed_within_blinded_path : true ,
1040
1044
} ) ;
1041
- return ;
1045
+ break ;
1042
1046
} ,
1043
1047
}
1044
1048
} ;
@@ -1053,7 +1057,7 @@ where
1053
1057
hmac. input ( & encrypted_packet. data [ 32 ..] ) ;
1054
1058
1055
1059
if !fixed_time_eq ( & Hmac :: from_engine ( hmac) . to_byte_array ( ) , & encrypted_packet. data [ ..32 ] ) {
1056
- return ;
1060
+ continue ;
1057
1061
}
1058
1062
1059
1063
let err_packet =
@@ -1073,7 +1077,7 @@ where
1073
1077
payment_failed_permanently : is_from_final_node,
1074
1078
failed_within_blinded_path : false ,
1075
1079
} ) ;
1076
- return ;
1080
+ break ;
1077
1081
} ,
1078
1082
} ;
1079
1083
@@ -1095,13 +1099,13 @@ where
1095
1099
payment_failed_permanently : is_from_final_node,
1096
1100
failed_within_blinded_path : false ,
1097
1101
} ) ;
1098
- return ;
1102
+ break ;
1099
1103
} ,
1100
1104
} ;
1101
1105
1102
1106
let error_code = u16:: from_be_bytes ( error_code_slice. try_into ( ) . expect ( "len is 2" ) ) ;
1103
- error_code_ret = Some ( error_code) ;
1104
- error_packet_ret = Some ( err_packet. failuremsg [ 2 ..] . to_vec ( ) ) ;
1107
+ _error_code_ret = Some ( error_code) ;
1108
+ _error_packet_ret = Some ( err_packet. failuremsg [ 2 ..] . to_vec ( ) ) ;
1105
1109
1106
1110
let ( debug_field, debug_field_size) = errors:: get_onion_debug_field ( error_code) ;
1107
1111
@@ -1212,16 +1216,9 @@ where
1212
1216
description
1213
1217
) ;
1214
1218
}
1215
- } ;
1216
1219
1217
- construct_onion_keys_generic_callback (
1218
- secp_ctx,
1219
- & path. hops ,
1220
- path. blinded_tail . as_ref ( ) ,
1221
- session_priv,
1222
- callback,
1223
- )
1224
- . expect ( "Route we used spontaneously grew invalid keys in the middle of it?" ) ;
1220
+ break ;
1221
+ }
1225
1222
1226
1223
if let Some ( FailureLearnings {
1227
1224
network_update,
@@ -1236,9 +1233,9 @@ where
1236
1233
payment_failed_permanently,
1237
1234
failed_within_blinded_path,
1238
1235
#[ cfg( any( test, feature = "_test_utils" ) ) ]
1239
- onion_error_code : error_code_ret ,
1236
+ onion_error_code : _error_code_ret ,
1240
1237
#[ cfg( any( test, feature = "_test_utils" ) ) ]
1241
- onion_error_data : error_packet_ret ,
1238
+ onion_error_data : _error_packet_ret ,
1242
1239
}
1243
1240
} else {
1244
1241
// only not set either packet unparseable or hmac does not match with any
0 commit comments