@@ -1151,26 +1151,22 @@ impl<L: Deref<Target = u64>, BRT: Deref<Target = HistoricalBucketRangeTracker>,
1151
1151
}
1152
1152
1153
1153
fn decayed_offset_msat ( & self , offset_msat : u64 ) -> u64 {
1154
- let elapsed_time = self . now . duration_since ( * self . last_updated ) . as_secs ( ) ;
1155
1154
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
+ }
1174
1170
}
1175
1171
}
1176
1172
}
0 commit comments