@@ -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
///
@@ -633,6 +638,7 @@ impl Default for ProbabilisticScoringParameters {
633
638
cost_function : ProbabilisticScoringCostFunction :: NegativeLogSuccessProbability ,
634
639
liquidity_penalty_multiplier_msat : 10_000 ,
635
640
liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
641
+ base_penalty_msat : 500 ,
636
642
}
637
643
}
638
644
}
@@ -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 ) {
@@ -1775,7 +1782,7 @@ mod tests {
1775
1782
fn increased_penalty_nearing_liquidity_upper_bound ( ) {
1776
1783
let network_graph = network_graph ( ) ;
1777
1784
let params = ProbabilisticScoringParameters {
1778
- liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1785
+ base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1779
1786
} ;
1780
1787
let scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1781
1788
let source = source_node_id ( ) ;
@@ -1799,6 +1806,7 @@ mod tests {
1799
1806
fn increased_penalty_linearly_nearing_liquidity_upper_bound ( ) {
1800
1807
let network_graph = network_graph ( ) ;
1801
1808
let params = ProbabilisticScoringParameters {
1809
+ base_penalty_msat : 0 ,
1802
1810
cost_function : ProbabilisticScoringCostFunction :: TwiceFailureProbability ,
1803
1811
liquidity_penalty_multiplier_msat : 1_000 ,
1804
1812
..Default :: default ( )
@@ -1826,7 +1834,7 @@ mod tests {
1826
1834
let last_updated = SinceEpoch :: now ( ) ;
1827
1835
let network_graph = network_graph ( ) ;
1828
1836
let params = ProbabilisticScoringParameters {
1829
- liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1837
+ base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1830
1838
} ;
1831
1839
let scorer = ProbabilisticScorer :: new ( params, & network_graph)
1832
1840
. with_channel ( 42 ,
@@ -1846,7 +1854,7 @@ mod tests {
1846
1854
fn does_not_further_penalize_own_channel ( ) {
1847
1855
let network_graph = network_graph ( ) ;
1848
1856
let params = ProbabilisticScoringParameters {
1849
- liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1857
+ base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1850
1858
} ;
1851
1859
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1852
1860
let sender = sender_node_id ( ) ;
@@ -1867,7 +1875,7 @@ mod tests {
1867
1875
fn sets_liquidity_lower_bound_on_downstream_failure ( ) {
1868
1876
let network_graph = network_graph ( ) ;
1869
1877
let params = ProbabilisticScoringParameters {
1870
- liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1878
+ base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1871
1879
} ;
1872
1880
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1873
1881
let source = source_node_id ( ) ;
@@ -1889,7 +1897,7 @@ mod tests {
1889
1897
fn sets_liquidity_upper_bound_on_failure ( ) {
1890
1898
let network_graph = network_graph ( ) ;
1891
1899
let params = ProbabilisticScoringParameters {
1892
- liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1900
+ base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1893
1901
} ;
1894
1902
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1895
1903
let source = source_node_id ( ) ;
@@ -1911,7 +1919,7 @@ mod tests {
1911
1919
fn reduces_liquidity_upper_bound_along_path_on_success ( ) {
1912
1920
let network_graph = network_graph ( ) ;
1913
1921
let params = ProbabilisticScoringParameters {
1914
- liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1922
+ base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1915
1923
} ;
1916
1924
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1917
1925
let sender = sender_node_id ( ) ;
@@ -1935,6 +1943,7 @@ mod tests {
1935
1943
fn decays_liquidity_bounds_over_time ( ) {
1936
1944
let network_graph = network_graph ( ) ;
1937
1945
let params = ProbabilisticScoringParameters {
1946
+ base_penalty_msat : 0 ,
1938
1947
liquidity_penalty_multiplier_msat : 1_000 ,
1939
1948
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1940
1949
..Default :: default ( )
@@ -1987,6 +1996,7 @@ mod tests {
1987
1996
fn decays_liquidity_bounds_without_shift_overflow ( ) {
1988
1997
let network_graph = network_graph ( ) ;
1989
1998
let params = ProbabilisticScoringParameters {
1999
+ base_penalty_msat : 0 ,
1990
2000
liquidity_penalty_multiplier_msat : 1_000 ,
1991
2001
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1992
2002
..Default :: default ( )
@@ -2012,6 +2022,7 @@ mod tests {
2012
2022
fn restricts_liquidity_bounds_after_decay ( ) {
2013
2023
let network_graph = network_graph ( ) ;
2014
2024
let params = ProbabilisticScoringParameters {
2025
+ base_penalty_msat : 0 ,
2015
2026
liquidity_penalty_multiplier_msat : 1_000 ,
2016
2027
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
2017
2028
..Default :: default ( )
@@ -2050,6 +2061,7 @@ mod tests {
2050
2061
fn restores_persisted_liquidity_bounds ( ) {
2051
2062
let network_graph = network_graph ( ) ;
2052
2063
let params = ProbabilisticScoringParameters {
2064
+ base_penalty_msat : 0 ,
2053
2065
liquidity_penalty_multiplier_msat : 1_000 ,
2054
2066
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
2055
2067
..Default :: default ( )
@@ -2080,6 +2092,7 @@ mod tests {
2080
2092
fn decays_persisted_liquidity_bounds ( ) {
2081
2093
let network_graph = network_graph ( ) ;
2082
2094
let params = ProbabilisticScoringParameters {
2095
+ base_penalty_msat : 0 ,
2083
2096
liquidity_penalty_multiplier_msat : 1_000 ,
2084
2097
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
2085
2098
..Default :: default ( )
@@ -2107,4 +2120,23 @@ mod tests {
2107
2120
SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
2108
2121
assert_eq ! ( deserialized_scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 371 ) ;
2109
2122
}
2123
+
2124
+ #[ test]
2125
+ fn adds_base_penalty_to_liquidity_penalty ( ) {
2126
+ let network_graph = network_graph ( ) ;
2127
+ let source = source_node_id ( ) ;
2128
+ let target = target_node_id ( ) ;
2129
+
2130
+ let params = ProbabilisticScoringParameters {
2131
+ base_penalty_msat : 0 , ..Default :: default ( )
2132
+ } ;
2133
+ let scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
2134
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 128 , 1_024 , & source, & target) , 585 ) ;
2135
+
2136
+ let params = ProbabilisticScoringParameters {
2137
+ base_penalty_msat : 500 , ..Default :: default ( )
2138
+ } ;
2139
+ let scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
2140
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 128 , 1_024 , & source, & target) , 1085 ) ;
2141
+ }
2110
2142
}
0 commit comments