diff --git a/packages/adapters/eth/src/websocket.rs b/packages/adapters/eth/src/websocket.rs index 9db207f2..8eac7bd8 100644 --- a/packages/adapters/eth/src/websocket.rs +++ b/packages/adapters/eth/src/websocket.rs @@ -282,7 +282,6 @@ impl WebsocketClient { }) } - #[must_use] pub fn connection_health_checker(&self) -> HealthChecker { self.inner.connection_health_checker() } diff --git a/packages/adapters/fuel/src/client.rs b/packages/adapters/fuel/src/client.rs index 09ccb9d6..4a8e89bd 100644 --- a/packages/adapters/fuel/src/client.rs +++ b/packages/adapters/fuel/src/client.rs @@ -29,7 +29,6 @@ pub struct HttpClient { } impl HttpClient { - #[must_use] pub fn new( url: &Url, unhealthy_after_n_errors: usize, @@ -166,7 +165,6 @@ impl HttpClient { } } - #[must_use] pub fn connection_health_checker(&self) -> HealthChecker { self.health_tracker.tracker() } diff --git a/packages/encoding/src/blob/encoder.rs b/packages/encoding/src/blob/encoder.rs index 4211885e..16495374 100644 --- a/packages/encoding/src/blob/encoder.rs +++ b/packages/encoding/src/blob/encoder.rs @@ -14,14 +14,12 @@ pub struct Encoder { } impl Encoder { - #[must_use] pub fn new() -> Self { Self::default() } } impl Encoder { - #[must_use] pub const fn blobs_needed_to_encode(&self, num_bytes: usize) -> usize { #[allow(clippy::cast_possible_truncation)] const USABLE_BITS_PER_BLOB: usize = USABLE_BITS_PER_FIELD_ELEMENT * FIELD_ELEMENTS_PER_BLOB; diff --git a/packages/encoding/src/bundle/encoder.rs b/packages/encoding/src/bundle/encoder.rs index 241bfd90..6e6e023b 100644 --- a/packages/encoding/src/bundle/encoder.rs +++ b/packages/encoding/src/bundle/encoder.rs @@ -130,7 +130,6 @@ impl FromStr for CompressionLevel { #[allow(dead_code)] impl CompressionLevel { - #[must_use] pub fn levels() -> Vec { vec![ Self::Disabled, diff --git a/packages/metrics/src/connection_health_tracker.rs b/packages/metrics/src/connection_health_tracker.rs index b2913cc5..dc2e3e4d 100644 --- a/packages/metrics/src/connection_health_tracker.rs +++ b/packages/metrics/src/connection_health_tracker.rs @@ -14,7 +14,6 @@ pub struct ConnectionHealthTracker { } impl ConnectionHealthTracker { - #[must_use] pub fn new(max_consecutive_failures: usize) -> Self { Self { max_consecutive_failures, @@ -30,7 +29,6 @@ impl ConnectionHealthTracker { self.consecutive_failures.store(0, Ordering::SeqCst); } - #[must_use] pub fn tracker(&self) -> HealthChecker { Box::new(self.clone()) } diff --git a/packages/services/src/block_bundler.rs b/packages/services/src/block_bundler.rs index 4a182504..dd9397de 100644 --- a/packages/services/src/block_bundler.rs +++ b/packages/services/src/block_bundler.rs @@ -160,7 +160,7 @@ pub mod service { ) .await? { - let still_time_to_accumulate_more = self.still_time_to_accumulate_more().await?; + let still_time_to_accumulate_more = self.still_time_to_accumulate_more()?; if blocks.len() < self.config.num_blocks_to_accumulate && still_time_to_accumulate_more { @@ -231,7 +231,7 @@ pub mod service { bundler.finish().await } - async fn still_time_to_accumulate_more(&self) -> Result { + fn still_time_to_accumulate_more(&self) -> Result { let elapsed = self.elapsed(self.last_time_bundled)?; Ok(elapsed < self.config.block_accumulation_time_limit) @@ -282,7 +282,7 @@ pub mod port { #[allow(async_fn_in_trait)] #[trait_variant::make(Send)] #[cfg_attr(feature = "test-helpers", mockall::automock)] - pub trait Api: Send + Sync { + pub trait Api: Sync { async fn latest_height(&self) -> crate::Result; } } @@ -309,7 +309,7 @@ pub mod port { #[allow(async_fn_in_trait)] #[trait_variant::make(Send)] - pub trait Storage: Send + Sync { + pub trait Storage: Sync { async fn lowest_sequence_of_unbundled_blocks( &self, starting_height: u32, diff --git a/packages/services/src/block_bundler/bundler.rs b/packages/services/src/block_bundler/bundler.rs index 614a6357..62ad96c1 100644 --- a/packages/services/src/block_bundler/bundler.rs +++ b/packages/services/src/block_bundler/bundler.rs @@ -13,7 +13,7 @@ use crate::{ Result, }; -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct Metadata { pub block_heights: RangeInclusive, pub known_to_be_optimal: bool, @@ -29,6 +29,8 @@ impl Metadata { self.block_heights.clone().count() } + // This is for metrics anyway, precission loss is ok + #[allow(clippy::cast_precision_loss)] pub fn compression_ratio(&self) -> f64 { self.uncompressed_data_size.get() as f64 / self.compressed_data_size.get() as f64 } @@ -56,7 +58,7 @@ impl Display for Metadata { } } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct BundleProposal { pub fragments: NonEmpty, pub metadata: Metadata, diff --git a/packages/services/src/block_committer.rs b/packages/services/src/block_committer.rs index 7c765dc2..c0c3559e 100644 --- a/packages/services/src/block_committer.rs +++ b/packages/services/src/block_committer.rs @@ -221,7 +221,7 @@ pub mod port { #[allow(async_fn_in_trait)] #[trait_variant::make(Send)] #[cfg_attr(feature = "test-helpers", mockall::automock)] - pub trait Contract: Send + Sync { + pub trait Contract: Sync { async fn submit(&self, hash: [u8; 32], height: u32) -> Result; fn commit_interval(&self) -> NonZeroU32; } @@ -246,7 +246,7 @@ pub mod port { #[allow(async_fn_in_trait)] #[trait_variant::make(Send)] #[cfg_attr(feature = "test-helpers", mockall::automock)] - pub trait Api: Send + Sync { + pub trait Api: Sync { async fn latest_block(&self) -> Result; async fn block_at_height(&self, height: u32) -> Result>; } @@ -254,7 +254,7 @@ pub mod port { #[allow(async_fn_in_trait)] #[trait_variant::make(Send)] - pub trait Storage: Send + Sync { + pub trait Storage: Sync { async fn record_block_submission( &self, submission_tx: BlockSubmissionTx, diff --git a/packages/services/src/block_importer.rs b/packages/services/src/block_importer.rs index 76870f29..ef9a7e79 100644 --- a/packages/services/src/block_importer.rs +++ b/packages/services/src/block_importer.rs @@ -83,7 +83,7 @@ pub mod port { #[allow(async_fn_in_trait)] #[trait_variant::make(Send)] - pub trait Storage: Send + Sync { + pub trait Storage: Sync { async fn insert_blocks(&self, block: NonEmpty) -> Result<()>; async fn missing_blocks( &self, @@ -102,7 +102,7 @@ pub mod port { #[allow(async_fn_in_trait)] #[trait_variant::make(Send)] #[cfg_attr(feature = "test-helpers", mockall::automock)] - pub trait Api: Send + Sync { + pub trait Api: Sync { fn compressed_blocks_in_height_range( &self, range: RangeInclusive, diff --git a/packages/services/src/fee_metrics_tracker/port.rs b/packages/services/src/fee_metrics_tracker/port.rs index 7d7e5397..f4ef80c2 100644 --- a/packages/services/src/fee_metrics_tracker/port.rs +++ b/packages/services/src/fee_metrics_tracker/port.rs @@ -8,7 +8,7 @@ pub mod l1 { impl Default for Fees { fn default() -> Self { - Fees { + Self { base_fee_per_gas: 1.try_into().unwrap(), reward: 1.try_into().unwrap(), base_fee_per_blob_gas: 1.try_into().unwrap(), @@ -96,6 +96,7 @@ pub mod l1 { base_fee_per_blob_gas: total.base_fee_per_blob_gas.saturating_div(count), } } + pub fn len(&self) -> usize { self.fees.len() } @@ -157,7 +158,7 @@ pub mod l1 { } impl ConstantFeeApi { - pub fn new(fees: Fees) -> Self { + pub const fn new(fees: Fees) -> Self { Self { fees } } } @@ -640,7 +641,7 @@ pub mod cache { } impl

