Skip to content

Commit a2f5be0

Browse files
committed
f: test forwarding failure
1 parent 4042464 commit a2f5be0

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
lines changed

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 46 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,48 @@ 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 route: &[&Node] = if success {
2656+
&[&nodes[1], &nodes[2], &nodes[4], &nodes[3]]
2657+
} else {
2658+
&[&nodes[1], &nodes[2]]
2659+
};
2660+
let args = PassAlongPathArgs::new(&nodes[0], route, amt_msat, payment_hash, first_message_event);
2661+
let args = if success {
2662+
args.with_payment_secret(payment_secret)
2663+
} else {
2664+
args.with_payment_preimage(payment_preimage)
2665+
.without_claimable_event()
2666+
.expect_failure(HTLCDestination::FailedTrampolineForward { requested_next_node_id: dave_node_id, forward_scid: None })
2667+
};
26572668
do_pass_along_path(args);
26582669

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

lightning/src/ln/onion_utils.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,8 +1672,8 @@ impl HTLCFailReason {
16721672
// failures here, but that would be insufficient as find_route
16731673
// generally ignores its view of our own channels as we provide them via
16741674
// ChannelDetails.
1675-
if let &HTLCSource::OutboundRoute { ref path, .. } = htlc_source {
1676-
DecodedOnionFailure {
1675+
match htlc_source {
1676+
HTLCSource::OutboundRoute { ref path, .. } => DecodedOnionFailure {
16771677
network_update: None,
16781678
payment_failed_permanently: false,
16791679
short_channel_id: Some(path.hops[0].short_channel_id),
@@ -1683,9 +1683,19 @@ impl HTLCFailReason {
16831683
onion_error_code: Some(*failure_code),
16841684
#[cfg(any(test, feature = "_test_utils"))]
16851685
onion_error_data: Some(data.clone()),
1686-
}
1687-
} else {
1688-
unreachable!();
1686+
},
1687+
HTLCSource::TrampolineForward { ref hops, .. } => DecodedOnionFailure {
1688+
network_update: None,
1689+
payment_failed_permanently: false,
1690+
short_channel_id: hops.first().map(|h| h.short_channel_id),
1691+
failed_within_blinded_path: false,
1692+
hold_times: Vec::new(),
1693+
#[cfg(any(test, feature = "_test_utils"))]
1694+
onion_error_code: Some(*failure_code),
1695+
#[cfg(any(test, feature = "_test_utils"))]
1696+
onion_error_data: Some(data.clone()),
1697+
},
1698+
_ => unreachable!(),
16891699
}
16901700
},
16911701
}

0 commit comments

Comments
 (0)