@@ -297,14 +297,14 @@ impl<'a, 'b> OnionPayload<'a, 'b> for msgs::OutboundTrampolinePayload<'a> {
297
297
}
298
298
299
299
#[ inline]
300
- fn construct_onion_keys_generic_callback < T , H , FType > (
301
- secp_ctx : & Secp256k1 < T > , hops : & [ H ] , blinded_tail : Option < & BlindedTail > ,
300
+ fn construct_onion_keys_generic_callback < ' a , T , H , FType > (
301
+ secp_ctx : & Secp256k1 < T > , hops : & ' a [ H ] , blinded_tail : Option < & BlindedTail > ,
302
302
session_priv : & SecretKey , mut callback : FType ,
303
303
) -> Result < ( ) , secp256k1:: Error >
304
304
where
305
305
T : secp256k1:: Signing ,
306
306
H : HopInfo ,
307
- FType : FnMut ( SharedSecret , [ u8 ; 32 ] , PublicKey , Option < & H > , usize ) ,
307
+ FType : FnMut ( SharedSecret , [ u8 ; 32 ] , PublicKey , Option < & ' a H > , usize ) ,
308
308
{
309
309
let mut blinded_priv = session_priv. clone ( ) ;
310
310
let mut blinded_pub = PublicKey :: from_secret_key ( secp_ctx, & blinded_priv) ;
@@ -974,6 +974,30 @@ where
974
974
const NODE : u16 = 0x2000 ;
975
975
const UPDATE : u16 = 0x1000 ;
976
976
977
+ enum ErrorHop < ' a > {
978
+ RouteHop ( & ' a RouteHop ) ,
979
+ }
980
+
981
+ impl < ' a > ErrorHop < ' a > {
982
+ fn fee_msat ( & self ) -> u64 {
983
+ match self {
984
+ ErrorHop :: RouteHop ( rh) => rh. fee_msat ,
985
+ }
986
+ }
987
+
988
+ fn pubkey ( & self ) -> & PublicKey {
989
+ match self {
990
+ ErrorHop :: RouteHop ( rh) => rh. node_pubkey ( ) ,
991
+ }
992
+ }
993
+
994
+ fn short_channel_id ( & self ) -> Option < u64 > {
995
+ match self {
996
+ ErrorHop :: RouteHop ( rh) => Some ( rh. short_channel_id ) ,
997
+ }
998
+ }
999
+ }
1000
+
977
1001
let num_blinded_hops = path. blinded_tail . as_ref ( ) . map_or ( 0 , |bt| bt. hops . len ( ) ) ;
978
1002
let mut onion_keys = Vec :: with_capacity ( path. hops . len ( ) + num_blinded_hops) ;
979
1003
construct_onion_keys_generic_callback (
@@ -982,7 +1006,7 @@ where
982
1006
path. blinded_tail . as_ref ( ) ,
983
1007
session_priv,
984
1008
|shared_secret, _, _, route_hop_option : Option < & RouteHop > , _| {
985
- onion_keys. push ( ( route_hop_option. cloned ( ) , shared_secret) )
1009
+ onion_keys. push ( ( route_hop_option. map ( |rh| ErrorHop :: RouteHop ( rh ) ) , shared_secret) )
986
1010
} ,
987
1011
)
988
1012
. expect ( "Route we used spontaneously grew invalid keys in the middle of it?" ) ;
@@ -1051,7 +1075,7 @@ where
1051
1075
}
1052
1076
} ;
1053
1077
1054
- let amt_to_forward = htlc_msat - route_hop. fee_msat ;
1078
+ let amt_to_forward = htlc_msat - route_hop. fee_msat ( ) ;
1055
1079
htlc_msat = amt_to_forward;
1056
1080
1057
1081
crypt_failure_packet ( shared_secret. as_ref ( ) , & mut encrypted_packet) ;
@@ -1068,13 +1092,13 @@ where
1068
1092
match msgs:: DecodedOnionErrorPacket :: read ( & mut Cursor :: new ( & encrypted_packet. data ) ) {
1069
1093
Ok ( p) => p,
1070
1094
Err ( _) => {
1071
- log_warn ! ( logger, "Unreadable failure from {}" , route_hop. pubkey) ;
1095
+ log_warn ! ( logger, "Unreadable failure from {}" , route_hop. pubkey( ) ) ;
1072
1096
1073
1097
let network_update = Some ( NetworkUpdate :: NodeFailure {
1074
- node_id : route_hop. pubkey ,
1098
+ node_id : * route_hop. pubkey ( ) ,
1075
1099
is_permanent : true ,
1076
1100
} ) ;
1077
- let short_channel_id = Some ( route_hop. short_channel_id ) ;
1101
+ let short_channel_id = route_hop. short_channel_id ( ) ;
1078
1102
res = Some ( FailureLearnings {
1079
1103
network_update,
1080
1104
short_channel_id,
@@ -1090,13 +1114,13 @@ where
1090
1114
None => {
1091
1115
// Useless packet that we can't use but it passed HMAC, so it definitely came from the peer
1092
1116
// in question
1093
- log_warn ! ( logger, "Missing error code in failure from {}" , route_hop. pubkey) ;
1117
+ log_warn ! ( logger, "Missing error code in failure from {}" , route_hop. pubkey( ) ) ;
1094
1118
1095
1119
let network_update = Some ( NetworkUpdate :: NodeFailure {
1096
- node_id : route_hop. pubkey ,
1120
+ node_id : * route_hop. pubkey ( ) ,
1097
1121
is_permanent : true ,
1098
1122
} ) ;
1099
- let short_channel_id = Some ( route_hop. short_channel_id ) ;
1123
+ let short_channel_id = route_hop. short_channel_id ( ) ;
1100
1124
res = Some ( FailureLearnings {
1101
1125
network_update,
1102
1126
short_channel_id,
@@ -1130,22 +1154,26 @@ where
1130
1154
// entirely, but we can't be confident in that, as it would allow any node to get us to
1131
1155
// completely ban one of its counterparties. Instead, we simply remove the channel in
1132
1156
// question.
1133
- network_update = Some ( NetworkUpdate :: ChannelFailure {
1134
- short_channel_id : failing_route_hop. short_channel_id ,
1135
- is_permanent : true ,
1136
- } ) ;
1157
+ if let ErrorHop :: RouteHop ( failing_route_hop) = failing_route_hop {
1158
+ network_update = Some ( NetworkUpdate :: ChannelFailure {
1159
+ short_channel_id : failing_route_hop. short_channel_id ,
1160
+ is_permanent : true ,
1161
+ } ) ;
1162
+ }
1137
1163
} else if error_code & NODE == NODE {
1138
1164
let is_permanent = error_code & PERM == PERM ;
1139
1165
network_update =
1140
- Some ( NetworkUpdate :: NodeFailure { node_id : route_hop. pubkey , is_permanent } ) ;
1141
- short_channel_id = Some ( route_hop. short_channel_id ) ;
1166
+ Some ( NetworkUpdate :: NodeFailure { node_id : * route_hop. pubkey ( ) , is_permanent } ) ;
1167
+ short_channel_id = route_hop. short_channel_id ( ) ;
1142
1168
} else if error_code & PERM == PERM {
1143
1169
if !payment_failed {
1144
- network_update = Some ( NetworkUpdate :: ChannelFailure {
1145
- short_channel_id : failing_route_hop. short_channel_id ,
1146
- is_permanent : true ,
1147
- } ) ;
1148
- short_channel_id = Some ( failing_route_hop. short_channel_id ) ;
1170
+ if let ErrorHop :: RouteHop ( failing_route_hop) = failing_route_hop {
1171
+ network_update = Some ( NetworkUpdate :: ChannelFailure {
1172
+ short_channel_id : failing_route_hop. short_channel_id ,
1173
+ is_permanent : true ,
1174
+ } ) ;
1175
+ }
1176
+ short_channel_id = failing_route_hop. short_channel_id ( ) ;
1149
1177
}
1150
1178
} else if error_code & UPDATE == UPDATE {
1151
1179
if let Some ( update_len_slice) =
@@ -1158,37 +1186,41 @@ where
1158
1186
. get ( debug_field_size + 4 ..debug_field_size + 4 + update_len)
1159
1187
. is_some ( )
1160
1188
{
1161
- network_update = Some ( NetworkUpdate :: ChannelFailure {
1162
- short_channel_id : failing_route_hop. short_channel_id ,
1163
- is_permanent : false ,
1164
- } ) ;
1165
- short_channel_id = Some ( failing_route_hop. short_channel_id ) ;
1189
+ if let ErrorHop :: RouteHop ( failing_route_hop) = failing_route_hop {
1190
+ network_update = Some ( NetworkUpdate :: ChannelFailure {
1191
+ short_channel_id : failing_route_hop. short_channel_id ,
1192
+ is_permanent : false ,
1193
+ } ) ;
1194
+ }
1195
+ short_channel_id = failing_route_hop. short_channel_id ( ) ;
1166
1196
}
1167
1197
}
1168
1198
if network_update. is_none ( ) {
1169
1199
// They provided an UPDATE which was obviously bogus, not worth
1170
1200
// trying to relay through them anymore.
1171
1201
network_update = Some ( NetworkUpdate :: NodeFailure {
1172
- node_id : route_hop. pubkey ,
1202
+ node_id : * route_hop. pubkey ( ) ,
1173
1203
is_permanent : true ,
1174
1204
} ) ;
1175
1205
}
1176
1206
if short_channel_id. is_none ( ) {
1177
- short_channel_id = Some ( route_hop. short_channel_id ) ;
1207
+ short_channel_id = route_hop. short_channel_id ( ) ;
1178
1208
}
1179
1209
} else if payment_failed {
1180
1210
// Only blame the hop when a value in the HTLC doesn't match the corresponding value in the
1181
1211
// onion.
1182
1212
short_channel_id = match error_code & 0xff {
1183
- 18 | 19 => Some ( route_hop. short_channel_id ) ,
1213
+ 18 | 19 => route_hop. short_channel_id ( ) ,
1184
1214
_ => None ,
1185
1215
} ;
1186
1216
} else {
1187
1217
// We can't understand their error messages and they failed to forward...they probably can't
1188
1218
// understand our forwards so it's really not worth trying any further.
1189
- network_update =
1190
- Some ( NetworkUpdate :: NodeFailure { node_id : route_hop. pubkey , is_permanent : true } ) ;
1191
- short_channel_id = Some ( route_hop. short_channel_id ) ;
1219
+ network_update = Some ( NetworkUpdate :: NodeFailure {
1220
+ node_id : * route_hop. pubkey ( ) ,
1221
+ is_permanent : true ,
1222
+ } ) ;
1223
+ short_channel_id = route_hop. short_channel_id ( )
1192
1224
}
1193
1225
1194
1226
res = Some ( FailureLearnings {
@@ -1203,7 +1235,7 @@ where
1203
1235
log_info ! (
1204
1236
logger,
1205
1237
"Onion Error[from {}: {}({:#x}) {}({})] {}" ,
1206
- route_hop. pubkey,
1238
+ route_hop. pubkey( ) ,
1207
1239
title,
1208
1240
error_code,
1209
1241
debug_field,
@@ -1214,7 +1246,7 @@ where
1214
1246
log_info ! (
1215
1247
logger,
1216
1248
"Onion Error[from {}: {}({:#x})] {}" ,
1217
- route_hop. pubkey,
1249
+ route_hop. pubkey( ) ,
1218
1250
title,
1219
1251
error_code,
1220
1252
description
0 commit comments