@@ -727,9 +727,16 @@ impl<L: Deref<Target = u64>, T: Time, U: Deref<Target = T>> DirectedChannelLiqui
727
727
} else {
728
728
let numerator = ( max_liquidity_msat - amount_msat) . saturating_add ( 1 ) ;
729
729
let denominator = ( max_liquidity_msat - min_liquidity_msat) . saturating_add ( 1 ) ;
730
- let negative_log10_times_2048 =
731
- approx:: negative_log10_times_2048 ( numerator, denominator) ;
732
- self . combined_penalty_msat ( amount_msat, negative_log10_times_2048, params)
730
+ if amount_msat - min_liquidity_msat < denominator / 64 {
731
+ // If the failure probability is < 1.5625%, don't bother trying to use the log
732
+ // approximation as it gets too noisy to be particularly helpful, instead just
733
+ // round down to 0 and return the base penalty.
734
+ params. base_penalty_msat
735
+ } else {
736
+ let negative_log10_times_2048 =
737
+ approx:: negative_log10_times_2048 ( numerator, denominator) ;
738
+ self . combined_penalty_msat ( amount_msat, negative_log10_times_2048, params)
739
+ }
733
740
}
734
741
}
735
742
@@ -2007,8 +2014,8 @@ mod tests {
2007
2014
let source = source_node_id ( ) ;
2008
2015
let target = target_node_id ( ) ;
2009
2016
2010
- assert_eq ! ( scorer. channel_penalty_msat( 42 , 1_024 , 1_024_000 , & source, & target) , 3 ) ;
2011
- assert_eq ! ( scorer. channel_penalty_msat( 42 , 10_240 , 1_024_000 , & source, & target) , 6 ) ;
2017
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 1_024 , 1_024_000 , & source, & target) , 0 ) ;
2018
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 10_240 , 1_024_000 , & source, & target) , 0 ) ;
2012
2019
assert_eq ! ( scorer. channel_penalty_msat( 42 , 102_400 , 1_024_000 , & source, & target) , 47 ) ;
2013
2020
assert_eq ! ( scorer. channel_penalty_msat( 42 , 1_024_000 , 1_024_000 , & source, & target) , 2_000 ) ;
2014
2021
@@ -2329,11 +2336,11 @@ mod tests {
2329
2336
assert_eq ! ( scorer. channel_penalty_msat( 42 , 100_000_000 , 3_950_000_000 , & source, & target) , 1223 ) ;
2330
2337
assert_eq ! ( scorer. channel_penalty_msat( 42 , 100_000_000 , 4_950_000_000 , & source, & target) , 877 ) ;
2331
2338
assert_eq ! ( scorer. channel_penalty_msat( 42 , 100_000_000 , 5_950_000_000 , & source, & target) , 845 ) ;
2332
- assert_eq ! ( scorer. channel_penalty_msat( 42 , 100_000_000 , 6_950_000_000 , & source, & target) , 782 ) ;
2333
- assert_eq ! ( scorer. channel_penalty_msat( 42 , 100_000_000 , 7_450_000_000 , & source, & target) , 1002 ) ;
2334
- assert_eq ! ( scorer. channel_penalty_msat( 42 , 100_000_000 , 7_950_000_000 , & source, & target) , 970 ) ;
2335
- assert_eq ! ( scorer. channel_penalty_msat( 42 , 100_000_000 , 8_950_000_000 , & source, & target) , 907 ) ;
2336
- assert_eq ! ( scorer. channel_penalty_msat( 42 , 100_000_000 , 9_950_000_000 , & source, & target) , 877 ) ;
2339
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 100_000_000 , 6_950_000_000 , & source, & target) , 500 ) ;
2340
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 100_000_000 , 7_450_000_000 , & source, & target) , 500 ) ;
2341
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 100_000_000 , 7_950_000_000 , & source, & target) , 500 ) ;
2342
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 100_000_000 , 8_950_000_000 , & source, & target) , 500 ) ;
2343
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 100_000_000 , 9_950_000_000 , & source, & target) , 500 ) ;
2337
2344
}
2338
2345
2339
2346
#[ test]
0 commit comments