Skip to content

Commit 1dfabcb

Browse files
committed
Add failure test cases for max_mpp_path_count.
1 parent 13b7cd5 commit 1dfabcb

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

lightning/src/routing/router.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ where L::Target: Logger {
887887
HashMap::with_capacity(network_nodes.len());
888888

889889
// Keeping track of how much value we already collected across other paths. Helps to decide
890-
// when we want to stop looking for new paths.
890+
// when we want to stop looking for new paths.
891891
let mut already_collected_value_msat = 0;
892892

893893
for (_, channels) in first_hop_targets.iter_mut() {
@@ -4015,7 +4015,8 @@ mod tests {
40154015
let scorer = test_utils::TestScorer::with_penalty(0);
40164016
let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
40174017
let random_seed_bytes = keys_manager.get_secure_random_bytes();
4018-
let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(InvoiceFeatures::known());
4018+
let payment_params = PaymentParameters::from_node_id(nodes[2])
4019+
.with_features(InvoiceFeatures::known());
40194020

40204021
// We need a route consisting of 3 paths:
40214022
// From our node to node2 via node0, node7, node1 (three paths one hop each).
@@ -4108,15 +4109,39 @@ mod tests {
41084109
{
41094110
// Attempt to route more than available results in a failure.
41104111
if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route(
4111-
&our_id, &payment_params, &network_graph.read_only(), None, 300_000, 42, Arc::clone(&logger), &scorer, &random_seed_bytes) {
4112-
assert_eq!(err, "Failed to find a sufficient route to the given destination");
4112+
&our_id, &payment_params, &network_graph.read_only(), None, 300_000, 42,
4113+
Arc::clone(&logger), &scorer, &random_seed_bytes) {
4114+
assert_eq!(err, "Failed to find a sufficient route to the given destination");
4115+
} else { panic!(); }
4116+
}
4117+
4118+
{
4119+
// Attempt to route while setting max_mpp_path_count to 0 results in a failure.
4120+
let zero_payment_params = payment_params.clone().with_max_mpp_path_count(0);
4121+
if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route(
4122+
&our_id, &zero_payment_params, &network_graph.read_only(), None, 100, 42,
4123+
Arc::clone(&logger), &scorer, &random_seed_bytes) {
4124+
assert_eq!(err, "Can't find an MPP route with no paths allowed.");
4125+
} else { panic!(); }
4126+
}
4127+
4128+
{
4129+
// Attempt to route while setting max_mpp_path_count to 3 results in a failure.
4130+
// This is the case because the minimal_value_contribution_msat would require each path
4131+
// to account for 1/3 of the total value, which is violated by 2 out of 3 paths.
4132+
let fail_payment_params = payment_params.clone().with_max_mpp_path_count(3);
4133+
if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route(
4134+
&our_id, &fail_payment_params, &network_graph.read_only(), None, 250_000, 42,
4135+
Arc::clone(&logger), &scorer, &random_seed_bytes) {
4136+
assert_eq!(err, "Failed to find a sufficient route to the given destination");
41134137
} else { panic!(); }
41144138
}
41154139

41164140
{
41174141
// Now, attempt to route 250 sats (just a bit below the capacity).
41184142
// Our algorithm should provide us with these 3 paths.
4119-
let route = get_route(&our_id, &payment_params, &network_graph.read_only(), None, 250_000, 42, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
4143+
let route = get_route(&our_id, &payment_params, &network_graph.read_only(), None,
4144+
250_000, 42, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
41204145
assert_eq!(route.paths.len(), 3);
41214146
let mut total_amount_paid_msat = 0;
41224147
for path in &route.paths {
@@ -4129,7 +4154,8 @@ mod tests {
41294154

41304155
{
41314156
// Attempt to route an exact amount is also fine
4132-
let route = get_route(&our_id, &payment_params, &network_graph.read_only(), None, 290_000, 42, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
4157+
let route = get_route(&our_id, &payment_params, &network_graph.read_only(), None,
4158+
290_000, 42, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
41334159
assert_eq!(route.paths.len(), 3);
41344160
let mut total_amount_paid_msat = 0;
41354161
for path in &route.paths {

0 commit comments

Comments
 (0)