Skip to content

Commit

Permalink
Properly attribute unreadable failures with a valid hmac
Browse files Browse the repository at this point in the history
This commit fixes a bug where a node penalty was not applied where it
should.
  • Loading branch information
joostjager committed Feb 28, 2025
1 parent 27ac5d4 commit fc11fe4
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion lightning/src/ln/onion_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,8 +1059,19 @@ where
Err(_) => {
log_warn!(logger, "Unreadable failure from {}", route_hop.pubkey);

let network_update = Some(NetworkUpdate::NodeFailure {
node_id: route_hop.pubkey,
is_permanent: true,
});
let short_channel_id = Some(route_hop.short_channel_id);
res = Some(FailureLearnings {
network_update,
short_channel_id,
payment_failed_permanently: is_from_final_node,
failed_within_blinded_path: false,
});
return;
}
},
};

let error_code_slice = match err_packet.failuremsg.get(0..2) {
Expand Down Expand Up @@ -2181,6 +2192,28 @@ mod tests {
assert_eq!(decrypted_failure.short_channel_id, None);
}

#[test]
fn test_unreadable_failure_packet_onion() {
// Create a failure packet with a valid hmac but unreadable failure message.
let onion_keys: Vec<OnionKeys> = build_test_onion_keys();
let shared_secret = onion_keys[0].shared_secret.as_ref();
let um = gen_um_from_shared_secret(&shared_secret);

// The failure message is a single 0 byte.
let mut packet = [0u8; 33];

let mut hmac = HmacEngine::<Sha256>::new(&um);
hmac.input(&packet[32..]);
let hmac = Hmac::from_engine(hmac).to_byte_array();
packet[..32].copy_from_slice(&hmac);

let packet = encrypt_failure_packet(shared_secret, &packet);

// For the unreadable failure, it is still expected that the failing channel can be identified.
let decrypted_failure = test_failure_attribution(&packet.data);
assert_eq!(decrypted_failure.short_channel_id, Some(0));
}

#[test]
fn test_missing_error_code() {
// Create a failure packet with a valid hmac and structure, but no error code.
Expand Down

0 comments on commit fc11fe4

Please sign in to comment.