@@ -392,6 +392,22 @@ 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 channel's available liquidity.
398
+ ///
399
+ /// Note that in this case the [`liquidity_penalty_multiplier_msat`] and
400
+ /// [`amount_penalty_multiplier_msat`]-based penalties are still included in the overall
401
+ /// penalty.
402
+ ///
403
+ /// If you wish to avoid creating paths with such channels entirely, setting this to a value of
404
+ /// `u64::max_value()` will guarantee that.
405
+ ///
406
+ /// Default value: `u64::max_value()`
407
+ ///
408
+ /// [`liquidity_penalty_multiplier_msat`]: Self::liquidity_penalty_multiplier_msat
409
+ /// [`amount_penalty_multiplier_msat`]: Self::amount_penalty_multiplier_msat
410
+ pub considered_impossible_penalty_msat : u64 ,
395
411
}
396
412
397
413
/// Accounting for channel liquidity balance uncertainty.
@@ -510,6 +526,7 @@ impl ProbabilisticScoringParameters {
510
526
amount_penalty_multiplier_msat : 0 ,
511
527
banned_nodes : HashSet :: new ( ) ,
512
528
anti_probing_penalty_msat : 0 ,
529
+ considered_impossible_penalty_msat : 0 ,
513
530
}
514
531
}
515
532
@@ -531,6 +548,7 @@ impl Default for ProbabilisticScoringParameters {
531
548
amount_penalty_multiplier_msat : 256 ,
532
549
banned_nodes : HashSet :: new ( ) ,
533
550
anti_probing_penalty_msat : 250 ,
551
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
534
552
}
535
553
}
536
554
}
@@ -608,17 +626,12 @@ impl<L: Deref<Target = u64>, T: Time, U: Deref<Target = T>> DirectedChannelLiqui
608
626
if amount_msat <= min_liquidity_msat {
609
627
0
610
628
} 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
- }
629
+ // Equivalent to hitting the else clause below with the amount equal to the effective
630
+ // capacity and without any certainty on the liquidity upper bound, plus the
631
+ // impossibility penalty.
632
+ let negative_log10_times_2048 = NEGATIVE_LOG10_UPPER_BOUND * 2048 ;
633
+ self . combined_penalty_msat ( amount_msat, negative_log10_times_2048, params)
634
+ . saturating_add ( params. considered_impossible_penalty_msat )
622
635
} else {
623
636
let numerator = ( max_liquidity_msat - amount_msat) . saturating_add ( 1 ) ;
624
637
let denominator = ( max_liquidity_msat - min_liquidity_msat) . saturating_add ( 1 ) ;
@@ -1600,7 +1613,7 @@ mod tests {
1600
1613
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
1601
1614
let usage = ChannelUsage { amount_msat : 102_400 , ..usage } ;
1602
1615
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 47 ) ;
1603
- let usage = ChannelUsage { amount_msat : 1_024_000 , ..usage } ;
1616
+ let usage = ChannelUsage { amount_msat : 1_023_999 , ..usage } ;
1604
1617
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1605
1618
1606
1619
let usage = ChannelUsage {
@@ -1630,6 +1643,7 @@ mod tests {
1630
1643
let network_graph = network_graph ( & logger) ;
1631
1644
let params = ProbabilisticScoringParameters {
1632
1645
liquidity_penalty_multiplier_msat : 1_000 ,
1646
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1633
1647
..ProbabilisticScoringParameters :: zero_penalty ( )
1634
1648
} ;
1635
1649
let scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger)
@@ -1721,6 +1735,7 @@ mod tests {
1721
1735
let network_graph = network_graph ( & logger) ;
1722
1736
let params = ProbabilisticScoringParameters {
1723
1737
liquidity_penalty_multiplier_msat : 1_000 ,
1738
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1724
1739
..ProbabilisticScoringParameters :: zero_penalty ( )
1725
1740
} ;
1726
1741
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
@@ -1787,6 +1802,7 @@ mod tests {
1787
1802
let params = ProbabilisticScoringParameters {
1788
1803
liquidity_penalty_multiplier_msat : 1_000 ,
1789
1804
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1805
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1790
1806
..ProbabilisticScoringParameters :: zero_penalty ( )
1791
1807
} ;
1792
1808
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
@@ -1796,10 +1812,10 @@ mod tests {
1796
1812
let usage = ChannelUsage {
1797
1813
amount_msat : 0 ,
1798
1814
inflight_htlc_msat : 0 ,
1799
- effective_capacity : EffectiveCapacity :: Total { capacity_msat : 1_024 , htlc_maximum_msat : Some ( 1_000 ) } ,
1815
+ effective_capacity : EffectiveCapacity :: Total { capacity_msat : 1_024 , htlc_maximum_msat : Some ( 1_024 ) } ,
1800
1816
} ;
1801
1817
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
1802
- let usage = ChannelUsage { amount_msat : 1_024 , ..usage } ;
1818
+ let usage = ChannelUsage { amount_msat : 1_023 , ..usage } ;
1803
1819
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1804
1820
1805
1821
scorer. payment_path_failed ( & payment_path_for_amount ( 768 ) . iter ( ) . collect :: < Vec < _ > > ( ) , 42 ) ;
@@ -1843,20 +1859,20 @@ mod tests {
1843
1859
let usage = ChannelUsage { amount_msat : 1_023 , ..usage } ;
1844
1860
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1845
1861
let usage = ChannelUsage { amount_msat : 1_024 , ..usage } ;
1846
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1862
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , u64 :: max_value ( ) ) ;
1847
1863
1848
1864
// Fully decay liquidity upper bound.
1849
1865
SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
1850
1866
let usage = ChannelUsage { amount_msat : 0 , ..usage } ;
1851
1867
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
1852
1868
let usage = ChannelUsage { amount_msat : 1_024 , ..usage } ;
1853
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1869
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , u64 :: max_value ( ) ) ;
1854
1870
1855
1871
SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
1856
1872
let usage = ChannelUsage { amount_msat : 0 , ..usage } ;
1857
1873
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
1858
1874
let usage = ChannelUsage { amount_msat : 1_024 , ..usage } ;
1859
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1875
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , u64 :: max_value ( ) ) ;
1860
1876
}
1861
1877
1862
1878
#[ test]
@@ -1941,6 +1957,7 @@ mod tests {
1941
1957
let params = ProbabilisticScoringParameters {
1942
1958
liquidity_penalty_multiplier_msat : 1_000 ,
1943
1959
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1960
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1944
1961
..ProbabilisticScoringParameters :: zero_penalty ( )
1945
1962
} ;
1946
1963
let mut scorer = ProbabilisticScorer :: new ( params. clone ( ) , & network_graph, & logger) ;
@@ -1977,6 +1994,7 @@ mod tests {
1977
1994
let params = ProbabilisticScoringParameters {
1978
1995
liquidity_penalty_multiplier_msat : 1_000 ,
1979
1996
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1997
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1980
1998
..ProbabilisticScoringParameters :: zero_penalty ( )
1981
1999
} ;
1982
2000
let mut scorer = ProbabilisticScorer :: new ( params. clone ( ) , & network_graph, & logger) ;
0 commit comments