+ #[test]
+ fn test_multi_node_hints_limited_to_3() {
+ let mut chanmon_cfgs = create_chanmon_cfgs(6);
+ let seed_1 = [42 as u8; 32];
+ let seed_2 = [43 as u8; 32];
+ let seed_3 = [44 as u8; 32];
+ let seed_4 = [45 as u8; 32];
+ let cross_node_seed = [44 as u8; 32];
+ chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
+ chanmon_cfgs[3].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
+ chanmon_cfgs[4].keys_manager.backing = PhantomKeysManager::new(&seed_3, 43, 44, &cross_node_seed);
+ chanmon_cfgs[5].keys_manager.backing = PhantomKeysManager::new(&seed_4, 43, 44, &cross_node_seed);
+ let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
+ let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
+ let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
+
+ // Setup each phantom node with two channels from distinct peers.
+ let chan_0_2 = create_unannounced_chan_between_nodes_with_value(&nodes, 0, 2, 10_000, 0);
+ let chan_1_2 = create_unannounced_chan_between_nodes_with_value(&nodes, 1, 2, 20_000, 0);
+ let chan_0_3 = create_unannounced_chan_between_nodes_with_value(&nodes, 0, 3, 20_000, 0);
+ let _chan_1_3 = create_unannounced_chan_between_nodes_with_value(&nodes, 1, 3, 10_000, 0);
+ let chan_0_4 = create_unannounced_chan_between_nodes_with_value(&nodes, 0, 4, 20_000, 0);
+ let _chan_1_4 = create_unannounced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000, 0);
+ let _chan_0_5 = create_unannounced_chan_between_nodes_with_value(&nodes, 0, 5, 20_000, 0);
+ let _chan_1_5 = create_unannounced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000, 0);
+
+ // Set invoice amount > all channels inbound so that every one is eligible for inclusion
+ // and hints will be sorted by largest inbound capacity.
+ let invoice_amt = Some(100_000_000);
+
+ // With 4 phantom nodes, assert that we include 1 hint per node, up to 3 nodes.
+ let mut scid_aliases = HashSet::new();
+ scid_aliases.insert(chan_1_2.0.short_channel_id_alias.unwrap());
+ scid_aliases.insert(chan_0_3.0.short_channel_id_alias.unwrap());
+ scid_aliases.insert(chan_0_4.0.short_channel_id_alias.unwrap());
+
+ match_multi_node_invoice_routes(
+ invoice_amt,
+ &nodes[3],
+ vec![&nodes[2], &nodes[3], &nodes[4], &nodes[5]],
+ scid_aliases,
+ false,
+ );
+
+ // With 2 phantom nodes, assert that we include no more than 3 hints.
+ let mut scid_aliases = HashSet::new();
+ scid_aliases.insert(chan_1_2.0.short_channel_id_alias.unwrap());
+ scid_aliases.insert(chan_0_3.0.short_channel_id_alias.unwrap());
+ scid_aliases.insert(chan_0_2.0.short_channel_id_alias.unwrap());
+
+ match_multi_node_invoice_routes(
+ invoice_amt,
+ &nodes[3],
+ vec![&nodes[2], &nodes[3]],
+ scid_aliases,
+ false,
+ );
+ }
+
+ #[test]
+ fn test_multi_node_hints_at_least_3() {
+ let mut chanmon_cfgs = create_chanmon_cfgs(5);
+ let seed_1 = [42 as u8; 32];
+ let seed_2 = [43 as u8; 32];
+ let cross_node_seed = [44 as u8; 32];
+ chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
+ chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
+ let node_cfgs = create_node_cfgs(5, &chanmon_cfgs);
+ let node_chanmgrs = create_node_chanmgrs(5, &node_cfgs, &[None, None, None, None, None]);
+ let nodes = create_network(5, &node_cfgs, &node_chanmgrs);
+
+ let _chan_0_3 = create_unannounced_chan_between_nodes_with_value(&nodes, 0, 3, 10_000, 0);
+ let chan_1_3 = create_unannounced_chan_between_nodes_with_value(&nodes, 1, 3, 20_000, 0);
+ let chan_2_3 = create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 30_000, 0);
+ let chan_0_4 = create_unannounced_chan_between_nodes_with_value(&nodes, 0, 4, 10_000, 0);
+
+ // Since the invoice amount is above all channels inbound, all four are eligible. Test that
+ // we still include 3 hints from 2 distinct nodes sorted by inbound.
+ let mut scid_aliases = HashSet::new();
+ scid_aliases.insert(chan_1_3.0.short_channel_id_alias.unwrap());
+ scid_aliases.insert(chan_2_3.0.short_channel_id_alias.unwrap());
+ scid_aliases.insert(chan_0_4.0.short_channel_id_alias.unwrap());
+
+ match_multi_node_invoice_routes(
+ Some(100_000_000),
+ &nodes[3],
+ vec![&nodes[3], &nodes[4],],
+ scid_aliases,
+ false,
+ );
+ }
+