diff --git a/src/internet_identity/src/storage/registration_rates.rs b/src/internet_identity/src/storage/registration_rates.rs index 67d255e12b..b683bcb0a2 100644 --- a/src/internet_identity/src/storage/registration_rates.rs +++ b/src/internet_identity/src/storage/registration_rates.rs @@ -53,26 +53,16 @@ impl RegistrationRates { }; let now = time(); - self.reference_rate_data - .push(&now) - .expect("out of memory"); - self.current_rate_data - .push(&now) - .expect("out of memory"); + self.reference_rate_data.push(&now).expect("out of memory"); + self.current_rate_data.push(&now).expect("out of memory"); } pub fn registration_rates(&self) -> Option { let config = dynamic_captcha_config()?; let now = time(); - let reference_rate_per_second = calculate_registration_rate( - now, - &self.reference_rate_data, - ); - let current_rate_per_second = calculate_registration_rate( - now, - &self.current_rate_data, - ); + let reference_rate_per_second = calculate_registration_rate(now, &self.reference_rate_data); + let current_rate_per_second = calculate_registration_rate(now, &self.current_rate_data); let captcha_threshold_rate = reference_rate_per_second * config.threshold_multiplier; let rates = NormalizedRegistrationRates { reference_rate_per_second, @@ -87,9 +77,18 @@ impl RegistrationRates { return; }; println!("in da prun_expired"); - println!("reference_rate {}", data_retention.reference_rate_retention_ns.to_string()); - prune_data(&mut self.reference_rate_data, data_retention.reference_rate_retention_ns); - prune_data(&mut self.current_rate_data, data_retention.current_rate_retention_ns); + println!( + "reference_rate {}", + data_retention.reference_rate_retention_ns.to_string() + ); + prune_data( + &mut self.reference_rate_data, + data_retention.reference_rate_retention_ns, + ); + prune_data( + &mut self.current_rate_data, + data_retention.current_rate_retention_ns, + ); } } @@ -112,10 +111,7 @@ impl RegistrationRates { /// However, because the data is not actually spanning 3 weeks, this underestimates the actual rate. /// Taking into account that the data is only spanning 3 days we get the following: /// 3 registrations / 259200 seconds = 0.00001157407407 registrations / second -fn calculate_registration_rate( - now: u64, - data: &MinHeap, -) -> f64 { +fn calculate_registration_rate(now: u64, data: &MinHeap) -> f64 { data // get the oldest value .peek() @@ -339,7 +335,7 @@ mod test { NormalizedRegistrationRates { current_rate_per_second: 2.0, reference_rate_per_second: 2.0, // increases too, but more slowly - captcha_threshold_rate: 2.2, // reference rate * 1.1 (as per config) + captcha_threshold_rate: 2.2, // reference rate * 1.1 (as per config) } ); }