Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b3e7ab0

Browse files
committedJan 30, 2025
iteratively decay with half life
It seems incorrect to always just decay one step, even if the time passed is much larger than the half life interval. In particular when decaying and merging external data, it is probably more important to do this correctly.
1 parent f8e833e commit b3e7ab0

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed
 

‎lightning/src/routing/scoring.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -493,14 +493,18 @@ impl ChannelLiquidities {
493493
liquidity.decayed_offset(liquidity.max_liquidity_offset_msat, duration_since_epoch, decay_params);
494494
liquidity.last_updated = duration_since_epoch;
495495

496-
// TODO: Call decay multiple times.
497-
let elapsed_time =
498-
duration_since_epoch.saturating_sub(liquidity.offset_history_last_updated);
499-
if elapsed_time > decay_params.historical_no_updates_half_life {
500-
let half_life = decay_params.historical_no_updates_half_life.as_secs_f64();
501-
if half_life != 0.0 {
496+
// Iteratively decay the liquidity history until we've caught up to the current time.
497+
let half_life = decay_params.historical_no_updates_half_life.as_secs_f64();
498+
if half_life != 0.0 {
499+
loop {
500+
let elapsed_time =
501+
duration_since_epoch.saturating_sub(liquidity.offset_history_last_updated);
502+
if elapsed_time <= decay_params.historical_no_updates_half_life {
503+
break;
504+
}
505+
502506
liquidity.liquidity_history.decay_buckets(elapsed_time.as_secs_f64() / half_life);
503-
liquidity.offset_history_last_updated = duration_since_epoch;
507+
liquidity.offset_history_last_updated += decay_params.historical_no_updates_half_life;
504508
}
505509
}
506510
liquidity.min_liquidity_offset_msat != 0 || liquidity.max_liquidity_offset_msat != 0 ||

0 commit comments

Comments
 (0)
Please sign in to comment.