mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
remove: Reduce unnecessary LoC
This commit is contained in:
@ -1 +0,0 @@
|
||||
pub const MAX_CONCURRENCY: usize = 100;
|
||||
@ -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<eyre::Error> for PseudoPeerError {
|
||||
fn from(err: eyre::Error) -> Self {
|
||||
PseudoPeerError::Config(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, PseudoPeerError>;
|
||||
@ -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},
|
||||
};
|
||||
|
||||
@ -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<TrustedPeer>) -> Self {
|
||||
self.boot_nodes = boot_nodes;
|
||||
self
|
||||
|
||||
@ -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::<u64>().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::<u64>().ok().map(|number| (number, file_raw.to_string()))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
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::<Vec<_>>();
|
||||
let files = files
|
||||
@ -206,7 +190,7 @@ impl LocalBlockSource {
|
||||
.map(|entry| entry.unwrap().path().to_string_lossy().to_string())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Self::name_with_largest_number_static(&files, is_dir)
|
||||
name_with_largest_number(&files, is_dir)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user