@@ -1156,16 +1156,17 @@ impl<L: Deref<Target = u64>, BRT: Deref<Target = HistoricalBucketRangeTracker>,
1156
1156
0
1157
1157
} else {
1158
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.
1159
+ // life has passed, approximate an additional three-quarter life to help smooth out the
1160
+ // decay.
1161
1161
let elapsed_time = self.now.duration_since(*self.last_updated).as_secs();
1162
1162
let half_decays = elapsed_time / (half_life / 2);
1163
1163
let decays = half_decays / 2;
1164
1164
let decayed_offset_msat = offset_msat.checked_shr(decays as u32).unwrap_or(0);
1165
1165
if half_decays % 2 == 0 {
1166
1166
decayed_offset_msat
1167
1167
} else {
1168
- (decayed_offset_msat >> 1) + (decayed_offset_msat >> 2)
1168
+ // 71 / 100 ~= core::f64::consts::FRAC_1_SQRT_2
1169
+ (decayed_offset_msat as u128 * 71 / 100) as u64
1169
1170
}
1170
1171
}
1171
1172
}
@@ -2442,11 +2443,11 @@ mod tests {
2442
2443
// Half decay (i.e., three-quarter life)
2443
2444
SinceEpoch::advance(Duration::from_secs(1));
2444
2445
let usage = ChannelUsage { amount_msat: 128, ..usage };
2445
- assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage, ¶ms), 18 );
2446
+ assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage, ¶ms), 22 );
2446
2447
let usage = ChannelUsage { amount_msat: 256, ..usage };
2447
- assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage, ¶ms), 103 );
2448
+ assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage, ¶ms), 106 );
2448
2449
let usage = ChannelUsage { amount_msat: 768, ..usage };
2449
- assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage, ¶ms), 957 );
2450
+ assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage, ¶ms), 916 );
2450
2451
let usage = ChannelUsage { amount_msat: 896, ..usage };
2451
2452
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage, ¶ms), u64::max_value());
2452
2453
0 commit comments