@@ -516,17 +516,22 @@ 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
- /// A multiplier used to determine the amount in msats willing to be paid to avoid routing
522
- /// through a channel, as per multiplying by the negative `log10` of the channel's success
523
- /// probability for a payment.
524
+ /// A fixed penalty in msats to apply to each channel.
524
525
///
525
- /// The success probability is determined by the effective channel capacity, the payment amount,
526
- /// and knowledge learned from prior successful and unsuccessful payments. The lower bound of
527
- /// the success probability is 0.01, effectively limiting the penalty to the range
528
- /// `0..=2*liquidity_penalty_multiplier_msat`. The knowledge learned is decayed over time based
529
- /// on [`liquidity_offset_half_life`].
526
+ /// Default value: 500 msat
527
+ pub base_penalty_msat : u64 ,
528
+
529
+ /// A multiplier used in conjunction with the negative `log10` of the channel's success
530
+ /// probability for a payment to determine the liquidity penalty.
531
+ ///
532
+ /// The penalty is based in part by the knowledge learned from prior successful and unsuccessful
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`.
530
535
///
531
536
/// Default value: 10,000 msat
532
537
///
@@ -549,11 +554,6 @@ pub struct ProbabilisticScoringParameters {
549
554
pub liquidity_offset_half_life : Duration ,
550
555
}
551
556
552
- impl_writeable_tlv_based ! ( ProbabilisticScoringParameters , {
553
- ( 0 , liquidity_penalty_multiplier_msat, required) ,
554
- ( 2 , liquidity_offset_half_life, required) ,
555
- } ) ;
556
-
557
557
/// Accounting for channel liquidity balance uncertainty.
558
558
///
559
559
/// Direction is defined in terms of [`NodeId`] partial ordering, where the source node is the
@@ -602,6 +602,7 @@ impl<G: Deref<Target = NetworkGraph>, T: Time> ProbabilisticScorerUsingTime<G, T
602
602
impl Default for ProbabilisticScoringParameters {
603
603
fn default ( ) -> Self {
604
604
Self {
605
+ base_penalty_msat : 500 ,
605
606
liquidity_penalty_multiplier_msat : 10_000 ,
606
607
liquidity_offset_half_life : Duration :: from_secs ( 3600 ) ,
607
608
}
@@ -757,6 +758,7 @@ impl<G: Deref<Target = NetworkGraph>, T: Time> Score for ProbabilisticScorerUsin
757
758
. unwrap_or ( & ChannelLiquidity :: new ( ) )
758
759
. as_directed ( source, target, capacity_msat, liquidity_offset_half_life)
759
760
. penalty_msat ( amount_msat, liquidity_penalty_multiplier_msat)
761
+ . saturating_add ( self . params . base_penalty_msat )
760
762
}
761
763
762
764
fn payment_path_failed ( & mut self , path : & [ & RouteHop ] , short_channel_id : u64 ) {
@@ -1734,7 +1736,7 @@ mod tests {
1734
1736
fn increased_penalty_nearing_liquidity_upper_bound ( ) {
1735
1737
let network_graph = network_graph ( ) ;
1736
1738
let params = ProbabilisticScoringParameters {
1737
- liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1739
+ base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1738
1740
} ;
1739
1741
let scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1740
1742
let source = source_node_id ( ) ;
@@ -1759,7 +1761,7 @@ mod tests {
1759
1761
let last_updated = SinceEpoch :: now ( ) ;
1760
1762
let network_graph = network_graph ( ) ;
1761
1763
let params = ProbabilisticScoringParameters {
1762
- liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1764
+ base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1763
1765
} ;
1764
1766
let scorer = ProbabilisticScorer :: new ( params, & network_graph)
1765
1767
. with_channel ( 42 ,
@@ -1779,7 +1781,7 @@ mod tests {
1779
1781
fn does_not_further_penalize_own_channel ( ) {
1780
1782
let network_graph = network_graph ( ) ;
1781
1783
let params = ProbabilisticScoringParameters {
1782
- liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1784
+ base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1783
1785
} ;
1784
1786
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1785
1787
let sender = sender_node_id ( ) ;
@@ -1800,7 +1802,7 @@ mod tests {
1800
1802
fn sets_liquidity_lower_bound_on_downstream_failure ( ) {
1801
1803
let network_graph = network_graph ( ) ;
1802
1804
let params = ProbabilisticScoringParameters {
1803
- liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1805
+ base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1804
1806
} ;
1805
1807
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1806
1808
let source = source_node_id ( ) ;
@@ -1822,7 +1824,7 @@ mod tests {
1822
1824
fn sets_liquidity_upper_bound_on_failure ( ) {
1823
1825
let network_graph = network_graph ( ) ;
1824
1826
let params = ProbabilisticScoringParameters {
1825
- liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1827
+ base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1826
1828
} ;
1827
1829
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1828
1830
let source = source_node_id ( ) ;
@@ -1844,7 +1846,7 @@ mod tests {
1844
1846
fn reduces_liquidity_upper_bound_along_path_on_success ( ) {
1845
1847
let network_graph = network_graph ( ) ;
1846
1848
let params = ProbabilisticScoringParameters {
1847
- liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1849
+ base_penalty_msat : 0 , liquidity_penalty_multiplier_msat : 1_000 , ..Default :: default ( )
1848
1850
} ;
1849
1851
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
1850
1852
let sender = sender_node_id ( ) ;
@@ -1868,6 +1870,7 @@ mod tests {
1868
1870
fn decays_liquidity_bounds_over_time ( ) {
1869
1871
let network_graph = network_graph ( ) ;
1870
1872
let params = ProbabilisticScoringParameters {
1873
+ base_penalty_msat : 0 ,
1871
1874
liquidity_penalty_multiplier_msat : 1_000 ,
1872
1875
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1873
1876
} ;
@@ -1919,6 +1922,7 @@ mod tests {
1919
1922
fn decays_liquidity_bounds_without_shift_overflow ( ) {
1920
1923
let network_graph = network_graph ( ) ;
1921
1924
let params = ProbabilisticScoringParameters {
1925
+ base_penalty_msat : 0 ,
1922
1926
liquidity_penalty_multiplier_msat : 1_000 ,
1923
1927
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1924
1928
} ;
@@ -1943,6 +1947,7 @@ mod tests {
1943
1947
fn restricts_liquidity_bounds_after_decay ( ) {
1944
1948
let network_graph = network_graph ( ) ;
1945
1949
let params = ProbabilisticScoringParameters {
1950
+ base_penalty_msat : 0 ,
1946
1951
liquidity_penalty_multiplier_msat : 1_000 ,
1947
1952
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1948
1953
} ;
@@ -1980,6 +1985,7 @@ mod tests {
1980
1985
fn restores_persisted_liquidity_bounds ( ) {
1981
1986
let network_graph = network_graph ( ) ;
1982
1987
let params = ProbabilisticScoringParameters {
1988
+ base_penalty_msat : 0 ,
1983
1989
liquidity_penalty_multiplier_msat : 1_000 ,
1984
1990
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1985
1991
} ;
@@ -2009,6 +2015,7 @@ mod tests {
2009
2015
fn decays_persisted_liquidity_bounds ( ) {
2010
2016
let network_graph = network_graph ( ) ;
2011
2017
let params = ProbabilisticScoringParameters {
2018
+ base_penalty_msat : 0 ,
2012
2019
liquidity_penalty_multiplier_msat : 1_000 ,
2013
2020
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
2014
2021
} ;
@@ -2035,4 +2042,23 @@ mod tests {
2035
2042
SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
2036
2043
assert_eq ! ( deserialized_scorer. channel_penalty_msat( 42 , 500 , 1_000 , & source, & target) , 371 ) ;
2037
2044
}
2045
+
2046
+ #[ test]
2047
+ fn adds_base_penalty_to_liquidity_penalty ( ) {
2048
+ let network_graph = network_graph ( ) ;
2049
+ let source = source_node_id ( ) ;
2050
+ let target = target_node_id ( ) ;
2051
+
2052
+ let params = ProbabilisticScoringParameters {
2053
+ base_penalty_msat : 0 , ..Default :: default ( )
2054
+ } ;
2055
+ let scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
2056
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 128 , 1_024 , & source, & target) , 585 ) ;
2057
+
2058
+ let params = ProbabilisticScoringParameters {
2059
+ base_penalty_msat : 500 , ..Default :: default ( )
2060
+ } ;
2061
+ let scorer = ProbabilisticScorer :: new ( params, & network_graph) ;
2062
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , 128 , 1_024 , & source, & target) , 1085 ) ;
2063
+ }
2038
2064
}
0 commit comments