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