Skip to content

Commit 6553205

Browse files
committed
f - Special case when short_channel_id is given for payment_failed
1 parent d4c85b3 commit 6553205

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

lightning/src/ln/onion_route_tests.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ fn test_fee_failures() {
281281
let short_channel_id = channels[0].0.contents.short_channel_id;
282282
run_onion_failure_test("fee_insufficient", 0, &nodes, &route, &payment_hash, &payment_secret, |msg| {
283283
msg.amount_msat -= 1;
284-
}, || {}, true, Some(UPDATE|12), Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent: true}), Some(short_channel_id));
284+
}, || {}, true, Some(UPDATE|12), Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent: true}), None);
285285

286286
// In an earlier version, we spuriously failed to forward payments if the expected feerate
287287
// changed between the channel open and the payment.
@@ -373,7 +373,7 @@ fn test_onion_failure() {
373373
let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
374374
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
375375
msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[0].shared_secret[..], NODE|2, &[0;0]);
376-
}, ||{}, true, Some(NODE|2), Some(NetworkUpdate::NodeFailure{node_id: route.paths[0][0].pubkey, is_permanent: false}), Some(route.paths[0][0].short_channel_id));
376+
}, ||{}, true, Some(NODE|2), Some(NetworkUpdate::NodeFailure{node_id: route.paths[0][0].pubkey, is_permanent: false}), None);
377377

378378
// final node failure
379379
run_onion_failure_test_with_fail_intercept("temporary_node_failure", 200, &nodes, &route, &payment_hash, &payment_secret, |_msg| {}, |msg| {
@@ -383,7 +383,7 @@ fn test_onion_failure() {
383383
msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[1].shared_secret[..], NODE|2, &[0;0]);
384384
}, ||{
385385
nodes[2].node.fail_htlc_backwards(&payment_hash);
386-
}, true, Some(NODE|2), Some(NetworkUpdate::NodeFailure{node_id: route.paths[0][1].pubkey, is_permanent: false}), Some(route.paths[0][1].short_channel_id));
386+
}, true, Some(NODE|2), Some(NetworkUpdate::NodeFailure{node_id: route.paths[0][1].pubkey, is_permanent: false}), None);
387387
let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
388388

389389
// intermediate node failure
@@ -393,7 +393,7 @@ fn test_onion_failure() {
393393
let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
394394
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
395395
msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[0].shared_secret[..], PERM|NODE|2, &[0;0]);
396-
}, ||{}, true, Some(PERM|NODE|2), Some(NetworkUpdate::NodeFailure{node_id: route.paths[0][0].pubkey, is_permanent: true}), Some(route.paths[0][0].short_channel_id));
396+
}, ||{}, true, Some(PERM|NODE|2), Some(NetworkUpdate::NodeFailure{node_id: route.paths[0][0].pubkey, is_permanent: true}), None);
397397

398398
// final node failure
399399
run_onion_failure_test_with_fail_intercept("permanent_node_failure", 200, &nodes, &route, &payment_hash, &payment_secret, |_msg| {}, |msg| {
@@ -402,7 +402,7 @@ fn test_onion_failure() {
402402
msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[1].shared_secret[..], PERM|NODE|2, &[0;0]);
403403
}, ||{
404404
nodes[2].node.fail_htlc_backwards(&payment_hash);
405-
}, false, Some(PERM|NODE|2), Some(NetworkUpdate::NodeFailure{node_id: route.paths[0][1].pubkey, is_permanent: true}), Some(route.paths[0][1].short_channel_id));
405+
}, false, Some(PERM|NODE|2), Some(NetworkUpdate::NodeFailure{node_id: route.paths[0][1].pubkey, is_permanent: true}), None);
406406
let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
407407

408408
// intermediate node failure
@@ -414,7 +414,7 @@ fn test_onion_failure() {
414414
msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[0].shared_secret[..], PERM|NODE|3, &[0;0]);
415415
}, ||{
416416
nodes[2].node.fail_htlc_backwards(&payment_hash);
417-
}, true, Some(PERM|NODE|3), Some(NetworkUpdate::NodeFailure{node_id: route.paths[0][0].pubkey, is_permanent: true}), Some(route.paths[0][0].short_channel_id));
417+
}, true, Some(PERM|NODE|3), Some(NetworkUpdate::NodeFailure{node_id: route.paths[0][0].pubkey, is_permanent: true}), None);
418418

