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