Skip to content

Commit b301aae

Browse files
committed
f - Include short_channel_id for BADONION errors
1 parent bcf8cab commit b301aae

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lightning/src/ln/onion_route_tests.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@ fn test_onion_failure() {
426426
}, false, Some(PERM|NODE|3), Some(NetworkUpdate::NodeFailure{node_id: route.paths[0][1].pubkey, is_permanent: true}), None);
427427
let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
428428

429+
// Our immediate peer sent UpdateFailMalformedHTLC because it couldn't understand the onion in
430+
// the UpdateAddHTLC that we sent. Thus, short_channel_id is None because there's no sense
431+
// blaming our own channel. We should instead close the channel instead.
429432
run_onion_failure_test("invalid_onion_version", 0, &nodes, &route, &payment_hash, &payment_secret, |msg| { msg.onion_routing_packet.version = 1; }, ||{}, true,
430433
Some(BADONION|PERM|4), None, None);
431434

lightning/src/ln/onion_utils.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(secp_ctx: &
367367

368368
if fixed_time_eq(&Hmac::from_engine(hmac).into_inner(), &err_packet.hmac) {
369369
if let Some(error_code_slice) = err_packet.failuremsg.get(0..2) {
370+
const BADONION: u16 = 0x8000;
370371
const PERM: u16 = 0x4000;
371372
const NODE: u16 = 0x2000;
372373
const UPDATE: u16 = 0x1000;
@@ -387,7 +388,10 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(secp_ctx: &
387388
let mut network_update = None;
388389
let mut short_channel_id = None;
389390

390-
if error_code & NODE == NODE {
391+
if error_code & BADONION == BADONION {
392+
short_channel_id = Some(route_hop.short_channel_id);
393+
}
394+
else if error_code & NODE == NODE {
391395
let is_permanent = error_code & PERM == PERM;
392396
network_update = Some(NetworkUpdate::NodeFailure { node_id: route_hop.pubkey, is_permanent });
393397
if !is_permanent {

0 commit comments

Comments
 (0)