419419
// final node failure
420420
run_onion_failure_test_with_fail_intercept("required_node_feature_missing", 200, &nodes, &route, &payment_hash, &payment_secret, |_msg| {}, |msg| {
@@ -423,7 +423,7 @@ fn test_onion_failure() {
423423
msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[1].shared_secret[..], PERM|NODE|3, &[0;0]);
424424
}, ||{
425425
nodes[2].node.fail_htlc_backwards(&payment_hash);
426-
}, false, Some(PERM|NODE|3), Some(NetworkUpdate::NodeFailure{node_id: route.paths[0][1].pubkey, is_permanent: true}), Some(route.paths[0][1].short_channel_id));
426+
}, 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

429429
run_onion_failure_test("invalid_onion_version", 0, &nodes, &route, &payment_hash, &payment_secret, |msg| { msg.onion_routing_packet.version = 1; }, ||{}, true,
@@ -487,13 +487,13 @@ fn test_onion_failure() {
487487
let short_channel_id = channels[0].0.contents.short_channel_id;
488488
run_onion_failure_test("fee_insufficient", 0, &nodes, &route, &payment_hash, &payment_secret, |msg| {
489489
msg.amount_msat -= 1;
490-
}, || {}, true, Some(UPDATE|12), Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent: true}), Some(short_channel_id));
490+
}, || {}, true, Some(UPDATE|12), Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent: true}), None);
491491

492492
let short_channel_id = channels[0].0.contents.short_channel_id;
493493
run_onion_failure_test("incorrect_cltv_expiry", 0, &nodes, &route, &payment_hash, &payment_secret, |msg| {
494494
// need to violate: cltv_expiry - cltv_expiry_delta >= outgoing_cltv_value
495495
msg.cltv_expiry -= 1;
496-
}, || {}, true, Some(UPDATE|13), Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent: true}), Some(short_channel_id));
496+
}, || {}, true, Some(UPDATE|13), Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent: true}), None);
497497

498498
let short_channel_id = channels[1].0.contents.short_channel_id;
499499
run_onion_failure_test("expiry_too_soon", 0, &nodes, &route, &payment_hash, &payment_secret, |msg| {
@@ -505,15 +505,15 @@ fn test_onion_failure() {
505505

506506
run_onion_failure_test("unknown_payment_hash", 2, &nodes, &route, &payment_hash, &payment_secret, |_| {}, || {
507507
nodes[2].node.fail_htlc_backwards(&payment_hash);
508-
}, false, Some(PERM|15), None, Some(channels[1].0.contents.short_channel_id));
508+
}, false, Some(PERM|15), None, None);
509509
let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
510510

511511
run_onion_failure_test("final_expiry_too_soon", 1, &nodes, &route, &payment_hash, &payment_secret, |msg| {
512512
let height = msg.cltv_expiry - CLTV_CLAIM_BUFFER - LATENCY_GRACE_PERIOD_BLOCKS + 1;
513513
connect_blocks(&nodes[0], height - nodes[0].best_block_info().1);
514514
connect_blocks(&nodes[1], height - nodes[1].best_block_info().1);
515515
connect_blocks(&nodes[2], height - nodes[2].best_block_info().1);
516-
}, || {}, true, Some(17), None, Some(channels[1].0.contents.short_channel_id));
516+
}, || {}, true, Some(17), None, None);
517517

518518
run_onion_failure_test("final_incorrect_cltv_expiry", 1, &nodes, &route, &payment_hash, &payment_secret, |_| {}, || {
519519
for (_, pending_forwards) in nodes[1].node.channel_state.lock().unwrap().forward_htlcs.iter_mut() {
@@ -560,5 +560,3 @@ fn test_onion_failure() {
560560
msg.onion_routing_packet = onion_packet;
561561
}, ||{}, true, Some(21), Some(NetworkUpdate::NodeFailure{node_id: route.paths[0][0].pubkey, is_permanent: true}), Some(route.paths[0][0].short_channel_id));
562562
}
563-
564-

lightning/src/ln/onion_utils.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,17 +442,21 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(secp_ctx: &
442442
is_permanent: true,
443443
});
444444
}
445-
} else if !payment_failed {
445+
} else if payment_failed {
446+
// Only blame the hop when a value in the HTLC doesn't match the
447+
// corresponding value in the onion.
448+
short_channel_id = match error_code & 0xff {
449+
18|19 => Some(route_hop.short_channel_id),
450+
_ => None,
451+
};
452+
} else {
446453
// We can't understand their error messages and they failed to
447454
// forward...they probably can't understand our forwards so its
448455
// really not worth trying any further.
449456
network_update = Some(NetworkUpdate::NodeFailure {
450457
node_id: route_hop.pubkey,
451458
is_permanent: true,
452459
});
453-
}
454-
455-
if short_channel_id.is_none() {
456460
short_channel_id = Some(route_hop.short_channel_id);
457461
}
458462

0 commit comments

Comments
 (0)