@@ -274,13 +274,17 @@ where
274
274
let mut remaining_hints = false ;
275
275
276
276
for hints in phantom_hints. iter ( ) {
277
+ if invoice_hints. len ( ) == 3 {
278
+ return invoice_hints
279
+ }
280
+
277
281
if hint_idx < hints. len ( ) {
278
282
invoice_hints. push ( hints[ hint_idx] . clone ( ) ) ;
279
283
remaining_hints = true
280
284
}
281
285
}
282
286
283
- if !remaining_hints || invoice_hints . len ( ) == 3 {
287
+ if !remaining_hints {
284
288
return invoice_hints
285
289
}
286
290
@@ -1751,38 +1755,58 @@ mod test {
1751
1755
1752
1756
#[ test]
1753
1757
fn test_multi_node_hints_limited_to_3 ( ) {
1754
- let mut chanmon_cfgs = create_chanmon_cfgs ( 5 ) ;
1758
+ let mut chanmon_cfgs = create_chanmon_cfgs ( 6 ) ;
1755
1759
let seed_1 = [ 42 as u8 ; 32 ] ;
1756
1760
let seed_2 = [ 43 as u8 ; 32 ] ;
1757
1761
let seed_3 = [ 44 as u8 ; 32 ] ;
1762
+ let seed_4 = [ 45 as u8 ; 32 ] ;
1758
1763
let cross_node_seed = [ 44 as u8 ; 32 ] ;
1759
1764
chanmon_cfgs[ 2 ] . keys_manager . backing = PhantomKeysManager :: new ( & seed_1, 43 , 44 , & cross_node_seed) ;
1760
1765
chanmon_cfgs[ 3 ] . keys_manager . backing = PhantomKeysManager :: new ( & seed_2, 43 , 44 , & cross_node_seed) ;
1761
1766
chanmon_cfgs[ 4 ] . keys_manager . backing = PhantomKeysManager :: new ( & seed_3, 43 , 44 , & cross_node_seed) ;
1762
- let node_cfgs = create_node_cfgs ( 5 , & chanmon_cfgs) ;
1763
- let node_chanmgrs = create_node_chanmgrs ( 5 , & node_cfgs, & [ None , None , None , None , None ] ) ;
1764
- let nodes = create_network ( 5 , & node_cfgs, & node_chanmgrs) ;
1767
+ chanmon_cfgs[ 5 ] . keys_manager . backing = PhantomKeysManager :: new ( & seed_4, 43 , 44 , & cross_node_seed) ;
1768
+ let node_cfgs = create_node_cfgs ( 6 , & chanmon_cfgs) ;
1769
+ let node_chanmgrs = create_node_chanmgrs ( 6 , & node_cfgs, & [ None , None , None , None , None , None ] ) ;
1770
+ let nodes = create_network ( 6 , & node_cfgs, & node_chanmgrs) ;
1765
1771
1766
1772
// Setup each phantom node with two channels from distinct peers.
1767
- let _chan_0_2 = create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 2 , 10_000 , 0 ) ;
1773
+ let chan_0_2 = create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 2 , 10_000 , 0 ) ;
1768
1774
let chan_1_2 = create_unannounced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 20_000 , 0 ) ;
1769
1775
let chan_0_3 = create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 3 , 20_000 , 0 ) ;
1770
1776
let _chan_1_3 = create_unannounced_chan_between_nodes_with_value ( & nodes, 1 , 3 , 10_000 , 0 ) ;
1771
1777
let chan_0_4 = create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 4 , 20_000 , 0 ) ;
1772
1778
let _chan_1_4 = create_unannounced_chan_between_nodes_with_value ( & nodes, 1 , 4 , 10_000 , 0 ) ;
1779
+ let _chan_0_5 = create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 5 , 20_000 , 0 ) ;
1780
+ let _chan_1_5 = create_unannounced_chan_between_nodes_with_value ( & nodes, 1 , 5 , 10_000 , 0 ) ;
1781
+
1782
+ // Set invoice amount > all channels inbound so that every one is eligible for inclusion
1783
+ // and hints will be sorted by largest inbound capacity.
1784
+ let invoice_amt = Some ( 100_000_000 ) ;
1773
1785
1786
+ // With 4 phantom nodes, assert that we include 1 hint per node, up to 3 nodes.
1774
1787
let mut scid_aliases = HashSet :: new ( ) ;
1775
1788
scid_aliases. insert ( chan_1_2. 0 . short_channel_id_alias . unwrap ( ) ) ;
1776
1789
scid_aliases. insert ( chan_0_3. 0 . short_channel_id_alias . unwrap ( ) ) ;
1777
1790
scid_aliases. insert ( chan_0_4. 0 . short_channel_id_alias . unwrap ( ) ) ;
1778
1791
1779
- // Since the invoice amount is above all channels inbound, every one is eligible and we'll
1780
- // sort by largest inbound capacity. Test that we include one channel from each of our
1781
- // three nodes.
1782
1792
match_multi_node_invoice_routes (
1783
- Some ( 100_000_000 ) ,
1793
+ invoice_amt,
1794
+ & nodes[ 3 ] ,
1795
+ vec ! [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes[ 4 ] , & nodes[ 5 ] ] ,
1796
+ scid_aliases,
1797
+ false ,
1798
+ ) ;
1799
+
1800
+ // With 2 phantom nodes, assert that we include no more than 3 hints.
1801
+ let mut scid_aliases = HashSet :: new ( ) ;
1802
+ scid_aliases. insert ( chan_1_2. 0 . short_channel_id_alias . unwrap ( ) ) ;
1803
+ scid_aliases. insert ( chan_0_3. 0 . short_channel_id_alias . unwrap ( ) ) ;
1804
+ scid_aliases. insert ( chan_0_2. 0 . short_channel_id_alias . unwrap ( ) ) ;
1805
+
1806
+ match_multi_node_invoice_routes (
1807
+ invoice_amt,
1784
1808
& nodes[ 3 ] ,
1785
- vec ! [ & nodes[ 2 ] , & nodes[ 3 ] , & nodes [ 4 ] , ] ,
1809
+ vec ! [ & nodes[ 2 ] , & nodes[ 3 ] , ] ,
1786
1810
scid_aliases,
1787
1811
false ,
1788
1812
) ;
0 commit comments