@@ -394,6 +394,25 @@ pub struct ProbabilisticScoringParameters {
394
394
///
395
395
/// Default value: 250 msat
396
396
pub anti_probing_penalty_msat : u64 ,
397
+
398
+ /// This penalty is applied when the amount we're attempting to send over a channel exceeds our
399
+ /// current estimate of the channel's available liquidity.
400
+ ///
401
+ /// Note that in this case all other penalties, including the
402
+ /// [`liquidity_penalty_multiplier_msat`] and [`amount_penalty_multiplier_msat`]-based
403
+ /// penalties, as well as the [`base_penalty_msat`] and the [`anti_probing_penalty_msat`], if
404
+ /// applicable, are still included in the overall penalty.
405
+ ///
406
+ /// If you wish to avoid creating paths with such channels entirely, setting this to a value of
407
+ /// `u64::max_value()` will guarantee that.
408
+ ///
409
+ /// Default value: 1_0000_0000_000 msat (1 Bitcoin)
410
+ ///
411
+ /// [`liquidity_penalty_multiplier_msat`]: Self::liquidity_penalty_multiplier_msat
412
+ /// [`amount_penalty_multiplier_msat`]: Self::amount_penalty_multiplier_msat
413
+ /// [`base_penalty_msat`]: Self::base_penalty_msat
414
+ /// [`anti_probing_penalty_msat`]: Self::anti_probing_penalty_msat
415
+ pub considered_impossible_penalty_msat : u64 ,
397
416
}
398
417
399
418
/// Accounting for channel liquidity balance uncertainty.
@@ -522,6 +541,7 @@ impl ProbabilisticScoringParameters {
522
541
amount_penalty_multiplier_msat : 0 ,
523
542
manual_node_penalties : HashMap :: new ( ) ,
524
543
anti_probing_penalty_msat : 0 ,
544
+ considered_impossible_penalty_msat : 0 ,
525
545
}
526
546
}
527
547
@@ -543,6 +563,7 @@ impl Default for ProbabilisticScoringParameters {
543
563
amount_penalty_multiplier_msat : 256 ,
544
564
manual_node_penalties : HashMap :: new ( ) ,
545
565
anti_probing_penalty_msat : 250 ,
566
+ considered_impossible_penalty_msat : 1_0000_0000_000 ,
546
567
}
547
568
}
548
569
}
@@ -620,17 +641,12 @@ impl<L: Deref<Target = u64>, T: Time, U: Deref<Target = T>> DirectedChannelLiqui
620
641
if amount_msat <= min_liquidity_msat {
621
642
0
622
643
} else if amount_msat >= max_liquidity_msat {
623
- if amount_msat > max_liquidity_msat {
624
- u64:: max_value ( )
625
- } else if max_liquidity_msat != self . capacity_msat {
626
- // Avoid using the failed channel on retry.
627
- u64:: max_value ( )
628
- } else {
629
- // Equivalent to hitting the else clause below with the amount equal to the
630
- // effective capacity and without any certainty on the liquidity upper bound.
631
- let negative_log10_times_2048 = NEGATIVE_LOG10_UPPER_BOUND * 2048 ;
632
- self . combined_penalty_msat ( amount_msat, negative_log10_times_2048, params)
633
- }
644
+ // Equivalent to hitting the else clause below with the amount equal to the effective
645
+ // capacity and without any certainty on the liquidity upper bound, plus the
646
+ // impossibility penalty.
647
+ let negative_log10_times_2048 = NEGATIVE_LOG10_UPPER_BOUND * 2048 ;
648
+ self . combined_penalty_msat ( amount_msat, negative_log10_times_2048, params)
649
+ . saturating_add ( params. considered_impossible_penalty_msat )
634
650
} else {
635
651
let numerator = ( max_liquidity_msat - amount_msat) . saturating_add ( 1 ) ;
636
652
let denominator = ( max_liquidity_msat - min_liquidity_msat) . saturating_add ( 1 ) ;
@@ -1624,7 +1640,7 @@ mod tests {
1624
1640
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
1625
1641
let usage = ChannelUsage { amount_msat : 102_400 , ..usage } ;
1626
1642
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 47 ) ;
1627
- let usage = ChannelUsage { amount_msat : 1_024_000 , ..usage } ;
1643
+ let usage = ChannelUsage { amount_msat : 1_023_999 , ..usage } ;
1628
1644
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1629
1645
1630
1646
let usage = ChannelUsage {
@@ -1654,6 +1670,7 @@ mod tests {
1654
1670
let network_graph = network_graph ( & logger) ;
1655
1671
let params = ProbabilisticScoringParameters {
1656
1672
liquidity_penalty_multiplier_msat : 1_000 ,
1673
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1657
1674
..ProbabilisticScoringParameters :: zero_penalty ( )
1658
1675
} ;
1659
1676
let scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger)
@@ -1745,6 +1762,7 @@ mod tests {
1745
1762
let network_graph = network_graph ( & logger) ;
1746
1763
let params = ProbabilisticScoringParameters {
1747
1764
liquidity_penalty_multiplier_msat : 1_000 ,
1765
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1748
1766
..ProbabilisticScoringParameters :: zero_penalty ( )
1749
1767
} ;
1750
1768
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
@@ -1811,6 +1829,7 @@ mod tests {
1811
1829
let params = ProbabilisticScoringParameters {
1812
1830
liquidity_penalty_multiplier_msat : 1_000 ,
1813
1831
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1832
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1814
1833
..ProbabilisticScoringParameters :: zero_penalty ( )
1815
1834
} ;
1816
1835
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
@@ -1820,10 +1839,10 @@ mod tests {
1820
1839
let usage = ChannelUsage {
1821
1840
amount_msat : 0 ,
1822
1841
inflight_htlc_msat : 0 ,
1823
- effective_capacity : EffectiveCapacity :: Total { capacity_msat : 1_024 , htlc_maximum_msat : Some ( 1_000 ) } ,
1842
+ effective_capacity : EffectiveCapacity :: Total { capacity_msat : 1_024 , htlc_maximum_msat : Some ( 1_024 ) } ,
1824
1843
} ;
1825
1844
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
1826
- let usage = ChannelUsage { amount_msat : 1_024 , ..usage } ;
1845
+ let usage = ChannelUsage { amount_msat : 1_023 , ..usage } ;
1827
1846
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1828
1847
1829
1848
scorer. payment_path_failed ( & payment_path_for_amount ( 768 ) . iter ( ) . collect :: < Vec < _ > > ( ) , 42 ) ;
@@ -1867,20 +1886,20 @@ mod tests {
1867
1886
let usage = ChannelUsage { amount_msat : 1_023 , ..usage } ;
1868
1887
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1869
1888
let usage = ChannelUsage { amount_msat : 1_024 , ..usage } ;
1870
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1889
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , u64 :: max_value ( ) ) ;
1871
1890
1872
1891
// Fully decay liquidity upper bound.
1873
1892
SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
1874
1893
let usage = ChannelUsage { amount_msat : 0 , ..usage } ;
1875
1894
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
1876
1895
let usage = ChannelUsage { amount_msat : 1_024 , ..usage } ;
1877
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1896
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , u64 :: max_value ( ) ) ;
1878
1897
1879
1898
SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
1880
1899
let usage = ChannelUsage { amount_msat : 0 , ..usage } ;
1881
1900
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
1882
1901
let usage = ChannelUsage { amount_msat : 1_024 , ..usage } ;
1883
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1902
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , u64 :: max_value ( ) ) ;
1884
1903
}
1885
1904
1886
1905
#[ test]
@@ -1965,6 +1984,7 @@ mod tests {
1965
1984
let params = ProbabilisticScoringParameters {
1966
1985
liquidity_penalty_multiplier_msat : 1_000 ,
1967
1986
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1987
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1968
1988
..ProbabilisticScoringParameters :: zero_penalty ( )
1969
1989
} ;
1970
1990
let mut scorer = ProbabilisticScorer :: new ( params. clone ( ) , & network_graph, & logger) ;
@@ -2001,6 +2021,7 @@ mod tests {
2001
2021
let params = ProbabilisticScoringParameters {
2002
2022
liquidity_penalty_multiplier_msat : 1_000 ,
2003
2023
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
2024
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
2004
2025
..ProbabilisticScoringParameters :: zero_penalty ( )
2005
2026
} ;
2006
2027
let mut scorer = ProbabilisticScorer :: new ( params. clone ( ) , & network_graph, & logger) ;
@@ -2171,7 +2192,10 @@ mod tests {
2171
2192
fn accounts_for_inflight_htlc_usage ( ) {
2172
2193
let logger = TestLogger :: new ( ) ;
2173
2194
let network_graph = network_graph ( & logger) ;
2174
- let params = ProbabilisticScoringParameters :: default ( ) ;
2195
+ let params = ProbabilisticScoringParameters {
2196
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
2197
+ ..ProbabilisticScoringParameters :: zero_penalty ( )
2198
+ } ;
2175
2199
let scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
2176
2200
let source = source_node_id ( ) ;
2177
2201
let target = target_node_id ( ) ;
0 commit comments