Skip to content

Commit 6383a44

Browse files
committed
f ?
1 parent c60d8d3 commit 6383a44

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lightning/src/routing/scoring.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,21 @@ struct HistoricalBucketRangeTracker {
443443
impl HistoricalBucketRangeTracker {
444444
fn new() -> Self { Self { buckets: [0; 8] } }
445445
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.
446458
debug_assert!(bucket < 8);
447459
if let Some(v) = self.buckets.get_mut(bucket as usize) {
448-
*v = v.saturating_add(8);
460+
*v = v.saturating_add(32);
449461
for e in self.buckets.iter_mut() {
450462
*e = ((*e as u64) * 2047 / 2048) as u16;
451463
}
@@ -791,18 +803,6 @@ impl<L: DerefMut<Target = u64>, BRT: DerefMut<Target = HistoricalBucketRangeTrac
791803
}
792804

793805
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.
806806
debug_assert!(*self.min_liquidity_offset_msat <= self.capacity_msat);
807807
self.min_liquidity_offset_history.track_datapoint(
808808
(self.min_liquidity_offset_msat.saturating_sub(1) * 8 / self.capacity_msat)

0 commit comments

Comments
 (0)