Skip to content

Commit a0114a8

Browse files
committed
f more comments
1 parent 937b850 commit a0114a8

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lightning/src/routing/scoring.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -822,21 +822,24 @@ impl<L: Deref<Target = u64>, BRT: Deref<Target = HistoricalBucketRangeTracker>,
822822
// sending less than 1/16th of a channel's capacity, or 1/8th if we used the top of the
823823
// bucket.
824824
let mut total_valid_points_tracked = 0;
825-
let decays = self.now.duration_since(*self.last_updated).as_secs()
825+
let reqd_decays = self.now.duration_since(*self.last_updated).as_secs()
826826
.checked_div(params.historical_no_updates_half_life.as_secs())
827827
.map_or(u32::max_value(), |decays| cmp::min(decays, u32::max_value() as u64) as u32);
828828
// Rather than actually decaying the individual buckets, which would lose precision, we
829-
// simply track whether any buckets have data which wouldn't be decayed to zero, and if
829+
// simply track whether all buckets would be decayed to zero, in which case we treat it
830+
// as if we had no data.
830831
// there are none, treat it as if we had no data.
831832
let mut is_fully_decayed = true;
832833
for (min_idx, min_bucket) in self.min_liquidity_offset_history.buckets.iter().enumerate() {
833-
if min_bucket.checked_shr(decays).unwrap_or(0) > 0 { is_fully_decayed = false; }
834+
if min_bucket.checked_shr(reqd_decays).unwrap_or(0) > 0 { is_fully_decayed = false; }
834835
for max_bucket in self.max_liquidity_offset_history.buckets.iter().take(8 - min_idx) {
835836
total_valid_points_tracked += (*min_bucket as u64) * (*max_bucket as u64);
836-
if max_bucket.checked_shr(decays).unwrap_or(0) > 0 { is_fully_decayed = false; }
837+
if max_bucket.checked_shr(reqd_decays).unwrap_or(0) > 0 { is_fully_decayed = false; }
837838
}
838839
}
839-
if total_valid_points_tracked.checked_shr(decays).unwrap_or(0) < 31*31 || is_fully_decayed {
840+
// If the total valid points is smaller than 1.0 (i.e. 32 in our fixed-point scheme),
841+
// treat it as if we were fully decayed.
842+
if total_valid_points_tracked.checked_shr(reqd_decays).unwrap_or(0) < 31*31 || is_fully_decayed {
840843
// If we don't have any valid points (or, once decayed, we have less than a full
841844
// point), redo the non-historical calculation with no liquidity bounds tracked and
842845
// the historical penalty multipliers.

0 commit comments

Comments
 (0)