Skip to content

Commit be2ce23

Browse files
Error if clear hints are provided for blinded PaymentParams
1 parent 4ec420b commit be2ce23

File tree

7 files changed

+36
-31
lines changed

7 files changed

+36
-31
lines changed

fuzz/src/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
300300
let final_cltv_expiry_delta = slice_to_be32(get_slice!(4));
301301
let route_params = RouteParameters {
302302
payment_params: PaymentParameters::from_node_id(*target, final_cltv_expiry_delta)
303-
.with_route_hints(last_hops.clone()),
303+
.with_route_hints(last_hops.clone()).unwrap(),
304304
final_value_msat,
305305
};
306306
let _ = find_route(&our_pubkey, &route_params, &net_graph,

lightning-invoice/src/payment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fn pay_invoice_using_amount<P: Deref>(
152152
let mut payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key(),
153153
invoice.min_final_cltv_expiry_delta() as u32)
154154
.with_expiry_time(expiry_time_from_unix_epoch(invoice).as_secs())
155-
.with_route_hints(invoice.route_hints());
155+
.with_route_hints(invoice.route_hints()).unwrap();
156156
if let Some(features) = invoice.features() {
157157
payment_params = payment_params.with_features(features.clone());
158158
}

lightning-invoice/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ mod test {
839839
let payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key(),
840840
invoice.min_final_cltv_expiry_delta() as u32)
841841
.with_features(invoice.features().unwrap().clone())
842-
.with_route_hints(invoice.route_hints());
842+
.with_route_hints(invoice.route_hints()).unwrap();
843843
let route_params = RouteParameters {
844844
payment_params,
845845
final_value_msat: invoice.amount_milli_satoshis().unwrap(),
@@ -1295,7 +1295,7 @@ mod test {
12951295
let payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key(),
12961296
invoice.min_final_cltv_expiry_delta() as u32)
12971297
.with_features(invoice.features().unwrap().clone())
1298-
.with_route_hints(invoice.route_hints());
1298+
.with_route_hints(invoice.route_hints()).unwrap();
12991299
let params = RouteParameters {
13001300
payment_params,
13011301
final_value_msat: invoice.amount_milli_satoshis().unwrap(),

lightning/src/ln/onion_route_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ fn do_test_onion_failure_stale_channel_update(announced_channel: bool) {
715715
}])];
716716
let payment_params = PaymentParameters::from_node_id(*channel_to_update_counterparty, TEST_FINAL_CLTV)
717717
.with_features(nodes[2].node.invoice_features())
718-
.with_route_hints(hop_hints);
718+
.with_route_hints(hop_hints).unwrap();
719719
get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, PAYMENT_AMT)
720720
};
721721
send_along_route_with_secret(&nodes[0], route.clone(), &[&[&nodes[1], &nodes[2]]], PAYMENT_AMT,
@@ -987,7 +987,7 @@ macro_rules! get_phantom_route {
987987
htlc_minimum_msat: None,
988988
htlc_maximum_msat: None,
989989
}
990-
])]);
990+
])]).unwrap();
991991
let scorer = test_utils::TestScorer::new();
992992
let network_graph = $nodes[0].network_graph.read_only();
993993
(get_route(

lightning/src/ln/payment_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ fn do_test_intercepted_payment(test: InterceptTest) {
14091409
htlc_minimum_msat: None,
14101410
htlc_maximum_msat: None,
14111411
}])
1412-
])
1412+
]).unwrap()
14131413
.with_features(nodes[2].node.invoice_features());
14141414
let route_params = RouteParameters {
14151415
payment_params,

lightning/src/ln/priv_short_conf_tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn test_priv_forwarding_rejection() {
6868
let last_hops = vec![route_hint];
6969
let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV)
7070
.with_features(nodes[2].node.invoice_features())
71-
.with_route_hints(last_hops);
71+
.with_route_hints(last_hops).unwrap();
7272
let (route, our_payment_hash, our_payment_preimage, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 10_000);
7373

7474
nodes[0].node.send_payment_with_route(&route, our_payment_hash,
@@ -237,7 +237,7 @@ fn test_routed_scid_alias() {
237237
}])];
238238
let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), 42)
239239
.with_features(nodes[2].node.invoice_features())
240-
.with_route_hints(hop_hints);
240+
.with_route_hints(hop_hints).unwrap();
241241
let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 100_000);
242242
assert_eq!(route.paths[0].hops[1].short_channel_id, last_hop[0].inbound_scid_alias.unwrap());
243243
nodes[0].node.send_payment_with_route(&route, payment_hash,
@@ -403,7 +403,7 @@ fn test_inbound_scid_privacy() {
403403
}])];
404404
let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), 42)
405405
.with_features(nodes[2].node.invoice_features())
406-
.with_route_hints(hop_hints.clone());
406+
.with_route_hints(hop_hints.clone()).unwrap();
407407
let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 100_000);
408408
assert_eq!(route.paths[0].hops[1].short_channel_id, last_hop[0].inbound_scid_alias.unwrap());
409409
nodes[0].node.send_payment_with_route(&route, payment_hash,
@@ -419,7 +419,7 @@ fn test_inbound_scid_privacy() {
419419

420420
let payment_params_2 = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), 42)
421421
.with_features(nodes[2].node.invoice_features())
422-
.with_route_hints(hop_hints);
422+
.with_route_hints(hop_hints).unwrap();
423423
let (route_2, payment_hash_2, _, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params_2, 100_000);
424424
assert_eq!(route_2.paths[0].hops[1].short_channel_id, last_hop[0].short_channel_id.unwrap());
425425
nodes[0].node.send_payment_with_route(&route_2, payment_hash_2,
@@ -471,7 +471,7 @@ fn test_scid_alias_returned() {
471471
}])];
472472
let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), 42)
473473
.with_features(nodes[2].node.invoice_features())
474-
.with_route_hints(hop_hints);
474+
.with_route_hints(hop_hints).unwrap();
475475
let (mut route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 10_000);
476476
assert_eq!(route.paths[0].hops[1].short_channel_id, nodes[2].node.list_usable_channels()[0].inbound_scid_alias.unwrap());
477477

