From: Jeffrey Czyz Date: Sat, 16 Oct 2021 02:31:33 +0000 (-0500) Subject: Simplify prefers_shorter_route_with_higher_fees X-Git-Tag: v0.0.103~13^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=57f0822f5a97b753901ac681e9787785b279e47a;p=rust-lightning 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. --- diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 4083114d..f33ef56a 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -4351,42 +4351,30 @@ mod tests { let (secp_ctx, net_graph_msg_handler, _, logger) = build_graph(); let (_, our_id, _, nodes) = get_nodes(&secp_ctx); + // Without penalizing each hop 100 msats, a longer path with lower fees is chosen. + let scorer = Scorer::new(0); + let route = get_route( + &our_id, &net_graph_msg_handler.network_graph, &nodes[6], None, None, + &last_hops(&nodes).iter().collect::>(), 100, 42, Arc::clone(&logger), &scorer + ).unwrap(); + let path = route.paths[0].iter().map(|hop| hop.short_channel_id).collect::>(); + + assert_eq!(route.get_total_fees(), 100); + assert_eq!(route.get_total_amount(), 100); + assert_eq!(path, vec![2, 4, 6, 11, 8]); + // Applying a 100 msat penalty to each hop results in taking channels 7 and 10 to nodes[6] // from nodes[2] rather than channel 6, 11, and 8, even though the longer path is cheaper. let scorer = Scorer::new(100); - let route = get_route(&our_id, &net_graph_msg_handler.network_graph, &nodes[6], None, None, &last_hops(&nodes).iter().collect::>(), 100, 42, Arc::clone(&logger), &scorer).unwrap(); - assert_eq!(route.paths[0].len(), 4); - - assert_eq!(route.paths[0][0].pubkey, nodes[1]); - assert_eq!(route.paths[0][0].short_channel_id, 2); - assert_eq!(route.paths[0][0].fee_msat, 200); - assert_eq!(route.paths[0][0].cltv_expiry_delta, (4 << 8) | 1); - assert_eq!(route.paths[0][0].node_features.le_flags(), &id_to_feature_flags(2)); - assert_eq!(route.paths[0][0].channel_features.le_flags(), &id_to_feature_flags(2)); - - assert_eq!(route.paths[0][1].pubkey, nodes[2]); - assert_eq!(route.paths[0][1].short_channel_id, 4); - assert_eq!(route.paths[0][1].fee_msat, 100); - assert_eq!(route.paths[0][1].cltv_expiry_delta, (7 << 8) | 1); - assert_eq!(route.paths[0][1].node_features.le_flags(), &id_to_feature_flags(3)); - assert_eq!(route.paths[0][1].channel_features.le_flags(), &id_to_feature_flags(4)); - - assert_eq!(route.paths[0][2].pubkey, nodes[5]); - assert_eq!(route.paths[0][2].short_channel_id, 7); - assert_eq!(route.paths[0][2].fee_msat, 0); - assert_eq!(route.paths[0][2].cltv_expiry_delta, (10 << 8) | 1); - assert_eq!(route.paths[0][2].node_features.le_flags(), &id_to_feature_flags(6)); - assert_eq!(route.paths[0][2].channel_features.le_flags(), &id_to_feature_flags(7)); - - assert_eq!(route.paths[0][3].pubkey, nodes[6]); - assert_eq!(route.paths[0][3].short_channel_id, 10); - assert_eq!(route.paths[0][3].fee_msat, 100); - assert_eq!(route.paths[0][3].cltv_expiry_delta, 42); - assert_eq!(route.paths[0][3].node_features.le_flags(), &Vec::::new()); // We don't pass flags in from invoices yet - assert_eq!(route.paths[0][3].channel_features.le_flags(), &Vec::::new()); // We can't learn any flags from invoices, sadly + let route = get_route( + &our_id, &net_graph_msg_handler.network_graph, &nodes[6], None, None, + &last_hops(&nodes).iter().collect::>(), 100, 42, Arc::clone(&logger), &scorer + ).unwrap(); + let path = route.paths[0].iter().map(|hop| hop.short_channel_id).collect::>(); assert_eq!(route.get_total_fees(), 300); assert_eq!(route.get_total_amount(), 100); + assert_eq!(path, vec![2, 4, 7, 10]); } #[test]