@@ -5724,6 +5724,50 @@ mod tests {
5724
5724
}
5725
5725
}
5726
5726
5727
+ #[ test]
5728
+ fn avoids_saturating_channels ( ) {
5729
+ let ( secp_ctx, network_graph, gossip_sync, _, logger) = build_graph ( ) ;
5730
+ let ( _, our_id, privkeys, nodes) = get_nodes ( & secp_ctx) ;
5731
+
5732
+ let scorer = ProbabilisticScorer :: new ( Default :: default ( ) , & * network_graph, Arc :: clone ( & logger) ) ;
5733
+
5734
+ // Set the fee on channel 13 to 100% to match channel 4 giving us two equivalent paths (us
5735
+ // -> node 7 -> node2 and us -> node 1 -> node 2) which we should balance over.
5736
+ update_channel ( & gossip_sync, & secp_ctx, & privkeys[ 1 ] , UnsignedChannelUpdate {
5737
+ chain_hash : genesis_block ( Network :: Testnet ) . header . block_hash ( ) ,
5738
+ short_channel_id : 4 ,
5739
+ timestamp : 2 ,
5740
+ flags : 0 ,
5741
+ cltv_expiry_delta : ( 4 << 4 ) | 1 ,
5742
+ htlc_minimum_msat : 0 ,
5743
+ htlc_maximum_msat : OptionalField :: Present ( 200_000_000 ) ,
5744
+ fee_base_msat : 0 ,
5745
+ fee_proportional_millionths : 0 ,
5746
+ excess_data : Vec :: new ( )
5747
+ } ) ;
5748
+ update_channel ( & gossip_sync, & secp_ctx, & privkeys[ 7 ] , UnsignedChannelUpdate {
5749
+ chain_hash : genesis_block ( Network :: Testnet ) . header . block_hash ( ) ,
5750
+ short_channel_id : 13 ,
5751
+ timestamp : 2 ,
5752
+ flags : 0 ,
5753
+ cltv_expiry_delta : ( 13 << 4 ) | 1 ,
5754
+ htlc_minimum_msat : 0 ,
5755
+ htlc_maximum_msat : OptionalField :: Present ( 200_000_000 ) ,
5756
+ fee_base_msat : 0 ,
5757
+ fee_proportional_millionths : 0 ,
5758
+ excess_data : Vec :: new ( )
5759
+ } ) ;
5760
+
5761
+ let payment_params = PaymentParameters :: from_node_id ( nodes[ 2 ] ) . with_features ( InvoiceFeatures :: known ( ) ) ;
5762
+ let keys_manager = test_utils:: TestKeysInterface :: new ( & [ 0u8 ; 32 ] , Network :: Testnet ) ;
5763
+ let random_seed_bytes = keys_manager. get_secure_random_bytes ( ) ;
5764
+ // 150,000 msat is less than the available liquidity on each channel, set above.
5765
+ let route = get_route ( & our_id, & payment_params, & network_graph. read_only ( ) , None , 150_000_000 , 42 , Arc :: clone ( & logger) , & scorer, & random_seed_bytes) . unwrap ( ) ;
5766
+ assert_eq ! ( route. paths. len( ) , 2 ) ;
5767
+ assert ! ( ( route. paths[ 0 ] [ 1 ] . short_channel_id == 4 && route. paths[ 1 ] [ 1 ] . short_channel_id == 13 ) ||
5768
+ ( route. paths[ 1 ] [ 1 ] . short_channel_id == 4 && route. paths[ 0 ] [ 1 ] . short_channel_id == 13 ) ) ;
5769
+ }
5770
+
5727
5771
#[ cfg( not( feature = "no-std" ) ) ]
5728
5772
pub ( super ) fn random_init_seed ( ) -> u64 {
5729
5773
// Because the default HashMap in std pulls OS randomness, we can use it as a (bad) RNG.
0 commit comments