@@ -386,6 +386,7 @@ fn filter_channels(channels: Vec<ChannelDetails>, min_inbound_capacity_msat: Opt
386
386
let min_inbound_capacity = min_inbound_capacity_msat. unwrap_or ( 0 ) ;
387
387
let mut min_capacity_channel_exists = false ;
388
388
let mut online_channel_exists = false ;
389
+ let mut online_min_capacity_channel_exists = false ;
389
390
390
391
for channel in channels. into_iter ( ) . filter ( |chan| chan. is_channel_ready ) {
391
392
if channel. get_inbound_payment_scid ( ) . is_none ( ) || channel. counterparty . forwarding_info . is_none ( ) {
@@ -400,7 +401,10 @@ fn filter_channels(channels: Vec<ChannelDetails>, min_inbound_capacity_msat: Opt
400
401
401
402
if channel. inbound_capacity_msat >= min_inbound_capacity {
402
403
min_capacity_channel_exists = true ;
403
- } ;
404
+ if channel. is_usable {
405
+ online_min_capacity_channel_exists = true ;
406
+ }
407
+ }
404
408
if channel. is_usable {
405
409
online_channel_exists = true ;
406
410
}
@@ -437,12 +441,16 @@ fn filter_channels(channels: Vec<ChannelDetails>, min_inbound_capacity_msat: Opt
437
441
// Further, if we are connected to our peer for any channels, only return those.
438
442
filtered_channels. into_iter ( )
439
443
. filter ( |( _counterparty_id, channel) | {
440
- if min_capacity_channel_exists {
444
+ if online_min_capacity_channel_exists {
445
+ channel. inbound_capacity_msat >= min_inbound_capacity && channel. is_usable
446
+ } else if min_capacity_channel_exists && online_channel_exists {
447
+ // If there are some online channels and some min_capacity channels, but no
448
+ // online-and-min_capacity channels, just include the min capacity ones and ignore
449
+ // online-ness.
441
450
channel. inbound_capacity_msat >= min_inbound_capacity
442
- } else { true }
443
- } )
444
- . filter ( |( _counterparty_id, channel) | {
445
- if online_channel_exists {
451
+ } else if min_capacity_channel_exists {
452
+ channel. inbound_capacity_msat >= min_inbound_capacity
453
+ } else if online_channel_exists {
446
454
channel. is_usable
447
455
} else { true }
448
456
} )
@@ -736,29 +744,31 @@ mod test {
736
744
737
745
#[ test]
738
746
fn test_hints_has_only_online_channels ( ) {
739
- let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
740
- let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
741
- let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
742
- let nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
747
+ let chanmon_cfgs = create_chanmon_cfgs ( 4 ) ;
748
+ let node_cfgs = create_node_cfgs ( 4 , & chanmon_cfgs) ;
749
+ let node_chanmgrs = create_node_chanmgrs ( 4 , & node_cfgs, & [ None , None , None , None ] ) ;
750
+ let nodes = create_network ( 4 , & node_cfgs, & node_chanmgrs) ;
743
751
let chan_a = create_unannounced_chan_between_nodes_with_value ( & nodes, 1 , 0 , 10_000_000 , 0 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
744
752
let chan_b = create_unannounced_chan_between_nodes_with_value ( & nodes, 2 , 0 , 10_000_000 , 0 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
753
+ let _chan_c = create_unannounced_chan_between_nodes_with_value ( & nodes, 3 , 0 , 1_000_000 , 0 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
745
754
746
- // With both peers connected we should get all hints
755
+ // With all peers connected we should get all hints that have sufficient value
747
756
let mut scid_aliases = HashSet :: new ( ) ;
748
757
scid_aliases. insert ( chan_a. 0 . short_channel_id_alias . unwrap ( ) ) ;
749
758
scid_aliases. insert ( chan_b. 0 . short_channel_id_alias . unwrap ( ) ) ;
750
759
751
- match_invoice_routes ( Some ( 5000 ) , & nodes[ 0 ] , scid_aliases. clone ( ) ) ;
760
+ match_invoice_routes ( Some ( 1_000_000_000 ) , & nodes[ 0 ] , scid_aliases. clone ( ) ) ;
752
761
753
- // With only one peer connected other hints should go away
762
+ // With only one sufficient-value peer connected we should only get its hint
754
763
scid_aliases. remove ( & chan_b. 0 . short_channel_id_alias . unwrap ( ) ) ;
755
764
nodes[ 0 ] . node . peer_disconnected ( & nodes[ 2 ] . node . get_our_node_id ( ) , false ) ;
756
- match_invoice_routes ( Some ( 5000 ) , & nodes[ 0 ] , scid_aliases. clone ( ) ) ;
765
+ match_invoice_routes ( Some ( 1_000_000_000 ) , & nodes[ 0 ] , scid_aliases. clone ( ) ) ;
757
766
758
- // With both peers disconnected we should just get all the hints
767
+ // If we don't have any sufficient-value peers connected we should get all hints with
768
+ // sufficient value, even though there is a conencted insufficient-value peer.
759
769
scid_aliases. insert ( chan_b. 0 . short_channel_id_alias . unwrap ( ) ) ;
760
770
nodes[ 0 ] . node . peer_disconnected ( & nodes[ 1 ] . node . get_our_node_id ( ) , false ) ;
761
- match_invoice_routes ( Some ( 5000 ) , & nodes[ 0 ] , scid_aliases) ;
771
+ match_invoice_routes ( Some ( 1_000_000_000 ) , & nodes[ 0 ] , scid_aliases) ;
762
772
}
763
773
764
774
#[ test]
0 commit comments