From 73a34a4bc14db201c2d08794d271894a8fbb93f6 Mon Sep 17 00:00:00 2001 From: sprites0 <199826320+sprites0@users.noreply.github.com> Date: Sat, 23 Aug 2025 06:00:44 -0400 Subject: [PATCH] chore: clippy --- src/hardforks/mod.rs | 2 +- src/pseudo_peer/sources/hl_node.rs | 42 +++++++++++++++++++----------- src/pseudo_peer/sources/mod.rs | 20 +++++++------- src/tx_forwarder.rs | 2 +- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/hardforks/mod.rs b/src/hardforks/mod.rs index 715d1b1ec..265fa91b5 100644 --- a/src/hardforks/mod.rs +++ b/src/hardforks/mod.rs @@ -7,7 +7,7 @@ use reth_chainspec::{EthereumHardforks, ForkCondition}; use std::sync::Arc; /// Extends [`EthereumHardforks`] with hl helper methods. -/// +/// /// Currently a placeholder for future use. pub trait HlHardforks: EthereumHardforks {} diff --git a/src/pseudo_peer/sources/hl_node.rs b/src/pseudo_peer/sources/hl_node.rs index 7d88b75cc..413051c0a 100644 --- a/src/pseudo_peer/sources/hl_node.rs +++ b/src/pseudo_peer/sources/hl_node.rs @@ -133,16 +133,19 @@ pub struct HlNodeBlockSource { } impl BlockSource for HlNodeBlockSource { - fn collect_block(&self, height: u64) -> BoxFuture> { + fn collect_block(&self, height: u64) -> BoxFuture<'static, eyre::Result> { + let fallback = self.fallback.clone(); + let local_blocks_cache = self.local_blocks_cache.clone(); + let last_local_fetch = self.last_local_fetch.clone(); Box::pin(async move { let now = OffsetDateTime::now_utc(); - if let Some(block) = self.try_collect_local_block(height).await { - self.update_last_fetch(height, now).await; + if let Some(block) = Self::try_collect_local_block(local_blocks_cache, height).await { + Self::update_last_fetch(last_local_fetch, height, now).await; return Ok(block); } - if let Some((last_height, last_poll_time)) = *self.last_local_fetch.lock().await { + if let Some((last_height, last_poll_time)) = *last_local_fetch.lock().await { let more_recent = last_height < height; let too_soon = now - last_poll_time < Self::MAX_ALLOWED_THRESHOLD_BEFORE_FALLBACK; if more_recent && too_soon { @@ -152,20 +155,22 @@ impl BlockSource for HlNodeBlockSource { } } - let block = self.fallback.collect_block(height).await?; - self.update_last_fetch(height, now).await; + let block = fallback.collect_block(height).await?; + Self::update_last_fetch(last_local_fetch, height, now).await; Ok(block) }) } - fn find_latest_block_number(&self) -> BoxFuture> { + fn find_latest_block_number(&self) -> BoxFuture<'static, Option> { + let fallback = self.fallback.clone(); + let local_ingest_dir = self.local_ingest_dir.clone(); Box::pin(async move { - let Some(dir) = Self::find_latest_hourly_file(&self.local_ingest_dir) else { + let Some(dir) = Self::find_latest_hourly_file(&local_ingest_dir) else { warn!( "No EVM blocks from hl-node found at {:?}; fallback to s3/ingest-dir", - self.local_ingest_dir + local_ingest_dir ); - return self.fallback.find_latest_block_number().await; + return fallback.find_latest_block_number().await; }; let mut file = File::open(&dir).expect("Failed to open hour file path"); @@ -177,7 +182,7 @@ impl BlockSource for HlNodeBlockSource { "Failed to parse the hl-node hourly file at {:?}; fallback to s3/ingest-dir", file ); - self.fallback.find_latest_block_number().await + fallback.find_latest_block_number().await } }) } @@ -228,15 +233,22 @@ impl HlNodeBlockSource { /// fallback attempts. pub(crate) const MAX_ALLOWED_THRESHOLD_BEFORE_FALLBACK: Duration = Duration::milliseconds(5000); - async fn update_last_fetch(&self, height: u64, now: OffsetDateTime) { - let mut last_fetch = self.last_local_fetch.lock().await; + async fn update_last_fetch( + last_local_fetch: Arc>>, + height: u64, + now: OffsetDateTime, + ) { + let mut last_fetch = last_local_fetch.lock().await; if last_fetch.is_none_or(|(h, _)| h < height) { *last_fetch = Some((height, now)); } } - async fn try_collect_local_block(&self, height: u64) -> Option { - let mut u_cache = self.local_blocks_cache.lock().await; + async fn try_collect_local_block( + local_blocks_cache: Arc>, + height: u64, + ) -> Option { + let mut u_cache = local_blocks_cache.lock().await; if let Some(block) = u_cache.cache.remove(&height) { return Some(block); } diff --git a/src/pseudo_peer/sources/mod.rs b/src/pseudo_peer/sources/mod.rs index f530203e6..b7ba1ff39 100644 --- a/src/pseudo_peer/sources/mod.rs +++ b/src/pseudo_peer/sources/mod.rs @@ -13,8 +13,8 @@ mod hl_node; pub use hl_node::HlNodeBlockSource; pub trait BlockSource: Send + Sync + std::fmt::Debug + Unpin + 'static { - fn collect_block(&self, height: u64) -> BoxFuture>; - fn find_latest_block_number(&self) -> BoxFuture>; + fn collect_block(&self, height: u64) -> BoxFuture<'static, eyre::Result>; + fn find_latest_block_number(&self) -> BoxFuture<'static, Option>; fn recommended_chunk_size(&self) -> u64; } @@ -81,7 +81,7 @@ impl S3BlockSource { } impl BlockSource for S3BlockSource { - fn collect_block(&self, height: u64) -> BoxFuture> { + fn collect_block(&self, height: u64) -> BoxFuture<'static, eyre::Result> { let client = self.client.clone(); let bucket = self.bucket.clone(); async move { @@ -100,7 +100,7 @@ impl BlockSource for S3BlockSource { .boxed() } - fn find_latest_block_number(&self) -> BoxFuture> { + fn find_latest_block_number(&self) -> BoxFuture<'static, Option> { let client = self.client.clone(); let bucket = self.bucket.clone(); async move { @@ -138,7 +138,7 @@ impl BlockSource for S3BlockSource { } impl BlockSource for LocalBlockSource { - fn collect_block(&self, height: u64) -> BoxFuture> { + fn collect_block(&self, height: u64) -> BoxFuture<'static, eyre::Result> { let dir = self.dir.clone(); async move { let path = dir.join(rmp_path(height)); @@ -152,7 +152,7 @@ impl BlockSource for LocalBlockSource { .boxed() } - fn find_latest_block_number(&self) -> BoxFuture> { + fn find_latest_block_number(&self) -> BoxFuture<'static, Option> { let dir = self.dir.clone(); async move { let (_, first_level) = Self::pick_path_with_highest_number(dir.clone(), true).await?; @@ -202,11 +202,11 @@ fn rmp_path(height: u64) -> String { } impl BlockSource for BlockSourceBoxed { - fn collect_block(&self, height: u64) -> BoxFuture> { + fn collect_block(&self, height: u64) -> BoxFuture<'static, eyre::Result> { self.as_ref().collect_block(height) } - fn find_latest_block_number(&self) -> BoxFuture> { + fn find_latest_block_number(&self) -> BoxFuture<'static, Option> { self.as_ref().find_latest_block_number() } @@ -229,7 +229,7 @@ impl CachedBlockSource { } impl BlockSource for CachedBlockSource { - fn collect_block(&self, height: u64) -> BoxFuture> { + fn collect_block(&self, height: u64) -> BoxFuture<'static, eyre::Result> { let block_source = self.block_source.clone(); let cache = self.cache.clone(); async move { @@ -243,7 +243,7 @@ impl BlockSource for CachedBlockSource { .boxed() } - fn find_latest_block_number(&self) -> BoxFuture> { + fn find_latest_block_number(&self) -> BoxFuture<'static, Option> { self.block_source.find_latest_block_number() } diff --git a/src/tx_forwarder.rs b/src/tx_forwarder.rs index dd533740d..0d473bd9f 100644 --- a/src/tx_forwarder.rs +++ b/src/tx_forwarder.rs @@ -37,7 +37,7 @@ impl EthForwarderExt { Self { client } } - fn from_client_error(e: ClientError, internal_error_prefix: &str) -> ErrorObject { + fn from_client_error(e: ClientError, internal_error_prefix: &str) -> ErrorObject<'static> { match e { ClientError::Call(e) => e, _ => ErrorObject::owned(