Skip to content

Commit 9fcc83a

Browse files
committed
Special-case the 0th minimum bucket in historical scoring
Points in the 0th minimum bucket either indicate we sent a payment which is < 1/16,384th of the channel's capacity or, more likely, we failed to send a payment. In either case, averaging the success probability across the full range of upper-bounds doesn't make a whole lot of sense - if we've never managed to send a "real" payment over a channel, we should be considering it quite poor. To address this, we special-case the 0th minimum bucket and only look at the largest-offset max bucket when calculating the success probability.
1 parent 9b5697b commit 9fcc83a

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

lightning/src/routing/scoring.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,32 @@ mod bucketed_history {
17581758
}
17591759

17601760
let mut cumulative_success_prob_times_billion = 0;
1761-
for (min_idx, min_bucket) in self.min_liquidity_offset_history.buckets.iter().enumerate() {
1761+
// Special-case the 0th min bucket - it generally means we failed a payment, so only
1762+
// consider the highest (i.e. largest-offset-from-max-capacity) max bucket for all
1763+
// points against the 0th min bucket!
1764+
if self.min_liquidity_offset_history.buckets[0] != 0 {
1765+
let mut highest_max_bucket_with_points = 0;
1766+
let mut total_max_points = 0;
1767+
for (max_idx, max_bucket) in self.max_liquidity_offset_history.buckets.iter().enumerate() {
1768+
if *max_bucket >= 32 {
1769+
highest_max_bucket_with_points = cmp::max(highest_max_bucket_with_points, max_idx);
1770+
}
1771+
total_max_points += *max_bucket as u64;
1772+
}
1773+
let max_bucket_end_pos = BUCKET_START_POS[32 - highest_max_bucket_with_points] - 1;
1774+
if payment_pos < max_bucket_end_pos {
1775+
let bucket_prob_times_billion =
1776+
(self.min_liquidity_offset_history.buckets[0] as u64) * total_max_points
1777+
* 1024 * 1024 * 1024 / total_valid_points_tracked;
1778+
cumulative_success_prob_times_billion += bucket_prob_times_billion *
1779+
((max_bucket_end_pos - payment_pos) as u64) /
1780+
// Add an additional one in the divisor as the payment bucket has been
1781+
// rounded down.
1782+
(max_bucket_end_pos + 1) as u64;
1783+
}
1784+
}
1785+
1786+
for (min_idx, min_bucket) in self.min_liquidity_offset_history.buckets.iter().enumerate().skip(1) {
17621787
let min_bucket_start_pos = BUCKET_START_POS[min_idx];
17631788
for (max_idx, max_bucket) in self.max_liquidity_offset_history.buckets.iter().enumerate().take(32 - min_idx) {
17641789
let max_bucket_end_pos = BUCKET_START_POS[32 - max_idx] - 1;

0 commit comments

Comments
 (0)