Skip to content

Commit

Permalink
f add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Dec 19, 2024
1 parent f852dfa commit f758163
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lightning/src/routing/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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 {
Expand Down

0 comments on commit f758163

Please sign in to comment.