@@ -374,6 +374,19 @@ pub struct ProbabilisticScoringParameters {
374
374
///
375
375
/// Default value: 250 msat
376
376
pub anti_probing_penalty_msat : u64 ,
377
+
378
+ /// This penalty is applied when the amount we're attempting to send over a channel exceeds our
379
+ /// current estimate of the liquidity available on a channel.
380
+ ///
381
+ /// Note that in this case the liquidity penalties are still included to ensure such channels
382
+ /// which may have enough liquidity are scored worse than channels which we do not believe have
383
+ /// enough.
384
+ ///
385
+ /// Note if you wish to avoid creating paths with such channels entirely, a penalty of
386
+ /// `u64::max_value()` will guarantee that.
387
+ ///
388
+ /// Default value: `u64::max_value()`
389
+ pub considered_impossible_penalty_msat : u64 ,
377
390
}
378
391
379
392
/// Accounting for channel liquidity balance uncertainty.
@@ -492,6 +505,7 @@ impl ProbabilisticScoringParameters {
492
505
amount_penalty_multiplier_msat : 0 ,
493
506
banned_nodes : HashSet :: new ( ) ,
494
507
anti_probing_penalty_msat : 0 ,
508
+ considered_impossible_penalty_msat : 0 ,
495
509
}
496
510
}
497
511
@@ -513,6 +527,7 @@ impl Default for ProbabilisticScoringParameters {
513
527
amount_penalty_multiplier_msat : 256 ,
514
528
banned_nodes : HashSet :: new ( ) ,
515
529
anti_probing_penalty_msat : 250 ,
530
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
516
531
}
517
532
}
518
533
}
@@ -590,17 +605,12 @@ impl<L: Deref<Target = u64>, T: Time, U: Deref<Target = T>> DirectedChannelLiqui
590
605
if amount_msat <= min_liquidity_msat {
591
606
0
592
607
} else if amount_msat >= max_liquidity_msat {
593
- if amount_msat > max_liquidity_msat {
594
- u64:: max_value ( )
595
- } else if max_liquidity_msat != self . capacity_msat {
596
- // Avoid using the failed channel on retry.
597
- u64:: max_value ( )
598
- } else {
599
- // Equivalent to hitting the else clause below with the amount equal to the
600
- // effective capacity and without any certainty on the liquidity upper bound.
601
- let negative_log10_times_2048 = NEGATIVE_LOG10_UPPER_BOUND * 2048 ;
602
- self . combined_penalty_msat ( amount_msat, negative_log10_times_2048, params)
603
- }
608
+ // Equivalent to hitting the else clause below with the amount equal to the effective
609
+ // capacity and without any certainty on the liquidity upper bound, plus the
610
+ // impossibility penalty.
611
+ let negative_log10_times_2048 = NEGATIVE_LOG10_UPPER_BOUND * 2048 ;
612
+ self . combined_penalty_msat ( amount_msat, negative_log10_times_2048, params)
613
+ . saturating_add ( params. considered_impossible_penalty_msat )
604
614
} else {
605
615
let numerator = ( max_liquidity_msat - amount_msat) . saturating_add ( 1 ) ;
606
616
let denominator = ( max_liquidity_msat - min_liquidity_msat) . saturating_add ( 1 ) ;
@@ -1574,7 +1584,7 @@ mod tests {
1574
1584
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
1575
1585
let usage = ChannelUsage { amount_msat : 102_400 , ..usage } ;
1576
1586
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 47 ) ;
1577
- let usage = ChannelUsage { amount_msat : 1_024_000 , ..usage } ;
1587
+ let usage = ChannelUsage { amount_msat : 1_023_999 , ..usage } ;
1578
1588
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1579
1589
1580
1590
let usage = ChannelUsage {
@@ -1604,6 +1614,7 @@ mod tests {
1604
1614
let network_graph = network_graph ( & logger) ;
1605
1615
let params = ProbabilisticScoringParameters {
1606
1616
liquidity_penalty_multiplier_msat : 1_000 ,
1617
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1607
1618
..ProbabilisticScoringParameters :: zero_penalty ( )
1608
1619
} ;
1609
1620
let scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger)
@@ -1695,6 +1706,7 @@ mod tests {
1695
1706
let network_graph = network_graph ( & logger) ;
1696
1707
let params = ProbabilisticScoringParameters {
1697
1708
liquidity_penalty_multiplier_msat : 1_000 ,
1709
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1698
1710
..ProbabilisticScoringParameters :: zero_penalty ( )
1699
1711
} ;
1700
1712
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
@@ -1761,6 +1773,7 @@ mod tests {
1761
1773
let params = ProbabilisticScoringParameters {
1762
1774
liquidity_penalty_multiplier_msat : 1_000 ,
1763
1775
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1776
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1764
1777
..ProbabilisticScoringParameters :: zero_penalty ( )
1765
1778
} ;
1766
1779
let mut scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
@@ -1770,10 +1783,10 @@ mod tests {
1770
1783
let usage = ChannelUsage {
1771
1784
amount_msat : 0 ,
1772
1785
inflight_htlc_msat : 0 ,
1773
- effective_capacity : EffectiveCapacity :: Total { capacity_msat : 1_024 , htlc_maximum_msat : Some ( 1_000 ) } ,
1786
+ effective_capacity : EffectiveCapacity :: Total { capacity_msat : 1_024 , htlc_maximum_msat : Some ( 1_024 ) } ,
1774
1787
} ;
1775
1788
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
1776
- let usage = ChannelUsage { amount_msat : 1_024 , ..usage } ;
1789
+ let usage = ChannelUsage { amount_msat : 1_023 , ..usage } ;
1777
1790
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1778
1791
1779
1792
scorer. payment_path_failed ( & payment_path_for_amount ( 768 ) . iter ( ) . collect :: < Vec < _ > > ( ) , 42 ) ;
@@ -1817,20 +1830,20 @@ mod tests {
1817
1830
let usage = ChannelUsage { amount_msat : 1_023 , ..usage } ;
1818
1831
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1819
1832
let usage = ChannelUsage { amount_msat : 1_024 , ..usage } ;
1820
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1833
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , u64 :: max_value ( ) ) ;
1821
1834
1822
1835
// Fully decay liquidity upper bound.
1823
1836
SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
1824
1837
let usage = ChannelUsage { amount_msat : 0 , ..usage } ;
1825
1838
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
1826
1839
let usage = ChannelUsage { amount_msat : 1_024 , ..usage } ;
1827
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1840
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , u64 :: max_value ( ) ) ;
1828
1841
1829
1842
SinceEpoch :: advance ( Duration :: from_secs ( 10 ) ) ;
1830
1843
let usage = ChannelUsage { amount_msat : 0 , ..usage } ;
1831
1844
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 0 ) ;
1832
1845
let usage = ChannelUsage { amount_msat : 1_024 , ..usage } ;
1833
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 2_000 ) ;
1846
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , u64 :: max_value ( ) ) ;
1834
1847
}
1835
1848
1836
1849
#[ test]
@@ -1915,6 +1928,7 @@ mod tests {
1915
1928
let params = ProbabilisticScoringParameters {
1916
1929
liquidity_penalty_multiplier_msat : 1_000 ,
1917
1930
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1931
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1918
1932
..ProbabilisticScoringParameters :: zero_penalty ( )
1919
1933
} ;
1920
1934
let mut scorer = ProbabilisticScorer :: new ( params. clone ( ) , & network_graph, & logger) ;
@@ -1951,6 +1965,7 @@ mod tests {
1951
1965
let params = ProbabilisticScoringParameters {
1952
1966
liquidity_penalty_multiplier_msat : 1_000 ,
1953
1967
liquidity_offset_half_life : Duration :: from_secs ( 10 ) ,
1968
+ considered_impossible_penalty_msat : u64:: max_value ( ) ,
1954
1969
..ProbabilisticScoringParameters :: zero_penalty ( )
1955
1970
} ;
1956
1971
let mut scorer = ProbabilisticScorer :: new ( params. clone ( ) , & network_graph, & logger) ;
@@ -2110,11 +2125,11 @@ mod tests {
2110
2125
} ;
2111
2126
2112
2127
let params = ProbabilisticScoringParameters {
2113
- liquidity_penalty_multiplier_msat : 40_000 ,
2128
+ considered_impossible_penalty_msat : 42_420 ,
2114
2129
..ProbabilisticScoringParameters :: zero_penalty ( )
2115
2130
} ;
2116
2131
let scorer = ProbabilisticScorer :: new ( params, & network_graph, & logger) ;
2117
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 80_000 ) ;
2132
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 42_420 ) ;
2118
2133
}
2119
2134
2120
2135
#[ test]
0 commit comments