File tree 1 file changed +11
-7
lines changed
1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -492,14 +492,18 @@ impl ChannelLiquidities {
492
492
liquidity. decayed_offset ( liquidity. max_liquidity_offset_msat , duration_since_epoch, decay_params) ;
493
493
liquidity. last_updated = duration_since_epoch;
494
494
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
+
501
505
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 ;
503
507
}
504
508
}
505
509
liquidity. min_liquidity_offset_msat != 0 || liquidity. max_liquidity_offset_msat != 0 ||
You can’t perform that action at this time.
0 commit comments