@@ -386,6 +386,7 @@ fn filter_channels(channels: Vec<ChannelDetails>, min_inbound_capacity_msat: Opt
386386 let min_inbound_capacity = min_inbound_capacity_msat. unwrap_or ( 0 ) ;
387387 let mut min_capacity_channel_exists = false ;
388388 let mut online_channel_exists = false ;
389+ let mut online_min_capacity_channel_exists = false ;
389390
390391 for channel in channels. into_iter ( ) . filter ( |chan| chan. is_channel_ready ) {
391392 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
400401
401402 if channel. inbound_capacity_msat >= min_inbound_capacity {
402403 min_capacity_channel_exists = true ;
403- } ;
404+ if channel. is_usable {
405+ online_min_capacity_channel_exists = true ;
406+ }
407+ }
404408 if channel. is_usable {
405409 online_channel_exists = true ;
406410 }
@@ -437,12 +441,16 @@ fn filter_channels(channels: Vec<ChannelDetails>, min_inbound_capacity_msat: Opt
437441 // Further, if we are connected to our peer for any channels, only return those.
438442 filtered_channels. into_iter ( )
439443 . 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.
441450 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 {
446454 channel. is_usable
447455 } else { true }
448456 } )
@@ -736,29 +744,31 @@ mod test {
736744
737745 #[ test]
738746 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) ;
743751 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 ( ) ) ;
744752 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 ( ) ) ;
745754
746- // With both peers connected we should get all hints
755+ // With all peers connected we should get all hints that have sufficient value
747756 let mut scid_aliases = HashSet :: new ( ) ;
748757 scid_aliases. insert ( chan_a. 0 . short_channel_id_alias . unwrap ( ) ) ;
749758 scid_aliases. insert ( chan_b. 0 . short_channel_id_alias . unwrap ( ) ) ;
750759
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 ( ) ) ;
752761
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
754763 scid_aliases. remove ( & chan_b. 0 . short_channel_id_alias . unwrap ( ) ) ;
755764 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 ( ) ) ;
757766
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.
759769 scid_aliases. insert ( chan_b. 0 . short_channel_id_alias . unwrap ( ) ) ;
760770 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) ;
762772 }
763773
764774 #[ test]
0 commit comments