Skip to content

Commit dae8f2c

Browse files
committed
f: test forwarding failure
1 parent 7aed821 commit dae8f2c

File tree

2 files changed

+59
-12
lines changed

2 files changed

+59
-12
lines changed

lightning/src/ln/blinded_payment_tests.rs

+44-7
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

+15-5
Original file line numberDiff line numberDiff line change
@@ -1674,8 +1674,8 @@ impl HTLCFailReason {
16741674
// failures here, but that would be insufficient as find_route
16751675
// generally ignores its view of our own channels as we provide them via
16761676
// ChannelDetails.
1677-
if let &HTLCSource::OutboundRoute { ref path, .. } = htlc_source {
1678-
DecodedOnionFailure {
1677+
match htlc_source {
1678+
HTLCSource::OutboundRoute { ref path, .. } => DecodedOnionFailure {
16791679
network_update: None,
16801680
payment_failed_permanently: false,
16811681
short_channel_id: Some(path.hops[0].short_channel_id),
@@ -1685,9 +1685,19 @@ impl HTLCFailReason {
16851685
onion_error_code: Some(*failure_code),
16861686
#[cfg(any(test, feature = "_test_utils"))]
16871687
onion_error_data: Some(data.clone()),
1688-
}
1689-
} else {
1690-
unreachable!();
1688+
},
1689+
HTLCSource::TrampolineForward { ref hops, .. } => DecodedOnionFailure {
1690+
network_update: None,
1691+
payment_failed_permanently: false,
1692+
short_channel_id: hops.first().map(|h| h.short_channel_id),
1693+
failed_within_blinded_path: false,
1694+
hold_times: Vec::new(),
1695+
#[cfg(any(test, feature = "_test_utils"))]
1696+
onion_error_code: Some(*failure_code),
1697+
#[cfg(any(test, feature = "_test_utils"))]
1698+
onion_error_data: Some(data.clone()),
1699+
},
1700+
_ => unreachable!(),
16911701
}
16921702
},
16931703
}

0 commit comments

Comments
 (0)