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