Skip to content

Commit 98633de

Browse files
committed
f use lambda for check
1 parent 1e6b54f commit 98633de

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lightning/src/routing/scoring.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -825,16 +825,19 @@ impl<L: Deref<Target = u64>, BRT: Deref<Target = HistoricalBucketRangeTracker>,
825825
let required_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);
828+
828829
// Rather than actually decaying the individual buckets, which would lose precision, we
829830
// simply track whether all buckets would be decayed to zero, in which case we treat it
830831
// as if we had no data.
831-
// there are none, treat it as if we had no data.
832832
let mut is_fully_decayed = true;
833+
let mut check_track_bucket_contains_undecayed_points =
834+
|bucket_val: u16| if bucket_val.checked_shr(required_decays).unwrap_or(0) > 0 { is_fully_decayed = false; };
835+
833836
for (min_idx, min_bucket) in self.min_liquidity_offset_history.buckets.iter().enumerate() {
834-
if min_bucket.checked_shr(required_decays).unwrap_or(0) > 0 { is_fully_decayed = false; }
837+
check_track_bucket_contains_undecayed_points(*min_bucket);
835838
for max_bucket in self.max_liquidity_offset_history.buckets.iter().take(8 - min_idx) {
836839
total_valid_points_tracked += (*min_bucket as u64) * (*max_bucket as u64);
837-
if max_bucket.checked_shr(required_decays).unwrap_or(0) > 0 { is_fully_decayed = false; }
840+
check_track_bucket_contains_undecayed_points(*max_bucket);
838841
}
839842
}
840843
// If the total valid points is smaller than 1.0 (i.e. 32 in our fixed-point scheme),

0 commit comments

Comments
 (0)