X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=lightning%2Fsrc%2Fln%2Fblinded_payment_tests.rs;h=9b580d1fa7599df71a70cf3d8819d4402545d5c8;hb=c92db69183143a58b3017ec450bdbf15a035bd9f;hp=e08ec16d5db0bd0ee59e4b35fd2f6c790d259356;hpb=a351301362508bf0fd4b444c3b37ec41d2c22450;p=rust-lightning diff --git a/lightning/src/ln/blinded_payment_tests.rs b/lightning/src/ln/blinded_payment_tests.rs index e08ec16d..9b580d1f 100644 --- a/lightning/src/ln/blinded_payment_tests.rs +++ b/lightning/src/ln/blinded_payment_tests.rs @@ -22,7 +22,7 @@ use crate::ln::onion_utils; use crate::ln::onion_utils::INVALID_ONION_BLINDING; use crate::ln::outbound_payment::Retry; use crate::prelude::*; -use crate::routing::router::{PaymentParameters, RouteParameters}; +use crate::routing::router::{Payee, PaymentParameters, RouteParameters}; use crate::util::config::UserConfig; use crate::util::test_utils; @@ -502,6 +502,11 @@ enum ReceiveCheckFail { // The incoming HTLC errors when added to the Channel, in this case due to the HTLC being // delivered out-of-order with a shutdown message. ChannelCheck, + // The HTLC is successfully added to the inbound channel but fails receive checks in + // process_pending_htlc_forwards. + ProcessPendingHTLCsCheck, + // The HTLC violates the `PaymentConstraints` contained within the receiver's encrypted payload. + PaymentConstraints, } #[test] @@ -510,6 +515,8 @@ fn multi_hop_receiver_fail() { do_multi_hop_receiver_fail(ReceiveCheckFail::OnionDecodeFail); do_multi_hop_receiver_fail(ReceiveCheckFail::ReceiveRequirements); do_multi_hop_receiver_fail(ReceiveCheckFail::ChannelCheck); + do_multi_hop_receiver_fail(ReceiveCheckFail::ProcessPendingHTLCsCheck); + do_multi_hop_receiver_fail(ReceiveCheckFail::PaymentConstraints); } fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) { @@ -530,12 +537,41 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) { }; let amt_msat = 5000; - let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], Some(amt_msat), None); - let route_params = get_blinded_route_parameters(amt_msat, payment_secret, + let final_cltv_delta = if check == ReceiveCheckFail::ProcessPendingHTLCsCheck { + // Set the final CLTV expiry too low to trigger the failure in process_pending_htlc_forwards. + Some(TEST_FINAL_CLTV as u16 - 2) + } else { None }; + let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], Some(amt_msat), final_cltv_delta); + let mut route_params = get_blinded_route_parameters(amt_msat, payment_secret, nodes.iter().skip(1).map(|n| n.node.get_our_node_id()).collect(), &[&chan_upd_1_2], &chanmon_cfgs[2].keys_manager); - let route = find_route(&nodes[0], &route_params).unwrap(); + let route = if check == ReceiveCheckFail::ProcessPendingHTLCsCheck { + let mut route = get_route(&nodes[0], &route_params).unwrap(); + // Set the final CLTV expiry too low to trigger the failure in process_pending_htlc_forwards. + route.paths[0].blinded_tail.as_mut().map(|bt| bt.excess_final_cltv_expiry_delta = TEST_FINAL_CLTV - 2); + route + } else if check == ReceiveCheckFail::PaymentConstraints { + // Create a blinded path where the receiver's encrypted payload has an htlc_minimum_msat that is + // violated by `amt_msat`, and stick it in the route_params without changing the corresponding + // BlindedPayInfo (to ensure pathfinding still succeeds). + let high_htlc_min_bp = { + let mut high_htlc_minimum_upd = chan_upd_1_2.clone(); + high_htlc_minimum_upd.htlc_minimum_msat = amt_msat + 1000; + let high_htlc_min_params = get_blinded_route_parameters(amt_msat, payment_secret, + nodes.iter().skip(1).map(|n| n.node.get_our_node_id()).collect(), &[&high_htlc_minimum_upd], + &chanmon_cfgs[2].keys_manager); + if let Payee::Blinded { route_hints, .. } = high_htlc_min_params.payment_params.payee { + route_hints[0].1.clone() + } else { panic!() } + }; + if let Payee::Blinded { ref mut route_hints, .. } = route_params.payment_params.payee { + route_hints[0].1 = high_htlc_min_bp; + } else { panic!() } + find_route(&nodes[0], &route_params).unwrap() + } else { + find_route(&nodes[0], &route_params).unwrap() + }; node_cfgs[0].router.expect_find_route(route_params.clone(), Ok(route.clone())); nodes[0].node.send_payment(payment_hash, RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap(); check_added_monitors(&nodes[0], 1); @@ -619,6 +655,20 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) { nodes[2].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_shutdown); commitment_signed_dance!(nodes[2], nodes[1], (), false, true, false, false); + }, + ReceiveCheckFail::ProcessPendingHTLCsCheck => { + nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event_1_2.msgs[0]); + check_added_monitors!(nodes[2], 0); + do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event_1_2.commitment_msg, true, true); + expect_pending_htlcs_forwardable!(nodes[2]); + expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!(nodes[2], + vec![HTLCDestination::FailedPayment { payment_hash }]); + check_added_monitors!(nodes[2], 1); + }, + ReceiveCheckFail::PaymentConstraints => { + nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event_1_2.msgs[0]); + check_added_monitors!(nodes[2], 0); + do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event_1_2.commitment_msg, true, true); } }