Skip to content

Commit

Permalink
clippy nits
Browse files Browse the repository at this point in the history
  • Loading branch information
segfault-magnet committed Jan 4, 2025
1 parent befce33 commit 4dda61d
Show file tree
Hide file tree
Showing 20 changed files with 88 additions and 135 deletions.
1 change: 0 additions & 1 deletion packages/adapters/eth/src/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ impl WebsocketClient {
})
}

#[must_use]
pub fn connection_health_checker(&self) -> HealthChecker {
self.inner.connection_health_checker()
}
Expand Down
2 changes: 0 additions & 2 deletions packages/adapters/fuel/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub struct HttpClient {
}

impl HttpClient {
#[must_use]
pub fn new(
url: &Url,
unhealthy_after_n_errors: usize,
Expand Down Expand Up @@ -166,7 +165,6 @@ impl HttpClient {
}
}

#[must_use]
pub fn connection_health_checker(&self) -> HealthChecker {
self.health_tracker.tracker()
}
Expand Down
2 changes: 0 additions & 2 deletions packages/encoding/src/blob/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/encoding/src/bundle/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ impl FromStr for CompressionLevel {

#[allow(dead_code)]
impl CompressionLevel {
#[must_use]
pub fn levels() -> Vec<Self> {
vec![
Self::Disabled,
Expand Down
2 changes: 0 additions & 2 deletions packages/metrics/src/connection_health_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub struct ConnectionHealthTracker {
}

impl ConnectionHealthTracker {
#[must_use]
pub fn new(max_consecutive_failures: usize) -> Self {
Self {
max_consecutive_failures,
Expand All @@ -30,7 +29,6 @@ impl ConnectionHealthTracker {
self.consecutive_failures.store(0, Ordering::SeqCst);
}

#[must_use]
pub fn tracker(&self) -> HealthChecker {
Box::new(self.clone())
}
Expand Down
8 changes: 4 additions & 4 deletions packages/services/src/block_bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -231,7 +231,7 @@ pub mod service {
bundler.finish().await
}

async fn still_time_to_accumulate_more(&self) -> Result<bool> {
fn still_time_to_accumulate_more(&self) -> Result<bool> {
let elapsed = self.elapsed(self.last_time_bundled)?;

Ok(elapsed < self.config.block_accumulation_time_limit)
Expand Down Expand Up @@ -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<u32>;
}
}
Expand All @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions packages/services/src/block_bundler/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
Result,
};

#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Metadata {
pub block_heights: RangeInclusive<u32>,
pub known_to_be_optimal: bool,
Expand All @@ -29,6 +29,8 @@ impl Metadata {
self.block_heights.clone().count()
}

// This is for metrics anyway, precission loss is ok

Check warning on line 32 in packages/services/src/block_bundler/bundler.rs

View workflow job for this annotation

GitHub Actions / cargo-verifications

"precission" should be "precision" or "percussion" or "precession".
#[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
}
Expand Down Expand Up @@ -56,7 +58,7 @@ impl Display for Metadata {
}
}

#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BundleProposal {
pub fragments: NonEmpty<Fragment>,
pub metadata: Metadata,
Expand Down
6 changes: 3 additions & 3 deletions packages/services/src/block_committer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockSubmissionTx>;
fn commit_interval(&self) -> NonZeroU32;
}
Expand All @@ -246,15 +246,15 @@ 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<FuelBlock>;
async fn block_at_height(&self, height: u32) -> Result<Option<FuelBlock>>;
}
}

#[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,
Expand Down
4 changes: 2 additions & 2 deletions packages/services/src/block_importer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompressedFuelBlock>) -> Result<()>;
async fn missing_blocks(
&self,
Expand All @@ -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<u32>,
Expand Down
16 changes: 8 additions & 8 deletions packages/services/src/fee_metrics_tracker/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -157,7 +158,7 @@ pub mod l1 {
}

impl ConstantFeeApi {
pub fn new(fees: Fees) -> Self {
pub const fn new(fees: Fees) -> Self {
Self { fees }
}
}
Expand Down Expand Up @@ -640,7 +641,7 @@ pub mod cache {
}

impl<P> CachingApi<P> {
pub fn inner(&self) -> &P {
pub const fn inner(&self) -> &P {
&self.fees_provider
}

Expand Down Expand Up @@ -691,11 +692,10 @@ pub mod cache {
height_range: RangeInclusive<u64>,
) -> Result<SequentialBlockFees> {
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);
Expand All @@ -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<u64, Fees>,
height_range: RangeInclusive<u64>,
) -> Vec<BlockFees> {
Expand All @@ -717,7 +717,7 @@ pub mod cache {
.collect()
}

async fn update_cache(&self, cache: &mut BTreeMap<u64, Fees>, fees: Vec<BlockFees>) {
fn update_cache(&self, cache: &mut BTreeMap<u64, Fees>, fees: Vec<BlockFees>) {
cache.extend(fees.into_iter().map(|bf| (bf.height, bf.fees)));

while cache.len() > self.cache_limit {
Expand Down
38 changes: 17 additions & 21 deletions packages/services/src/fee_metrics_tracker/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -36,19 +36,19 @@ 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,
}
}
}

impl<P> RegistersMetrics for FeeMetricsTracker<P> {
fn metrics(&self) -> Vec<Box<dyn Collector>> {
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()),
]
}
}
Expand All @@ -57,7 +57,7 @@ impl<P> RegistersMetrics for FeeMetricsTracker<P> {
pub struct FeeMetricsTracker<P> {
fee_provider: P,
sma_periods: SmaPeriods,
metrics: Metrics,
metrics: FeeMetrics,
}

#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -109,7 +109,7 @@ impl<P: Api> FeeMetricsTracker<P> {
}
}

fn last_n_blocks(current_block: u64, n: NonZeroU64) -> RangeInclusive<u64> {
const fn last_n_blocks(current_block: u64, n: NonZeroU64) -> RangeInclusive<u64> {
current_block.saturating_sub(n.get().saturating_sub(1))..=current_block
}

Expand All @@ -118,7 +118,7 @@ impl<P> FeeMetricsTracker<P> {
Self {
fee_provider,
sma_periods,
metrics: Metrics::default(),
metrics: FeeMetrics::default(),
}
}
}
Expand Down Expand Up @@ -150,13 +150,9 @@ impl<P: Api> FeeMetricsTracker<P> {
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(())
}
Expand Down
2 changes: 0 additions & 2 deletions packages/services/src/health_reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ 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,
eth_connection: eth_health_check,
}
}

#[must_use]
pub fn report(&self) -> HealthReport {
HealthReport {
fuel_connection_up: self.fuel_connection.healthy(),
Expand Down
4 changes: 2 additions & 2 deletions packages/services/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -50,6 +50,6 @@ impl From<String> for Error {
pub type Result<T> = std::result::Result<T, Error>;

#[trait_variant::make(Send)]
pub trait Runner: Send + Sync {
pub trait Runner: Sync {
async fn run(&mut self) -> Result<()>;
}
Loading

0 comments on commit 4dda61d

Please sign in to comment.