@@ -392,6 +392,19 @@ pub struct ProbabilisticScoringParameters {
392
392
///
393
393
/// Default value: 250 msat
394
394
pub anti_probing_penalty_msat : u64 ,
395
+
396
+ /// This penalty is applied when the amount we're attempting to send over a channel exceeds our
397
+ /// current estimate of the liquidity available on a channel.
398
+ ///
399
+ /// Note that in this case the liquidity penalties are still included to ensure such channels
400
+ /// which may have enough liquidity are scored worse than channels which we do not believe have
401
+ /// enough.
402
+ ///
403
+ /// Note if you wish to avoid creating paths with such channels entirely, a penalty of
404
+ /// `u64::max_value()` will guarantee that.
405
+ ///
406
+ /// Default value: `u64::max_value()`
407
+ pub considered_impossible_penalty_msat : u64 ,
395
408
}
396
409
397
410
/// Accounting for channel liquidity balance uncertainty.
@@ -510,6 +523,7 @@ impl ProbabilisticScoringParameters {
510
523
amount_penalty_multiplier_msat : 0 ,
511
524
banned_nodes : HashSet :: new ( ) ,
512
525
anti_probing_penalty_msat : 0 ,
526
+ considered_impossible_penalty_msat : 0 ,
513
527
}
514
528
}
515
529
@@ -531,6 +545,7 @@ impl Default for ProbabilisticScoringParameters {
531
545
amount_penalty_multiplier_msat : 256 ,
532
546
banned_nodes : HashSet :: new ( ) ,
533
547
anti_probing_penalty_msat : 250 ,
548
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
534
549
}
535
550
}
536
551
}
@@ -608,17 +623,12 @@ impl<L: Deref<Target = u64>, T: Time, U: Deref<Target = T>> DirectedChannelLiqui
608
623
if amount_msat <= min_liquidity_msat {
609
624
0
610
625
} else if amount_msat >= max_liquidity_msat {
611
- if amount_msat > max_liquidity_msat {
612
- u64:: max_value ( )
613
- } else if max_liquidity_msat != self . capacity_msat {
614
- // Avoid using the failed channel on retry.
615
- u64:: max_value ( )
616
- } else {
617
- // Equivalent to hitting the else clause below with the amount equal to the
618
- // effective capacity and without any certainty on the liquidity upper bound.
619
- let negative_log10_times_2048 = NEGATIVE_LOG10_UPPER_BOUND * 2048 ;
620
- self . combined_penalty_msat ( amount_msat, negative_log10_times_2048, params)
621
- }
626
+ // Equivalent to hitting the else clause below with the amount equal to the effective
627
+ // capacity and without any certainty on the liquidity upper bound, plus the
628
+ // impossibility penalty.
629
+ let negative_log10_times_2048 = NEGATIVE_LOG10_UPPER_BOUND * 2048 ;
630
+ self . combined_penalty_msat ( amount_msat, negative_log10_times_2048, params)
631
+ . saturating_add ( params. considered_impossible_penalty_msat )
622
632
} else {
623
633
let numerator = ( max_liquidity_msat - amount_msat) . saturating_add ( 1 ) ;
624
634
let denominator = ( max_liquidity_msat - min_liquidity_msat) . saturating_add ( 1 ) ;
@@ -1600,7 +1610,7 @@ mod tests {
1600
1610
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
1601
1611
let usage = ChannelUsage { amount_msat : 102_400 , ..usage } ;
1602
1612
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 47 ) ;
1603
- let usage = ChannelUsage { amount_msat : 1_024_000 , ..usage } ;
1613
+ let usage = ChannelUsage { amount_msat : 1_023_999 , ..usage } ;
1604
1614
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1605
1615
1606
1616
let usage = ChannelUsage {
@@ -1630,6 +1640,7 @@ mod tests {
1630
1640
let network_graph = network_graph ( & logger) ;
1631
1641
let params = ProbabilisticScoringParameters {
1632
1642
liquidity_penalty_multiplier_msat : 1_000 ,
1643
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1633
1644
..ProbabilisticScoringParameters :: zero_penalty ( )
1634
1645
} ;
1635
1646
let scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger)
@@ -1721,6 +1732,7 @@ mod tests {
1721
1732
let network_graph = network_graph ( & logger) ;
1722
1733
let params = ProbabilisticScoringParameters {
1723
1734
liquidity_penalty_multiplier_msat : 1_000 ,
1735
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1724
1736
..ProbabilisticScoringParameters :: zero_penalty ( )
1725
1737
} ;
1726
1738
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
@@ -1787,6 +1799,7 @@ mod tests {
1787
1799
let params = ProbabilisticScoringParameters {
1788
1800
liquidity_penalty_multiplier_msat : 1_000 ,
1789
1801
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1802
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1790
1803
..ProbabilisticScoringParameters :: zero_penalty ( )
1791
1804
} ;
1792
1805
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
@@ -1796,10 +1809,10 @@ mod tests {
1796
1809
let usage = ChannelUsage {
1797
1810
amount_msat : 0 ,
1798
1811
inflight_htlc_msat : 0 ,
1799
- effective_capacity : EffectiveCapacity :: Total { capacity_msat : 1_024 , htlc_maximum_msat : Some ( 1_000 ) } ,
1812
+ effective_capacity : EffectiveCapacity :: Total { capacity_msat : 1_024 , htlc_maximum_msat : Some ( 1_024 ) } ,
1800
1813
} ;
1801
1814
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
1802
- let usage = ChannelUsage { amount_msat : 1_024 , ..usage } ;
1815
+ let usage = ChannelUsage { amount_msat : 1_023 , ..usage } ;
1803
1816
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1804
1817
1805
1818
scorer. payment_path_failed ( & payment_path_for_amount ( 768 ) . iter ( ) . collect :: < Vec < _ > > ( ) , 42 ) ;
@@ -1843,20 +1856,20 @@ mod tests {
1843
1856
let usage = ChannelUsage { amount_msat : 1_023 , ..usage } ;
1844
1857
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1845
1858
let usage = ChannelUsage { amount_msat : 1_024 , ..usage } ;
1846
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1859
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , u64 :: max_value ( ) ) ;
1847
1860
1848
1861
// Fully decay liquidity upper bound.
1849
1862
SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
1850
1863
let usage = ChannelUsage { amount_msat : 0 , ..usage } ;
1851
1864
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
1852
1865
let usage = ChannelUsage { amount_msat : 1_024 , ..usage } ;
1853
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1866
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , u64 :: max_value ( ) ) ;
1854
1867
1855
1868
SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
1856
1869
let usage = ChannelUsage { amount_msat : 0 , ..usage } ;
1857
1870
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
1858
1871
let usage = ChannelUsage { amount_msat : 1_024 , ..usage } ;
1859
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1872
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , u64 :: max_value ( ) ) ;
1860
1873
}
1861
1874
1862
1875
#[ test]
@@ -1941,6 +1954,7 @@ mod tests {
1941
1954
let params = ProbabilisticScoringParameters {
1942
1955
liquidity_penalty_multiplier_msat : 1_000 ,
1943
1956
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1957
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1944
1958
..ProbabilisticScoringParameters :: zero_penalty ( )
1945
1959
} ;
1946
1960
let mut scorer = ProbabilisticScorer :: new ( params. clone ( ) , & network_graph, & logger) ;
@@ -1977,6 +1991,7 @@ mod tests {
1977
1991
let params = ProbabilisticScoringParameters {
1978
1992
liquidity_penalty_multiplier_msat : 1_000 ,
1979
1993
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1994
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1980
1995
..ProbabilisticScoringParameters :: zero_penalty ( )
1981
1996
} ;
1982
1997
let mut scorer = ProbabilisticScorer :: new ( params. clone ( ) , & network_graph, & logger) ;
@@ -2136,11 +2151,11 @@ mod tests {
2136
2151
} ;
2137
2152
2138
2153
let params = ProbabilisticScoringParameters {
2139
- liquidity_penalty_multiplier_msat : 40_000 ,
2154
+ considered_impossible_penalty_msat : 42_420 ,
2140
2155
..ProbabilisticScoringParameters :: zero_penalty ( )
2141
2156
} ;
2142
2157
let scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
2143
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 80_000 ) ;
2158
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 42_420 ) ;
2144
2159
}
2145
2160
2146
2161
#[ test]
0 commit comments