Skip to content

Commit 4322b19

Browse files
authored
Merge pull request #3368 from TheBlueMatt/2024-10-decayed-non-null
Don't interpret decayed data as we've failed to send tiny values
2 parents 70add14 + 41a91a3 commit 4322b19

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lightning/src/routing/scoring.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -1828,15 +1828,27 @@ mod bucketed_history {
18281828
// values, which will result in us thinking we have some nontrivial probability of
18291829
// routing up to that amount.
18301830
if min_liquidity_offset_history_buckets[0] != 0 {
1831-
let mut highest_max_bucket_with_points = 0; // The highest max-bucket with any data
1831+
// Track the highest max-buckets with any data at all, as well as the highest
1832+
// max-bucket with at least BUCKET_FIXED_POINT_ONE.
1833+
let mut highest_max_bucket_with_points = 0;
1834+
let mut highest_max_bucket_with_full_points = None;
18321835
let mut total_max_points = 0; // Total points in max-buckets to consider
18331836
for (max_idx, max_bucket) in max_liquidity_offset_history_buckets.iter().enumerate() {
18341837
if *max_bucket >= BUCKET_FIXED_POINT_ONE {
1838+
highest_max_bucket_with_full_points = Some(cmp::max(highest_max_bucket_with_full_points.unwrap_or(0), max_idx));
1839+
}
1840+
if *max_bucket != 0 {
18351841
highest_max_bucket_with_points = cmp::max(highest_max_bucket_with_points, max_idx);
18361842
}
18371843
total_max_points += *max_bucket as u64;
18381844
}
1839-
let max_bucket_end_pos = BUCKET_START_POS[32 - highest_max_bucket_with_points] - 1;
1845+
// Use the highest max-bucket with at least BUCKET_FIXED_POINT_ONE, but if none is
1846+
// available use the highest max-bucket with any non-zero value. This ensures that
1847+
// if we have substantially decayed data we don't end up thinking the highest
1848+
// max-bucket is zero even though we have no points in the 0th max-bucket and do
1849+
// have points elsewhere.
1850+
let selected_max = highest_max_bucket_with_full_points.unwrap_or(highest_max_bucket_with_points);
1851+
let max_bucket_end_pos = BUCKET_START_POS[32 - selected_max] - 1;
18401852
if payment_pos < max_bucket_end_pos {
18411853
let (numerator, denominator) = success_probability(payment_pos as u64, 0,
18421854
max_bucket_end_pos as u64, POSITION_TICKS as u64 - 1, params, true);

0 commit comments

Comments
 (0)