Skip to content

Commit d4d48e2

Browse files
Error if clear hints are provided for blinded PaymentParams
1 parent 06eeefc commit d4d48e2

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.
@@ -2934,13 +2939,13 @@ mod tests {
29342939
let mut invalid_last_hops = last_hops_multi_private_channels(&nodes);
29352940
invalid_last_hops.push(invalid_last_hop);
29362941
{
2937-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(invalid_last_hops);
2942+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(invalid_last_hops).unwrap();
29382943
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) {
29392944
assert_eq!(err, "Route hint cannot have the payee as the source.");
29402945
} else { panic!(); }
29412946
}
29422947

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

@@ -3010,7 +3015,7 @@ mod tests {
30103015
fn ignores_empty_last_hops_test() {
30113016
let (secp_ctx, network_graph, _, _, logger) = build_graph();
30123017
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
3013-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(empty_last_hop(&nodes));
3018+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(empty_last_hop(&nodes)).unwrap();
30143019
let scorer = ln_test_utils::TestScorer::new();
30153020
let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
30163021
let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -3090,7 +3095,7 @@ mod tests {
30903095
let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
30913096
let (_, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
30923097
let last_hops = multi_hop_last_hops_hint([nodes[2], nodes[3]]);
3093-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops.clone());
3098+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops.clone()).unwrap();
30943099
let scorer = ln_test_utils::TestScorer::new();
30953100
let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
30963101
let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -3164,7 +3169,7 @@ mod tests {
31643169
let non_announced_pubkey = PublicKey::from_secret_key(&secp_ctx, &non_announced_privkey);
31653170

31663171
let last_hops = multi_hop_last_hops_hint([nodes[2], non_announced_pubkey]);
3167-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops.clone());
3172+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops.clone()).unwrap();
31683173
let scorer = ln_test_utils::TestScorer::new();
31693174
// Test through channels 2, 3, 0xff00, 0xff01.
31703175
// Test shows that multiple hop hints are considered.
@@ -3270,7 +3275,7 @@ mod tests {
32703275
fn last_hops_with_public_channel_test() {
32713276
let (secp_ctx, network_graph, _, _, logger) = build_graph();
32723277
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
3273-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops_with_public_channel(&nodes));
3278+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops_with_public_channel(&nodes)).unwrap();
32743279
let scorer = ln_test_utils::TestScorer::new();
32753280
let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
32763281
let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -3329,7 +3334,7 @@ mod tests {
33293334
// Simple test with outbound channel to 4 to test that last_hops and first_hops connect
33303335
let our_chans = vec![get_channel_details(Some(42), nodes[3].clone(), InitFeatures::from_le_bytes(vec![0b11]), 250_000_000)];
33313336
let mut last_hops = last_hops(&nodes);
3332-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops.clone());
3337+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops.clone()).unwrap();
33333338
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();
33343339
assert_eq!(route.paths[0].hops.len(), 2);
33353340

@@ -3350,7 +3355,7 @@ mod tests {
33503355
last_hops[0].0[0].fees.base_msat = 1000;
33513356

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

@@ -3443,7 +3448,7 @@ mod tests {
34433448
htlc_minimum_msat: None,
34443449
htlc_maximum_msat: last_hop_htlc_max,
34453450
}]);
3446-
let payment_params = PaymentParameters::from_node_id(target_node_id, 42).with_route_hints(vec![last_hops]);
3451+
let payment_params = PaymentParameters::from_node_id(target_node_id, 42).with_route_hints(vec![last_hops]).unwrap();
34473452
let our_chans = vec![get_channel_details(Some(42), middle_node_id, InitFeatures::from_le_bytes(vec![0b11]), outbound_capacity_msat)];
34483453
let scorer = ln_test_utils::TestScorer::new();
34493454
let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
@@ -4644,7 +4649,7 @@ mod tests {
46444649
cltv_expiry_delta: 42,
46454650
htlc_minimum_msat: None,
46464651
htlc_maximum_msat: None,
4647-
}])]).with_max_channel_saturation_power_of_half(0);
4652+
}])]).unwrap().with_max_channel_saturation_power_of_half(0);
46484653

46494654
// Keep only two paths from us to nodes[2], both with a 99sat HTLC maximum, with one with
46504655
// no fee and one with a 1msat fee. Previously, trying to route 100 sats to nodes[2] here
@@ -5218,7 +5223,7 @@ mod tests {
52185223
fn prefers_shorter_route_with_higher_fees() {
52195224
let (secp_ctx, network_graph, _, _, logger) = build_graph();
52205225
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
5221-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops(&nodes));
5226+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops(&nodes)).unwrap();
52225227

52235228
// Without penalizing each hop 100 msats, a longer path with lower fees is chosen.
52245229
let scorer = ln_test_utils::TestScorer::new();
@@ -5291,7 +5296,7 @@ mod tests {
52915296
fn avoids_routing_through_bad_channels_and_nodes() {
52925297
let (secp_ctx, network, _, _, logger) = build_graph();
52935298
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
5294-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops(&nodes));
5299+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops(&nodes)).unwrap();
52955300
let network_graph = network.read_only();
52965301

52975302
// A path to nodes[6] exists when no penalties are applied to any channel.
@@ -5414,7 +5419,7 @@ mod tests {
54145419

54155420
// Make sure that generally there is at least one route available
54165421
let feasible_max_total_cltv_delta = 1008;
5417-
let feasible_payment_params = PaymentParameters::from_node_id(nodes[6], 0).with_route_hints(last_hops(&nodes))
5422+
let feasible_payment_params = PaymentParameters::from_node_id(nodes[6], 0).with_route_hints(last_hops(&nodes)).unwrap()
54185423
.with_max_total_cltv_expiry_delta(feasible_max_total_cltv_delta);
54195424
let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
54205425
let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -5424,7 +5429,7 @@ mod tests {
54245429

54255430
// But not if we exclude all paths on the basis of their accumulated CLTV delta
54265431
let fail_max_total_cltv_delta = 23;
5427-
let fail_payment_params = PaymentParameters::from_node_id(nodes[6], 0).with_route_hints(last_hops(&nodes))
5432+
let fail_payment_params = PaymentParameters::from_node_id(nodes[6], 0).with_route_hints(last_hops(&nodes)).unwrap()
54285433
.with_max_total_cltv_expiry_delta(fail_max_total_cltv_delta);
54295434
match get_route(&our_id, &fail_payment_params, &network_graph, None, 100, Arc::clone(&logger), &scorer, &random_seed_bytes)
54305435
{
@@ -5444,7 +5449,7 @@ mod tests {
54445449
let network_graph = network.read_only();
54455450

54465451
let scorer = ln_test_utils::TestScorer::new();
5447-
let mut payment_params = PaymentParameters::from_node_id(nodes[6], 0).with_route_hints(last_hops(&nodes))
5452+
let mut payment_params = PaymentParameters::from_node_id(nodes[6], 0).with_route_hints(last_hops(&nodes)).unwrap()
54485453
.with_max_path_count(1);
54495454
let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
54505455
let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -5500,7 +5505,7 @@ mod tests {
55005505

55015506
let scorer = ln_test_utils::TestScorer::new();
55025507

5503-
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops(&nodes));
5508+
let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops(&nodes)).unwrap();
55045509
let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
55055510
let random_seed_bytes = keys_manager.get_secure_random_bytes();
55065511
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)