Skip to content

Commit f68238b

Browse files
committed
f - remove unneeded checks
1 parent 03def88 commit f68238b

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

lightning/src/routing/scoring.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,26 +1151,22 @@ impl<L: Deref<Target = u64>, BRT: Deref<Target = HistoricalBucketRangeTracker>,
11511151
}
11521152

11531153
fn decayed_offset_msat(&self, offset_msat: u64) -> u64 {
1154-
let elapsed_time = self.now.duration_since(*self.last_updated).as_secs();
11551154
let half_life = self.decay_params.liquidity_offset_half_life.as_secs();
1156-
1157-
match elapsed_time.checked_div(half_life) {
1158-
None => 0,
1159-
Some(decays) => match elapsed_time.checked_div(half_life / 2) {
1160-
None => 0,
1161-
Some(half_decays) => {
1162-
// Decay the offset by the appropriate number of half lives. If half of the next
1163-
// half life has passed, approximate an additional three-quarter life by summing
1164-
// the results of taking both the *next two* half lives instead. This helps
1165-
// smooth out the decay.
1166-
let decayed_offset_msat = offset_msat.checked_shr(decays as u32).unwrap_or(0);
1167-
if half_decays % 2 == 0 {
1168-
decayed_offset_msat
1169-
} else {
1170-
(decayed_offset_msat >> 1) + (decayed_offset_msat >> 2)
1171-
}
1172-
}
1173-
},
1155+
if half_life == 0 {
1156+
0
1157+
} else {
1158+
// Decay the offset by the appropriate number of half lives. If half of the next half
1159+
// life has passed, approximate an additional three-quarter life by summing the results
1160+
// of taking both the *next two* half lives instead. This helps smooth out the decay.
1161+
let elapsed_time = self.now.duration_since(*self.last_updated).as_secs();
1162+
let half_decays = elapsed_time / (half_life / 2);
1163+
let decays = half_decays / 2;
1164+
let decayed_offset_msat = offset_msat.checked_shr(decays as u32).unwrap_or(0);
1165+
if half_decays % 2 == 0 {
1166+
decayed_offset_msat
1167+
} else {
1168+
(decayed_offset_msat >> 1) + (decayed_offset_msat >> 2)
1169+
}
11741170
}
11751171
}
11761172
}

0 commit comments

Comments
 (0)