Skip to content

Commit b234645

Browse files
committed
Log cases where an onion failure cannot be attributed or interpreted
Create more visibility into these edge cases. The non-attributable failure in particular can be used to disrupt sender operation and it is therefore good to at least log these cases clearly.
1 parent eaeed77 commit b234645

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

lightning/src/ln/onion_utils.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,22 +1044,31 @@ where
10441044
let amt_to_forward = htlc_msat - route_hop.fee_msat;
10451045
htlc_msat = amt_to_forward;
10461046

1047-
let err_packet = match decrypt_onion_error_packet(&mut encrypted_packet, shared_secret) {
1048-
Ok(p) => p,
1049-
Err(_) => return,
1050-
};
1047+
let decrypt_result = decrypt_onion_error_packet(&mut encrypted_packet, shared_secret);
1048+
10511049
let um = gen_um_from_shared_secret(shared_secret.as_ref());
10521050
let mut hmac = HmacEngine::<Sha256>::new(&um);
1053-
hmac.input(&err_packet.encode()[32..]);
1051+
hmac.input(&encrypted_packet[32..]);
10541052

1055-
if !fixed_time_eq(&Hmac::from_engine(hmac).to_byte_array(), &err_packet.hmac) {
1053+
if !fixed_time_eq(&Hmac::from_engine(hmac).to_byte_array(), &encrypted_packet[..32]) {
10561054
return;
10571055
}
1056+
1057+
let err_packet = match decrypt_result {
1058+
Ok(p) => p,
1059+
Err(_) => {
1060+
log_warn!(logger, "Unreadable failure from {}", route_hop.pubkey);
1061+
return;
1062+
},
1063+
};
1064+
10581065
let error_code_slice = match err_packet.failuremsg.get(0..2) {
10591066
Some(s) => s,
10601067
None => {
10611068
// Useless packet that we can't use but it passed HMAC, so it definitely came from the peer
10621069
// in question
1070+
log_warn!(logger, "Missing error code in failure from {}", route_hop.pubkey);
1071+
10631072
let network_update = Some(NetworkUpdate::NodeFailure {
10641073
node_id: route_hop.pubkey,
10651074
is_permanent: true,
@@ -1219,6 +1228,12 @@ where
12191228
} else {
12201229
// only not set either packet unparseable or hmac does not match with any
12211230
// payment not retryable only when garbage is from the final node
1231+
log_warn!(
1232+
logger,
1233+
"Non-attributable failure encountered on route {}",
1234+
path.hops.iter().map(|h| h.pubkey.to_string()).collect::<Vec<_>>().join("->")
1235+
);
1236+
12221237
DecodedOnionFailure {
12231238
network_update: None,
12241239
short_channel_id: None,

0 commit comments

Comments
 (0)