@@ -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,14 +974,38 @@ 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 mut onion_keys = Vec :: with_capacity ( path. hops . len ( ) ) ;
978
1002
construct_onion_keys_generic_callback (
979
1003
secp_ctx,
980
1004
& path. hops ,
981
1005
path. blinded_tail . as_ref ( ) ,
982
1006
session_priv,
983
1007
|shared_secret, _, _, route_hop_option : Option < & RouteHop > , _| {
984
- onion_keys. push ( ( route_hop_option. cloned ( ) , shared_secret) )
1008
+ onion_keys. push ( ( route_hop_option. map ( |rh| ErrorHop :: RouteHop ( rh ) ) , shared_secret) )
985
1009
} ,
986
1010
)
987
1011
. expect ( "Route we used spontaneously grew invalid keys in the middle of it?" ) ;
@@ -1048,7 +1072,7 @@ where
1048
1072
}
1049
1073
} ;
1050
1074
1051
- let amt_to_forward = htlc_msat - route_hop. fee_msat ;
1075
+ let amt_to_forward = htlc_msat - route_hop. fee_msat ( ) ;
1052
1076
htlc_msat = amt_to_forward;
1053
1077
1054
1078
crypt_failure_packet ( shared_secret. as_ref ( ) , & mut encrypted_packet) ;
@@ -1065,13 +1089,13 @@ where
1065
1089
match msgs:: DecodedOnionErrorPacket :: read ( & mut Cursor :: new ( & encrypted_packet. data ) ) {
1066
1090
Ok ( p) => p,
1067
1091
Err ( _) => {
1068
- log_warn ! ( logger, "Unreadable failure from {}" , route_hop. pubkey) ;
1092
+ log_warn ! ( logger, "Unreadable failure from {}" , route_hop. pubkey( ) ) ;
1069
1093
1070
1094
let network_update = Some ( NetworkUpdate :: NodeFailure {
1071
- node_id : route_hop. pubkey ,
1095
+ node_id : * route_hop. pubkey ( ) ,
1072
1096
is_permanent : true ,
1073
1097
} ) ;
1074
- let short_channel_id = Some ( route_hop. short_channel_id ) ;
1098
+ let short_channel_id = route_hop. short_channel_id ( ) ;
1075
1099
res = Some ( FailureLearnings {
1076
1100
network_update,
1077
1101
short_channel_id,
@@ -1087,13 +1111,13 @@ where
1087
1111
None => {
1088
1112
// Useless packet that we can't use but it passed HMAC, so it definitely came from the peer
1089
1113
// in question
1090
- log_warn ! ( logger, "Missing error code in failure from {}" , route_hop. pubkey) ;
1114
+ log_warn ! ( logger, "Missing error code in failure from {}" , route_hop. pubkey( ) ) ;
1091
1115
1092
1116
let network_update = Some ( NetworkUpdate :: NodeFailure {
1093
- node_id : route_hop. pubkey ,
1117
+ node_id : * route_hop. pubkey ( ) ,
1094
1118
is_permanent : true ,
1095
1119
} ) ;
1096
- let short_channel_id = Some ( route_hop. short_channel_id ) ;
1120
+ let short_channel_id = route_hop. short_channel_id ( ) ;
1097
1121
res = Some ( FailureLearnings {
1098
1122
network_update,
1099
1123
short_channel_id,
@@ -1127,22 +1151,26 @@ where
1127
1151
// entirely, but we can't be confident in that, as it would allow any node to get us to
1128
1152
// completely ban one of its counterparties. Instead, we simply remove the channel in
1129
1153
// question.
1130
- network_update = Some ( NetworkUpdate :: ChannelFailure {
1131
- short_channel_id : failing_route_hop. short_channel_id ,
1132
- is_permanent : true ,
1133
- } ) ;
1154
+ if let ErrorHop :: RouteHop ( failing_route_hop) = failing_route_hop {
1155
+ network_update = Some ( NetworkUpdate :: ChannelFailure {
1156
+ short_channel_id : failing_route_hop. short_channel_id ,
1157
+ is_permanent : true ,
1158
+ } ) ;
1159
+ }
1134
1160
} else if error_code & NODE == NODE {
1135
1161
let is_permanent = error_code & PERM == PERM ;
1136
1162
network_update =
1137
- Some ( NetworkUpdate :: NodeFailure { node_id : route_hop. pubkey , is_permanent } ) ;
1138
- short_channel_id = Some ( route_hop. short_channel_id ) ;
1163
+ Some ( NetworkUpdate :: NodeFailure { node_id : * route_hop. pubkey ( ) , is_permanent } ) ;
1164
+ short_channel_id = route_hop. short_channel_id ( ) ;
1139
1165
} else if error_code & PERM == PERM {
1140
1166
if !payment_failed {
1141
- network_update = Some ( NetworkUpdate :: ChannelFailure {
1142
- short_channel_id : failing_route_hop. short_channel_id ,
1143
- is_permanent : true ,
1144
- } ) ;
1145
- short_channel_id = Some ( failing_route_hop. short_channel_id ) ;
1167
+ if let ErrorHop :: RouteHop ( failing_route_hop) = failing_route_hop {
1168
+ network_update = Some ( NetworkUpdate :: ChannelFailure {
1169
+ short_channel_id : failing_route_hop. short_channel_id ,
1170
+ is_permanent : true ,
1171
+ } ) ;
1172
+ }
1173
+ short_channel_id = failing_route_hop. short_channel_id ( ) ;
1146
1174
}
1147
1175
} else if error_code & UPDATE == UPDATE {
1148
1176
if let Some ( update_len_slice) =
@@ -1155,37 +1183,41 @@ where
1155
1183
. get ( debug_field_size + 4 ..debug_field_size + 4 + update_len)
1156
1184
. is_some ( )
1157
1185
{
1158
- network_update = Some ( NetworkUpdate :: ChannelFailure {
1159
- short_channel_id : failing_route_hop. short_channel_id ,
1160
- is_permanent : false ,
1161
- } ) ;
1162
- short_channel_id = Some ( failing_route_hop. short_channel_id ) ;
1186
+ if let ErrorHop :: RouteHop ( failing_route_hop) = failing_route_hop {
1187
+ network_update = Some ( NetworkUpdate :: ChannelFailure {
1188
+ short_channel_id : failing_route_hop. short_channel_id ,
1189
+ is_permanent : false ,
1190
+ } ) ;
1191
+ }
1192
+ short_channel_id = failing_route_hop. short_channel_id ( ) ;
1163
1193
}
1164
1194
}
1165
1195
if network_update. is_none ( ) {
1166
1196
// They provided an UPDATE which was obviously bogus, not worth
1167
1197
// trying to relay through them anymore.
1168
1198
network_update = Some ( NetworkUpdate :: NodeFailure {
1169
- node_id : route_hop. pubkey ,
1199
+ node_id : * route_hop. pubkey ( ) ,
1170
1200
is_permanent : true ,
1171
1201
} ) ;
1172
1202
}
1173
1203
if short_channel_id. is_none ( ) {
1174
- short_channel_id = Some ( route_hop. short_channel_id ) ;
1204
+ short_channel_id = route_hop. short_channel_id ( ) ;
1175
1205
}
1176
1206
} else if payment_failed {
1177
1207
// Only blame the hop when a value in the HTLC doesn't match the corresponding value in the
1178
1208
// onion.
1179
1209
short_channel_id = match error_code & 0xff {
1180
- 18 | 19 => Some ( route_hop. short_channel_id ) ,
1210
+ 18 | 19 => route_hop. short_channel_id ( ) ,
1181
1211
_ => None ,
1182
1212
} ;
1183
1213
} else {
1184
1214
// We can't understand their error messages and they failed to forward...they probably can't
1185
1215
// understand our forwards so it's really not worth trying any further.
1186
- network_update =
1187
- Some ( NetworkUpdate :: NodeFailure { node_id : route_hop. pubkey , is_permanent : true } ) ;
1188
- short_channel_id = Some ( route_hop. short_channel_id ) ;
1216
+ network_update = Some ( NetworkUpdate :: NodeFailure {
1217
+ node_id : * route_hop. pubkey ( ) ,
1218
+ is_permanent : true ,
1219
+ } ) ;
1220
+ short_channel_id = route_hop. short_channel_id ( )
1189
1221
}
1190
1222
1191
1223
res = Some ( FailureLearnings {
@@ -1200,7 +1232,7 @@ where
1200
1232
log_info ! (
1201
1233
logger,
1202
1234
"Onion Error[from {}: {}({:#x}) {}({})] {}" ,
1203
- route_hop. pubkey,
1235
+ route_hop. pubkey( ) ,
1204
1236
title,
1205
1237
error_code,
1206
1238
debug_field,
@@ -1211,7 +1243,7 @@ where
1211
1243
log_info ! (
1212
1244
logger,
1213
1245
"Onion Error[from {}: {}({:#x})] {}" ,
1214
- route_hop. pubkey,
1246
+ route_hop. pubkey( ) ,
1215
1247
title,
1216
1248
error_code,
1217
1249
description
0 commit comments