@@ -531,7 +531,10 @@ pub struct ProbabilisticScoringParameters {
531
531
///
532
532
/// The penalty is based in part by the knowledge learned from prior successful and unsuccessful
533
533
/// payments. This knowledge is decayed over time based on [`liquidity_offset_half_life`]. The
534
- /// penalty is effectively limited to `2 * liquidity_penalty_multiplier_msat`.
534
+ /// penalty is effectively limited to `2 * liquidity_penalty_multiplier_msat` (corresponding to
535
+ /// lower bounding the success probability to `0.01`) when the amount falls within the
536
+ /// uncertainty bounds of the channel liquidity balance. Amounts above the upper bound will
537
+ /// result in a `u64::max_value` penalty, however.
535
538
///
536
539
/// Default value: 40,000 msat
537
540
///
@@ -669,10 +672,17 @@ impl<L: Deref<Target = u64>, T: Time, U: Deref<Target = T>> DirectedChannelLiqui
669
672
let max_penalty_msat = liquidity_penalty_multiplier_msat. saturating_mul ( 2 ) ;
670
673
let max_liquidity_msat = self . max_liquidity_msat ( ) ;
671
674
let min_liquidity_msat = core:: cmp:: min ( self . min_liquidity_msat ( ) , max_liquidity_msat) ;
672
- if amount_msat > max_liquidity_msat {
673
- max_penalty_msat
674
- } else if amount_msat <= min_liquidity_msat {
675
+ if amount_msat <= min_liquidity_msat {
675
676
0
677
+ } else if amount_msat >= max_liquidity_msat {
678
+ if amount_msat > max_liquidity_msat {
679
+ u64:: max_value ( )
680
+ } else if max_liquidity_msat != self . capacity_msat {
681
+ // Avoid using the failed channel on retry.
682
+ u64:: max_value ( )
683
+ } else {
684
+ max_penalty_msat
685
+ }
676
686
} else {
677
687
let numerator = ( max_liquidity_msat - amount_msat) . saturating_add ( 1 ) ;
678
688
let denominator = ( max_liquidity_msat - min_liquidity_msat) . saturating_add ( 1 ) ;
@@ -1774,8 +1784,8 @@ mod tests {
1774
1784
1775
1785
assert_eq ! ( scorer. channel_penalty_msat( 42 , 39 , 100 , & source, & target) , 0 ) ;
1776
1786
assert_ne ! ( scorer. channel_penalty_msat( 42 , 50 , 100 , & source, & target) , 0 ) ;
1777
- assert_ne ! ( scorer. channel_penalty_msat( 42 , 50 , 100 , & source, & target) , 2_000 ) ;
1778
- assert_eq ! ( scorer. channel_penalty_msat( 42 , 61 , 100 , & source, & target) , 2_000 ) ;
1787
+ assert_ne ! ( scorer. channel_penalty_msat( 42 , 50 , 100 , & source, & target) , u64 :: max_value ( ) ) ;
1788
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 61 , 100 , & source, & target) , u64 :: max_value ( ) ) ;
1779
1789
}
1780
1790
1781
1791
#[ test]
@@ -1839,8 +1849,8 @@ mod tests {
1839
1849
scorer. payment_path_failed ( & path. iter ( ) . collect :: < Vec < _ > > ( ) , 42 ) ;
1840
1850
1841
1851
assert_eq ! ( scorer. channel_penalty_msat( 42 , 250 , 1_000 , & source, & target) , 300 ) ;
1842
- assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 2_000 ) ;
1843
- assert_eq ! ( scorer. channel_penalty_msat( 42 , 750 , 1_000 , & source, & target) , 2_000 ) ;
1852
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , u64 :: max_value ( ) ) ;
1853
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 750 , 1_000 , & source, & target) , u64 :: max_value ( ) ) ;
1844
1854
}
1845
1855
1846
1856
#[ test]
@@ -1888,19 +1898,19 @@ mod tests {
1888
1898
assert_eq ! ( scorer. channel_penalty_msat( 42 , 128 , 1_024 , & source, & target) , 0 ) ;
1889
1899
assert_eq ! ( scorer. channel_penalty_msat( 42 , 256 , 1_024 , & source, & target) , 97 ) ;
1890
1900
assert_eq ! ( scorer. channel_penalty_msat( 42 , 768 , 1_024 , & source, & target) , 1_409 ) ;
1891
- assert_eq ! ( scorer. channel_penalty_msat( 42 , 896 , 1_024 , & source, & target) , 2_000 ) ;
1901
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 896 , 1_024 , & source, & target) , u64 :: max_value ( ) ) ;
1892
1902
1893
1903
SinceEpoch :: advance ( Duration :: from_secs ( 9 ) ) ;
1894
1904
assert_eq ! ( scorer. channel_penalty_msat( 42 , 128 , 1_024 , & source, & target) , 0 ) ;
1895
1905
assert_eq ! ( scorer. channel_penalty_msat( 42 , 256 , 1_024 , & source, & target) , 97 ) ;
1896
1906
assert_eq ! ( scorer. channel_penalty_msat( 42 , 768 , 1_024 , & source, & target) , 1_409 ) ;
1897
- assert_eq ! ( scorer. channel_penalty_msat( 42 , 896 , 1_024 , & source, & target) , 2_000 ) ;
1907
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 896 , 1_024 , & source, & target) , u64 :: max_value ( ) ) ;
1898
1908
1899
1909
SinceEpoch :: advance ( Duration :: from_secs ( 1 ) ) ;
1900
1910
assert_eq ! ( scorer. channel_penalty_msat( 42 , 64 , 1_024 , & source, & target) , 0 ) ;
1901
1911
assert_eq ! ( scorer. channel_penalty_msat( 42 , 128 , 1_024 , & source, & target) , 34 ) ;
1902
1912
assert_eq ! ( scorer. channel_penalty_msat( 42 , 896 , 1_024 , & source, & target) , 1_773 ) ;
1903
- assert_eq ! ( scorer. channel_penalty_msat( 42 , 960 , 1_024 , & source, & target) , 2_000 ) ;
1913
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 960 , 1_024 , & source, & target) , u64 :: max_value ( ) ) ;
1904
1914
1905
1915
// Fully decay liquidity lower bound.
1906
1916
SinceEpoch :: advance ( Duration :: from_secs ( 10 * 7 ) ) ;
@@ -1995,7 +2005,7 @@ mod tests {
1995
2005
let target = target_node_id ( ) ;
1996
2006
1997
2007
scorer. payment_path_failed ( & payment_path_for_amount ( 500 ) . iter ( ) . collect :: < Vec < _ > > ( ) , 42 ) ;
1998
- assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 2_000 ) ;
2008
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , u64 :: max_value ( ) ) ;
1999
2009
2000
2010
SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
2001
2011
assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 472 ) ;
@@ -2025,7 +2035,7 @@ mod tests {
2025
2035
let target = target_node_id ( ) ;
2026
2036
2027
2037
scorer. payment_path_failed ( & payment_path_for_amount ( 500 ) . iter ( ) . collect :: < Vec < _ > > ( ) , 42 ) ;
2028
- assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 2_000 ) ;
2038
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , u64 :: max_value ( ) ) ;
2029
2039
2030
2040
let mut serialized_scorer = Vec :: new ( ) ;
2031
2041
scorer. write ( & mut serialized_scorer) . unwrap ( ) ;
0 commit comments