CachingApi

{ - pub fn inner(&self) -> &P { + pub const fn inner(&self) -> &P { &self.fees_provider } @@ -691,11 +692,10 @@ pub mod cache { height_range: RangeInclusive, ) -> Result { let mut cache_guard = self.cache.lock().await; - let mut fees = Self::read_cached_fees(&cache_guard, height_range.clone()).await; + let mut fees = Self::read_cached_fees(&cache_guard, height_range.clone()); let missing_fees = self.download_missing_fees(&fees, height_range).await?; - self.update_cache(&mut cache_guard, missing_fees.clone()) - .await; + self.update_cache(&mut cache_guard, missing_fees.clone()); drop(cache_guard); fees.extend(missing_fees); @@ -704,7 +704,7 @@ pub mod cache { SequentialBlockFees::try_from(fees).map_err(|e| Error::Other(e.to_string())) } - async fn read_cached_fees( + fn read_cached_fees( cache: &BTreeMap, height_range: RangeInclusive, ) -> Vec { @@ -717,7 +717,7 @@ pub mod cache { .collect() } - async fn update_cache(&self, cache: &mut BTreeMap, fees: Vec) { + fn update_cache(&self, cache: &mut BTreeMap, fees: Vec) { cache.extend(fees.into_iter().map(|bf| (bf.height, bf.fees))); while cache.len() > self.cache_limit { diff --git a/packages/services/src/fee_metrics_tracker/service.rs b/packages/services/src/fee_metrics_tracker/service.rs index 3e160007..72823d22 100644 --- a/packages/services/src/fee_metrics_tracker/service.rs +++ b/packages/services/src/fee_metrics_tracker/service.rs @@ -9,13 +9,13 @@ use super::port::l1::{Api, BlockFees, Fees}; use crate::{Error, Result, Runner}; #[derive(Debug, Clone)] -struct Metrics { - current_blob_tx_fee: IntGauge, - short_term_blob_tx_fee: IntGauge, - long_term_blob_tx_fee: IntGauge, +struct FeeMetrics { + current: IntGauge, + short: IntGauge, + long: IntGauge, } -impl Default for Metrics { +impl Default for FeeMetrics { fn default() -> Self { let current_blob_tx_fee = IntGauge::with_opts(Opts::new( "current_blob_tx_fee", @@ -36,9 +36,9 @@ impl Default for Metrics { .expect("metric config to be correct"); Self { - current_blob_tx_fee, - short_term_blob_tx_fee, - long_term_blob_tx_fee, + current: current_blob_tx_fee, + short: short_term_blob_tx_fee, + long: long_term_blob_tx_fee, } } } @@ -46,9 +46,9 @@ impl Default for Metrics { impl

RegistersMetrics for FeeMetricsTracker

{ fn metrics(&self) -> Vec> { vec![ - Box::new(self.metrics.current_blob_tx_fee.clone()), - Box::new(self.metrics.short_term_blob_tx_fee.clone()), - Box::new(self.metrics.long_term_blob_tx_fee.clone()), + Box::new(self.metrics.current.clone()), + Box::new(self.metrics.short.clone()), + Box::new(self.metrics.long.clone()), ] } } @@ -57,7 +57,7 @@ impl

RegistersMetrics for FeeMetricsTracker

{ pub struct FeeMetricsTracker

{ fee_provider: P, sma_periods: SmaPeriods, - metrics: Metrics, + metrics: FeeMetrics, } #[derive(Debug, Clone, Copy)] @@ -109,7 +109,7 @@ impl FeeMetricsTracker

{ } } -fn last_n_blocks(current_block: u64, n: NonZeroU64) -> RangeInclusive { +const fn last_n_blocks(current_block: u64, n: NonZeroU64) -> RangeInclusive { current_block.saturating_sub(n.get().saturating_sub(1))..=current_block } @@ -118,7 +118,7 @@ impl

FeeMetricsTracker

{ Self { fee_provider, sma_periods, - metrics: Metrics::default(), + metrics: FeeMetrics::default(), } } } @@ -150,13 +150,9 @@ impl FeeMetricsTracker

{ let calc_fee = |fees: &Fees| i64::try_from(calculate_blob_tx_fee(6, fees)).unwrap_or(i64::MAX); - self.metrics.current_blob_tx_fee.set(calc_fee(&latest_fees)); - self.metrics - .short_term_blob_tx_fee - .set(calc_fee(&short_term_sma)); - self.metrics - .long_term_blob_tx_fee - .set(calc_fee(&long_term_sma)); + self.metrics.current.set(calc_fee(&latest_fees)); + self.metrics.short.set(calc_fee(&short_term_sma)); + self.metrics.long.set(calc_fee(&long_term_sma)); Ok(()) } diff --git a/packages/services/src/health_reporter.rs b/packages/services/src/health_reporter.rs index b5e9c8f3..6cee715a 100644 --- a/packages/services/src/health_reporter.rs +++ b/packages/services/src/health_reporter.rs @@ -20,7 +20,6 @@ pub mod service { } impl HealthReporter { - #[must_use] pub fn new(fuel_health_check: HealthChecker, eth_health_check: HealthChecker) -> Self { Self { fuel_connection: fuel_health_check, @@ -28,7 +27,6 @@ pub mod service { } } - #[must_use] pub fn report(&self) -> HealthReport { HealthReport { fuel_connection_up: self.fuel_connection.healthy(), diff --git a/packages/services/src/lib.rs b/packages/services/src/lib.rs index 4300bcf0..11b3138b 100644 --- a/packages/services/src/lib.rs +++ b/packages/services/src/lib.rs @@ -23,7 +23,7 @@ pub use block_bundler::{ pub use state_committer::service::{Config as StateCommitterConfig, StateCommitter}; use types::InvalidL1Height; -#[derive(thiserror::Error, Debug, PartialEq)] +#[derive(thiserror::Error, Debug, PartialEq, Eq)] pub enum Error { #[error("{0}")] Other(String), @@ -50,6 +50,6 @@ impl From for Error { pub type Result = std::result::Result; #[trait_variant::make(Send)] -pub trait Runner: Send + Sync { +pub trait Runner: Sync { async fn run(&mut self) -> Result<()>; } diff --git a/packages/services/src/state_committer/fee_algo.rs b/packages/services/src/state_committer/fee_algo.rs index 21b244db..f785c37b 100644 --- a/packages/services/src/state_committer/fee_algo.rs +++ b/packages/services/src/state_committer/fee_algo.rs @@ -75,7 +75,7 @@ impl FeeMultiplierRange { } #[cfg(feature = "test-helpers")] - pub fn new_unchecked(starting_multiplier: f64, ending_multiplier: f64) -> Self { + pub const fn new_unchecked(starting_multiplier: f64, ending_multiplier: f64) -> Self { Self { starting_multiplier, ending_multiplier, @@ -98,47 +98,12 @@ pub struct FeeThresholds { pub always_acceptable_fee: u128, } -#[derive(Default, Copy, Clone, Debug, PartialEq)] -pub struct Percentage(f64); - -impl TryFrom for Percentage { - type Error = Error; - - fn try_from(value: f64) -> std::result::Result { - if value < 0. { - return Err(Error::Other(format!("Invalid percentage value {value}"))); - } - - Ok(Self(value)) - } -} - -impl From for f64 { - fn from(value: Percentage) -> Self { - value.0 - } -} - -impl Percentage { - pub const ZERO: Self = Percentage(0.); - pub const HUNDRED: Self = Percentage(1.); - pub const PPM: u128 = 1_000_000; - - pub fn ppm(&self) -> u128 { - (self.0 * 1_000_000.) as u128 - } - - pub fn get(&self) -> f64 { - self.0 - } -} - #[cfg(feature = "test-helpers")] impl Default for FeeThresholds { fn default() -> Self { Self { max_l2_blocks_behind: NonZeroU32::new(u32::MAX).unwrap(), - multiplier_range: Default::default(), + multiplier_range: FeeMultiplierRange::default(), always_acceptable_fee: u128::MAX, } } @@ -151,23 +116,23 @@ pub struct SmaFeeAlgo

{ } impl

SmaFeeAlgo

{ - pub fn new(fee_provider: P, config: Config) -> Self { + pub const fn new(fee_provider: P, config: Config) -> Self { Self { fee_provider, config, } } - fn too_far_behind(&self, num_l2_blocks_behind: u32) -> bool { + const fn too_far_behind(&self, num_l2_blocks_behind: u32) -> bool { num_l2_blocks_behind >= self.config.fee_thresholds.max_l2_blocks_behind.get() } - fn fee_always_acceptable(&self, short_term_tx_fee: u128) -> bool { + const fn fee_always_acceptable(&self, short_term_tx_fee: u128) -> bool { short_term_tx_fee <= self.config.fee_thresholds.always_acceptable_fee } } -fn last_n_blocks(current_block: u64, n: NonZeroU64) -> RangeInclusive { +const fn last_n_blocks(current_block: u64, n: NonZeroU64) -> RangeInclusive { current_block.saturating_sub(n.get().saturating_sub(1))..=current_block } @@ -181,9 +146,7 @@ fn calculate_max_upper_fee( debug_assert!( blocks_behind <= max_blocks_behind, - "blocks_behind ({}) should not exceed max_blocks_behind ({}), it should have been handled earlier", - blocks_behind, - max_blocks_behind + "blocks_behind ({blocks_behind}) should not exceed max_blocks_behind ({max_blocks_behind}), it should have been handled earlier", ); let multiplier_ppm = { @@ -210,11 +173,11 @@ fn calculate_max_upper_fee( max_fee } -fn to_ppm(val: f64) -> u128 { +const fn to_ppm(val: f64) -> u128 { (val * 1_000_000.) as u128 } -fn from_ppm(val: u128) -> u128 { +const fn from_ppm(val: u128) -> u128 { val.saturating_div(1_000_000) } diff --git a/packages/services/src/state_committer/port.rs b/packages/services/src/state_committer/port.rs index 0e77e0df..f9be8f6a 100644 --- a/packages/services/src/state_committer/port.rs +++ b/packages/services/src/state_committer/port.rs @@ -15,7 +15,7 @@ pub mod l1 { #[allow(async_fn_in_trait)] #[trait_variant::make(Send)] #[cfg_attr(feature = "test-helpers", mockall::automock)] - pub trait Contract: Send + Sync { + pub trait Contract: Sync { async fn submit(&self, hash: [u8; 32], height: u32) -> Result; } @@ -40,14 +40,14 @@ pub mod fuel { #[allow(async_fn_in_trait)] #[trait_variant::make(Send)] #[cfg_attr(feature = "test-helpers", mockall::automock)] - pub trait Api: Send + Sync { + pub trait Api: Sync { async fn latest_height(&self) -> Result; } } #[allow(async_fn_in_trait)] #[trait_variant::make(Send)] -pub trait Storage: Send + Sync { +pub trait Storage: Sync { async fn has_nonfinalized_txs(&self) -> Result; async fn last_time_a_fragment_was_finalized(&self) -> Result>>; async fn record_pending_tx( @@ -72,6 +72,6 @@ pub trait Clock { self.now() .signed_duration_since(since) .to_std() - .map_err(|e| Error::Other(format!("failed to convert time: {}", e))) + .map_err(|e| Error::Other(format!("failed to convert time: {e}"))) } } diff --git a/packages/services/src/state_committer/service.rs b/packages/services/src/state_committer/service.rs index 9cdf11c2..5eb67118 100644 --- a/packages/services/src/state_committer/service.rs +++ b/packages/services/src/state_committer/service.rs @@ -33,7 +33,7 @@ impl Default for Config { fragment_accumulation_timeout: Duration::from_secs(0), fragments_to_accumulate: 1.try_into().unwrap(), gas_bump_timeout: Duration::from_secs(300), - fee_algo: Default::default(), + fee_algo: AlgoConfig::default(), } } } @@ -97,7 +97,7 @@ where config, clock, startup_time, - metrics: Default::default(), + metrics: Metrics::default(), } } } @@ -123,7 +123,7 @@ where let elapsed = self.clock.now() - reference_time; let std_elapsed = elapsed .to_std() - .map_err(|e| crate::Error::Other(format!("Failed to convert time: {}", e)))?; + .map_err(|e| crate::Error::Other(format!("Failed to convert time: {e}")))?; Ok(std_elapsed >= self.config.fragment_accumulation_timeout) } @@ -131,7 +131,7 @@ where let l1_height = self.l1_adapter.current_height().await?; let l2_height = self.fuel_api.latest_height().await?; - let oldest_l2_block = self.oldest_l2_block_in_fragments(fragments); + let oldest_l2_block = Self::oldest_l2_block_in_fragments(fragments); self.update_oldest_block_metric(oldest_l2_block); let num_l2_blocks_behind = l2_height.saturating_sub(oldest_l2_block); @@ -145,7 +145,7 @@ where .await } - fn oldest_l2_block_in_fragments(&self, fragments: &NonEmpty) -> u32 { + fn oldest_l2_block_in_fragments(fragments: &NonEmpty) -> u32 { fragments .minimum_by_key(|b| b.oldest_block_in_bundle) .oldest_block_in_bundle @@ -220,7 +220,7 @@ where if let Some(fragments) = fragments.as_ref() { // Tracking the metric here as well to get updates more often -- because // submit_fragments might not be called - self.update_oldest_block_metric(self.oldest_l2_block_in_fragments(fragments)); + self.update_oldest_block_metric(Self::oldest_l2_block_in_fragments(fragments)); } Ok(fragments) @@ -229,7 +229,7 @@ where fn update_oldest_block_metric(&self, oldest_height: u32) { self.metrics .current_height_to_commit - .set(oldest_height as i64); + .set(oldest_height.into()); } async fn should_submit_fragments(&self, fragments: &NonEmpty) -> Result { @@ -282,7 +282,7 @@ where self.metrics .current_height_to_commit - .set(current_height_to_commit as i64); + .set(current_height_to_commit.into()); } Ok(()) @@ -300,13 +300,12 @@ where ) -> Result> { let fragments = self.storage.fragments_submitted_by_tx(tx_hash).await?; - match NonEmpty::collect(fragments) { - Some(fragments) => Ok(fragments), - None => Err(crate::Error::Other(format!( + NonEmpty::collect(fragments).ok_or_else(|| { + crate::Error::Other(format!( "no fragments found for previously submitted tx {}", hex::encode(tx_hash) - ))), - } + )) + }) } async fn resubmit_fragments_if_stalled(&self) -> Result<()> { @@ -344,9 +343,9 @@ where { async fn run(&mut self) -> Result<()> { if self.storage.has_nonfinalized_txs().await? { - self.resubmit_fragments_if_stalled().await? + self.resubmit_fragments_if_stalled().await?; } else { - self.submit_fragments_if_ready().await? + self.submit_fragments_if_ready().await?; }; Ok(()) diff --git a/packages/services/src/state_listener.rs b/packages/services/src/state_listener.rs index 61a28370..83455ab9 100644 --- a/packages/services/src/state_listener.rs +++ b/packages/services/src/state_listener.rs @@ -138,7 +138,7 @@ pub mod service { self.metrics .last_eth_block_w_blob - .set(i64::try_from(tx_response.block_number()).unwrap_or(i64::MAX)) + .set(i64::try_from(tx_response.block_number()).unwrap_or(i64::MAX)); } selective_change.retain(|(_, nonce, _)| !skip_nonces.contains(nonce)); @@ -232,7 +232,7 @@ pub mod port { #[allow(async_fn_in_trait)] #[trait_variant::make(Send)] - pub trait Storage: Send + Sync { + pub trait Storage: Sync { async fn get_non_finalized_txs(&self) -> Result>; async fn update_tx_states_and_costs( &self, diff --git a/packages/services/src/state_pruner.rs b/packages/services/src/state_pruner.rs index 327af849..60468c6e 100644 --- a/packages/services/src/state_pruner.rs +++ b/packages/services/src/state_pruner.rs @@ -188,7 +188,7 @@ pub mod port { Result, }; - #[derive(Debug, Clone, PartialEq, PartialOrd)] + #[derive(Debug, Clone, PartialEq, PartialOrd, Eq)] pub struct TableSizes { pub blob_transactions: u32, pub fragments: u32, @@ -202,7 +202,7 @@ pub mod port { #[allow(async_fn_in_trait)] #[trait_variant::make(Send)] - pub trait Storage: Send + Sync { + pub trait Storage: Sync { async fn prune_entries_older_than(&self, date: DateTime) -> Result<()>; async fn table_sizes(&self) -> Result; } diff --git a/packages/services/src/types/storage.rs b/packages/services/src/types/storage.rs index 368c24f3..60012162 100644 --- a/packages/services/src/types/storage.rs +++ b/packages/services/src/types/storage.rs @@ -82,7 +82,7 @@ pub struct InvalidSequence { } impl InvalidSequence { - pub fn new(reason: String) -> Self { + pub const fn new(reason: String) -> Self { Self { reason } } } @@ -143,7 +143,7 @@ mod tests { fn create_non_empty_fuel_blocks(block_heights: &[u32]) -> NonEmpty { block_heights .iter() - .cloned() + .copied() .map(create_fuel_block) .collect_nonempty() .unwrap() @@ -177,7 +177,7 @@ mod tests { let blocks = create_non_empty_fuel_blocks(&[1, 3, 2, 4, 5]); // when - let seq_blocks = SequentialFuelBlocks::try_from(blocks.clone()); + let seq_blocks = SequentialFuelBlocks::try_from(blocks); // then assert!( @@ -199,7 +199,7 @@ mod tests { let blocks = create_non_empty_fuel_blocks(&[1, 2, 4, 5]); // when - let seq_blocks = SequentialFuelBlocks::try_from(blocks.clone()); + let seq_blocks = SequentialFuelBlocks::try_from(blocks); // then assert!( @@ -219,10 +219,10 @@ mod tests { fn iterates_over_sequential_fuel_blocks_correctly() { // given let blocks = create_non_empty_fuel_blocks(&[10, 11, 12]); - let seq_blocks = SequentialFuelBlocks::try_from(blocks.clone()).unwrap(); + let seq_blocks = SequentialFuelBlocks::try_from(blocks).unwrap(); // when - let collected: Vec = seq_blocks.clone().into_iter().collect(); + let collected: Vec = seq_blocks.into_iter().collect(); // then assert_eq!( @@ -241,7 +241,7 @@ mod tests { fn indexing_returns_correct_fuel_block() { // given let blocks = create_non_empty_fuel_blocks(&[100, 101, 102, 103]); - let seq_blocks = SequentialFuelBlocks::try_from(blocks.clone()).unwrap(); + let seq_blocks = SequentialFuelBlocks::try_from(blocks).unwrap(); // when & Then assert_eq!( @@ -281,7 +281,7 @@ mod tests { fn len_returns_correct_number_of_blocks() { // given let blocks = create_non_empty_fuel_blocks(&[7, 8, 9, 10]); - let seq_blocks = SequentialFuelBlocks::try_from(blocks.clone()).unwrap(); + let seq_blocks = SequentialFuelBlocks::try_from(blocks).unwrap(); // when let length = seq_blocks.len(); @@ -299,7 +299,7 @@ mod tests { fn height_range_returns_correct_range() { // given let blocks = create_non_empty_fuel_blocks(&[20, 21, 22, 23]); - let seq_blocks = SequentialFuelBlocks::try_from(blocks.clone()).unwrap(); + let seq_blocks = SequentialFuelBlocks::try_from(blocks).unwrap(); // when let range = seq_blocks.height_range(); @@ -422,7 +422,7 @@ mod tests { let blocks = nonempty![create_fuel_block(1), create_fuel_block(1)]; // when - let seq_blocks = SequentialFuelBlocks::try_from(blocks.clone()); + let seq_blocks = SequentialFuelBlocks::try_from(blocks); // then assert!( @@ -444,7 +444,7 @@ mod tests { let blocks = nonempty![create_fuel_block(1), create_fuel_block(3)]; // when - let seq_blocks = SequentialFuelBlocks::try_from(blocks.clone()); + let seq_blocks = SequentialFuelBlocks::try_from(blocks); // then assert!( diff --git a/packages/services/src/wallet_balance_tracker.rs b/packages/services/src/wallet_balance_tracker.rs index a779f0bf..55715775 100644 --- a/packages/services/src/wallet_balance_tracker.rs +++ b/packages/services/src/wallet_balance_tracker.rs @@ -28,7 +28,7 @@ pub mod service { pub fn new(api: Api) -> Self { Self { api, - tracking: Default::default(), + tracking: HashMap::default(), } } @@ -100,7 +100,10 @@ mod tests { use alloy::primitives::U256; use metrics::{ - prometheus::{proto::Metric, Registry}, + prometheus::{ + proto::{Metric, MetricFamily}, + Registry, + }, RegistersMetrics, }; use mockall::predicate::eq; @@ -143,7 +146,7 @@ mod tests { let eth_balance_metric = metrics .iter() .filter(|metric_group| metric_group.get_name() == "wallet_balance") - .flat_map(|metric_group| metric_group.get_metric()) + .flat_map(MetricFamily::get_metric) .filter(|metric| { metric.get_label().iter().any(|label| { label.get_name() == "usage" && (label.get_value() == expected_label_value)