Skip to content

Commit dce5556

Browse files
committed
iteratively decay with half life
1 parent 5a39900 commit dce5556

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
@@ -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)