@@ -1780,7 +1780,36 @@ mod bucketed_history {
1780
1780
}
1781
1781
1782
1782
let mut cumulative_success_prob_times_billion = 0 ;
1783
- for ( min_idx, min_bucket) in self . min_liquidity_offset_history . buckets . iter ( ) . enumerate ( ) {
1783
+ // Special-case the 0th min bucket - it generally means we failed a payment, so only
1784
+ // consider the highest (i.e. largest-offset-from-max-capacity) max bucket for all
1785
+ // points against the 0th min bucket. This avoids the case where we fail to route
1786
+ // increasingly lower values over a channel, but treat each failure as a separate
1787
+ // datapoint, many of which may have relatively high maximum-available-liquidity
1788
+ // values, which will result in us thinking we have some nontrivial probability of
1789
+ // routing up to that amount.
1790
+ if self . min_liquidity_offset_history . buckets [ 0 ] != 0 {
1791
+ let mut highest_max_bucket_with_points = 0 ;
1792
+ let mut total_max_points = 0 ;
1793
+ for ( max_idx, max_bucket) in self . max_liquidity_offset_history . buckets . iter ( ) . enumerate ( ) {
1794
+ if * max_bucket >= 32 {
1795
+ highest_max_bucket_with_points = cmp:: max ( highest_max_bucket_with_points, max_idx) ;
1796
+ }
1797
+ total_max_points += * max_bucket as u64 ;
1798
+ }
1799
+ let max_bucket_end_pos = BUCKET_START_POS [ 32 - highest_max_bucket_with_points] - 1 ;
1800
+ if payment_pos < max_bucket_end_pos {
1801
+ let bucket_prob_times_billion =
1802
+ ( self . min_liquidity_offset_history . buckets [ 0 ] as u64 ) * total_max_points
1803
+ * 1024 * 1024 * 1024 / total_valid_points_tracked;
1804
+ cumulative_success_prob_times_billion += bucket_prob_times_billion *
1805
+ ( ( max_bucket_end_pos - payment_pos) as u64 ) /
1806
+ // Add an additional one in the divisor as the payment bucket has been
1807
+ // rounded down.
1808
+ ( max_bucket_end_pos + 1 ) as u64 ;
1809
+ }
1810
+ }
1811
+
1812
+ for ( min_idx, min_bucket) in self . min_liquidity_offset_history . buckets . iter ( ) . enumerate ( ) . skip ( 1 ) {
1784
1813
let min_bucket_start_pos = BUCKET_START_POS [ min_idx] ;
1785
1814
for ( max_idx, max_bucket) in self . max_liquidity_offset_history . buckets . iter ( ) . enumerate ( ) . take ( 32 - min_idx) {
1786
1815
let max_bucket_end_pos = BUCKET_START_POS [ 32 - max_idx] - 1 ;
@@ -3047,7 +3076,7 @@ mod tests {
3047
3076
// Even after we tell the scorer we definitely have enough available liquidity, it will
3048
3077
// still remember that there was some failure in the past, and assign a non-0 penalty.
3049
3078
scorer. payment_path_failed ( & payment_path_for_amount ( 1000 ) , 43 ) ;
3050
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage, & params) , 198 ) ;
3079
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage, & params) , 32 ) ;
3051
3080
// The first points should be decayed just slightly and the last bucket has a new point.
3052
3081
assert_eq ! ( scorer. historical_estimated_channel_liquidity_probabilities( 42 , & target) ,
3053
3082
Some ( ( [ 31 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32 , 0 , 0 , 0 , 0 , 0 ] ,
@@ -3057,12 +3086,12 @@ mod tests {
3057
3086
// simply check bounds here.
3058
3087
let five_hundred_prob =
3059
3088
scorer. historical_estimated_payment_success_probability ( 42 , & target, 500 ) . unwrap ( ) ;
3060
- assert ! ( five_hundred_prob > 0.5 ) ;
3061
- assert ! ( five_hundred_prob < 0.52 ) ;
3089
+ assert ! ( five_hundred_prob > 0.66 ) ;
3090
+ assert ! ( five_hundred_prob < 0.68 ) ;
3062
3091
let one_prob =
3063
3092
scorer. historical_estimated_payment_success_probability ( 42 , & target, 1 ) . unwrap ( ) ;
3064
- assert ! ( one_prob < 0.95 ) ;
3065
- assert ! ( one_prob > 0.90 ) ;
3093
+ assert ! ( one_prob < 1.0 ) ;
3094
+ assert ! ( one_prob > 0.95 ) ;
3066
3095
3067
3096
// Advance the time forward 16 half-lives (which the docs claim will ensure all data is
3068
3097
// gone), and check that we're back to where we started.
@@ -3082,7 +3111,7 @@ mod tests {
3082
3111
scorer. payment_path_failed ( & payment_path_for_amount ( 1 ) , 42 ) ;
3083
3112
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage, & params) , 2048 ) ;
3084
3113
usage. inflight_htlc_msat = 0 ;
3085
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage, & params) , 409 ) ;
3114
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage, & params) , 866 ) ;
3086
3115
3087
3116
let usage = ChannelUsage {
3088
3117
amount_msat : 1 ,
@@ -3268,9 +3297,7 @@ mod tests {
3268
3297
assert_eq ! ( scorer. historical_estimated_channel_liquidity_probabilities( 42 , & target) ,
3269
3298
Some ( ( [ 63 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
3270
3299
[ 32 , 31 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ) ) ;
3271
- assert ! ( scorer. historical_estimated_payment_success_probability( 42 , & target, amount_msat)
3272
- . unwrap( ) > 0.24 ) ;
3273
- assert ! ( scorer. historical_estimated_payment_success_probability( 42 , & target, amount_msat)
3274
- . unwrap( ) < 0.25 ) ;
3300
+ assert_eq ! ( scorer. historical_estimated_payment_success_probability( 42 , & target, amount_msat) ,
3301
+ Some ( 0.0 ) ) ;
3275
3302
}
3276
3303
}
0 commit comments