@@ -517,7 +517,7 @@ pub struct ProbabilisticScorerUsingTime<G: Deref<Target = NetworkGraph>, T: Time
517
517
518
518
/// Parameters for configuring [`ProbabilisticScorer`].
519
519
///
520
- /// Used to configure a base penalty and a liquidity penalty , the sum of which is the channel
520
+ /// Used to configure base, liquidity, and amount penalties , the sum of which comprises the channel
521
521
/// penalty (i.e., the amount in msats willing to be paid to avoid routing through the channel).
522
522
#[ derive( Clone , Copy ) ]
523
523
pub struct ProbabilisticScoringParameters {
@@ -529,9 +529,12 @@ pub struct ProbabilisticScoringParameters {
529
529
/// A multiplier used in conjunction with the negative `log10` of the channel's success
530
530
/// probability for a payment to determine the liquidity penalty.
531
531
///
532
- /// The penalty is based in part by the knowledge learned from prior successful and unsuccessful
532
+ /// The penalty is based in part on 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
///
@@ -552,6 +555,25 @@ pub struct ProbabilisticScoringParameters {
552
555
/// When built with the `no-std` feature, time will never elapse. Therefore, the channel
553
556
/// liquidity knowledge will never decay except when the bounds cross.
554
557
pub liquidity_offset_half_life : Duration ,
558
+
559
+ /// A multiplier used in conjunction with a payment amount and the negative `log10` of the
560
+ /// channel's success probability for the payment to determine the amount penalty.
561
+ ///
562
+ /// The purpose of the amount penalty is to avoid having fees dominate the channel cost (i.e.,
563
+ /// fees plus penalty) for large payments. The penalty is computed as the product of this
564
+ /// multiplier and `2^20`ths of the payment amount, weighted by the negative `log10` of the
565
+ /// success probability.
566
+ ///
567
+ /// `-log10(success_probability) * amount_penalty_multiplier_msat * amount_msat / 2^20`
568
+ ///
569
+ /// In practice, this means for 0.1 success probability (`-log10(0.1) == 1`) each `2^20`th of
570
+ /// the amount will result in a penalty of the multiplier. And, as the success probability
571
+ /// decreases, the negative `log10` weighting will increase dramatically. For higher success
572
+ /// probabilities, the multiplier will have a decreasing effect as the negative `log10` will
573
+ /// fall below `1`.
574
+ ///
575
+ /// Default value: 256 msat
576
+ pub amount_penalty_multiplier_msat : u64 ,
555
577
}
556
578
557
579
/// Accounting for channel liquidity balance uncertainty.
@@ -599,12 +621,25 @@ impl<G: Deref<Target = NetworkGraph>, T: Time> ProbabilisticScorerUsingTime<G, T
599
621
}
600
622
}
601
623
624
+ impl ProbabilisticScoringParameters {
625
+ #[ cfg( test) ]
626
+ fn zero_penalty ( ) -> Self {
627
+ Self {
628
+ base_penalty_msat : 0 ,
629
+ liquidity_penalty_multiplier_msat : 0 ,
630
+ liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
631
+ amount_penalty_multiplier_msat : 0 ,
632
+ }
633
+ }
634
+ }
635
+
602
636
impl Default for ProbabilisticScoringParameters {
603
637
fn default ( ) -> Self {
604
638
Self {
605
639
base_penalty_msat : 500 ,
606
640
liquidity_penalty_multiplier_msat : 40_000 ,
607
641
liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
642
+ amount_penalty_multiplier_msat : 256 ,
608
643
}
609
644
}
610
645
}
@@ -662,27 +697,63 @@ impl<T: Time> ChannelLiquidity<T> {
662
697
}
663
698
}
664
699
700
+ /// Bounds `-log10` to avoid excessive liquidity penalties for payments with low success
701
+ /// probabilities.
702
+ const NEGATIVE_LOG10_UPPER_BOUND : u64 = 2 ;
703
+
704
+ /// The divisor used when computing the amount penalty.
705
+ const AMOUNT_PENALTY_DIVISOR : u64 = 1 << 20 ;
706
+
665
707
impl < L : Deref < Target = u64 > , T : Time , U : Deref < Target = T > > DirectedChannelLiquidity < L , T , U > {
666
708
/// Returns a penalty for routing the given HTLC `amount_msat` through the channel in this
667
709
/// direction.
668
- fn penalty_msat ( & self , amount_msat : u64 , liquidity_penalty_multiplier_msat : u64 ) -> u64 {
669
- let max_penalty_msat = liquidity_penalty_multiplier_msat. saturating_mul ( 2 ) ;
710
+ fn penalty_msat ( & self , amount_msat : u64 , params : ProbabilisticScoringParameters ) -> u64 {
670
711
let max_liquidity_msat = self . max_liquidity_msat ( ) ;
671
712
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 {
713
+ if amount_msat <= min_liquidity_msat {
675
714
0
715
+ } else if amount_msat >= max_liquidity_msat {
716
+ if amount_msat > max_liquidity_msat {
717
+ u64:: max_value ( )
718
+ } else if max_liquidity_msat != self . capacity_msat {
719
+ // Avoid using the failed channel on retry.
720
+ u64:: max_value ( )
721
+ } else {
722
+ // Equivalent to hitting the else clause below with the amount equal to the
723
+ // effective capacity and without any certainty on the liquidity upper bound.
724
+ let negative_log10_times_1024 = NEGATIVE_LOG10_UPPER_BOUND * 1024 ;
725
+ self . combined_penalty_msat ( amount_msat, negative_log10_times_1024, params)
726
+ }
676
727
} else {
677
728
let numerator = ( max_liquidity_msat - amount_msat) . saturating_add ( 1 ) ;
678
729
let denominator = ( max_liquidity_msat - min_liquidity_msat) . saturating_add ( 1 ) ;
679
- let penalty_msat = approx:: negative_log10_times_1024 ( numerator, denominator)
680
- . saturating_mul ( liquidity_penalty_multiplier_msat) / 1024 ;
681
- // Upper bound the penalty to ensure some channel is selected.
682
- penalty_msat. min ( max_penalty_msat)
730
+ let negative_log10_times_1024 =
731
+ approx:: negative_log10_times_1024 ( numerator, denominator) ;
732
+ self . combined_penalty_msat ( amount_msat, negative_log10_times_1024, params)
683
733
}
684
734
}
685
735
736
+ /// Computes the liquidity and amount penalties and adds them to the base penalty.
737
+ #[ inline( always) ]
738
+ fn combined_penalty_msat (
739
+ & self , amount_msat : u64 , negative_log10_times_1024 : u64 ,
740
+ params : ProbabilisticScoringParameters
741
+ ) -> u64 {
742
+ let liquidity_penalty_msat = {
743
+ // Upper bound the liquidity penalty to ensure some channel is selected.
744
+ let multiplier_msat = params. liquidity_penalty_multiplier_msat ;
745
+ let max_penalty_msat = multiplier_msat. saturating_mul ( NEGATIVE_LOG10_UPPER_BOUND ) ;
746
+ ( negative_log10_times_1024. saturating_mul ( multiplier_msat) / 1024 ) . min ( max_penalty_msat)
747
+ } ;
748
+ let amount_penalty_msat = negative_log10_times_1024
749
+ . saturating_mul ( params. amount_penalty_multiplier_msat )
750
+ . saturating_mul ( amount_msat) / 1024 / AMOUNT_PENALTY_DIVISOR ;
751
+
752
+ params. base_penalty_msat
753
+ . saturating_add ( liquidity_penalty_msat)
754
+ . saturating_add ( amount_penalty_msat)
755
+ }
756
+
686
757
/// Returns the lower bound of the channel liquidity balance in this direction.
687
758
fn min_liquidity_msat ( & self ) -> u64 {
688
759
self . decayed_offset_msat ( * self . min_liquidity_offset_msat )
@@ -752,14 +823,12 @@ impl<G: Deref<Target = NetworkGraph>, T: Time> Score for ProbabilisticScorerUsin
752
823
& self , short_channel_id : u64 , amount_msat : u64 , capacity_msat : u64 , source : & NodeId ,
753
824
target : & NodeId
754
825
) -> u64 {
755
- let liquidity_penalty_multiplier_msat = self . params . liquidity_penalty_multiplier_msat ;
756
826
let liquidity_offset_half_life = self . params . liquidity_offset_half_life ;
757
827
self . channel_liquidities
758
828
. get ( & short_channel_id)
759
829
. unwrap_or ( & ChannelLiquidity :: new ( ) )
760
830
. as_directed ( source, target, capacity_msat, liquidity_offset_half_life)
761
- . penalty_msat ( amount_msat, liquidity_penalty_multiplier_msat)
762
- . saturating_add ( self . params . base_penalty_msat )
831
+ . penalty_msat ( amount_msat, self . params )
763
832
}
764
833
765
834
fn payment_path_failed ( & mut self , path : & [ & RouteHop ] , short_channel_id : u64 ) {
@@ -1737,7 +1806,8 @@ mod tests {
1737
1806
fn increased_penalty_nearing_liquidity_upper_bound ( ) {
1738
1807
let network_graph = network_graph ( ) ;
1739
1808
let params = ProbabilisticScoringParameters {
1740
- base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1809
+ liquidity_penalty_multiplier_msat : 1_000 ,
1810
+ ..ProbabilisticScoringParameters :: zero_penalty ( )
1741
1811
} ;
1742
1812
let scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1743
1813
let source = source_node_id ( ) ;
@@ -1762,7 +1832,8 @@ mod tests {
1762
1832
let last_updated = SinceEpoch :: now ( ) ;
1763
1833
let network_graph = network_graph ( ) ;
1764
1834
let params = ProbabilisticScoringParameters {
1765
- base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1835
+ liquidity_penalty_multiplier_msat : 1_000 ,
1836
+ ..ProbabilisticScoringParameters :: zero_penalty ( )
1766
1837
} ;
1767
1838
let scorer = ProbabilisticScorer :: new ( params, & network_graph)
1768
1839
. with_channel ( 42 ,
@@ -1774,15 +1845,16 @@ mod tests {
1774
1845
1775
1846
assert_eq ! ( scorer. channel_penalty_msat( 42 , 39 , 100 , & source, & target) , 0 ) ;
1776
1847
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 ) ;
1848
+ assert_ne ! ( scorer. channel_penalty_msat( 42 , 50 , 100 , & source, & target) , u64 :: max_value ( ) ) ;
1849
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 61 , 100 , & source, & target) , u64 :: max_value ( ) ) ;
1779
1850
}
1780
1851
1781
1852
#[ test]
1782
1853
fn does_not_further_penalize_own_channel ( ) {
1783
1854
let network_graph = network_graph ( ) ;
1784
1855
let params = ProbabilisticScoringParameters {
1785
- base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1856
+ liquidity_penalty_multiplier_msat : 1_000 ,
1857
+ ..ProbabilisticScoringParameters :: zero_penalty ( )
1786
1858
} ;
1787
1859
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1788
1860
let sender = sender_node_id ( ) ;
@@ -1803,7 +1875,8 @@ mod tests {
1803
1875
fn sets_liquidity_lower_bound_on_downstream_failure ( ) {
1804
1876
let network_graph = network_graph ( ) ;
1805
1877
let params = ProbabilisticScoringParameters {
1806
- base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1878
+ liquidity_penalty_multiplier_msat : 1_000 ,
1879
+ ..ProbabilisticScoringParameters :: zero_penalty ( )
1807
1880
} ;
1808
1881
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1809
1882
let source = source_node_id ( ) ;
@@ -1825,7 +1898,8 @@ mod tests {
1825
1898
fn sets_liquidity_upper_bound_on_failure ( ) {
1826
1899
let network_graph = network_graph ( ) ;
1827
1900
let params = ProbabilisticScoringParameters {
1828
- base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1901
+ liquidity_penalty_multiplier_msat : 1_000 ,
1902
+ ..ProbabilisticScoringParameters :: zero_penalty ( )
1829
1903
} ;
1830
1904
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1831
1905
let source = source_node_id ( ) ;
@@ -1839,15 +1913,16 @@ mod tests {
1839
1913
scorer. payment_path_failed ( & path. iter ( ) . collect :: < Vec < _ > > ( ) , 42 ) ;
1840
1914
1841
1915
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 ) ;
1916
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , u64 :: max_value ( ) ) ;
1917
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 750 , 1_000 , & source, & target) , u64 :: max_value ( ) ) ;
1844
1918
}
1845
1919
1846
1920
#[ test]
1847
1921
fn reduces_liquidity_upper_bound_along_path_on_success ( ) {
1848
1922
let network_graph = network_graph ( ) ;
1849
1923
let params = ProbabilisticScoringParameters {
1850
- base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1924
+ liquidity_penalty_multiplier_msat : 1_000 ,
1925
+ ..ProbabilisticScoringParameters :: zero_penalty ( )
1851
1926
} ;
1852
1927
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1853
1928
let sender = sender_node_id ( ) ;
@@ -1871,9 +1946,9 @@ mod tests {
1871
1946
fn decays_liquidity_bounds_over_time ( ) {
1872
1947
let network_graph = network_graph ( ) ;
1873
1948
let params = ProbabilisticScoringParameters {
1874
- base_penalty_msat : 0 ,
1875
1949
liquidity_penalty_multiplier_msat : 1_000 ,
1876
1950
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1951
+ ..ProbabilisticScoringParameters :: zero_penalty ( )
1877
1952
} ;
1878
1953
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1879
1954
let source = source_node_id ( ) ;
@@ -1888,19 +1963,19 @@ mod tests {
1888
1963
assert_eq ! ( scorer. channel_penalty_msat( 42 , 128 , 1_024 , & source, & target) , 0 ) ;
1889
1964
assert_eq ! ( scorer. channel_penalty_msat( 42 , 256 , 1_024 , & source, & target) , 97 ) ;
1890
1965
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 ) ;
1966
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 896 , 1_024 , & source, & target) , u64 :: max_value ( ) ) ;
1892
1967
1893
1968
SinceEpoch :: advance ( Duration :: from_secs ( 9 ) ) ;
1894
1969
assert_eq ! ( scorer. channel_penalty_msat( 42 , 128 , 1_024 , & source, & target) , 0 ) ;
1895
1970
assert_eq ! ( scorer. channel_penalty_msat( 42 , 256 , 1_024 , & source, & target) , 97 ) ;
1896
1971
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 ) ;
1972
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 896 , 1_024 , & source, & target) , u64 :: max_value ( ) ) ;
1898
1973
1899
1974
SinceEpoch :: advance ( Duration :: from_secs ( 1 ) ) ;
1900
1975
assert_eq ! ( scorer. channel_penalty_msat( 42 , 64 , 1_024 , & source, & target) , 0 ) ;
1901
1976
assert_eq ! ( scorer. channel_penalty_msat( 42 , 128 , 1_024 , & source, & target) , 34 ) ;
1902
1977
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 ) ;
1978
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 960 , 1_024 , & source, & target) , u64 :: max_value ( ) ) ;
1904
1979
1905
1980
// Fully decay liquidity lower bound.
1906
1981
SinceEpoch :: advance ( Duration :: from_secs ( 10 * 7 ) ) ;
@@ -1923,9 +1998,9 @@ mod tests {
1923
1998
fn decays_liquidity_bounds_without_shift_overflow ( ) {
1924
1999
let network_graph = network_graph ( ) ;
1925
2000
let params = ProbabilisticScoringParameters {
1926
- base_penalty_msat : 0 ,
1927
2001
liquidity_penalty_multiplier_msat : 1_000 ,
1928
2002
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
2003
+ ..ProbabilisticScoringParameters :: zero_penalty ( )
1929
2004
} ;
1930
2005
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1931
2006
let source = source_node_id ( ) ;
@@ -1948,9 +2023,9 @@ mod tests {
1948
2023
fn restricts_liquidity_bounds_after_decay ( ) {
1949
2024
let network_graph = network_graph ( ) ;
1950
2025
let params = ProbabilisticScoringParameters {
1951
- base_penalty_msat : 0 ,
1952
2026
liquidity_penalty_multiplier_msat : 1_000 ,
1953
2027
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
2028
+ ..ProbabilisticScoringParameters :: zero_penalty ( )
1954
2029
} ;
1955
2030
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1956
2031
let source = source_node_id ( ) ;
@@ -1986,16 +2061,16 @@ mod tests {
1986
2061
fn restores_persisted_liquidity_bounds ( ) {
1987
2062
let network_graph = network_graph ( ) ;
1988
2063
let params = ProbabilisticScoringParameters {
1989
- base_penalty_msat : 0 ,
1990
2064
liquidity_penalty_multiplier_msat : 1_000 ,
1991
2065
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
2066
+ ..ProbabilisticScoringParameters :: zero_penalty ( )
1992
2067
} ;
1993
2068
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1994
2069
let source = source_node_id ( ) ;
1995
2070
let target = target_node_id ( ) ;
1996
2071
1997
2072
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 ) ;
2073
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , u64 :: max_value ( ) ) ;
1999
2074
2000
2075
SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
2001
2076
assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 472 ) ;
@@ -2016,16 +2091,16 @@ mod tests {
2016
2091
fn decays_persisted_liquidity_bounds ( ) {
2017
2092
let network_graph = network_graph ( ) ;
2018
2093
let params = ProbabilisticScoringParameters {
2019
- base_penalty_msat : 0 ,
2020
2094
liquidity_penalty_multiplier_msat : 1_000 ,
2021
2095
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
2096
+ ..ProbabilisticScoringParameters :: zero_penalty ( )
2022
2097
} ;
2023
2098
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
2024
2099
let source = source_node_id ( ) ;
2025
2100
let target = target_node_id ( ) ;
2026
2101
2027
2102
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 ) ;
2103
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , u64 :: max_value ( ) ) ;
2029
2104
2030
2105
let mut serialized_scorer = Vec :: new ( ) ;
2031
2106
scorer. write ( & mut serialized_scorer) . unwrap ( ) ;
@@ -2051,7 +2126,8 @@ mod tests {
2051
2126
let target = target_node_id ( ) ;
2052
2127
2053
2128
let params = ProbabilisticScoringParameters {
2054
- base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
2129
+ liquidity_penalty_multiplier_msat : 1_000 ,
2130
+ ..ProbabilisticScoringParameters :: zero_penalty ( )
2055
2131
} ;
2056
2132
let scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
2057
2133
assert_eq ! ( scorer. channel_penalty_msat( 42 , 128 , 1_024 , & source, & target) , 58 ) ;
@@ -2063,14 +2139,38 @@ mod tests {
2063
2139
assert_eq ! ( scorer. channel_penalty_msat( 42 , 128 , 1_024 , & source, & target) , 558 ) ;
2064
2140
}
2065
2141
2142
+ #[ test]
2143
+ fn adds_amount_penalty_to_liquidity_penalty ( ) {
2144
+ let network_graph = network_graph ( ) ;
2145
+ let source = source_node_id ( ) ;
2146
+ let target = target_node_id ( ) ;
2147
+
2148
+ let params = ProbabilisticScoringParameters {
2149
+ liquidity_penalty_multiplier_msat : 1_000 ,
2150
+ amount_penalty_multiplier_msat : 0 ,
2151
+ ..ProbabilisticScoringParameters :: zero_penalty ( )
2152
+ } ;
2153
+ let scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
2154
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 512_000 , 1_024_000 , & source, & target) , 300 ) ;
2155
+
2156
+ let params = ProbabilisticScoringParameters {
2157
+ liquidity_penalty_multiplier_msat : 1_000 ,
2158
+ amount_penalty_multiplier_msat : 256 ,
2159
+ ..ProbabilisticScoringParameters :: zero_penalty ( )
2160
+ } ;
2161
+ let scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
2162
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 512_000 , 1_024_000 , & source, & target) , 337 ) ;
2163
+ }
2164
+
2066
2165
#[ test]
2067
2166
fn calculates_log10_without_overflowing_u64_max_value ( ) {
2068
2167
let network_graph = network_graph ( ) ;
2069
2168
let source = source_node_id ( ) ;
2070
2169
let target = target_node_id ( ) ;
2071
2170
2072
2171
let params = ProbabilisticScoringParameters {
2073
- base_penalty_msat : 0 , ..Default :: default ( )
2172
+ liquidity_penalty_multiplier_msat : 40_000 ,
2173
+ ..ProbabilisticScoringParameters :: zero_penalty ( )
2074
2174
} ;
2075
2175
let scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
2076
2176
assert_eq ! (
0 commit comments