Skip to content

Commit 8c1aaf6

Browse files
committed
f: test forwarding failure
1 parent 58c47cf commit 8c1aaf6

File tree

2 files changed

+59
-12
lines changed

2 files changed

+59
-12
lines changed

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,8 +2497,7 @@ fn test_trampoline_constraint_enforcement() {
24972497
}
24982498
}
24992499

2500-
#[test]
2501-
fn test_unblinded_trampoline_forward() {
2500+
fn do_test_unblinded_trampoline_forward(success: bool) {
25022501
// Simulate a payment of A (0) -> B (1) -> C(Trampoline) (2) -> D(Trampoline(receive)) (3)
25032502
// trampoline hops C -> T0 (4) -> D
25042503
// make it fail at B, then at C's outer onion, then at C's inner onion
@@ -2512,7 +2511,9 @@ fn test_unblinded_trampoline_forward() {
25122511

25132512
let (_, _, chan_id_alice_bob, _) = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0);
25142513
let (_, _, chan_id_bob_carol, _) = create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 1_000_000, 0);
2515-
let (_, _, _, _) = create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 1_000_000, 0);
2514+
if success {
2515+
let (_, _, _, _) = create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 1_000_000, 0);
2516+
}
25162517
let (_, _, _, _) = create_announced_chan_between_nodes_with_value(&nodes, 4, 3, 1_000_000, 0);
25172518

25182519
for i in 0..TOTAL_NODE_COUNT { // connect all nodes' blocks
@@ -2651,10 +2652,46 @@ fn test_unblinded_trampoline_forward() {
26512652
msg.onion_routing_packet = replacement_onion.clone();
26522653
});
26532654

2654-
let route: &[&Node] = &[&nodes[1], &nodes[2], &nodes[4], &nodes[3]];
2655-
let args = PassAlongPathArgs::new(&nodes[0], route, amt_msat, payment_hash, first_message_event)
2656-
.with_payment_secret(payment_secret);
2655+
let success_route = [&nodes[1], &nodes[2], &nodes[4], &nodes[3]];
2656+
let failure_route = [&nodes[1], &nodes[2]];
2657+
let route: &[&Node] = if success { &success_route } else { &failure_route };
2658+
let args = PassAlongPathArgs::new(&nodes[0], route, amt_msat, payment_hash, first_message_event);
2659+
let args = if success {
2660+
args.with_payment_secret(payment_secret)
2661+
} else {
2662+
args.with_payment_preimage(payment_preimage)
2663+
.without_claimable_event()
2664+
.expect_failure(HTLCDestination::FailedTrampolineForward { requested_next_node_id: dave_node_id, forward_scid: None })
2665+
};
26572666
do_pass_along_path(args);
26582667

2659-
claim_payment(&nodes[0], &[&nodes[1], &nodes[2], &nodes[4], &nodes[3]], payment_preimage);
2668+
if success {
2669+
claim_payment(&nodes[0], &[&nodes[1], &nodes[2], &nodes[4], &nodes[3]], payment_preimage);
2670+
} else {
2671+
{
2672+
let unblinded_node_updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
2673+
nodes[1].node.handle_update_fail_htlc(
2674+
nodes[2].node.get_our_node_id(), &unblinded_node_updates.update_fail_htlcs[0]
2675+
);
2676+
do_commitment_signed_dance(&nodes[1], &nodes[2], &unblinded_node_updates.commitment_signed, true, false);
2677+
}
2678+
{
2679+
let unblinded_node_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
2680+
nodes[0].node.handle_update_fail_htlc(
2681+
nodes[1].node.get_our_node_id(), &unblinded_node_updates.update_fail_htlcs[0]
2682+
);
2683+
do_commitment_signed_dance(&nodes[0], &nodes[1], &unblinded_node_updates.commitment_signed, false, false);
2684+
}
2685+
{
2686+
let payment_failed_conditions = PaymentFailedConditions::new()
2687+
.expected_htlc_error_data(0x2000 | 25, &[0; 0]);
2688+
expect_payment_failed_conditions(&nodes[0], payment_hash, false, payment_failed_conditions);
2689+
}
2690+
}
2691+
}
2692+
2693+
#[test]
2694+
fn test_unblinded_trampoline_forward() {
2695+
do_test_unblinded_trampoline_forward(true);
2696+
do_test_unblinded_trampoline_forward(false);
26602697
}

lightning/src/ln/onion_utils.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,8 +1651,8 @@ impl HTLCFailReason {
16511651
// failures here, but that would be insufficient as find_route
16521652
// generally ignores its view of our own channels as we provide them via
16531653
// ChannelDetails.
1654-
if let &HTLCSource::OutboundRoute { ref path, .. } = htlc_source {
1655-
DecodedOnionFailure {
1654+
match htlc_source {
1655+
HTLCSource::OutboundRoute { ref path, .. } => DecodedOnionFailure {
16561656
network_update: None,
16571657
payment_failed_permanently: false,
16581658
short_channel_id: Some(path.hops[0].short_channel_id),
@@ -1662,9 +1662,19 @@ impl HTLCFailReason {
16621662
onion_error_code: Some(*failure_code),
16631663
#[cfg(any(test, feature = "_test_utils"))]
16641664
onion_error_data: Some(data.clone()),
1665-
}
1666-
} else {
1667-
unreachable!();
1665+
},
1666+
HTLCSource::TrampolineForward { ref hops, .. } => DecodedOnionFailure {
1667+
network_update: None,
1668+
payment_failed_permanently: false,
1669+
short_channel_id: hops.first().map(|h| h.short_channel_id),
1670+
failed_within_blinded_path: false,
1671+
hold_times: Vec::new(),
1672+
#[cfg(any(test, feature = "_test_utils"))]
1673+
onion_error_code: Some(*failure_code),
1674+
#[cfg(any(test, feature = "_test_utils"))]
1675+
onion_error_data: Some(data.clone()),
1676+
},
1677+
_ => unreachable!(),
16681678
}
16691679
},
16701680
}

0 commit comments

Comments
 (0)