Skip to content

Commit 41a91a3

Browse files
committed
Don't interpret decayed data as we've failed to send tiny values
When we're calculating the success probability for min-/max-bucket pairs and are looking at the 0th' min-bucket, we only look at the highest max-bucket to decide the success probability. We ignore max-buckets which have a value below `BUCKET_FIXED_POINT_ONE` to only consider values which aren't substantially decayed. However, if all of our data is substantially decayed, this filter causes us to conclude that the highest max-bucket is bucket zero even though we really should then be looking at any bucket. We make this change here, looking at the highest non-zero max-bucket if no max-buckets have a value above `BUCKET_FIXED_POINT_ONE`.
1 parent 46d8a0d commit 41a91a3

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
@@ -1818,15 +1818,27 @@ mod bucketed_history {
18181818
// values, which will result in us thinking we have some nontrivial probability of
18191819
// routing up to that amount.
18201820
if min_liquidity_offset_history_buckets[0] != 0 {
1821-
let mut highest_max_bucket_with_points = 0; // The highest max-bucket with any data
1821+
// Track the highest max-buckets with any data at all, as well as the highest
1822+
// max-bucket with at least BUCKET_FIXED_POINT_ONE.
1823+
let mut highest_max_bucket_with_points = 0;
1824+
let mut highest_max_bucket_with_full_points = None;
18221825
let mut total_max_points = 0; // Total points in max-buckets to consider
18231826
for (max_idx, max_bucket) in max_liquidity_offset_history_buckets.iter().enumerate() {
18241827
if *max_bucket >= BUCKET_FIXED_POINT_ONE {
1828+
highest_max_bucket_with_full_points = Some(cmp::max(highest_max_bucket_with_full_points.unwrap_or(0), max_idx));
1829+
}
1830+
if *max_bucket != 0 {
18251831
highest_max_bucket_with_points = cmp::max(highest_max_bucket_with_points, max_idx);
18261832
}
18271833
total_max_points += *max_bucket as u64;
18281834
}
1829-
let max_bucket_end_pos = BUCKET_START_POS[32 - highest_max_bucket_with_points] - 1;
1835+
// Use the highest max-bucket with at least BUCKET_FIXED_POINT_ONE, but if none is
1836+
// available use the highest max-bucket with any non-zero value. This ensures that
1837+
// if we have substantially decayed data we don't end up thinking the highest
1838+
// max-bucket is zero even though we have no points in the 0th max-bucket and do
1839+
// have points elsewhere.
1840+
let selected_max = highest_max_bucket_with_full_points.unwrap_or(highest_max_bucket_with_points);
1841+
let max_bucket_end_pos = BUCKET_START_POS[32 - selected_max] - 1;
18301842
if payment_pos < max_bucket_end_pos {
18311843
let (numerator, denominator) = success_probability(payment_pos as u64, 0,
18321844
max_bucket_end_pos as u64, POSITION_TICKS as u64 - 1, params, true);

0 commit comments

Comments
 (0)