lightning/src/routing/router.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -637,11 +637,16 @@ impl PaymentParameters {
637637
Self { features: Some(features), ..self }
638638
}
639639

640-
/// Includes hints for routing to the payee.
640+
/// Includes hints for routing to the payee. Errors if the parameters were initialized with
641+
/// blinded payment paths.
641642
///
642643
/// This is not exported to bindings users since bindings don't support move semantics
643-
pub fn with_route_hints(self, route_hints: Vec<RouteHint>) -> Self {
644-
Self { payee: Payee::Clear { route_hints }, ..self }
644+
pub fn with_route_hints(self, route_hints: Vec<RouteHint>) -> Result<Self, ()> {
645+
match self.payee {
646+
Payee::Blinded(_) => Err(()),
647+
Payee::Clear { .. } =>
648+
Ok(Self { payee: Payee::Clear { route_hints }, ..self })
649+
}
645650
}
646651

647652
/// Includes a payment expiration in seconds relative to the UNIX epoch.
@@ -2930,13 +2935,13 @@ mod tests {
29302935
let mut invalid_last_hops = last_hops_multi_private_channels(&nodes);
29312936
invalid_last_hops.push(invalid_last_hop);
29322937
{
2933-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(invalid_last_hops);
2938+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(invalid_last_hops).unwrap();
29342939
if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route(&our_id, &payment_params, &network_graph.read_only(), None, 100, Arc::clone(&logger), &scorer, &random_seed_bytes) {
29352940
assert_eq!(err, "Route hint cannot have the payee as the source.");
29362941
} else { panic!(); }
29372942
}
29382943

2939-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops_multi_private_channels(&nodes));
2944+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops_multi_private_channels(&nodes)).unwrap();
29402945
let route = get_route(&our_id, &payment_params, &network_graph.read_only(), None, 100, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
29412946
assert_eq!(route.paths[0].hops.len(), 5);
29422947

@@ -3006,7 +3011,7 @@ mod tests {
30063011
fn ignores_empty_last_hops_test() {
30073012
let (secp_ctx, network_graph, _, _, logger) = build_graph();
30083013
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
3009-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(empty_last_hop(&nodes));
3014+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(empty_last_hop(&nodes)).unwrap();
30103015
let scorer = ln_test_utils::TestScorer::new();
30113016
let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
30123017
let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -3086,7 +3091,7 @@ mod tests {
30863091
let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
30873092
let (_, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
30883093
let last_hops = multi_hop_last_hops_hint([nodes[2], nodes[3]]);
3089-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops.clone());
3094+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops.clone()).unwrap();
30903095
let scorer = ln_test_utils::TestScorer::new();
30913096
let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
30923097
let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -3160,7 +3165,7 @@ mod tests {
31603165
let non_announced_pubkey = PublicKey::from_secret_key(&secp_ctx, &non_announced_privkey);
31613166

31623167
let last_hops = multi_hop_last_hops_hint([nodes[2], non_announced_pubkey]);
3163-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops.clone());
3168+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops.clone()).unwrap();
31643169
let scorer = ln_test_utils::TestScorer::new();
31653170
// Test through channels 2, 3, 0xff00, 0xff01.
31663171
// Test shows that multiple hop hints are considered.
@@ -3266,7 +3271,7 @@ mod tests {
32663271
fn last_hops_with_public_channel_test() {
32673272
let (secp_ctx, network_graph, _, _, logger) = build_graph();
32683273
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
3269-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops_with_public_channel(&nodes));
3274+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops_with_public_channel(&nodes)).unwrap();
32703275
let scorer = ln_test_utils::TestScorer::new();
32713276
let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
32723277
let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -3325,7 +3330,7 @@ mod tests {
33253330
// Simple test with outbound channel to 4 to test that last_hops and first_hops connect
33263331
let our_chans = vec![get_channel_details(Some(42), nodes[3].clone(), InitFeatures::from_le_bytes(vec![0b11]), 250_000_000)];
33273332
let mut last_hops = last_hops(&nodes);
3328-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops.clone());
3333+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops.clone()).unwrap();
33293334
let route = get_route(&our_id, &payment_params, &network_graph.read_only(), Some(&our_chans.iter().collect::<Vec<_>>()), 100, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
33303335
assert_eq!(route.paths[0].hops.len(), 2);
33313336

@@ -3346,7 +3351,7 @@ mod tests {
33463351
last_hops[0].0[0].fees.base_msat = 1000;
33473352

33483353
// Revert to via 6 as the fee on 8 goes up
3349-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops);
3354+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops).unwrap();
33503355
let route = get_route(&our_id, &payment_params, &network_graph.read_only(), None, 100, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
33513356
assert_eq!(route.paths[0].hops.len(), 4);
33523357

@@ -3439,7 +3444,7 @@ mod tests {
34393444
htlc_minimum_msat: None,
34403445
htlc_maximum_msat: last_hop_htlc_max,
34413446
}]);
3442-
let payment_params = PaymentParameters::from_node_id(target_node_id, 42).with_route_hints(vec![last_hops]);
3447+
let payment_params = PaymentParameters::from_node_id(target_node_id, 42).with_route_hints(vec![last_hops]).unwrap();
34433448
let our_chans = vec![get_channel_details(Some(42), middle_node_id, InitFeatures::from_le_bytes(vec![0b11]), outbound_capacity_msat)];
34443449
let scorer = ln_test_utils::TestScorer::new();
34453450
let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
@@ -4640,7 +4645,7 @@ mod tests {
46404645
cltv_expiry_delta: 42,
46414646
htlc_minimum_msat: None,
46424647
htlc_maximum_msat: None,
4643-
}])]).with_max_channel_saturation_power_of_half(0);
4648+
}])]).unwrap().with_max_channel_saturation_power_of_half(0);
46444649

