@@ -516,27 +516,32 @@ pub struct ProbabilisticScorerUsingTime<G: Deref<Target = NetworkGraph>, T: Time
516
516
}
517
517
518
518
/// Parameters for configuring [`ProbabilisticScorer`].
519
+ ///
520
+ /// Used to configure a base penalty and a liquidity penalty, the sum of which is the channel
521
+ /// penalty (i.e., the amount in msats willing to be paid to avoid routing through the channel).
519
522
#[ derive( Clone , Copy ) ]
520
523
pub struct ProbabilisticScoringParameters {
521
- /// The function calculating the cost of routing an amount through a channel.
524
+ /// A fixed penalty in msats to apply to each channel.
522
525
///
523
- /// The cost is multiplied by [`liquidity_penalty_multiplier_msat`] to determine the channel
524
- /// penalty (i.e., the amount msats willing to be paid to avoid routing through the channel).
525
- /// Penalties are limited to `2 * liquidity_penalty_multiplier_msat`.
526
+ /// Default value: 500 msat
527
+ pub base_penalty_msat : u64 ,
528
+
529
+ /// The function calculating the cost of routing an amount through a channel.
526
530
///
527
- /// The cost is based in part by the knowledge learned from prior successful and unsuccessful
528
- /// payments. This knowledge is decayed over time based on [`liquidity_offset_half_life`].
531
+ /// The cost is multiplied by [`liquidity_penalty_multiplier_msat`] to determine the liquidity
532
+ /// penalty, which is limited to `2 * liquidity_penalty_multiplier_msat`. The cost is based in
533
+ /// part by the knowledge learned from prior successful and unsuccessful payments. This
534
+ /// knowledge is decayed over time based on [`liquidity_offset_half_life`].
529
535
///
530
536
/// Default value: [`ProbabilisticScoringCostFunction::NegativeLogSuccessProbability`]
531
537
///
532
538
/// [`liquidity_penalty_multiplier_msat`]: Self::liquidity_penalty_multiplier_msat
533
539
/// [`liquidity_offset_half_life`]: Self::liquidity_offset_half_life
534
540
pub cost_function : ProbabilisticScoringCostFunction ,
535
541
536
- /// A multiplier used in conjunction with [`cost_function`] to determine the channel penalty.
542
+ /// A multiplier used in conjunction with [`cost_function`] to determine the liquidity penalty.
537
543
///
538
- /// The channel penalty is the amount in msats willing to be paid to avoid routing through a
539
- /// channel. It is effectively limited to `2 * liquidity_penalty_multiplier_msat`.
544
+ /// The liquidity penalty is effectively limited to `2 * liquidity_penalty_multiplier_msat`.
540
545
///
541
546
/// Default value: 10,000 msat
542
547
///
@@ -630,6 +635,7 @@ impl<G: Deref<Target = NetworkGraph>, T: Time> ProbabilisticScorerUsingTime<G, T
630
635
impl Default for ProbabilisticScoringParameters {
631
636
fn default ( ) -> Self {
632
637
Self {
638
+ base_penalty_msat : 500 ,
633
639
cost_function : ProbabilisticScoringCostFunction :: NegativeLogSuccessProbability ,
634
640
liquidity_penalty_multiplier_msat : 10_000 ,
635
641
liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
@@ -795,6 +801,7 @@ impl<G: Deref<Target = NetworkGraph>, T: Time> Score for ProbabilisticScorerUsin
795
801
. unwrap_or ( & ChannelLiquidity :: new ( ) )
796
802
. as_directed ( source, target, capacity_msat, self . params . liquidity_offset_half_life )
797
803
. penalty_msat ( amount_msat, & self . params )
804
+ . saturating_add ( self . params . base_penalty_msat )
798
805
}
799
806
800
807
fn payment_path_failed ( & mut self , path : & [ & RouteHop ] , short_channel_id : u64 ) {
@@ -1772,7 +1779,7 @@ mod tests {
1772
1779
fn increased_penalty_nearing_liquidity_upper_bound ( ) {
1773
1780
let network_graph = network_graph ( ) ;
1774
1781
let params = ProbabilisticScoringParameters {
1775
- liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1782
+ base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1776
1783
} ;
1777
1784
let scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1778
1785
let source = source_node_id ( ) ;
@@ -1796,6 +1803,7 @@ mod tests {
1796
1803
fn increased_penalty_linearly_nearing_liquidity_upper_bound ( ) {
1797
1804
let network_graph = network_graph ( ) ;
1798
1805
let params = ProbabilisticScoringParameters {
1806
+ base_penalty_msat : 0 ,
1799
1807
cost_function : ProbabilisticScoringCostFunction :: TwiceFailureProbability ,
1800
1808
liquidity_penalty_multiplier_msat : 1_000 ,
1801
1809
..Default :: default ( )
@@ -1823,7 +1831,7 @@ mod tests {
1823
1831
let last_updated = SinceEpoch :: now ( ) ;
1824
1832
let network_graph = network_graph ( ) ;
1825
1833
let params = ProbabilisticScoringParameters {
1826
- liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1834
+ base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1827
1835
} ;
1828
1836
let scorer = ProbabilisticScorer :: new ( params, & network_graph)
1829
1837
. with_channel ( 42 ,
@@ -1843,7 +1851,7 @@ mod tests {
1843
1851
fn does_not_further_penalize_own_channel ( ) {
1844
1852
let network_graph = network_graph ( ) ;
1845
1853
let params = ProbabilisticScoringParameters {
1846
- liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1854
+ base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1847
1855
} ;
1848
1856
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1849
1857
let sender = sender_node_id ( ) ;
@@ -1864,7 +1872,7 @@ mod tests {
1864
1872
fn sets_liquidity_lower_bound_on_downstream_failure ( ) {
1865
1873
let network_graph = network_graph ( ) ;
1866
1874
let params = ProbabilisticScoringParameters {
1867
- liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1875
+ base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1868
1876
} ;
1869
1877
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1870
1878
let source = source_node_id ( ) ;
@@ -1886,7 +1894,7 @@ mod tests {
1886
1894
fn sets_liquidity_upper_bound_on_failure ( ) {
1887
1895
let network_graph = network_graph ( ) ;
1888
1896
let params = ProbabilisticScoringParameters {
1889
- liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1897
+ base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1890
1898
} ;
1891
1899
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1892
1900
let source = source_node_id ( ) ;
@@ -1908,7 +1916,7 @@ mod tests {
1908
1916
fn reduces_liquidity_upper_bound_along_path_on_success ( ) {
1909
1917
let network_graph = network_graph ( ) ;
1910
1918
let params = ProbabilisticScoringParameters {
1911
- liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1919
+ base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1912
1920
} ;
1913
1921
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1914
1922
let sender = sender_node_id ( ) ;
@@ -1932,6 +1940,7 @@ mod tests {
1932
1940
fn decays_liquidity_bounds_over_time ( ) {
1933
1941
let network_graph = network_graph ( ) ;
1934
1942
let params = ProbabilisticScoringParameters {
1943
+ base_penalty_msat : 0 ,
1935
1944
liquidity_penalty_multiplier_msat : 1_000 ,
1936
1945
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1937
1946
..Default :: default ( )
@@ -1984,6 +1993,7 @@ mod tests {
1984
1993
fn decays_liquidity_bounds_without_shift_overflow ( ) {
1985
1994
let network_graph = network_graph ( ) ;
1986
1995
let params = ProbabilisticScoringParameters {
1996
+ base_penalty_msat : 0 ,
1987
1997
liquidity_penalty_multiplier_msat : 1_000 ,
1988
1998
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1989
1999
..Default :: default ( )
@@ -2009,6 +2019,7 @@ mod tests {
2009
2019
fn restricts_liquidity_bounds_after_decay ( ) {
2010
2020
let network_graph = network_graph ( ) ;
2011
2021
let params = ProbabilisticScoringParameters {
2022
+ base_penalty_msat : 0 ,
2012
2023
liquidity_penalty_multiplier_msat : 1_000 ,
2013
2024
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
2014
2025
..Default :: default ( )
@@ -2047,6 +2058,7 @@ mod tests {
2047
2058
fn restores_persisted_liquidity_bounds ( ) {
2048
2059
let network_graph = network_graph ( ) ;
2049
2060
let params = ProbabilisticScoringParameters {
2061
+ base_penalty_msat : 0 ,
2050
2062
liquidity_penalty_multiplier_msat : 1_000 ,
2051
2063
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
2052
2064
..Default :: default ( )
@@ -2077,6 +2089,7 @@ mod tests {
2077
2089
fn decays_persisted_liquidity_bounds ( ) {
2078
2090
let network_graph = network_graph ( ) ;
2079
2091
let params = ProbabilisticScoringParameters {
2092
+ base_penalty_msat : 0 ,
2080
2093
liquidity_penalty_multiplier_msat : 1_000 ,
2081
2094
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
2082
2095
..Default :: default ( )
@@ -2104,4 +2117,23 @@ mod tests {
2104
2117
SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
2105
2118
assert_eq ! ( deserialized_scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 371 ) ;
2106
2119
}
2120
+
2121
+ #[ test]
2122
+ fn adds_base_penalty_to_liquidity_penalty ( ) {
2123
+ let network_graph = network_graph ( ) ;
2124
+ let source = source_node_id ( ) ;
2125
+ let target = target_node_id ( ) ;
2126
+
2127
+ let params = ProbabilisticScoringParameters {
2128
+ base_penalty_msat : 0 , ..Default :: default ( )
2129
+ } ;
2130
+ let scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
2131
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 128 , 1_024 , & source, & target) , 585 ) ;
2132
+
2133
+ let params = ProbabilisticScoringParameters {
2134
+ base_penalty_msat : 500 , ..Default :: default ( )
2135
+ } ;
2136
+ let scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
2137
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 128 , 1_024 , & source, & target) , 1085 ) ;
2138
+ }
2107
2139
}
0 commit comments