Skip to content

Commit 95a9d76

Browse files
committed
Move to a constant for "bucket one" in the scoring buckets
Scoring buckets are stored as fixed point ints, with a 5-bit fractional part (i.e. a value of 1.0 is stored as "32"). Now that we also have 32 buckets, this leads to the codebase having many references to 32 which could reasonably be confused for each other. Thus, we add a constant here for the value 1.0 in our fixed-point scheme.
1 parent 34d9290 commit 95a9d76

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lightning/src/routing/scoring.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,10 @@ mod bucketed_history {
16911691
buckets: [u16; 32],
16921692
}
16931693

1694+
/// Buckets are stored in fixed point numbers with a 5 bit fractional part. Thus, the value
1695+
/// "one" is 32, or this constant.
1696+
pub const BUCKET_FIXED_POINT_ONE: u16 = 32;
1697+
16941698
impl HistoricalBucketRangeTracker {
16951699
pub(super) fn new() -> Self { Self { buckets: [0; 32] } }
16961700
pub(super) fn track_datapoint(&mut self, liquidity_offset_msat: u64, capacity_msat: u64) {
@@ -1721,7 +1725,7 @@ mod bucketed_history {
17211725
*e = ((*e as u32) * 2047 / 2048) as u16;
17221726
}
17231727
let bucket = pos_to_bucket(pos);
1724-
self.buckets[bucket] = self.buckets[bucket].saturating_add(32);
1728+
self.buckets[bucket] = self.buckets[bucket].saturating_add(BUCKET_FIXED_POINT_ONE);
17251729
}
17261730
}
17271731
/// Decay all buckets by the given number of half-lives. Used to more aggressively remove old
@@ -1799,7 +1803,7 @@ mod bucketed_history {
17991803
let mut highest_max_bucket_with_points = 0;
18001804
let mut total_max_points = 0;
18011805
for (max_idx, max_bucket) in self.max_liquidity_offset_history.buckets.iter().enumerate() {
1802-
if *max_bucket >= 32 {
1806+
if *max_bucket >= BUCKET_FIXED_POINT_ONE {
18031807
highest_max_bucket_with_points = cmp::max(highest_max_bucket_with_points, max_idx);
18041808
}
18051809
total_max_points += *max_bucket as u64;

0 commit comments

Comments
 (0)