Skip to content

Commit cb022c5

Browse files
Test sending + receiving custom TLVs to blinded paths.
1 parent 143b8b3 commit cb022c5

File tree

3 files changed

+60
-10
lines changed

3 files changed

+60
-10
lines changed

lightning/src/ln/blinded_payment_tests.rs

+47
Original file line numberDiff line numberDiff line change
@@ -1264,3 +1264,50 @@ fn blinded_mpp_keysend() {
12641264
Some(payment_secret), ev.clone(), true, Some(keysend_preimage));
12651265
claim_payment_along_route(&nodes[0], expected_route, false, keysend_preimage);
12661266
}
1267+
1268+
#[test]
1269+
fn custom_tlvs_to_blinded_path() {
1270+
let chanmon_cfgs = create_chanmon_cfgs(2);
1271+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
1272+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
1273+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
1274+
let chan_upd = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0).0.contents;
1275+
1276+
let amt_msat = 5000;
1277+
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[1], Some(amt_msat), None);
1278+
let payee_tlvs = ReceiveTlvs {
1279+
payment_secret,
1280+
payment_constraints: PaymentConstraints {
1281+
max_cltv_expiry: u32::max_value(),
1282+
htlc_minimum_msat: chan_upd.htlc_minimum_msat,
1283+
},
1284+
};
1285+
let mut secp_ctx = Secp256k1::new();
1286+
let blinded_path = BlindedPath::one_hop_for_payment(
1287+
nodes[1].node.get_our_node_id(), payee_tlvs, TEST_FINAL_CLTV as u16,
1288+
&chanmon_cfgs[1].keys_manager, &secp_ctx
1289+
).unwrap();
1290+
1291+
let route_params = RouteParameters::from_payment_params_and_value(
1292+
PaymentParameters::blinded(vec![blinded_path]),
1293+
amt_msat,
1294+
);
1295+
1296+
let recipient_onion_fields = RecipientOnionFields::spontaneous_empty()
1297+
.with_custom_tlvs(vec![((1 << 16) + 1, vec![42, 42])])
1298+
.unwrap();
1299+
nodes[0].node.send_payment(payment_hash, recipient_onion_fields.clone(),
1300+
PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap();
1301+
check_added_monitors(&nodes[0], 1);
1302+
1303+
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
1304+
assert_eq!(events.len(), 1);
1305+
let ev = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut events);
1306+
1307+
let path = &[&nodes[1]];
1308+
let args = PassAlongPathArgs::new(&nodes[0], path, amt_msat, payment_hash, ev)
1309+
.with_payment_secret(payment_secret)
1310+
.with_custom_tlvs(recipient_onion_fields.custom_tlvs.clone());
1311+
do_pass_along_path(args);
1312+
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage);
1313+
}

lightning/src/ln/functional_test_utils.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -2512,6 +2512,7 @@ pub struct PassAlongPathArgs<'a, 'b, 'c, 'd> {
25122512
pub clear_recipient_events: bool,
25132513
pub expected_preimage: Option<PaymentPreimage>,
25142514
pub is_probe: bool,
2515+
pub custom_tlvs: Vec<(u64, Vec<u8>)>,
25152516
}
25162517

25172518
impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
@@ -2522,7 +2523,7 @@ impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
25222523
Self {
25232524
origin_node, expected_path, recv_value, payment_hash, payment_secret: None, event,
25242525
payment_claimable_expected: true, clear_recipient_events: true, expected_preimage: None,
2525-
is_probe: false,
2526+
is_probe: false, custom_tlvs: Vec::new(),
25262527
}
25272528
}
25282529
pub fn without_clearing_recipient_events(mut self) -> Self {
@@ -2546,13 +2547,17 @@ impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
25462547
self.expected_preimage = Some(payment_preimage);
25472548
self
25482549
}
2550+
pub fn with_custom_tlvs(mut self, custom_tlvs: Vec<(u64, Vec<u8>)>) -> Self {
2551+
self.custom_tlvs = custom_tlvs;
2552+
self
2553+
}
25492554
}
25502555

25512556
pub fn do_pass_along_path<'a, 'b, 'c>(args: PassAlongPathArgs) -> Option<Event> {
25522557
let PassAlongPathArgs {
25532558
origin_node, expected_path, recv_value, payment_hash: our_payment_hash,
25542559
payment_secret: our_payment_secret, event: ev, payment_claimable_expected,
2555-
clear_recipient_events, expected_preimage, is_probe
2560+
clear_recipient_events, expected_preimage, is_probe, custom_tlvs
25562561
} = args;
25572562

25582563
let mut payment_event = SendEvent::from_event(ev);
@@ -2585,6 +2590,7 @@ pub fn do_pass_along_path<'a, 'b, 'c>(args: PassAlongPathArgs) -> Option<Event>
25852590
assert_eq!(our_payment_hash, *payment_hash);
25862591
assert_eq!(node.node.get_our_node_id(), receiver_node_id.unwrap());
25872592
assert!(onion_fields.is_some());
2593+
assert_eq!(onion_fields.as_ref().unwrap().custom_tlvs, custom_tlvs);
25882594
match &purpose {
25892595
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
25902596
assert_eq!(expected_preimage, *payment_preimage);

lightning/src/ln/payment_tests.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -3813,14 +3813,11 @@ fn test_retry_custom_tlvs() {
38133813
check_added_monitors!(nodes[0], 1);
38143814
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
38153815
assert_eq!(events.len(), 1);
3816-
let payment_claimable = pass_along_path(&nodes[0], &[&nodes[1], &nodes[2]], 1_000_000,
3817-
payment_hash, Some(payment_secret), events.pop().unwrap(), true, None).unwrap();
3818-
match payment_claimable {
3819-
Event::PaymentClaimable { onion_fields, .. } => {
3820-
assert_eq!(&onion_fields.unwrap().custom_tlvs()[..], &custom_tlvs[..]);
3821-
},
3822-
_ => panic!("Unexpected event"),
3823-
};
3816+
let path = &[&nodes[1], &nodes[2]];
3817+
let args = PassAlongPathArgs::new(&nodes[0], path, 1_000_000, payment_hash, events.pop().unwrap())
3818+
.with_payment_secret(payment_secret)
3819+
.with_custom_tlvs(custom_tlvs);
3820+
do_pass_along_path(args);
38243821
claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], false, payment_preimage);
38253822
}
38263823

0 commit comments

Comments
 (0)