|
7 | 7 | // You may not use this file except in accordance with one or both of these
|
8 | 8 | // licenses.
|
9 | 9 |
|
10 |
| -use bitcoin::secp256k1::{Secp256k1, SecretKey}; |
| 10 | +use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey}; |
11 | 11 | use crate::blinded_path::BlindedPath;
|
12 | 12 | use crate::blinded_path::payment::{ForwardNode, ForwardTlvs, PaymentConstraints, PaymentRelay, ReceiveTlvs};
|
13 | 13 | use crate::events::MessageSendEventsProvider;
|
| 14 | +use crate::ln::PaymentSecret; |
14 | 15 | use crate::ln::channelmanager;
|
15 | 16 | use crate::ln::channelmanager::{PaymentId, RecipientOnionFields};
|
16 | 17 | use crate::ln::features::BlindedHopFeatures;
|
17 | 18 | use crate::ln::functional_test_utils::*;
|
| 19 | +use crate::ln::msgs; |
18 | 20 | use crate::ln::msgs::ChannelMessageHandler;
|
19 | 21 | use crate::ln::onion_utils;
|
20 | 22 | use crate::ln::onion_utils::INVALID_ONION_BLINDING;
|
21 | 23 | use crate::ln::outbound_payment::Retry;
|
22 | 24 | use crate::prelude::*;
|
23 | 25 | use crate::routing::router::{PaymentParameters, RouteParameters};
|
24 | 26 | use crate::util::config::UserConfig;
|
| 27 | +use crate::util::test_utils; |
| 28 | + |
| 29 | +pub fn get_blinded_route_parameters( |
| 30 | + amt_msat: u64, payment_secret: PaymentSecret, node_ids: Vec<PublicKey>, |
| 31 | + channel_upds: &[&msgs::UnsignedChannelUpdate], keys_manager: &test_utils::TestKeysInterface |
| 32 | +) -> RouteParameters { |
| 33 | + let mut intermediate_nodes = Vec::new(); |
| 34 | + for (node_id, chan_upd) in node_ids.iter().zip(channel_upds) { |
| 35 | + intermediate_nodes.push(ForwardNode { |
| 36 | + node_id: *node_id, |
| 37 | + tlvs: ForwardTlvs { |
| 38 | + short_channel_id: chan_upd.short_channel_id, |
| 39 | + payment_relay: PaymentRelay { |
| 40 | + cltv_expiry_delta: chan_upd.cltv_expiry_delta, |
| 41 | + fee_proportional_millionths: chan_upd.fee_proportional_millionths, |
| 42 | + fee_base_msat: chan_upd.fee_base_msat, |
| 43 | + }, |
| 44 | + payment_constraints: PaymentConstraints { |
| 45 | + max_cltv_expiry: u32::max_value(), |
| 46 | + htlc_minimum_msat: chan_upd.htlc_minimum_msat, |
| 47 | + }, |
| 48 | + features: BlindedHopFeatures::empty(), |
| 49 | + }, |
| 50 | + htlc_maximum_msat: chan_upd.htlc_maximum_msat, |
| 51 | + }); |
| 52 | + } |
| 53 | + let payee_tlvs = ReceiveTlvs { |
| 54 | + payment_secret, |
| 55 | + payment_constraints: PaymentConstraints { |
| 56 | + max_cltv_expiry: u32::max_value(), |
| 57 | + htlc_minimum_msat: channel_upds.last().unwrap().htlc_minimum_msat, |
| 58 | + }, |
| 59 | + }; |
| 60 | + let mut secp_ctx = Secp256k1::new(); |
| 61 | + let blinded_path = BlindedPath::new_for_payment( |
| 62 | + &intermediate_nodes[..], *node_ids.last().unwrap(), payee_tlvs, |
| 63 | + channel_upds.last().unwrap().htlc_maximum_msat, keys_manager, &secp_ctx |
| 64 | + ).unwrap(); |
| 65 | + |
| 66 | + RouteParameters::from_payment_params_and_value( |
| 67 | + PaymentParameters::blinded(vec![blinded_path]), amt_msat |
| 68 | + ) |
| 69 | +} |
25 | 70 |
|
26 | 71 | #[test]
|
27 | 72 | fn one_hop_blinded_path() {
|
@@ -145,38 +190,10 @@ fn do_forward_checks_failure(check: ForwardCheckFail) {
|
145 | 190 |
|
146 | 191 | let amt_msat = 5000;
|
147 | 192 | let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], Some(amt_msat), None);
|
148 |
| - let intermediate_nodes = vec![ForwardNode { |
149 |
| - node_id: nodes[1].node.get_our_node_id(), |
150 |
| - tlvs: ForwardTlvs { |
151 |
| - short_channel_id: chan_upd_1_2.short_channel_id, |
152 |
| - payment_relay: PaymentRelay { |
153 |
| - cltv_expiry_delta: chan_upd_1_2.cltv_expiry_delta, |
154 |
| - fee_proportional_millionths: chan_upd_1_2.fee_proportional_millionths, |
155 |
| - fee_base_msat: chan_upd_1_2.fee_base_msat, |
156 |
| - }, |
157 |
| - payment_constraints: PaymentConstraints { |
158 |
| - max_cltv_expiry: u32::max_value(), |
159 |
| - htlc_minimum_msat: chan_upd_1_2.htlc_minimum_msat, |
160 |
| - }, |
161 |
| - features: BlindedHopFeatures::empty(), |
162 |
| - }, |
163 |
| - htlc_maximum_msat: chan_upd_1_2.htlc_maximum_msat, |
164 |
| - }]; |
165 |
| - let payee_tlvs = ReceiveTlvs { |
166 |
| - payment_secret, |
167 |
| - payment_constraints: PaymentConstraints { |
168 |
| - max_cltv_expiry: u32::max_value(), |
169 |
| - htlc_minimum_msat: chan_upd_1_2.htlc_minimum_msat, |
170 |
| - }, |
171 |
| - }; |
172 |
| - let mut secp_ctx = Secp256k1::new(); |
173 |
| - let blinded_path = BlindedPath::new_for_payment( |
174 |
| - &intermediate_nodes[..], nodes[2].node.get_our_node_id(), payee_tlvs, |
175 |
| - chan_upd_1_2.htlc_maximum_msat, &chanmon_cfgs[2].keys_manager, &secp_ctx |
176 |
| - ).unwrap(); |
| 193 | + let route_params = get_blinded_route_parameters(amt_msat, payment_secret, |
| 194 | + nodes.iter().skip(1).map(|n| n.node.get_our_node_id()).collect(), &[&chan_upd_1_2], |
| 195 | + &chanmon_cfgs[2].keys_manager); |
177 | 196 |
|
178 |
| - let route_params = RouteParameters::from_payment_params_and_value( |
179 |
| - PaymentParameters::blinded(vec![blinded_path]), amt_msat); |
180 | 197 | let route = get_route(&nodes[0], &route_params).unwrap();
|
181 | 198 | node_cfgs[0].router.expect_find_route(route_params.clone(), Ok(route.clone()));
|
182 | 199 | nodes[0].node.send_payment(payment_hash, RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap();
|
|
0 commit comments