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 50dda5d

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 5a39900 commit 50dda5d

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed
 

‎lightning/src/routing/scoring.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,14 +492,18 @@ impl ChannelLiquidities {
492492
liquidity.decayed_offset(liquidity.max_liquidity_offset_msat, duration_since_epoch, decay_params);
493493
liquidity.last_updated = duration_since_epoch;
494494

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

0 commit comments

Comments
 (0)
Please sign in to comment.