Skip to content

Commit

Permalink
SLOW u128 version
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Dec 18, 2024
1 parent c8ee3c4 commit 1f3e604
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lightning/src/routing/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,7 @@ mod bucketed_history {
// Because the first thing we do is check if `total_valid_points` is sufficient to consider
// the data here at all, and can return early if it is not, we want this to go first to
// avoid hitting a second cache line load entirely in that case.
total_valid_points_tracked: u64,
total_valid_points_tracked: u128,
min_liquidity_offset_history: HistoricalBucketRangeTracker,
max_liquidity_offset_history: HistoricalBucketRangeTracker,
}
Expand Down Expand Up @@ -1795,9 +1795,8 @@ mod bucketed_history {
self.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) {
let mut bucket_weight = (*min_bucket as u64) * (*max_bucket as u64);
let mut bucket_weight = (*min_bucket as u128) * (*max_bucket as u128);
bucket_weight *= bucket_weight;
debug_assert!(bucket_weight < (1 << 54));
self.total_valid_points_tracked += bucket_weight;
}
}
Expand Down Expand Up @@ -1886,7 +1885,7 @@ mod bucketed_history {
let mut actual_valid_points_tracked = 0;
for (min_idx, min_bucket) in min_liquidity_offset_history_buckets.iter().enumerate() {
for max_bucket in max_liquidity_offset_history_buckets.iter().take(32 - min_idx) {
let mut bucket_weight = (*min_bucket as u64) * (*max_bucket as u64);
let mut bucket_weight = (*min_bucket as u128) * (*max_bucket as u128);
bucket_weight *= bucket_weight;
actual_valid_points_tracked += bucket_weight;
}
Expand Down Expand Up @@ -1936,7 +1935,7 @@ mod bucketed_history {
let (numerator, denominator) = success_probability(payment_pos as u64, 0,
max_bucket_end_pos as u64, POSITION_TICKS as u64 - 1, params, true);
let mut bucket_weight =
(min_liquidity_offset_history_buckets[0] as u64) * total_max_points;
(min_liquidity_offset_history_buckets[0] as u128) * (total_max_points as u128);
bucket_weight *= bucket_weight;
let bucket_prob_times_billion =
bucket_weight * 1024 * 1024 * 1024 / total_valid_points_tracked;
Expand All @@ -1950,7 +1949,7 @@ 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);
let mut bucket_weight = (*min_bucket as u128) * (*max_bucket as u128);
bucket_weight *= bucket_weight;
let bucket_prob_times_billion =
bucket_weight * 1024 * 1024 * 1024 / total_valid_points_tracked;
Expand Down

0 comments on commit 1f3e604

Please sign in to comment.