Skip to content

Commit 4d43ccd

Browse files
Test intro node failing blinded intercept HTLC.
1 parent 0a45870 commit 4d43ccd

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

lightning/src/ln/blinded_payment_tests.rs

+58
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,61 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck)
374374
expect_payment_failed_conditions(&nodes[0], payment_hash, false,
375375
PaymentFailedConditions::new().expected_htlc_error_data(INVALID_ONION_BLINDING, &[0; 32]));
376376
}
377+
378+
#[test]
379+
fn blinded_intercept_payment() {
380+
let chanmon_cfgs = create_chanmon_cfgs(3);
381+
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
382+
let mut intercept_forwards_config = test_default_channel_config();
383+
intercept_forwards_config.accept_intercept_htlcs = true;
384+
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, Some(intercept_forwards_config), None]);
385+
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
386+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0);
387+
let chan_upd = create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 1_000_000, 0).0.contents;
388+
389+
let amt_msat = 5000;
390+
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], Some(amt_msat), None);
391+
let intercept_scid = nodes[1].node.get_intercept_scid();
392+
let mut intercept_chan_upd = chan_upd;
393+
intercept_chan_upd.short_channel_id = intercept_scid;
394+
let route_params = get_blinded_route_parameters(amt_msat, payment_secret,
395+
nodes.iter().skip(1).map(|n| n.node.get_our_node_id()).collect(), &[&intercept_chan_upd],
396+
&chanmon_cfgs[2].keys_manager);
397+
398+
nodes[0].node.send_payment(payment_hash, RecipientOnionFields::spontaneous_empty(),
399+
PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap();
400+
check_added_monitors(&nodes[0], 1);
401+
let payment_event = {
402+
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
403+
assert_eq!(events.len(), 1);
404+
SendEvent::from_event(events.remove(0))
405+
};
406+
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
407+
commitment_signed_dance!(nodes[1], nodes[0], &payment_event.commitment_msg, false, true);
408+
409+
let events = nodes[1].node.get_and_clear_pending_events();
410+
assert_eq!(events.len(), 1);
411+
let intercept_id = match events[0] {
412+
crate::events::Event::HTLCIntercepted {
413+
intercept_id, payment_hash: pmt_hash,
414+
requested_next_hop_scid: short_channel_id, ..
415+
} => {
416+
assert_eq!(pmt_hash, payment_hash);
417+
assert_eq!(short_channel_id, intercept_scid);
418+
intercept_id
419+
},
420+
_ => panic!()
421+
};
422+
423+
nodes[1].node.fail_intercepted_htlc(intercept_id).unwrap();
424+
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!(nodes[1], vec![HTLCDestination::UnknownNextHop { requested_forward_scid: intercept_scid }]);
425+
nodes[1].node.process_pending_htlc_forwards();
426+
let update_fail = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
427+
check_added_monitors!(&nodes[1], 1);
428+
assert!(update_fail.update_fail_htlcs.len() == 1);
429+
let fail_msg = update_fail.update_fail_htlcs[0].clone();
430+
nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_msg);
431+
commitment_signed_dance!(nodes[0], nodes[1], update_fail.commitment_signed, false);
432+
expect_payment_failed_conditions(&nodes[0], payment_hash, false,
433+
PaymentFailedConditions::new().expected_htlc_error_data(INVALID_ONION_BLINDING, &[0; 32]));
434+
}

0 commit comments

Comments
 (0)