Skip to content

Commit

Permalink
f more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Sep 1, 2022
1 parent cdb784f commit d4365a4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lightning/src/routing/scoring.rs
Expand Up @@ -822,21 +822,24 @@ impl<L: Deref<Target = u64>, BRT: Deref<Target = HistoricalBucketRangeTracker>,
// sending less than 1/16th of a channel's capacity, or 1/8th if we used the top of the
// bucket.
let mut total_valid_points_tracked = 0;
let decays = self.now.duration_since(*self.last_updated).as_secs()
let reqd_decays = self.now.duration_since(*self.last_updated).as_secs()
.checked_div(params.historical_no_updates_half_life.as_secs())
.map_or(u32::max_value(), |decays| cmp::min(decays, u32::max_value() as u64) as u32);
// Rather than actually decaying the individual buckets, which would lose precision, we
// simply track whether any buckets have data which wouldn't be decayed to zero, and if
// simply track whether all buckets would be decayed to zero, in which case we treat it
// as if we had no data.
// there are none, treat it as if we had no data.
let mut is_fully_decayed = true;
for (min_idx, min_bucket) in self.min_liquidity_offset_history.buckets.iter().enumerate() {
if min_bucket.checked_shr(decays).unwrap_or(0) > 0 { is_fully_decayed = false; }
if min_bucket.checked_shr(reqd_decays).unwrap_or(0) > 0 { is_fully_decayed = false; }
for max_bucket in self.max_liquidity_offset_history.buckets.iter().take(8 - min_idx) {
total_valid_points_tracked += (*min_bucket as u64) * (*max_bucket as u64);
if max_bucket.checked_shr(decays).unwrap_or(0) > 0 { is_fully_decayed = false; }
if max_bucket.checked_shr(reqd_decays).unwrap_or(0) > 0 { is_fully_decayed = false; }
}
}
if total_valid_points_tracked.checked_shr(decays).unwrap_or(0) < 31*31 || is_fully_decayed {
// If the total valid points is smaller than 1.0 (i.e. 32 in our fixed-point scheme),
// treat it as if we were fully decayed.
if total_valid_points_tracked.checked_shr(reqd_decays).unwrap_or(0) < 31*31 || is_fully_decayed {
// If we don't have any valid points (or, once decayed, we have less than a full
// point), redo the non-historical calculation with no liquidity bounds tracked and
// the historical penalty multipliers.
Expand Down

0 comments on commit d4365a4

Please sign in to comment.