@@ -1002,16 +1002,17 @@ impl<L: Deref<Target = u64>, BRT: Deref<Target = HistoricalBucketRangeTracker>,
1002
1002
0
1003
1003
} else {
1004
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.
1005
+ // life has passed, approximate an additional three-quarter life to help smooth out the
1006
+ // decay.
1007
1007
let elapsed_time = self . now . duration_since ( * self . last_updated ) . as_secs ( ) ;
1008
1008
let half_decays = elapsed_time / ( half_life / 2 ) ;
1009
1009
let decays = half_decays / 2 ;
1010
1010
let decayed_offset_msat = offset_msat. checked_shr ( decays as u32 ) . unwrap_or ( 0 ) ;
1011
1011
if half_decays % 2 == 0 {
1012
1012
decayed_offset_msat
1013
1013
} else {
1014
- ( decayed_offset_msat >> 1 ) + ( decayed_offset_msat >> 2 )
1014
+ // 71 / 100 ~= core::f64::consts::FRAC_1_SQRT_2
1015
+ ( decayed_offset_msat as u128 * 71 / 100 ) as u64
1015
1016
}
1016
1017
}
1017
1018
}
@@ -2229,11 +2230,11 @@ mod tests {
2229
2230
// Half decay (i.e., three-quarter life)
2230
2231
SinceEpoch :: advance ( Duration :: from_secs ( 1 ) ) ;
2231
2232
let usage = ChannelUsage { amount_msat : 128 , ..usage } ;
2232
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 18 ) ;
2233
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 22 ) ;
2233
2234
let usage = ChannelUsage { amount_msat : 256 , ..usage } ;
2234
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 103 ) ;
2235
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 106 ) ;
2235
2236
let usage = ChannelUsage { amount_msat : 768 , ..usage } ;
2236
- assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 957 ) ;
2237
+ assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , 916 ) ;
2237
2238
let usage = ChannelUsage { amount_msat : 896 , ..usage } ;
2238
2239
assert_eq ! ( scorer. channel_penalty_msat( 42 , & source, & target, usage) , u64 :: max_value( ) ) ;
2239
2240
0 commit comments