|
8 | 8 | // licenses.
|
9 | 9 |
|
10 | 10 | use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
|
| 11 | +use crate::blinded_path::utils::is_properly_padded; |
11 | 12 | use crate::blinded_path::BlindedPath;
|
12 | 13 | use crate::blinded_path::payment::{ForwardNode, ForwardTlvs, PaymentConstraints, PaymentContext, PaymentRelay, ReceiveTlvs};
|
13 | 14 | use crate::events::{Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, PaymentFailureReason};
|
@@ -1337,3 +1338,39 @@ fn custom_tlvs_to_blinded_path() {
|
1337 | 1338 | .with_custom_tlvs(recipient_onion_fields.custom_tlvs.clone())
|
1338 | 1339 | );
|
1339 | 1340 | }
|
| 1341 | + |
| 1342 | +#[test] |
| 1343 | +fn blinded_payment_path_padding() { |
| 1344 | + // Make sure that for a blinded payment path, all encrypted payloads are padded to equal lengths. |
| 1345 | + let chanmon_cfgs = create_chanmon_cfgs(5); |
| 1346 | + let node_cfgs = create_node_cfgs(5, &chanmon_cfgs); |
| 1347 | + let node_chanmgrs = create_node_chanmgrs(5, &node_cfgs, &[None, None, None, None, None]); |
| 1348 | + let mut nodes = create_network(5, &node_cfgs, &node_chanmgrs); |
| 1349 | + create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0); |
| 1350 | + create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 1_000_000, 0); |
| 1351 | + let chan_upd_2_3 = create_announced_chan_between_nodes_with_value(&nodes, 2, 3, 1_000_000, 0).0.contents; |
| 1352 | + let chan_upd_3_4 = create_announced_chan_between_nodes_with_value(&nodes, 3, 4, 1_000_000, 0).0.contents; |
| 1353 | + |
| 1354 | + // Get all our nodes onto the same height so payments don't fail for CLTV violations. |
| 1355 | + connect_blocks(&nodes[0], nodes[4].best_block_info().1 - nodes[0].best_block_info().1); |
| 1356 | + connect_blocks(&nodes[1], nodes[4].best_block_info().1 - nodes[1].best_block_info().1); |
| 1357 | + connect_blocks(&nodes[2], nodes[4].best_block_info().1 - nodes[2].best_block_info().1); |
| 1358 | + assert_eq!(nodes[4].best_block_info().1, nodes[3].best_block_info().1); |
| 1359 | + |
| 1360 | + let amt_msat = 5000; |
| 1361 | + let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[4], Some(amt_msat), None); |
| 1362 | + |
| 1363 | + let blinded_path = blinded_payment_path(payment_secret, 1, 1_0000_0000, |
| 1364 | + nodes.iter().skip(2).map(|n| n.node.get_our_node_id()).collect(), &[&chan_upd_2_3, &chan_upd_3_4], |
| 1365 | + &chanmon_cfgs[4].keys_manager |
| 1366 | + ); |
| 1367 | + |
| 1368 | + assert!(is_properly_padded(&blinded_path.1)); |
| 1369 | + |
| 1370 | + let route_params = RouteParameters::from_payment_params_and_value(PaymentParameters::blinded(vec![blinded_path]), amt_msat); |
| 1371 | + |
| 1372 | + nodes[0].node.send_payment(payment_hash, RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap(); |
| 1373 | + check_added_monitors(&nodes[0], 1); |
| 1374 | + pass_along_route(&nodes[0], &[&[&nodes[1], &nodes[2], &nodes[3], &nodes[4]]], amt_msat, payment_hash, payment_secret); |
| 1375 | + claim_payment(&nodes[0], &[&nodes[1], &nodes[2], &nodes[3], &nodes[4]], payment_preimage); |
| 1376 | +} |
0 commit comments