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