46454650
// Keep only two paths from us to nodes[2], both with a 99sat HTLC maximum, with one with
46464651
// no fee and one with a 1msat fee. Previously, trying to route 100 sats to nodes[2] here
@@ -5214,7 +5219,7 @@ mod tests {
52145219
fn prefers_shorter_route_with_higher_fees() {
52155220
let (secp_ctx, network_graph, _, _, logger) = build_graph();
52165221
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
5217-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops(&nodes));
5222+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops(&nodes)).unwrap();
52185223

52195224
// Without penalizing each hop 100 msats, a longer path with lower fees is chosen.
52205225
let scorer = ln_test_utils::TestScorer::new();
@@ -5287,7 +5292,7 @@ mod tests {
52875292
fn avoids_routing_through_bad_channels_and_nodes() {
52885293
let (secp_ctx, network, _, _, logger) = build_graph();
52895294
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
5290-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops(&nodes));
5295+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops(&nodes)).unwrap();
52915296
let network_graph = network.read_only();
52925297

52935298
// A path to nodes[6] exists when no penalties are applied to any channel.
@@ -5410,7 +5415,7 @@ mod tests {
54105415

54115416
// Make sure that generally there is at least one route available
54125417
let feasible_max_total_cltv_delta = 1008;
5413-
let feasible_payment_params = PaymentParameters::from_node_id(nodes[6], 0).with_route_hints(last_hops(&nodes))
5418+
let feasible_payment_params = PaymentParameters::from_node_id(nodes[6], 0).with_route_hints(last_hops(&nodes)).unwrap()
54145419
.with_max_total_cltv_expiry_delta(feasible_max_total_cltv_delta);
54155420
let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
54165421
let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -5420,7 +5425,7 @@ mod tests {
54205425

54215426
// But not if we exclude all paths on the basis of their accumulated CLTV delta
54225427
let fail_max_total_cltv_delta = 23;
5423-
let fail_payment_params = PaymentParameters::from_node_id(nodes[6], 0).with_route_hints(last_hops(&nodes))
5428+
let fail_payment_params = PaymentParameters::from_node_id(nodes[6], 0).with_route_hints(last_hops(&nodes)).unwrap()
54245429
.with_max_total_cltv_expiry_delta(fail_max_total_cltv_delta);
54255430
match get_route(&our_id, &fail_payment_params, &network_graph, None, 100, Arc::clone(&logger), &scorer, &random_seed_bytes)
54265431
{
@@ -5440,7 +5445,7 @@ mod tests {
54405445
let network_graph = network.read_only();
54415446

54425447
let scorer = ln_test_utils::TestScorer::new();
5443-
let mut payment_params = PaymentParameters::from_node_id(nodes[6], 0).with_route_hints(last_hops(&nodes))
5448+
let mut payment_params = PaymentParameters::from_node_id(nodes[6], 0).with_route_hints(last_hops(&nodes)).unwrap()
54445449
.with_max_path_count(1);
54455450
let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
54465451
let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -5496,7 +5501,7 @@ mod tests {
54965501

54975502
let scorer = ln_test_utils::TestScorer::new();
54985503

5499-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops(&nodes));
5504+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops(&nodes)).unwrap();
55005505
let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
55015506
let random_seed_bytes = keys_manager.get_secure_random_bytes();
55025507
let route = get_route(&our_id, &payment_params, &network_graph.read_only(), None, 100, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();

0 commit comments

Comments
 (0)