Skip to content

Commit 30c754a

Browse files
Error if BOLT 11 features are provided for blinded payment params
1 parent 5a3e383 commit 30c754a

10 files changed

+60
-58
lines changed

lightning-invoice/src/payment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fn pay_invoice_using_amount<P: Deref>(
154154
.with_expiry_time(expiry_time_from_unix_epoch(invoice).as_secs())
155155
.with_route_hints(invoice.route_hints()).unwrap();
156156
if let Some(features) = invoice.features() {
157-
payment_params = payment_params.with_features(features.clone());
157+
payment_params = payment_params.with_bolt11_features(features.clone()).unwrap();
158158
}
159159
let route_params = RouteParameters {
160160
payment_params,

lightning-invoice/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ mod test {
838838

839839
let payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key(),
840840
invoice.min_final_cltv_expiry_delta() as u32)
841-
.with_features(invoice.features().unwrap().clone())
841+
.with_bolt11_features(invoice.features().unwrap().clone()).unwrap()
842842
.with_route_hints(invoice.route_hints()).unwrap();
843843
let route_params = RouteParameters {
844844
payment_params,
@@ -1294,7 +1294,7 @@ mod test {
12941294

12951295
let payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key(),
12961296
invoice.min_final_cltv_expiry_delta() as u32)
1297-
.with_features(invoice.features().unwrap().clone())
1297+
.with_bolt11_features(invoice.features().unwrap().clone()).unwrap()
12981298
.with_route_hints(invoice.route_hints()).unwrap();
12991299
let params = RouteParameters {
13001300
payment_params,

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9180,7 +9180,7 @@ pub mod bench {
91809180
macro_rules! send_payment {
91819181
($node_a: expr, $node_b: expr) => {
91829182
let payment_params = PaymentParameters::from_node_id($node_b.get_our_node_id(), TEST_FINAL_CLTV)
9183-
.with_features($node_b.invoice_features());
9183+
.with_bolt11_features($node_b.invoice_features()).unwrap();
91849184
let mut payment_preimage = PaymentPreimage([0; 32]);
91859185
payment_preimage.0[0..8].copy_from_slice(&payment_count.to_le_bytes());
91869186
payment_count += 1;

lightning/src/ln/functional_test_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,7 @@ macro_rules! get_route {
17231723
macro_rules! get_route_and_payment_hash {
17241724
($send_node: expr, $recv_node: expr, $recv_value: expr) => {{
17251725
let payment_params = $crate::routing::router::PaymentParameters::from_node_id($recv_node.node.get_our_node_id(), TEST_FINAL_CLTV)
1726-
.with_features($recv_node.node.invoice_features());
1726+
.with_bolt11_features($recv_node.node.invoice_features()).unwrap();
17271727
$crate::get_route_and_payment_hash!($send_node, $recv_node, payment_params, $recv_value)
17281728
}};
17291729
($send_node: expr, $recv_node: expr, $payment_params: expr, $recv_value: expr) => {{
@@ -2272,7 +2272,7 @@ pub const TEST_FINAL_CLTV: u32 = 70;
22722272

22732273
pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) -> (PaymentPreimage, PaymentHash, PaymentSecret) {
22742274
let payment_params = PaymentParameters::from_node_id(expected_route.last().unwrap().node.get_our_node_id(), TEST_FINAL_CLTV)
2275-
.with_features(expected_route.last().unwrap().node.invoice_features());
2275+
.with_bolt11_features(expected_route.last().unwrap().node.invoice_features()).unwrap();
22762276
let route = get_route(origin_node, &payment_params, recv_value).unwrap();
22772277
assert_eq!(route.paths.len(), 1);
22782278
assert_eq!(route.paths[0].hops.len(), expected_route.len());
@@ -2286,7 +2286,7 @@ pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route:
22862286

22872287
pub fn route_over_limit<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) {
22882288
let payment_params = PaymentParameters::from_node_id(expected_route.last().unwrap().node.get_our_node_id(), TEST_FINAL_CLTV)
2289-
.with_features(expected_route.last().unwrap().node.invoice_features());
2289+
.with_bolt11_features(expected_route.last().unwrap().node.invoice_features()).unwrap();
22902290
let network_graph = origin_node.network_graph.read_only();
22912291
let scorer = test_utils::TestScorer::new();
22922292
let seed = [0u8; 32];

lightning/src/ln/functional_tests.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ fn test_channel_reserve_holding_cell_htlcs() {
18291829
// attempt to send amt_msat > their_max_htlc_value_in_flight_msat
18301830
{
18311831
let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV)
1832-
.with_features(nodes[2].node.invoice_features()).with_max_channel_saturation_power_of_half(0);
1832+
.with_bolt11_features(nodes[2].node.invoice_features()).unwrap().with_max_channel_saturation_power_of_half(0);
18331833
let (mut route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, recv_value_0);
18341834
route.paths[0].hops.last_mut().unwrap().fee_msat += 1;
18351835
assert!(route.paths[0].hops.iter().rev().skip(1).all(|h| h.fee_msat == feemsat));
@@ -1856,7 +1856,7 @@ fn test_channel_reserve_holding_cell_htlcs() {
18561856
}
18571857

18581858
let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV)
1859-
.with_features(nodes[2].node.invoice_features()).with_max_channel_saturation_power_of_half(0);
1859+
.with_bolt11_features(nodes[2].node.invoice_features()).unwrap().with_max_channel_saturation_power_of_half(0);
18601860
let route = get_route!(nodes[0], payment_params, recv_value_0).unwrap();
18611861
let (payment_preimage, ..) = send_along_route(&nodes[0], route, &[&nodes[1], &nodes[2]], recv_value_0);
18621862
claim_payment(&nodes[0], &[&nodes[1], &nodes[2]], payment_preimage);
@@ -4795,7 +4795,7 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
47954795
// script push size limit so that the below script length checks match
47964796
// ACCEPTED_HTLC_SCRIPT_WEIGHT.
47974797
let payment_params = PaymentParameters::from_node_id(nodes[3].node.get_our_node_id(), TEST_FINAL_CLTV - 40)
4798-
.with_features(nodes[3].node.invoice_features());
4798+
.with_bolt11_features(nodes[3].node.invoice_features()).unwrap();
47994799
let (route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[3], payment_params, 800_000);
48004800
send_along_route_with_secret(&nodes[0], route, &[&[&nodes[1], &nodes[2], &nodes[3]]], 800_000, duplicate_payment_hash, payment_secret);
48014801

@@ -6101,7 +6101,7 @@ fn test_update_add_htlc_bolt2_sender_cltv_expiry_too_high() {
61016101
let _chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 0);
61026102

61036103
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), 0)
6104-
.with_features(nodes[1].node.invoice_features());
6104+
.with_bolt11_features(nodes[1].node.invoice_features()).unwrap();
61056105
let (mut route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], payment_params, 100000000);
61066106
route.paths[0].hops.last_mut().unwrap().cltv_expiry_delta = 500000001;
61076107
unwrap_send_err!(nodes[0].node.send_payment_with_route(&route, our_payment_hash,
@@ -7043,7 +7043,7 @@ fn test_check_htlc_underpaying() {
70437043

70447044
let scorer = test_utils::TestScorer::new();
70457045
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
7046-
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV).with_features(nodes[1].node.invoice_features());
7046+
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV).with_bolt11_features(nodes[1].node.invoice_features()).unwrap();
70477047
let route = get_route(&nodes[0].node.get_our_node_id(), &payment_params, &nodes[0].network_graph.read_only(), None, 10_000, nodes[0].logger, &scorer, &random_seed_bytes).unwrap();
70487048
let (_, our_payment_hash, _) = get_payment_preimage_hash!(nodes[0]);
70497049
let our_payment_secret = nodes[1].node.create_inbound_payment_for_hash(our_payment_hash, Some(100_000), 7200, None).unwrap();
@@ -7189,7 +7189,7 @@ fn test_bump_penalty_txn_on_revoked_commitment() {
71897189

71907190
let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0;
71917191
let payment_params = PaymentParameters::from_node_id(nodes[0].node.get_our_node_id(), 30)
7192-
.with_features(nodes[0].node.invoice_features());
7192+
.with_bolt11_features(nodes[0].node.invoice_features()).unwrap();
71937193
let (route,_, _, _) = get_route_and_payment_hash!(nodes[1], nodes[0], payment_params, 3000000);
71947194
send_along_route(&nodes[1], route, &vec!(&nodes[0])[..], 3000000);
71957195

@@ -7294,13 +7294,13 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
72947294

72957295
let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000);
72967296
// Lock HTLC in both directions (using a slightly lower CLTV delay to provide timely RBF bumps)
7297-
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), 50).with_features(nodes[1].node.invoice_features());
7297+
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), 50).with_bolt11_features(nodes[1].node.invoice_features()).unwrap();
72987298
let scorer = test_utils::TestScorer::new();
72997299
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
73007300
let route = get_route(&nodes[0].node.get_our_node_id(), &payment_params, &nodes[0].network_graph.read_only(), None,
73017301
3_000_000, nodes[0].logger, &scorer, &random_seed_bytes).unwrap();
73027302
let payment_preimage = send_along_route(&nodes[0], route, &[&nodes[1]], 3_000_000).0;
7303-
let payment_params = PaymentParameters::from_node_id(nodes[0].node.get_our_node_id(), 50).with_features(nodes[0].node.invoice_features());
7303+
let payment_params = PaymentParameters::from_node_id(nodes[0].node.get_our_node_id(), 50).with_bolt11_features(nodes[0].node.invoice_features()).unwrap();
73047304
let route = get_route(&nodes[1].node.get_our_node_id(), &payment_params, &nodes[1].network_graph.read_only(), None,
73057305
3_000_000, nodes[0].logger, &scorer, &random_seed_bytes).unwrap();
73067306
send_along_route(&nodes[1], route, &[&nodes[0]], 3_000_000);
@@ -9300,7 +9300,7 @@ fn do_test_dup_htlc_second_rejected(test_for_second_fail_panic: bool) {
93009300
let _chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 10001);
93019301

93029302
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
9303-
.with_features(nodes[1].node.invoice_features());
9303+
.with_bolt11_features(nodes[1].node.invoice_features()).unwrap();
93049304
let route = get_route!(nodes[0], payment_params, 10_000).unwrap();
93059305

93069306
let (our_payment_preimage, our_payment_hash, our_payment_secret) = get_payment_preimage_hash!(&nodes[1]);
@@ -9409,7 +9409,7 @@ fn test_inconsistent_mpp_params() {
94099409
let chan_2_3 =create_announced_chan_between_nodes_with_value(&nodes, 2, 3, 100_000, 0);
94109410

94119411
let payment_params = PaymentParameters::from_node_id(nodes[3].node.get_our_node_id(), TEST_FINAL_CLTV)
9412-
.with_features(nodes[3].node.invoice_features());
9412+
.with_bolt11_features(nodes[3].node.invoice_features()).unwrap();
94139413
let mut route = get_route!(nodes[0], payment_params, 15_000_000).unwrap();
94149414
assert_eq!(route.paths.len(), 2);
94159415
route.paths.sort_by(|path_a, _| {

lightning/src/ln/onion_route_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ fn do_test_onion_failure_stale_channel_update(announced_channel: bool) {
714714
htlc_minimum_msat: None,
715715
}])];
716716
let payment_params = PaymentParameters::from_node_id(*channel_to_update_counterparty, TEST_FINAL_CLTV)
717-
.with_features(nodes[2].node.invoice_features())
717+
.with_bolt11_features(nodes[2].node.invoice_features()).unwrap()
718718
.with_route_hints(hop_hints).unwrap();
719719
get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, PAYMENT_AMT)
720720
};
@@ -861,7 +861,7 @@ fn test_always_create_tlv_format_onion_payloads() {
861861
create_announced_chan_between_nodes(&nodes, 1, 2);
862862

863863
let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV)
864-
.with_features(InvoiceFeatures::empty());
864+
.with_bolt11_features(InvoiceFeatures::empty()).unwrap();
865865
let (route, _payment_hash, _payment_preimage, _payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 40000);
866866

867867
let hops = &route.paths[0].hops;
@@ -963,7 +963,7 @@ macro_rules! get_phantom_route {
963963
let phantom_pubkey = $nodes[1].keys_manager.get_node_id(Recipient::PhantomNode).unwrap();
964964
let phantom_route_hint = $nodes[1].node.get_phantom_route_hints();
965965
let payment_params = PaymentParameters::from_node_id(phantom_pubkey, TEST_FINAL_CLTV)
966-
.with_features($nodes[1].node.invoice_features())
966+
.with_bolt11_features($nodes[1].node.invoice_features()).unwrap()
967967
.with_route_hints(vec![RouteHint(vec![
968968
RouteHintHop {
969969
src_node_id: $nodes[0].node.get_our_node_id(),

lightning/src/ln/payment_tests.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ fn get_ldk_payment_preimage() {
857857
let (payment_hash, payment_secret) = nodes[1].node.create_inbound_payment(Some(amt_msat), expiry_secs, None).unwrap();
858858

859859
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
860-
.with_features(nodes[1].node.invoice_features());
860+
.with_bolt11_features(nodes[1].node.invoice_features()).unwrap();
861861
let scorer = test_utils::TestScorer::new();
862862
let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
863863
let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -1410,7 +1410,7 @@ fn do_test_intercepted_payment(test: InterceptTest) {
14101410
htlc_maximum_msat: None,
14111411
}])
14121412
]).unwrap()
1413-
.with_features(nodes[2].node.invoice_features());
1413+
.with_bolt11_features(nodes[2].node.invoice_features()).unwrap();
14141414
let route_params = RouteParameters {
14151415
payment_params,
14161416
final_value_msat: amt_msat,
@@ -1600,7 +1600,7 @@ fn do_automatic_retries(test: AutoRetry) {
16001600
invoice_features.set_basic_mpp_optional();
16011601
let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV)
16021602
.with_expiry_time(payment_expiry_secs as u64)
1603-
.with_features(invoice_features);
1603+
.with_bolt11_features(invoice_features).unwrap();
16041604
let route_params = RouteParameters {
16051605
payment_params,
16061606
final_value_msat: amt_msat,
@@ -1819,7 +1819,7 @@ fn auto_retry_partial_failure() {
18191819
invoice_features.set_basic_mpp_optional();
18201820
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
18211821
.with_expiry_time(payment_expiry_secs as u64)
1822-
.with_features(invoice_features);
1822+
.with_bolt11_features(invoice_features).unwrap();
18231823
let route_params = RouteParameters {
18241824
payment_params,
18251825
final_value_msat: amt_msat,
@@ -2031,7 +2031,7 @@ fn auto_retry_zero_attempts_send_error() {
20312031
invoice_features.set_basic_mpp_optional();
20322032
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
20332033
.with_expiry_time(payment_expiry_secs as u64)
2034-
.with_features(invoice_features);
2034+
.with_bolt11_features(invoice_features).unwrap();
20352035
let route_params = RouteParameters {
20362036
payment_params,
20372037
final_value_msat: amt_msat,
@@ -2071,7 +2071,7 @@ fn fails_paying_after_rejected_by_payee() {
20712071
invoice_features.set_basic_mpp_optional();
20722072
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
20732073
.with_expiry_time(payment_expiry_secs as u64)
2074-
.with_features(invoice_features);
2074+
.with_bolt11_features(invoice_features).unwrap();
20752075
let route_params = RouteParameters {
20762076
payment_params,
20772077
final_value_msat: amt_msat,
@@ -2118,7 +2118,7 @@ fn retry_multi_path_single_failed_payment() {
21182118
invoice_features.set_basic_mpp_optional();
21192119
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
21202120
.with_expiry_time(payment_expiry_secs as u64)
2121-
.with_features(invoice_features);
2121+
.with_bolt11_features(invoice_features).unwrap();
21222122
let route_params = RouteParameters {
21232123
payment_params: payment_params.clone(),
21242124
final_value_msat: amt_msat,
@@ -2212,7 +2212,7 @@ fn immediate_retry_on_failure() {
22122212
invoice_features.set_basic_mpp_optional();
22132213
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
22142214
.with_expiry_time(payment_expiry_secs as u64)
2215-
.with_features(invoice_features);
2215+
.with_bolt11_features(invoice_features).unwrap();
22162216
let route_params = RouteParameters {
22172217
payment_params,
22182218
final_value_msat: amt_msat,
@@ -2301,7 +2301,7 @@ fn no_extra_retries_on_back_to_back_fail() {
23012301
invoice_features.set_basic_mpp_optional();
23022302
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
23032303
.with_expiry_time(payment_expiry_secs as u64)
2304-
.with_features(invoice_features);
2304+
.with_bolt11_features(invoice_features).unwrap();
23052305
let route_params = RouteParameters {
23062306
payment_params,
23072307
final_value_msat: amt_msat,
@@ -2503,7 +2503,7 @@ fn test_simple_partial_retry() {
25032503
invoice_features.set_basic_mpp_optional();
25042504
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
25052505
.with_expiry_time(payment_expiry_secs as u64)
2506-
.with_features(invoice_features);
2506+
.with_bolt11_features(invoice_features).unwrap();
25072507
let route_params = RouteParameters {
25082508
payment_params,
25092509
final_value_msat: amt_msat,
@@ -2669,7 +2669,7 @@ fn test_threaded_payment_retries() {
26692669
invoice_features.set_basic_mpp_optional();
26702670
let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
26712671
.with_expiry_time(payment_expiry_secs as u64)
2672-
.with_features(invoice_features);
2672+
.with_bolt11_features(invoice_features).unwrap();
26732673
let mut route_params = RouteParameters {
26742674
payment_params,
26752675
final_value_msat: amt_msat,
@@ -2906,7 +2906,7 @@ fn do_claim_from_closed_chan(fail_payment: bool) {
29062906
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[3]);
29072907
let mut route_params = RouteParameters {
29082908
payment_params: PaymentParameters::from_node_id(nodes[3].node.get_our_node_id(), TEST_FINAL_CLTV)
2909-
.with_features(nodes[1].node.invoice_features()),
2909+
.with_bolt11_features(nodes[1].node.invoice_features()).unwrap(),
29102910
final_value_msat: 10_000_000,
29112911
};
29122912
let mut route = nodes[0].router.find_route(&nodes[0].node.get_our_node_id(), &route_params,
@@ -3050,7 +3050,7 @@ fn do_test_payment_metadata_consistency(do_reload: bool, do_modify: bool) {
30503050
let payment_metadata = vec![44, 49, 52, 142];
30513051

30523052
let payment_params = PaymentParameters::from_node_id(nodes[3].node.get_our_node_id(), TEST_FINAL_CLTV)
3053-
.with_features(nodes[1].node.invoice_features());
3053+
.with_bolt11_features(nodes[1].node.invoice_features()).unwrap();
30543054
let mut route_params = RouteParameters {
30553055
payment_params,
30563056
final_value_msat: amt_msat,

0 commit comments

Comments
 (0)