From 0fce48f41b4e1ec738c73ae8d8fd319fa7f2a324 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 18 Oct 2024 10:16:00 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20cargo-fmt=20auto-update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/storage/registration_rates.rs | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) 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) } ); }