@@ -822,21 +822,24 @@ impl<L: Deref<Target = u64>, BRT: Deref<Target = HistoricalBucketRangeTracker>,
822
822
// sending less than 1/16th of a channel's capacity, or 1/8th if we used the top of the
823
823
// bucket.
824
824
let mut total_valid_points_tracked = 0 ;
825
- let decays = self . now . duration_since ( * self . last_updated ) . as_secs ( )
825
+ let reqd_decays = self . now . duration_since ( * self . last_updated ) . as_secs ( )
826
826
. checked_div ( params. historical_no_updates_half_life . as_secs ( ) )
827
827
. map_or ( u32:: max_value ( ) , |decays| cmp:: min ( decays, u32:: max_value ( ) as u64 ) as u32 ) ;
828
828
// Rather than actually decaying the individual buckets, which would lose precision, we
829
- // simply track whether any buckets have data which wouldn't be decayed to zero, and if
829
+ // simply track whether all buckets would be decayed to zero, in which case we treat it
830
+ // as if we had no data.
830
831
// there are none, treat it as if we had no data.
831
832
let mut is_fully_decayed = true ;
832
833
for ( min_idx, min_bucket) in self . min_liquidity_offset_history . buckets . iter ( ) . enumerate ( ) {
833
- if min_bucket. checked_shr ( decays ) . unwrap_or ( 0 ) > 0 { is_fully_decayed = false ; }
834
+ if min_bucket. checked_shr ( reqd_decays ) . unwrap_or ( 0 ) > 0 { is_fully_decayed = false ; }
834
835
for max_bucket in self . max_liquidity_offset_history . buckets . iter ( ) . take ( 8 - min_idx) {
835
836
total_valid_points_tracked += ( * min_bucket as u64 ) * ( * max_bucket as u64 ) ;
836
- if max_bucket. checked_shr ( decays ) . unwrap_or ( 0 ) > 0 { is_fully_decayed = false ; }
837
+ if max_bucket. checked_shr ( reqd_decays ) . unwrap_or ( 0 ) > 0 { is_fully_decayed = false ; }
837
838
}
838
839
}
839
- if total_valid_points_tracked. checked_shr ( decays) . unwrap_or ( 0 ) < 31 * 31 || is_fully_decayed {
840
+ // If the total valid points is smaller than 1.0 (i.e. 32 in our fixed-point scheme),
841
+ // treat it as if we were fully decayed.
842
+ if total_valid_points_tracked. checked_shr ( reqd_decays) . unwrap_or ( 0 ) < 31 * 31 || is_fully_decayed {
840
843
// If we don't have any valid points (or, once decayed, we have less than a full
841
844
// point), redo the non-historical calculation with no liquidity bounds tracked and
842
845
// the historical penalty multipliers.
0 commit comments