@@ -1780,7 +1780,32 @@ 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!
1786
+ if self . min_liquidity_offset_history . buckets [ 0 ] != 0 {
1787
+ let mut highest_max_bucket_with_points = 0 ;
1788
+ let mut total_max_points = 0 ;
1789
+ for ( max_idx, max_bucket) in self . max_liquidity_offset_history . buckets . iter ( ) . enumerate ( ) {
1790
+ if * max_bucket >= 32 {
1791
+ highest_max_bucket_with_points = cmp:: max ( highest_max_bucket_with_points, max_idx) ;
1792
+ }
1793
+ total_max_points += * max_bucket as u64 ;
1794
+ }
1795
+ let max_bucket_end_pos = BUCKET_START_POS [ 32 - highest_max_bucket_with_points] - 1 ;
1796
+ if payment_pos < max_bucket_end_pos {
1797
+ let bucket_prob_times_billion =
1798
+ ( self . min_liquidity_offset_history . buckets [ 0 ] as u64 ) * total_max_points
1799
+ * 1024 * 1024 * 1024 / total_valid_points_tracked;
1800
+ cumulative_success_prob_times_billion += bucket_prob_times_billion *
1801
+ ( ( max_bucket_end_pos - payment_pos) as u64 ) /
1802
+ // Add an additional one in the divisor as the payment bucket has been
1803
+ // rounded down.
1804
+ ( max_bucket_end_pos + 1 ) as u64 ;
1805
+ }
1806
+ }
1807
+
1808
+ for ( min_idx, min_bucket) in self . min_liquidity_offset_history . buckets . iter ( ) . enumerate ( ) . skip ( 1 ) {
1784
1809
let min_bucket_start_pos = BUCKET_START_POS [ min_idx] ;
1785
1810
for ( max_idx, max_bucket) in self . max_liquidity_offset_history . buckets . iter ( ) . enumerate ( ) . take ( 32 - min_idx) {
1786
1811
let max_bucket_end_pos = BUCKET_START_POS [ 32 - max_idx] - 1 ;
@@ -3047,7 +3072,7 @@ mod tests {
3047
3072
// Even after we tell the scorer we definitely have enough available liquidity, it will
3048
3073
// still remember that there was some failure in the past, and assign a non-0 penalty.
3049
3074
scorer. payment_path_failed ( & payment_path_for_amount ( 1000 ) , 43 ) ;
3050
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage, & params) , 198 ) ;
3075
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage, & params) , 32 ) ;
3051
3076
// The first points should be decayed just slightly and the last bucket has a new point.
3052
3077
assert_eq ! ( scorer. historical_estimated_channel_liquidity_probabilities( 42 , & target) ,
3053
3078
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 +3082,12 @@ mod tests {
3057
3082
// simply check bounds here.
3058
3083
let five_hundred_prob =
3059
3084
scorer. historical_estimated_payment_success_probability ( 42 , & target, 500 ) . unwrap ( ) ;
3060
- assert ! ( five_hundred_prob > 0.5 ) ;
3061
- assert ! ( five_hundred_prob < 0.52 ) ;
3085
+ assert ! ( five_hundred_prob > 0.66 ) ;
3086
+ assert ! ( five_hundred_prob < 0.68 ) ;
3062
3087
let one_prob =
3063
3088
scorer. historical_estimated_payment_success_probability ( 42 , & target, 1 ) . unwrap ( ) ;
3064
- assert ! ( one_prob < 0.95 ) ;
3065
- assert ! ( one_prob > 0.90 ) ;
3089
+ assert ! ( one_prob < 1.0 ) ;
3090
+ assert ! ( one_prob > 0.95 ) ;
3066
3091
3067
3092
// Advance the time forward 16 half-lives (which the docs claim will ensure all data is
3068
3093
// gone), and check that we're back to where we started.
@@ -3082,7 +3107,7 @@ mod tests {
3082
3107
scorer. payment_path_failed ( & payment_path_for_amount ( 1 ) , 42 ) ;
3083
3108
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage, & params) , 2048 ) ;
3084
3109
usage. inflight_htlc_msat = 0 ;
3085
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage, & params) , 409 ) ;
3110
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage, & params) , 866 ) ;
3086
3111
3087
3112
let usage = ChannelUsage {
3088
3113
amount_msat : 1 ,
@@ -3268,9 +3293,7 @@ mod tests {
3268
3293
assert_eq ! ( scorer. historical_estimated_channel_liquidity_probabilities( 42 , & target) ,
3269
3294
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
3295
[ 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 ) ;
3296
+ assert_eq ! ( scorer. historical_estimated_payment_success_probability( 42 , & target, amount_msat) ,
3297
+ Some ( 0.0 ) ) ;
3275
3298
}
3276
3299
}
0 commit comments