Skip to content

Commit 5b509c5

Browse files
Test received blinded HTLC failure in process_pending_htlc_forwards
1 parent be9bea5 commit 5b509c5

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

lightning/src/ln/blinded_payment_tests.rs

+26-2
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ enum ReceiveCheckFail {
502502
// The incoming HTLC errors when added to the Channel, in this case due to the HTLC being
503503
// delivered out-of-order with a shutdown message.
504504
ChannelCheck,
505+
// The HTLC is successfully added to the inbound channel but fails receive checks in
506+
// process_pending_htlc_forwards.
507+
ProcessPendingHTLCsCheck,
505508
}
506509

507510
#[test]
@@ -510,6 +513,7 @@ fn multi_hop_receiver_fail() {
510513
do_multi_hop_receiver_fail(ReceiveCheckFail::OnionDecodeFail);
511514
do_multi_hop_receiver_fail(ReceiveCheckFail::ReceiveRequirements);
512515
do_multi_hop_receiver_fail(ReceiveCheckFail::ChannelCheck);
516+
do_multi_hop_receiver_fail(ReceiveCheckFail::ProcessPendingHTLCsCheck);
513517
}
514518

515519
fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
@@ -530,12 +534,23 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
530534
};
531535

532536
let amt_msat = 5000;
533-
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], Some(amt_msat), None);
537+
let final_cltv_delta = if check == ReceiveCheckFail::ProcessPendingHTLCsCheck {
538+
// Set the final CLTV expiry too low to trigger the failure in process_pending_htlc_forwards.
539+
Some(TEST_FINAL_CLTV as u16 - 2)
540+
} else { None };
541+
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], Some(amt_msat), final_cltv_delta);
534542
let route_params = get_blinded_route_parameters(amt_msat, payment_secret,
535543
nodes.iter().skip(1).map(|n| n.node.get_our_node_id()).collect(), &[&chan_upd_1_2],
536544
&chanmon_cfgs[2].keys_manager);
537545

538-
let route = find_route(&nodes[0], &route_params).unwrap();
546+
let route = if check == ReceiveCheckFail::ProcessPendingHTLCsCheck {
547+
let mut route = get_route(&nodes[0], &route_params).unwrap();
548+
// Set the final CLTV expiry too low to trigger the failure in process_pending_htlc_forwards.
549+
route.paths[0].blinded_tail.as_mut().map(|bt| bt.excess_final_cltv_expiry_delta = TEST_FINAL_CLTV - 2);
550+
route
551+
} else {
552+
find_route(&nodes[0], &route_params).unwrap()
553+
};
539554
node_cfgs[0].router.expect_find_route(route_params.clone(), Ok(route.clone()));
540555
nodes[0].node.send_payment(payment_hash, RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap();
541556
check_added_monitors(&nodes[0], 1);
@@ -619,6 +634,15 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
619634

620635
nodes[2].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_shutdown);
621636
commitment_signed_dance!(nodes[2], nodes[1], (), false, true, false, false);
637+
},
638+
ReceiveCheckFail::ProcessPendingHTLCsCheck => {
639+
nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event_1_2.msgs[0]);
640+
check_added_monitors!(nodes[2], 0);
641+
do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event_1_2.commitment_msg, true, true);
642+
expect_pending_htlcs_forwardable!(nodes[2]);
643+
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!(nodes[2],
644+
vec![HTLCDestination::FailedPayment { payment_hash }]);
645+
check_added_monitors!(nodes[2], 1);
622646
}
623647
}
624648

0 commit comments

Comments
 (0)