Skip to content

Commit 2c22055

Browse files
Test 3-hop blinded path recipient failure.
This tests an intermediate forwarding node being failed back to with malformed and then failing back themselves with malformed.
1 parent 5fbc44e commit 2c22055

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,59 @@ fn three_hop_blinded_path_success() {
681681
claim_payment(&nodes[0], &[&nodes[1], &nodes[2], &nodes[3], &nodes[4]], payment_preimage);
682682
}
683683

684+
#[test]
685+
fn three_hop_blinded_path_fail() {
686+
// Test that an intermediate blinded forwarding node gets failed back to with
687+
// malformed and also fails back themselves with malformed.
688+
let chanmon_cfgs = create_chanmon_cfgs(4);
689+
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
690+
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
691+
let mut nodes = create_network(4, &node_cfgs, &node_chanmgrs);
692+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0);
693+
let chan_upd_1_2 = create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 1_000_000, 0).0.contents;
694+
let chan_upd_2_3 = create_announced_chan_between_nodes_with_value(&nodes, 2, 3, 1_000_000, 0).0.contents;
695+
696+
let amt_msat = 5000;
697+
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[3], Some(amt_msat), None);
698+
let route_params = get_blinded_route_parameters(amt_msat, payment_secret,
699+
nodes.iter().skip(1).map(|n| n.node.get_our_node_id()).collect(),
700+
&[&chan_upd_1_2, &chan_upd_2_3], &chanmon_cfgs[3].keys_manager);
701+
702+
nodes[0].node.send_payment(payment_hash, RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap();
703+
check_added_monitors(&nodes[0], 1);
704+
pass_along_route(&nodes[0], &[&[&nodes[1], &nodes[2], &nodes[3]]], amt_msat, payment_hash, payment_secret);
705+
706+
nodes[3].node.fail_htlc_backwards(&payment_hash);
707+
expect_pending_htlcs_forwardable_conditions(
708+
nodes[3].node.get_and_clear_pending_events(), &[HTLCDestination::FailedPayment { payment_hash }]
709+
);
710+
nodes[3].node.process_pending_htlc_forwards();
711+
check_added_monitors!(nodes[3], 1);
712+
713+
let updates_3_2 = get_htlc_update_msgs!(nodes[3], nodes[2].node.get_our_node_id());
714+
assert_eq!(updates_3_2.update_fail_malformed_htlcs.len(), 1);
715+
let update_malformed = &updates_3_2.update_fail_malformed_htlcs[0];
716+
assert_eq!(update_malformed.sha256_of_onion, [0; 32]);
717+
assert_eq!(update_malformed.failure_code, INVALID_ONION_BLINDING);
718+
nodes[2].node.handle_update_fail_malformed_htlc(&nodes[3].node.get_our_node_id(), update_malformed);
719+
do_commitment_signed_dance(&nodes[2], &nodes[3], &updates_3_2.commitment_signed, true, false);
720+
721+
let updates_2_1 = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
722+
assert_eq!(updates_2_1.update_fail_malformed_htlcs.len(), 1);
723+
let update_malformed = &updates_2_1.update_fail_malformed_htlcs[0];
724+
assert_eq!(update_malformed.sha256_of_onion, [0; 32]);
725+
assert_eq!(update_malformed.failure_code, INVALID_ONION_BLINDING);
726+
nodes[1].node.handle_update_fail_malformed_htlc(&nodes[2].node.get_our_node_id(), update_malformed);
727+
do_commitment_signed_dance(&nodes[1], &nodes[2], &updates_2_1.commitment_signed, true, false);
728+
729+
let updates_1_0 = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
730+
assert_eq!(updates_1_0.update_fail_htlcs.len(), 1);
731+
nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates_1_0.update_fail_htlcs[0]);
732+
do_commitment_signed_dance(&nodes[0], &nodes[1], &updates_1_0.commitment_signed, false, false);
733+
expect_payment_failed_conditions(&nodes[0], payment_hash, false,
734+
PaymentFailedConditions::new().expected_htlc_error_data(INVALID_ONION_BLINDING, &[0; 32]));
735+
}
736+
684737
#[derive(PartialEq)]
685738
enum ReceiveCheckFail {
686739
// The recipient fails the payment upon `PaymentClaimable`.

0 commit comments

Comments
 (0)