Skip to content

Commit 7cf67ea

Browse files
committed
f - remove unneeded checks
1 parent 1a732b9 commit 7cf67ea

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

lightning/src/routing/scoring.rs

+15-19
Original file line numberDiff line numberDiff line change
@@ -997,26 +997,22 @@ impl<L: Deref<Target = u64>, BRT: Deref<Target = HistoricalBucketRangeTracker>,
997997
}
998998

999999
fn decayed_offset_msat(&self, offset_msat: u64) -> u64 {
1000-
let elapsed_time = self.now.duration_since(*self.last_updated).as_secs();
10011000
let half_life = self.params.liquidity_offset_half_life.as_secs();
1002-
1003-
match elapsed_time.checked_div(half_life) {
1004-
None => 0,
1005-
Some(decays) => match elapsed_time.checked_div(half_life / 2) {
1006-
None => 0,
1007-
Some(half_decays) => {
1008-
// Decay the offset by the appropriate number of half lives. If half of the next
1009-
// half life has passed, approximate an additional three-quarter life by summing
1010-
// the results of taking both the *next two* half lives instead. This helps
1011-
// smooth out the decay.
1012-
let decayed_offset_msat = offset_msat.checked_shr(decays as u32).unwrap_or(0);
1013-
if half_decays % 2 == 0 {
1014-
decayed_offset_msat
1015-
} else {
1016-
(decayed_offset_msat >> 1) + (decayed_offset_msat >> 2)
1017-
}
1018-
}
1019-
},
1001+
if half_life == 0 {
1002+
0
1003+
} else {
1004+
// Decay the offset by the appropriate number of half lives. If half of the next half
1005+
// life has passed, approximate an additional three-quarter life by summing the results
1006+
// of taking both the *next two* half lives instead. This helps smooth out the decay.
1007+
let elapsed_time = self.now.duration_since(*self.last_updated).as_secs();
1008+
let half_decays = elapsed_time / (half_life / 2);
1009+
let decays = half_decays / 2;
1010+
let decayed_offset_msat = offset_msat.checked_shr(decays as u32).unwrap_or(0);
1011+
if half_decays % 2 == 0 {
1012+
decayed_offset_msat
1013+
} else {
1014+
(decayed_offset_msat >> 1) + (decayed_offset_msat >> 2)
1015+
}
10201016
}
10211017
}
10221018
}

0 commit comments

Comments
 (0)