From d8eef6305b904a22a66bdbf1e5b21ec9ba7dfb05 Mon Sep 17 00:00:00 2001 From: sprites0 <199826320+sprites0@users.noreply.github.com> Date: Sat, 23 Aug 2025 04:33:40 -0400 Subject: [PATCH] remove: Reduce unnecessary LoC --- src/chainspec/hl.rs | 1 - src/chainspec/mod.rs | 19 +----- src/evm/handler.rs | 1 - src/evm/mod.rs | 1 - src/hardforks/hl.rs | 83 -------------------------- src/hardforks/mod.rs | 19 +++--- src/hl_node_compliance.rs | 43 +++----------- src/node/engine.rs | 87 +--------------------------- src/node/evm/mod.rs | 3 +- src/node/mod.rs | 13 +++-- src/node/network/mod.rs | 1 - src/node/primitives/tx_wrapper.rs | 19 ------ src/node/rpc/engine_api/validator.rs | 4 +- src/pseudo_peer/consts.rs | 1 - src/pseudo_peer/error.rs | 36 ------------ src/pseudo_peer/mod.rs | 14 ++--- src/pseudo_peer/network.rs | 10 ---- src/pseudo_peer/sources/mod.rs | 22 +------ src/pseudo_peer/tests.rs | 11 ---- 19 files changed, 42 insertions(+), 346 deletions(-) delete mode 100644 src/evm/handler.rs delete mode 100644 src/pseudo_peer/consts.rs delete mode 100644 src/pseudo_peer/error.rs diff --git a/src/chainspec/hl.rs b/src/chainspec/hl.rs index a7dbb4f11..bc095550e 100644 --- a/src/chainspec/hl.rs +++ b/src/chainspec/hl.rs @@ -7,7 +7,6 @@ use std::sync::LazyLock; static GENESIS_HASH: B256 = b256!("d8fcc13b6a195b88b7b2da3722ff6cad767b13a8c1e9ffb1c73aa9d216d895f0"); -/// Dev hardforks pub static HL_HARDFORKS: LazyLock = LazyLock::new(|| { ChainHardforks::new(vec![ (EthereumHardfork::Frontier.boxed(), ForkCondition::Block(0)), diff --git a/src/chainspec/mod.rs b/src/chainspec/mod.rs index 084e83871..0d3846218 100644 --- a/src/chainspec/mod.rs +++ b/src/chainspec/mod.rs @@ -1,8 +1,7 @@ -//! Chain specification for HyperEVM. pub mod hl; pub mod parser; -use crate::hardforks::{hl::HlHardfork, HlHardforks}; +use crate::hardforks::HlHardforks; use alloy_consensus::Header; use alloy_eips::eip7840::BlobParams; use alloy_genesis::Genesis; @@ -13,15 +12,13 @@ use reth_chainspec::{ }; use reth_discv4::NodeRecord; use reth_evm::eth::spec::EthExecutorSpec; -use std::{fmt::Display, sync::Arc}; +use std::fmt::Display; pub const MAINNET_CHAIN_ID: u64 = 999; pub const TESTNET_CHAIN_ID: u64 = 998; -/// Hl chain spec type. #[derive(Debug, Default, Clone, PartialEq, Eq)] pub struct HlChainSpec { - /// [`ChainSpec`]. pub inner: ChainSpec, } @@ -117,11 +114,7 @@ impl EthereumHardforks for HlChainSpec { } } -impl HlHardforks for HlChainSpec { - fn hl_fork_activation(&self, fork: HlHardfork) -> ForkCondition { - self.fork(fork) - } -} +impl HlHardforks for HlChainSpec {} impl EthExecutorSpec for HlChainSpec { fn deposit_contract_address(&self) -> Option
{ @@ -135,12 +128,6 @@ impl From for ChainSpec { } } -impl HlHardforks for Arc { - fn hl_fork_activation(&self, fork: HlHardfork) -> ForkCondition { - self.as_ref().hl_fork_activation(fork) - } -} - impl HlChainSpec { pub const MAINNET_RPC_URL: &str = "https://rpc.hyperliquid.xyz/evm"; pub const TESTNET_RPC_URL: &str = "https://rpc.hyperliquid-testnet.xyz/evm"; diff --git a/src/evm/handler.rs b/src/evm/handler.rs deleted file mode 100644 index 8b1378917..000000000 --- a/src/evm/handler.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/evm/mod.rs b/src/evm/mod.rs index 5c38c2a29..7034df9c7 100644 --- a/src/evm/mod.rs +++ b/src/evm/mod.rs @@ -1,4 +1,3 @@ pub mod api; -mod handler; pub mod spec; pub mod transaction; diff --git a/src/hardforks/hl.rs b/src/hardforks/hl.rs index d4b2ec8ce..e3ecc0458 100644 --- a/src/hardforks/hl.rs +++ b/src/hardforks/hl.rs @@ -13,88 +13,5 @@ hardfork!( HlHardfork { /// Initial version V1, - /// block.number bugfix - V2, - /// gas mismatch bugfix - V3, } ); - -impl HlHardfork { - /// Retrieves the activation block for the specified hardfork on the given chain. - pub fn activation_block(self, fork: H, chain: Chain) -> Option { - if chain == Chain::from_named(NamedChain::Hyperliquid) { - return Self::hl_mainnet_activation_block(fork); - } - - None - } - - /// Retrieves the activation timestamp for the specified hardfork on the given chain. - pub fn activation_timestamp(self, fork: H, chain: Chain) -> Option { - None - } - - /// Retrieves the activation block for the specified hardfork on the HyperLiquid mainnet. - pub fn hl_mainnet_activation_block(fork: H) -> Option { - match_hardfork( - fork, - |fork| match fork { - EthereumHardfork::Frontier | - EthereumHardfork::Homestead | - EthereumHardfork::Tangerine | - EthereumHardfork::SpuriousDragon | - EthereumHardfork::Byzantium | - EthereumHardfork::Constantinople | - EthereumHardfork::Petersburg | - EthereumHardfork::Istanbul | - EthereumHardfork::MuirGlacier | - EthereumHardfork::Berlin | - EthereumHardfork::London | - EthereumHardfork::Shanghai | - EthereumHardfork::Cancun => Some(0), - _ => None, - }, - |fork| match fork { - Self::V1 | Self::V2 | Self::V3 => Some(0), - _ => None, - }, - ) - } - - /// Hl mainnet list of hardforks. - pub fn hl_mainnet() -> ChainHardforks { - ChainHardforks::new(vec![ - (EthereumHardfork::Frontier.boxed(), ForkCondition::Block(0)), - (EthereumHardfork::Homestead.boxed(), ForkCondition::Block(0)), - (EthereumHardfork::Tangerine.boxed(), ForkCondition::Block(0)), - (EthereumHardfork::SpuriousDragon.boxed(), ForkCondition::Block(0)), - (EthereumHardfork::Byzantium.boxed(), ForkCondition::Block(0)), - (EthereumHardfork::Constantinople.boxed(), ForkCondition::Block(0)), - (EthereumHardfork::Petersburg.boxed(), ForkCondition::Block(0)), - (EthereumHardfork::Istanbul.boxed(), ForkCondition::Block(0)), - (EthereumHardfork::MuirGlacier.boxed(), ForkCondition::Block(0)), - (EthereumHardfork::Berlin.boxed(), ForkCondition::Block(0)), - (EthereumHardfork::London.boxed(), ForkCondition::Block(0)), - (EthereumHardfork::Shanghai.boxed(), ForkCondition::Block(0)), - (EthereumHardfork::Cancun.boxed(), ForkCondition::Block(0)), - (Self::V1.boxed(), ForkCondition::Block(0)), - (Self::V2.boxed(), ForkCondition::Block(0)), - (Self::V3.boxed(), ForkCondition::Block(0)), - ]) - } -} - -/// Match helper method since it's not possible to match on `dyn Hardfork` -fn match_hardfork(fork: H, hardfork_fn: HF, hl_hardfork_fn: HHF) -> Option -where - H: Hardfork, - HF: Fn(&EthereumHardfork) -> Option, - HHF: Fn(&HlHardfork) -> Option, -{ - let fork: &dyn Any = ⋔ - if let Some(fork) = fork.downcast_ref::() { - return hardfork_fn(fork); - } - fork.downcast_ref::().and_then(hl_hardfork_fn) -} diff --git a/src/hardforks/mod.rs b/src/hardforks/mod.rs index 7349a7a22..715d1b1ec 100644 --- a/src/hardforks/mod.rs +++ b/src/hardforks/mod.rs @@ -1,13 +1,14 @@ -//! Hard forks of hl protocol. +//! Hard forks of HyperEVM. #![allow(unused)] -use hl::HlHardfork; -use reth_chainspec::{EthereumHardforks, ForkCondition}; - pub mod hl; +use hl::HlHardfork; +use reth_chainspec::{EthereumHardforks, ForkCondition}; +use std::sync::Arc; + /// Extends [`EthereumHardforks`] with hl helper methods. -pub trait HlHardforks: EthereumHardforks { - /// Retrieves [`ForkCondition`] by an [`HlHardfork`]. If `fork` is not present, returns - /// [`ForkCondition::Never`]. - fn hl_fork_activation(&self, fork: HlHardfork) -> ForkCondition; -} +/// +/// Currently a placeholder for future use. +pub trait HlHardforks: EthereumHardforks {} + +impl HlHardforks for Arc {} diff --git a/src/hl_node_compliance.rs b/src/hl_node_compliance.rs index c00333589..3c1ee63b3 100644 --- a/src/hl_node_compliance.rs +++ b/src/hl_node_compliance.rs @@ -1,6 +1,6 @@ //! Overrides for RPC methods to post-filter system transactions and logs. //! -//! System transactions are always at the beginning of the block, +//! System transactions are always at the beginning of the block, //! so we can use the transaction index to determine if the log is from a system transaction, //! and if it is, we can exclude it. //! @@ -18,13 +18,10 @@ use alloy_rpc_types::{ use jsonrpsee::{proc_macros::rpc, PendingSubscriptionSink, SubscriptionMessage, SubscriptionSink}; use jsonrpsee_core::{async_trait, RpcResult}; use jsonrpsee_types::ErrorObject; -use reth::{ - api::FullNodeComponents, builder::rpc::RpcContext, rpc::result::internal_rpc_err, - tasks::TaskSpawner, -}; +use reth::{api::FullNodeComponents, builder::rpc::RpcContext, tasks::TaskSpawner}; use reth_primitives_traits::{BlockBody as _, SignedTransaction}; use reth_provider::{BlockIdReader, BlockReader, BlockReaderIdExt, ReceiptProvider}; -use reth_rpc::{EthFilter, EthPubSub}; +use reth_rpc::{eth::pubsub::SubscriptionSerializeError, EthFilter, EthPubSub}; use reth_rpc_eth_api::{ helpers::{EthBlocks, EthTransactions, LoadReceipt}, transaction::ConvertReceiptInput, @@ -34,12 +31,9 @@ use reth_rpc_eth_api::{ use serde::Serialize; use std::{borrow::Cow, marker::PhantomData, sync::Arc}; use tokio_stream::{Stream, StreamExt}; -use tracing::{info, trace, Instrument}; +use tracing::{trace, Instrument}; -use crate::{ - node::primitives::{HlPrimitives, TransactionSigned}, - HlBlock, -}; +use crate::{node::primitives::HlPrimitives, HlBlock}; pub trait EthWrapper: EthApiServer< @@ -197,22 +191,6 @@ fn adjust_log(mut log: Log, provider: &Eth::Provider) -> Option Some(log) } -#[derive(Debug, thiserror::Error)] -#[error("Failed to serialize subscription item: {0}")] -pub struct SubscriptionSerializeError(#[from] serde_json::Error); - -impl SubscriptionSerializeError { - const fn new(err: serde_json::Error) -> Self { - Self(err) - } -} - -impl From for ErrorObject<'static> { - fn from(value: SubscriptionSerializeError) -> Self { - internal_rpc_err(value.to_string()) - } -} - async fn pipe_from_stream + Unpin>( sink: SubscriptionSink, mut stream: St, @@ -223,7 +201,7 @@ async fn pipe_from_stream + Unpin>( maybe_item = stream.next() => { let Some(item) = maybe_item else { break Ok(()) }; let msg = SubscriptionMessage::new(sink.method_name(), sink.subscription_id(), &item) - .map_err(SubscriptionSerializeError::new)?; + .map_err(SubscriptionSerializeError::from)?; if sink.send(msg).await.is_err() { break Ok(()); } } } @@ -274,10 +252,6 @@ macro_rules! engine_span { }; } -fn is_system_tx(tx: &TransactionSigned) -> bool { - tx.is_system_transaction() -} - fn adjust_block( recovered_block: &RpcBlock, eth_api: &Eth, @@ -365,7 +339,6 @@ async fn adjust_transaction_receipt( Some((_, meta, _)) => { // LoadReceipt::block_transaction_receipt loads the block again, so loading blocks again // doesn't hurt performance much - info!("block hash: {:?}", meta.block_hash); let Some((system_tx_count, block_receipts)) = adjust_block_receipts(meta.block_hash.into(), eth_api).await? else { @@ -377,10 +350,12 @@ async fn adjust_transaction_receipt( } } +// This function assumes that `block_id` is already validated by the caller. fn system_tx_count_for_block(eth_api: &Eth, block_id: BlockId) -> usize { let provider = eth_api.provider(); let block = provider.block_by_id(block_id).unwrap().unwrap(); - let system_tx_count = block.body.transactions().iter().filter(|tx| is_system_tx(tx)).count(); + let system_tx_count = + block.body.transactions().iter().filter(|tx| tx.is_system_transaction()).count(); system_tx_count } diff --git a/src/node/engine.rs b/src/node/engine.rs index 9f821f9c9..4d5c56b01 100644 --- a/src/node/engine.rs +++ b/src/node/engine.rs @@ -1,22 +1,9 @@ -use std::sync::Arc; - -use crate::{ - node::{rpc::engine_api::payload::HlPayloadTypes, HlNode}, - HlBlock, HlPrimitives, -}; +use crate::{HlBlock, HlPrimitives}; use alloy_eips::eip7685::Requests; use alloy_primitives::U256; -use reth::{ - api::FullNodeTypes, - builder::{components::PayloadServiceBuilder, BuilderContext}, - payload::{PayloadBuilderHandle, PayloadServiceCommand}, - transaction_pool::TransactionPool, -}; -use reth_evm::ConfigureEvm; use reth_payload_primitives::BuiltPayload; use reth_primitives::SealedBlock; -use tokio::sync::{broadcast, mpsc}; -use tracing::warn; +use std::sync::Arc; /// Built payload for Hl. This is similar to [`EthBuiltPayload`] but without sidecars as those /// included into [`HlBlock`]. @@ -45,73 +32,3 @@ impl BuiltPayload for HlBuiltPayload { self.requests.clone() } } - -#[derive(Debug, Clone, Copy, Default)] -#[non_exhaustive] -pub struct HlPayloadServiceBuilder; - -impl PayloadServiceBuilder for HlPayloadServiceBuilder -where - Node: FullNodeTypes, - Pool: TransactionPool, - Evm: ConfigureEvm, -{ - async fn spawn_payload_builder_service( - self, - ctx: &BuilderContext, - _pool: Pool, - _evm_config: Evm, - ) -> eyre::Result> { - let (tx, mut rx) = mpsc::unbounded_channel(); - - ctx.task_executor().spawn_critical("payload builder", async move { - let mut subscriptions = Vec::new(); - - while let Some(message) = rx.recv().await { - match message { - PayloadServiceCommand::Subscribe(tx) => { - let (events_tx, events_rx) = broadcast::channel(100); - // Retain senders to make sure that channels are not getting closed - subscriptions.push(events_tx); - let _ = tx.send(events_rx); - } - message => warn!(?message, "Noop payload service received a message"), - } - } - }); - - Ok(PayloadBuilderHandle::new(tx)) - } -} - -// impl From for HlBuiltPayload { -// fn from(value: EthBuiltPayload) -> Self { -// let EthBuiltPayload { id, block, fees, sidecars, requests } = value; -// HlBuiltPayload { -// id, -// block: block.into(), -// fees, -// requests, -// } -// } -// } - -// pub struct HlPayloadBuilder { -// inner: Inner, -// } - -// impl PayloadBuilder for HlPayloadBuilder -// where -// Inner: PayloadBuilder, -// { -// type Attributes = Inner::Attributes; -// type BuiltPayload = HlBuiltPayload; -// type Error = Inner::Error; - -// fn try_build( -// &self, -// args: BuildArguments, -// ) -> Result, PayloadBuilderError> { -// let outcome = self.inner.try_build(args)?; -// } -// } diff --git a/src/node/evm/mod.rs b/src/node/evm/mod.rs index bad92e601..f489fbf5e 100644 --- a/src/node/evm/mod.rs +++ b/src/node/evm/mod.rs @@ -165,7 +165,6 @@ where type EVM = HlEvmConfig; async fn build_evm(self, ctx: &BuilderContext) -> eyre::Result { - let evm_config = HlEvmConfig::hl(ctx.chain_spec()); - Ok(evm_config) + Ok(HlEvmConfig::hl(ctx.chain_spec())) } } diff --git a/src/node/mod.rs b/src/node/mod.rs index 6dbe0dfef..63dd730a3 100644 --- a/src/node/mod.rs +++ b/src/node/mod.rs @@ -15,12 +15,15 @@ use crate::{ pseudo_peer::BlockSourceConfig, }; use consensus::HlConsensusBuilder; -use engine::HlPayloadServiceBuilder; use evm::HlExecutorBuilder; use network::HlNetworkBuilder; use reth::{ api::{FullNodeTypes, NodeTypes}, - builder::{components::ComponentsBuilder, rpc::RpcAddOns, Node, NodeAdapter}, + builder::{ + components::{ComponentsBuilder, NoopPayloadServiceBuilder}, + rpc::RpcAddOns, + Node, NodeAdapter, + }, }; use reth_engine_primitives::ConsensusEngineHandle; use std::{marker::PhantomData, sync::Arc}; @@ -65,7 +68,7 @@ impl HlNode { ) -> ComponentsBuilder< Node, HlPoolBuilder, - HlPayloadServiceBuilder, + NoopPayloadServiceBuilder, HlNetworkBuilder, HlExecutorBuilder, HlConsensusBuilder, @@ -77,7 +80,7 @@ impl HlNode { .node_types::() .pool(HlPoolBuilder) .executor(HlExecutorBuilder::default()) - .payload(HlPayloadServiceBuilder::default()) + .payload(NoopPayloadServiceBuilder::default()) .network(HlNetworkBuilder { engine_handle_rx: self.engine_handle_rx.clone(), block_source_config: self.block_source_config.clone(), @@ -100,7 +103,7 @@ where type ComponentsBuilder = ComponentsBuilder< N, HlPoolBuilder, - HlPayloadServiceBuilder, + NoopPayloadServiceBuilder, HlNetworkBuilder, HlExecutorBuilder, HlConsensusBuilder, diff --git a/src/node/network/mod.rs b/src/node/network/mod.rs index 0dbdcaa1f..81d35fff1 100644 --- a/src/node/network/mod.rs +++ b/src/node/network/mod.rs @@ -12,7 +12,6 @@ use crate::{ HlBlock, }; use alloy_rlp::{Decodable, Encodable}; -// use handshake::HlHandshake; use reth::{ api::{FullNodeTypes, TxTy}, builder::{components::NetworkBuilder, BuilderContext}, diff --git a/src/node/primitives/tx_wrapper.rs b/src/node/primitives/tx_wrapper.rs index 59cf4a178..8f4c77333 100644 --- a/src/node/primitives/tx_wrapper.rs +++ b/src/node/primitives/tx_wrapper.rs @@ -114,11 +114,6 @@ impl reth_codecs::Compact for TransactionSigned { } } -pub fn convert_recovered(value: Recovered) -> Recovered { - let (tx, signer) = value.into_parts(); - Recovered::new_unchecked(tx.into_inner(), signer) -} - impl FromRecoveredTx for TxEnv { fn from_recovered_tx(tx: &TransactionSigned, sender: Address) -> Self { TxEnv::from_recovered_tx(&tx.inner(), sender) @@ -192,20 +187,6 @@ impl SerdeBincodeCompat for TransactionSigned { pub type BlockBody = alloy_consensus::BlockBody; -impl From for EthereumTxEnvelope { - fn from(value: TransactionSigned) -> Self { - value.into_inner() - } -} - -impl TryFrom for EthereumTxEnvelope { - type Error = >>::Error; - - fn try_from(value: TransactionSigned) -> Result { - value.into_inner().try_into() - } -} - impl TryFrom for EthereumTxEnvelope> { diff --git a/src/node/rpc/engine_api/validator.rs b/src/node/rpc/engine_api/validator.rs index 6cd2b2d00..04218ab22 100644 --- a/src/node/rpc/engine_api/validator.rs +++ b/src/node/rpc/engine_api/validator.rs @@ -36,7 +36,7 @@ where } } -/// Validator for Optimism engine API. +/// Validator for HyperEVM engine API. #[derive(Debug, Clone)] pub struct HlPayloadValidator { inner: HlExecutionPayloadValidator, @@ -123,7 +123,7 @@ where return Err(PayloadError::BlockHash { execution: sealed_block.hash(), consensus: expected_hash, - })?; + }); } Ok(sealed_block) diff --git a/src/pseudo_peer/consts.rs b/src/pseudo_peer/consts.rs deleted file mode 100644 index 8404c4db8..000000000 --- a/src/pseudo_peer/consts.rs +++ /dev/null @@ -1 +0,0 @@ -pub const MAX_CONCURRENCY: usize = 100; diff --git a/src/pseudo_peer/error.rs b/src/pseudo_peer/error.rs deleted file mode 100644 index ad4344ca3..000000000 --- a/src/pseudo_peer/error.rs +++ /dev/null @@ -1,36 +0,0 @@ -use thiserror::Error; - -#[derive(Error, Debug)] -pub enum PseudoPeerError { - #[error("Block source error: {0}")] - BlockSource(String), - - #[error("Network error: {0}")] - Network(#[from] reth_network::error::NetworkError), - - #[error("Configuration error: {0}")] - Config(String), - - #[error("AWS S3 error: {0}")] - S3(#[from] aws_sdk_s3::Error), - - #[error("IO error: {0}")] - Io(#[from] std::io::Error), - - #[error("Serialization error: {0}")] - Serialization(#[from] rmp_serde::encode::Error), - - #[error("Deserialization error: {0}")] - Deserialization(#[from] rmp_serde::decode::Error), - - #[error("Compression error: {0}")] - Compression(String), -} - -impl From for PseudoPeerError { - fn from(err: eyre::Error) -> Self { - PseudoPeerError::Config(err.to_string()) - } -} - -pub type Result = std::result::Result; diff --git a/src/pseudo_peer/mod.rs b/src/pseudo_peer/mod.rs index 9dba0f3e5..c540d6891 100644 --- a/src/pseudo_peer/mod.rs +++ b/src/pseudo_peer/mod.rs @@ -5,33 +5,27 @@ pub mod cli; pub mod config; -pub mod consts; -pub mod error; pub mod network; pub mod service; pub mod sources; +#[cfg(test)] +mod tests; pub mod utils; use std::sync::Arc; +use tokio::sync::mpsc; +use tracing::info; pub use cli::*; pub use config::*; -pub use error::*; pub use network::*; pub use service::*; pub use sources::*; -#[cfg(test)] -mod tests; - -use tokio::sync::mpsc; -use tracing::info; - /// Re-export commonly used types pub mod prelude { pub use super::{ config::BlockSourceConfig, - error::{PseudoPeerError, Result}, service::{BlockPoller, PseudoPeer}, sources::{BlockSource, CachedBlockSource, LocalBlockSource, S3BlockSource}, }; diff --git a/src/pseudo_peer/network.rs b/src/pseudo_peer/network.rs index 0f6be1196..67296ecd3 100644 --- a/src/pseudo_peer/network.rs +++ b/src/pseudo_peer/network.rs @@ -32,16 +32,6 @@ impl Default for NetworkBuilder { } impl NetworkBuilder { - pub fn with_secret(mut self, secret: SecretKey) -> Self { - self.secret = secret; - self - } - - pub fn with_peer_config(mut self, peer_config: PeersConfig) -> Self { - self.peer_config = peer_config; - self - } - pub fn with_boot_nodes(mut self, boot_nodes: Vec) -> Self { self.boot_nodes = boot_nodes; self diff --git a/src/pseudo_peer/sources/mod.rs b/src/pseudo_peer/sources/mod.rs index dfd497c0c..f530203e6 100644 --- a/src/pseudo_peer/sources/mod.rs +++ b/src/pseudo_peer/sources/mod.rs @@ -24,7 +24,8 @@ fn name_with_largest_number(files: &[String], is_dir: bool) -> Option<(u64, Stri let mut files = files .iter() .filter_map(|file_raw| { - let file = file_raw.strip_suffix("/").unwrap_or(file_raw).split("/").last().unwrap(); + let file = file_raw.strip_suffix("/").unwrap_or(file_raw); + let file = file.split("/").last().unwrap(); let stem = if is_dir { file } else { file.strip_suffix(".rmp.lz4")? }; stem.parse::().ok().map(|number| (number, file_raw.to_string())) }) @@ -181,23 +182,6 @@ impl LocalBlockSource { Self { dir: dir.into() } } - fn name_with_largest_number_static(files: &[String], is_dir: bool) -> Option<(u64, String)> { - let mut files = files - .iter() - .filter_map(|file_raw| { - let file = file_raw.strip_suffix("/").unwrap_or(file_raw); - let file = file.split("/").last().unwrap(); - let stem = if is_dir { file } else { file.strip_suffix(".rmp.lz4")? }; - stem.parse::().ok().map(|number| (number, file_raw.to_string())) - }) - .collect::>(); - if files.is_empty() { - return None; - } - files.sort_by_key(|(number, _)| *number); - files.last().map(|(number, file)| (*number, file.to_string())) - } - async fn pick_path_with_highest_number(dir: PathBuf, is_dir: bool) -> Option<(u64, String)> { let files = std::fs::read_dir(&dir).unwrap().collect::>(); let files = files @@ -206,7 +190,7 @@ impl LocalBlockSource { .map(|entry| entry.unwrap().path().to_string_lossy().to_string()) .collect::>(); - Self::name_with_largest_number_static(&files, is_dir) + name_with_largest_number(&files, is_dir) } } diff --git a/src/pseudo_peer/tests.rs b/src/pseudo_peer/tests.rs index 4c8b064bc..7e71e223a 100644 --- a/src/pseudo_peer/tests.rs +++ b/src/pseudo_peer/tests.rs @@ -17,14 +17,3 @@ async fn test_block_source_config_local() { matches!(config.source_type, BlockSourceType::Local { path } if path == Path::new("/test/path")) ); } - -#[test] -fn test_error_types() { - let io_error = std::io::Error::new(std::io::ErrorKind::NotFound, "File not found"); - let benchmark_error: PseudoPeerError = io_error.into(); - - match benchmark_error { - PseudoPeerError::Io(_) => (), - _ => panic!("Expected Io error"), - } -}