Skip to content

Commit 57f0822

Browse files
committed
Simplify prefers_shorter_route_with_higher_fees
In order to make the scoring tests easier to read, only check the relevant RouteHop fields. The remaining fields are tested elsewhere. Expand the test to show the path used without scoring.
1 parent 001bc71 commit 57f0822

File tree

1 file changed

+18
-30
lines changed

1 file changed

+18
-30
lines changed

lightning/src/routing/router.rs

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4351,42 +4351,30 @@ mod tests {
43514351
let (secp_ctx, net_graph_msg_handler, _, logger) = build_graph();
43524352
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
43534353

4354+
// Without penalizing each hop 100 msats, a longer path with lower fees is chosen.
4355+
let scorer = Scorer::new(0);
4356+
let route = get_route(
4357+
&our_id, &net_graph_msg_handler.network_graph, &nodes[6], None, None,
4358+
&last_hops(&nodes).iter().collect::<Vec<_>>(), 100, 42, Arc::clone(&logger), &scorer
4359+
).unwrap();
4360+
let path = route.paths[0].iter().map(|hop| hop.short_channel_id).collect::<Vec<_>>();
4361+
4362+
assert_eq!(route.get_total_fees(), 100);
4363+
assert_eq!(route.get_total_amount(), 100);
4364+
assert_eq!(path, vec![2, 4, 6, 11, 8]);
4365+
43544366
// Applying a 100 msat penalty to each hop results in taking channels 7 and 10 to nodes[6]
43554367
// from nodes[2] rather than channel 6, 11, and 8, even though the longer path is cheaper.
43564368
let scorer = Scorer::new(100);
4357-
let route = get_route(&our_id, &net_graph_msg_handler.network_graph, &nodes[6], None, None, &last_hops(&nodes).iter().collect::<Vec<_>>(), 100, 42, Arc::clone(&logger), &scorer).unwrap();
4358-
assert_eq!(route.paths[0].len(), 4);
4359-
4360-
assert_eq!(route.paths[0][0].pubkey, nodes[1]);
4361-
assert_eq!(route.paths[0][0].short_channel_id, 2);
4362-
assert_eq!(route.paths[0][0].fee_msat, 200);
4363-
assert_eq!(route.paths[0][0].cltv_expiry_delta, (4 << 8) | 1);
4364-
assert_eq!(route.paths[0][0].node_features.le_flags(), &id_to_feature_flags(2));
4365-
assert_eq!(route.paths[0][0].channel_features.le_flags(), &id_to_feature_flags(2));
4366-
4367-
assert_eq!(route.paths[0][1].pubkey, nodes[2]);
4368-
assert_eq!(route.paths[0][1].short_channel_id, 4);
4369-
assert_eq!(route.paths[0][1].fee_msat, 100);
4370-
assert_eq!(route.paths[0][1].cltv_expiry_delta, (7 << 8) | 1);
4371-
assert_eq!(route.paths[0][1].node_features.le_flags(), &id_to_feature_flags(3));
4372-
assert_eq!(route.paths[0][1].channel_features.le_flags(), &id_to_feature_flags(4));
4373-
4374-
assert_eq!(route.paths[0][2].pubkey, nodes[5]);
4375-
assert_eq!(route.paths[0][2].short_channel_id, 7);
4376-
assert_eq!(route.paths[0][2].fee_msat, 0);
4377-
assert_eq!(route.paths[0][2].cltv_expiry_delta, (10 << 8) | 1);
4378-
assert_eq!(route.paths[0][2].node_features.le_flags(), &id_to_feature_flags(6));
4379-
assert_eq!(route.paths[0][2].channel_features.le_flags(), &id_to_feature_flags(7));
4380-
4381-
assert_eq!(route.paths[0][3].pubkey, nodes[6]);
4382-
assert_eq!(route.paths[0][3].short_channel_id, 10);
4383-
assert_eq!(route.paths[0][3].fee_msat, 100);
4384-
assert_eq!(route.paths[0][3].cltv_expiry_delta, 42);
4385-
assert_eq!(route.paths[0][3].node_features.le_flags(), &Vec::<u8>::new()); // We don't pass flags in from invoices yet
4386-
assert_eq!(route.paths[0][3].channel_features.le_flags(), &Vec::<u8>::new()); // We can't learn any flags from invoices, sadly
4369+
let route = get_route(
4370+
&our_id, &net_graph_msg_handler.network_graph, &nodes[6], None, None,
4371+
&last_hops(&nodes).iter().collect::<Vec<_>>(), 100, 42, Arc::clone(&logger), &scorer
4372+
).unwrap();
4373+
let path = route.paths[0].iter().map(|hop| hop.short_channel_id).collect::<Vec<_>>();
43874374

43884375
assert_eq!(route.get_total_fees(), 300);
43894376
assert_eq!(route.get_total_amount(), 100);
4377+
assert_eq!(path, vec![2, 4, 7, 10]);
43904378
}
43914379

43924380
#[test]

0 commit comments

Comments
 (0)