@@ -443,9 +443,21 @@ struct HistoricalBucketRangeTracker {
443
443
impl HistoricalBucketRangeTracker {
444
444
fn new ( ) -> Self { Self { buckets : [ 0 ; 8 ] } }
445
445
fn track_datapoint ( & mut self , bucket : u8 ) {
446
+ // We have 8 leaky buckets for min and max liquidity. Each bucket tracks the amount of time
447
+ // we spend in each bucket as a fixed-point number with 5 bits for the fractional part.
448
+ //
449
+ // Each time we update our liquidity estimate, we add 32 to the buckets for the current
450
+ // min and max liquidity offset positions.
451
+ //
452
+ // We then decay each bucket by multiplying by 2047/2048. This ensures we can't actually
453
+ // reach 65,535 - when we get to 63,457 adding 32 and decaying by 2047/2048 leaves us back
454
+ // at 63,457.
455
+ //
456
+ // In total, this allows us to track data for the last 8,000 or so payments across a given
457
+ // channel.
446
458
debug_assert ! ( bucket < 8 ) ;
447
459
if let Some ( v) = self . buckets . get_mut ( bucket as usize ) {
448
- * v = v. saturating_add ( 8 ) ;
460
+ * v = v. saturating_add ( 32 ) ;
449
461
for e in self . buckets . iter_mut ( ) {
450
462
* e = ( ( * e as u64 ) * 2047 / 2048 ) as u16 ;
451
463
}
@@ -791,18 +803,6 @@ impl<L: DerefMut<Target = u64>, BRT: DerefMut<Target = HistoricalBucketRangeTrac
791
803
}
792
804
793
805
fn update_history_buckets ( & mut self ) {
794
- // We have 8 leaky buckets for min and max liquidity. Each bucket tracks the amount of time
795
- // we spend in each bucket as a fixed-point number with 5 bits for the fractional part.
796
- //
797
- // Each time we update our liquidity estimate, we add 32 to the buckets for the current
798
- // min and max liquidity offset positions.
799
- //
800
- // We then decay each bucket by multiplying by 2047/2048. This ensures we can't actually
801
- // reach 65,535 - when we get to 63,457 adding 32 and decaying by 2047/2048 leaves us back
802
- // at 63,457.
803
- //
804
- // In total, this allows us to track data for the last 8,000 or so payments across a given
805
- // channel.
806
806
debug_assert ! ( * self . min_liquidity_offset_msat <= self . capacity_msat) ;
807
807
self . min_liquidity_offset_history . track_datapoint (
808
808
( self . min_liquidity_offset_msat . saturating_sub ( 1 ) * 8 / self . capacity_msat )
0 commit comments