Skip to content

Commit f6a1f3e

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 3ae568b commit f6a1f3e

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

lightning/src/ln/onion_utils.rs

Lines changed: 40 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,
@@ -2104,6 +2119,25 @@ mod tests {
21042119
assert_eq!(decrypted_failure.onion_error_code, Some(0x2002));
21052120
}
21062121

2122+
#[test]
2123+
fn test_non_attributable_failure_packet_onion() {
2124+
let corrupt_failure_packet = vec![1u8; 292];
2125+
2126+
let logger: Arc<TestLogger> = Arc::new(TestLogger::new());
2127+
let ctx_full = Secp256k1::new();
2128+
let path = build_test_path();
2129+
let htlc_source = HTLCSource::OutboundRoute {
2130+
path: path,
2131+
session_priv: get_test_session_key(),
2132+
first_hop_htlc_msat: 0,
2133+
payment_id: PaymentId([1; 32])
2134+
, };
2135+
2136+
// For a corrupt failure message, the failing channel cannot be identified.
2137+
let decrypted_failure = process_onion_failure(&ctx_full, &logger, &htlc_source, corrupt_failure_packet);
2138+
assert_eq!(decrypted_failure.short_channel_id, None);
2139+
}
2140+
21072141
struct RawOnionHopData {
21082142
data: Vec<u8>,
21092143
}

0 commit comments

Comments
 (0)