Skip to content

Commit

Permalink
interleave FP loop
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Dec 13, 2023
1 parent 0f6557a commit feeb925
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions lightning/src/routing/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2000,19 +2000,35 @@ mod bucketed_history {
cumulative_success_prob_times_billion += bucket_prob_times_billion_b;
}
} else {
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;
if payment_pos >= max_bucket_end_pos {
for (idx, chunk) in max_liquidity_offset_history_buckets.chunks(2).enumerate().take(16 - min_idx/2) {
let max_idx_a = idx * 2;
let max_idx_b = idx * 2 + 1;

let max_bucket_a = chunk[0];
let mut max_bucket_b = chunk[1];

let max_bucket_end_pos_a = BUCKET_START_POS[32 - max_idx_a] - 1;
if payment_pos >= max_bucket_end_pos_a {
// Success probability 0, the payment amount may be above the max liquidity
break;
}
let max_bucket_end_pos_b = BUCKET_START_POS[32 - max_idx_b] - 1;
if max_idx_b > max_max_idx || payment_pos >= max_bucket_end_pos_b { max_bucket_b = 0 }

// Note that this multiply can only barely not overflow - two 16 bit ints plus
// 30 bits is 62 bits.
let bucket_points = ((*min_bucket as u32) * (*max_bucket as u32)) as u64;
let bucket_points_a = ((*min_bucket as u32) * (max_bucket_a as u32)) as u64;
let bucket_points_b = ((*min_bucket as u32) * (max_bucket_b as u32)) as u64;
cumulative_success_prob_times_billion += success_probability_times_value_times_billion(
payment_pos as u64, min_bucket_start_pos as u64,
max_bucket_end_pos as u64, POSITION_TICKS as u64 - 1, params, true,
bucket_points, total_valid_points_tracked);
max_bucket_end_pos_a as u64, POSITION_TICKS as u64 - 1, params, true,
bucket_points_a, total_valid_points_tracked);
if payment_pos < max_bucket_end_pos_b {
cumulative_success_prob_times_billion += success_probability_times_value_times_billion(
payment_pos as u64, min_bucket_start_pos as u64,
max_bucket_end_pos_b as u64, POSITION_TICKS as u64 - 1, params, true,
bucket_points_b, total_valid_points_tracked);
}
}
}
}
Expand Down

0 comments on commit feeb925

Please sign in to comment.