diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index 6b1c67ea7f1..382b17330fb 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -1852,6 +1852,9 @@ mod bucketed_history { let mut total_valid_points_tracked = 0; for (min_idx, min_bucket) in self.min_liquidity_offset_history.buckets.iter().enumerate() { for max_bucket in self.max_liquidity_offset_history.buckets.iter().take(32 - min_idx) { + // In testing, raising the weights of buckets to a high power led to better + // scoring results. Thus, we raise the bucket weights to the 4th power here (by + // squaring the result of multiplying the weights). let mut bucket_weight = (*min_bucket as u64) * (*max_bucket as u64); bucket_weight *= bucket_weight; total_valid_points_tracked += bucket_weight; @@ -1980,6 +1983,10 @@ mod bucketed_history { if *max_bucket != 0 { highest_max_bucket_with_points = cmp::max(highest_max_bucket_with_points, max_idx); } + // In testing, raising the weights of buckets to a high power led to better + // scoring results. Thus, we raise the bucket weights to the 4th power here (by + // squaring the result of multiplying the weights), matching the logic in + // `recalculate_valid_point_count`. total_weight += (*max_bucket as u64) * (*max_bucket as u64) * (min_liquidity_offset_history_buckets[0] as u64) * (min_liquidity_offset_history_buckets[0] as u64); } @@ -2003,16 +2010,20 @@ mod bucketed_history { let min_bucket_start_pos = BUCKET_START_POS[min_idx]; for (max_idx, max_bucket) in max_liquidity_offset_history_buckets.iter().enumerate().take(32 - min_idx) { let max_bucket_end_pos = BUCKET_START_POS[32 - max_idx] - 1; - let mut bucket_weight = (*min_bucket as u64) * (*max_bucket as u64); - bucket_weight *= bucket_weight; - debug_assert!(bucket_weight as f64 <= total_valid_points_tracked); - if payment_pos >= max_bucket_end_pos { // Success probability 0, the payment amount may be above the max liquidity break; } + // In testing, raising the weights of buckets to a high power led to better + // scoring results. Thus, we raise the bucket weights to the 4th power here (by + // squaring the result of multiplying the weights), matching the logic in + // `recalculate_valid_point_count`. + let mut bucket_weight = (*min_bucket as u64) * (*max_bucket as u64); + bucket_weight *= bucket_weight; + debug_assert!(bucket_weight as f64 <= total_valid_points_tracked); let bucket_prob = bucket_weight as f64 / total_valid_points_tracked; + if payment_pos < min_bucket_start_pos { cumulative_success_prob += bucket_prob; } else {