diff --git a/bin/reth-bench/src/authenticated_transport.rs b/bin/reth-bench/src/authenticated_transport.rs index e92b581bc5fa2..60cde6e9109a5 100644 --- a/bin/reth-bench/src/authenticated_transport.rs +++ b/bin/reth-bench/src/authenticated_transport.rs @@ -1,7 +1,10 @@ //! This contains an authenticated rpc transport that can be used to send engine API newPayload //! requests. -use std::sync::Arc; +use std::{ + sync::Arc, + task::{Context, Poll}, +}; use alloy_json_rpc::{RequestPacket, ResponsePacket}; use alloy_pubsub::{PubSubConnect, PubSubFrontend}; @@ -15,7 +18,6 @@ use alloy_transport_ipc::IpcConnect; use alloy_transport_ws::WsConnect; use futures::FutureExt; use reqwest::header::HeaderValue; -use std::task::{Context, Poll}; use tokio::sync::RwLock; use tower::Service; diff --git a/bin/reth-bench/src/bench/context.rs b/bin/reth-bench/src/bench/context.rs index 7f45ee6adfe80..5347db138108a 100644 --- a/bin/reth-bench/src/bench/context.rs +++ b/bin/reth-bench/src/bench/context.rs @@ -1,7 +1,6 @@ //! This contains the [`BenchContext`], which is information that all replay-based benchmarks need. //! The initialization code is also the same, so this can be shared across benchmark commands. -use crate::{authenticated_transport::AuthenticatedTransportConnect, bench_mode::BenchMode}; use alloy_eips::BlockNumberOrTag; use alloy_provider::{ network::{AnyNetwork, Ethereum}, @@ -15,6 +14,8 @@ use reqwest::{Client, Url}; use reth_node_core::args::BenchmarkArgs; use tracing::info; +use crate::{authenticated_transport::AuthenticatedTransportConnect, bench_mode::BenchMode}; + /// This is intended to be used by benchmarks that replay blocks from an RPC. /// /// It contains an authenticated provider for engine API queries, a block provider for block diff --git a/bin/reth-bench/src/bench/new_payload_fcu.rs b/bin/reth-bench/src/bench/new_payload_fcu.rs index c7ea5683175f6..fbdac63d9bf82 100644 --- a/bin/reth-bench/src/bench/new_payload_fcu.rs +++ b/bin/reth-bench/src/bench/new_payload_fcu.rs @@ -1,6 +1,18 @@ //! Runs the `reth bench` command, calling first newPayload for each block, then calling //! forkchoiceUpdated. +use std::time::Instant; + +use alloy_provider::Provider; +use alloy_rpc_types_engine::ForkchoiceState; +use clap::Parser; +use csv::Writer; +use reth_cli_runner::CliContext; +use reth_node_core::args::BenchmarkArgs; +use reth_primitives::{Block, B256}; +use reth_rpc_types_compat::engine::payload::block_to_payload; +use tracing::{debug, info}; + use crate::{ bench::{ context::BenchContext, @@ -11,16 +23,6 @@ use crate::{ }, valid_payload::{call_forkchoice_updated, call_new_payload}, }; -use alloy_provider::Provider; -use alloy_rpc_types_engine::ForkchoiceState; -use clap::Parser; -use csv::Writer; -use reth_cli_runner::CliContext; -use reth_node_core::args::BenchmarkArgs; -use reth_primitives::{Block, B256}; -use reth_rpc_types_compat::engine::payload::block_to_payload; -use std::time::Instant; -use tracing::{debug, info}; /// `reth benchmark new-payload-fcu` command #[derive(Debug, Parser)] diff --git a/bin/reth-bench/src/bench/new_payload_only.rs b/bin/reth-bench/src/bench/new_payload_only.rs index 3fa85e5749ac4..a02bbdd7ec00b 100644 --- a/bin/reth-bench/src/bench/new_payload_only.rs +++ b/bin/reth-bench/src/bench/new_payload_only.rs @@ -1,5 +1,16 @@ //! Runs the `reth bench` command, sending only newPayload, without a forkchoiceUpdated call. +use std::time::Instant; + +use alloy_provider::Provider; +use clap::Parser; +use csv::Writer; +use reth_cli_runner::CliContext; +use reth_node_core::args::BenchmarkArgs; +use reth_primitives::{Block, B256}; +use reth_rpc_types_compat::engine::payload::block_to_payload; +use tracing::{debug, info}; + use crate::{ bench::{ context::BenchContext, @@ -10,15 +21,6 @@ use crate::{ }, valid_payload::call_new_payload, }; -use alloy_provider::Provider; -use clap::Parser; -use csv::Writer; -use reth_cli_runner::CliContext; -use reth_node_core::args::BenchmarkArgs; -use reth_primitives::{Block, B256}; -use reth_rpc_types_compat::engine::payload::block_to_payload; -use std::time::Instant; -use tracing::{debug, info}; /// `reth benchmark new-payload-only` command #[derive(Debug, Parser)] diff --git a/bin/reth-bench/src/bench/output.rs b/bin/reth-bench/src/bench/output.rs index 83103418d9294..bdfbeef868724 100644 --- a/bin/reth-bench/src/bench/output.rs +++ b/bin/reth-bench/src/bench/output.rs @@ -1,9 +1,10 @@ //! Contains various benchmark output formats, either for logging or for //! serialization to / from files. +use std::time::Duration; + use reth_primitives::constants::gas_units::GIGAGAS; use serde::{ser::SerializeStruct, Serialize}; -use std::time::Duration; /// This is the suffix for gas output csv files. pub(crate) const GAS_OUTPUT_SUFFIX: &str = "total_gas.csv"; @@ -179,10 +180,12 @@ impl Serialize for TotalGasRow { #[cfg(test)] mod tests { - use super::*; - use csv::Writer; use std::io::BufRead; + use csv::Writer; + + use super::*; + #[test] fn test_write_total_gas_row_csv() { let row = TotalGasRow { block_number: 1, gas_used: 1_000, time: Duration::from_secs(1) }; diff --git a/bin/reth/src/cli/mod.rs b/bin/reth/src/cli/mod.rs index 4dd5676307567..375dbde25d0d2 100644 --- a/bin/reth/src/cli/mod.rs +++ b/bin/reth/src/cli/mod.rs @@ -1,24 +1,13 @@ //! CLI definition and entrypoint to executable -use crate::{ - args::{ - utils::{chain_help, chain_value_parser, SUPPORTED_CHAINS}, - LogArgs, - }, - commands::{ - config_cmd, db, debug_cmd, dump_genesis, import, init_cmd, init_state, - node::{self, NoArgs}, - p2p, prune, recover, stage, test_vectors, - }, - version::{LONG_VERSION, SHORT_VERSION}, -}; +use std::{ffi::OsString, fmt, future::Future, sync::Arc}; + use clap::{value_parser, Parser, Subcommand}; use reth_chainspec::ChainSpec; use reth_cli_runner::CliRunner; use reth_db::DatabaseEnv; use reth_node_builder::{NodeBuilder, WithLaunchContext}; use reth_tracing::FileWorkerGuard; -use std::{ffi::OsString, fmt, future::Future, sync::Arc}; use tracing::info; /// Re-export of the `reth_node_core` types specifically in the `cli` module. @@ -27,6 +16,18 @@ use tracing::info; /// `reth::cli` but were moved to the `reth_node_core` crate. This re-export avoids a breaking /// change. pub use crate::core::cli::*; +use crate::{ + args::{ + utils::{chain_help, chain_value_parser, SUPPORTED_CHAINS}, + LogArgs, + }, + commands::{ + config_cmd, db, debug_cmd, dump_genesis, import, init_cmd, init_state, + node::{self, NoArgs}, + p2p, prune, recover, stage, test_vectors, + }, + version::{LONG_VERSION, SHORT_VERSION}, +}; /// The main reth cli interface. /// @@ -231,9 +232,10 @@ pub enum Commands { #[cfg(test)] mod tests { + use clap::CommandFactory; + use super::*; use crate::args::ColorMode; - use clap::CommandFactory; #[test] fn parse_color_mode() { diff --git a/bin/reth/src/commands/common.rs b/bin/reth/src/commands/common.rs index 41758a9f09dac..a08e9a703ac14 100644 --- a/bin/reth/src/commands/common.rs +++ b/bin/reth/src/commands/common.rs @@ -1,5 +1,7 @@ //! Contains common `reth` arguments +use std::{path::PathBuf, sync::Arc}; + use clap::Parser; use reth_beacon_consensus::EthBeaconConsensus; use reth_chainspec::ChainSpec; @@ -19,7 +21,6 @@ use reth_primitives::B256; use reth_provider::{providers::StaticFileProvider, ProviderFactory, StaticFileProviderFactory}; use reth_stages::{sets::DefaultStages, Pipeline, PipelineTarget}; use reth_static_file::StaticFileProducer; -use std::{path::PathBuf, sync::Arc}; use tokio::sync::watch; use tracing::{debug, info, warn}; diff --git a/bin/reth/src/commands/db/checksum.rs b/bin/reth/src/commands/db/checksum.rs index 9af9a23216372..50b57239f108d 100644 --- a/bin/reth/src/commands/db/checksum.rs +++ b/bin/reth/src/commands/db/checksum.rs @@ -1,16 +1,18 @@ -use crate::commands::db::get::{maybe_json_value_parser, table_key}; -use ahash::RandomState; -use clap::Parser; -use reth_db::{DatabaseEnv, RawKey, RawTable, RawValue, TableViewer, Tables}; -use reth_db_api::{cursor::DbCursorRO, database::Database, table::Table, transaction::DbTx}; -use reth_db_common::DbTool; use std::{ hash::{BuildHasher, Hasher}, sync::Arc, time::{Duration, Instant}, }; + +use ahash::RandomState; +use clap::Parser; +use reth_db::{DatabaseEnv, RawKey, RawTable, RawValue, TableViewer, Tables}; +use reth_db_api::{cursor::DbCursorRO, database::Database, table::Table, transaction::DbTx}; +use reth_db_common::DbTool; use tracing::{info, warn}; +use crate::commands::db::get::{maybe_json_value_parser, table_key}; + #[derive(Parser, Debug)] /// The arguments for the `reth db checksum` command pub struct Command { diff --git a/bin/reth/src/commands/db/diff.rs b/bin/reth/src/commands/db/diff.rs index cd9e24c1d7616..119f78941d3b2 100644 --- a/bin/reth/src/commands/db/diff.rs +++ b/bin/reth/src/commands/db/diff.rs @@ -1,11 +1,3 @@ -use crate::{ - args::DatabaseArgs, - dirs::{DataDirPath, PlatformPath}, -}; -use clap::Parser; -use reth_db::{open_db_read_only, tables_to_generic, DatabaseEnv, Tables}; -use reth_db_api::{cursor::DbCursorRO, database::Database, table::Table, transaction::DbTx}; -use reth_db_common::DbTool; use std::{ collections::HashMap, fmt::Debug, @@ -15,8 +7,18 @@ use std::{ path::{Path, PathBuf}, sync::Arc, }; + +use clap::Parser; +use reth_db::{open_db_read_only, tables_to_generic, DatabaseEnv, Tables}; +use reth_db_api::{cursor::DbCursorRO, database::Database, table::Table, transaction::DbTx}; +use reth_db_common::DbTool; use tracing::{info, warn}; +use crate::{ + args::DatabaseArgs, + dirs::{DataDirPath, PlatformPath}, +}; + #[derive(Parser, Debug)] /// The arguments for the `reth db diff` command pub struct Command { diff --git a/bin/reth/src/commands/db/get.rs b/bin/reth/src/commands/db/get.rs index cd721a1db4b1b..5de43714d46b8 100644 --- a/bin/reth/src/commands/db/get.rs +++ b/bin/reth/src/commands/db/get.rs @@ -201,12 +201,14 @@ pub(crate) fn maybe_json_value_parser(value: &str) -> Result. -use crate::commands::common::{AccessRights, Environment, EnvironmentArgs}; +use std::path::{Path, PathBuf}; + use clap::Parser; use reth_db::tables; use reth_db_api::{database::Database, transaction::DbTx}; @@ -20,9 +21,10 @@ use reth_provider::{ }; use reth_stages::StageId; use reth_static_file_types::StaticFileSegment; -use std::path::{Path, PathBuf}; use tracing::{debug, error, info, trace}; +use crate::commands::common::{AccessRights, Environment, EnvironmentArgs}; + /// Initializes the database with the genesis block. #[derive(Debug, Parser)] pub struct ImportReceiptsOpCommand { diff --git a/bin/reth/src/commands/init_cmd.rs b/bin/reth/src/commands/init_cmd.rs index 22657f0c02550..db6779f800d7d 100644 --- a/bin/reth/src/commands/init_cmd.rs +++ b/bin/reth/src/commands/init_cmd.rs @@ -1,10 +1,11 @@ //! Command that initializes the node from a genesis file. -use crate::commands::common::{AccessRights, Environment, EnvironmentArgs}; use clap::Parser; use reth_provider::BlockHashReader; use tracing::info; +use crate::commands::common::{AccessRights, Environment, EnvironmentArgs}; + /// Initializes the database with the genesis block. #[derive(Debug, Parser)] pub struct InitCommand { diff --git a/bin/reth/src/commands/init_state.rs b/bin/reth/src/commands/init_state.rs index dbf45e5816a6f..ee5d89c07dd93 100644 --- a/bin/reth/src/commands/init_state.rs +++ b/bin/reth/src/commands/init_state.rs @@ -1,16 +1,17 @@ //! Command that initializes the node from a genesis file. -use crate::commands::common::{AccessRights, Environment, EnvironmentArgs}; +use std::{fs::File, io::BufReader, path::PathBuf}; + use clap::Parser; use reth_config::config::EtlConfig; use reth_db_api::database::Database; use reth_db_common::init::init_from_state_dump; use reth_primitives::B256; use reth_provider::ProviderFactory; - -use std::{fs::File, io::BufReader, path::PathBuf}; use tracing::info; +use crate::commands::common::{AccessRights, Environment, EnvironmentArgs}; + /// Initializes the database with the genesis block. #[derive(Debug, Parser)] pub struct InitStateCommand { diff --git a/bin/reth/src/commands/node/mod.rs b/bin/reth/src/commands/node/mod.rs index f4c355b1757f0..b97eefc3d212b 100644 --- a/bin/reth/src/commands/node/mod.rs +++ b/bin/reth/src/commands/node/mod.rs @@ -1,17 +1,19 @@ //! Main node command for launching a node -use crate::args::{ - utils::{chain_help, chain_value_parser, parse_socket_address, SUPPORTED_CHAINS}, - DatabaseArgs, DatadirArgs, DebugArgs, DevArgs, NetworkArgs, PayloadBuilderArgs, PruningArgs, - RpcServerArgs, TxPoolArgs, -}; +use std::{ffi::OsString, fmt, future::Future, net::SocketAddr, path::PathBuf, sync::Arc}; + use clap::{value_parser, Args, Parser}; use reth_chainspec::ChainSpec; use reth_cli_runner::CliContext; use reth_db::{init_db, DatabaseEnv}; use reth_node_builder::{NodeBuilder, WithLaunchContext}; use reth_node_core::{node_config::NodeConfig, version}; -use std::{ffi::OsString, fmt, future::Future, net::SocketAddr, path::PathBuf, sync::Arc}; + +use crate::args::{ + utils::{chain_help, chain_value_parser, parse_socket_address, SUPPORTED_CHAINS}, + DatabaseArgs, DatadirArgs, DebugArgs, DevArgs, NetworkArgs, PayloadBuilderArgs, PruningArgs, + RpcServerArgs, TxPoolArgs, +}; /// Start the node #[derive(Debug, Parser)] @@ -196,13 +198,15 @@ pub struct NoArgs; #[cfg(test)] mod tests { - use super::*; - use reth_discv4::DEFAULT_DISCOVERY_PORT; use std::{ net::{IpAddr, Ipv4Addr}, path::Path, }; + use reth_discv4::DEFAULT_DISCOVERY_PORT; + + use super::*; + #[test] fn parse_help_node_command() { let err = NodeCommand::try_parse_args_from(["reth", "--help"]).unwrap_err(); diff --git a/bin/reth/src/commands/p2p/mod.rs b/bin/reth/src/commands/p2p/mod.rs index 290a0a0b08bb8..e07327169ad4d 100644 --- a/bin/reth/src/commands/p2p/mod.rs +++ b/bin/reth/src/commands/p2p/mod.rs @@ -1,13 +1,11 @@ //! P2P Debugging tool -use crate::{ - args::{ - get_secret_key, - utils::{chain_help, chain_value_parser, hash_or_num_value_parser, SUPPORTED_CHAINS}, - DatabaseArgs, DiscoveryArgs, NetworkArgs, - }, - utils::get_single_header, +use std::{ + net::{IpAddr, SocketAddrV4, SocketAddrV6}, + path::PathBuf, + sync::Arc, }; + use backon::{ConstantBuilder, Retryable}; use clap::{Parser, Subcommand}; use discv5::ListenConfig; @@ -19,10 +17,14 @@ use reth_network_p2p::bodies::client::BodiesClient; use reth_node_core::args::DatadirArgs; use reth_primitives::BlockHashOrNumber; use reth_provider::{providers::StaticFileProvider, ProviderFactory}; -use std::{ - net::{IpAddr, SocketAddrV4, SocketAddrV6}, - path::PathBuf, - sync::Arc, + +use crate::{ + args::{ + get_secret_key, + utils::{chain_help, chain_value_parser, hash_or_num_value_parser, SUPPORTED_CHAINS}, + DatabaseArgs, DiscoveryArgs, NetworkArgs, + }, + utils::get_single_header, }; /// `reth p2p` command diff --git a/bin/reth/src/commands/prune.rs b/bin/reth/src/commands/prune.rs index f3b0fcaab9660..778e86b34d79e 100644 --- a/bin/reth/src/commands/prune.rs +++ b/bin/reth/src/commands/prune.rs @@ -1,11 +1,12 @@ //! Command that runs pruning without any limits. -use crate::commands::common::{AccessRights, Environment, EnvironmentArgs}; use clap::Parser; use reth_prune::PrunerBuilder; use reth_static_file::StaticFileProducer; use tracing::info; +use crate::commands::common::{AccessRights, Environment, EnvironmentArgs}; + /// Prunes according to the configuration without any limits #[derive(Debug, Parser)] pub struct PruneCommand { diff --git a/bin/reth/src/commands/recover/storage_tries.rs b/bin/reth/src/commands/recover/storage_tries.rs index b1dbbfa88ce57..94423bee5bd28 100644 --- a/bin/reth/src/commands/recover/storage_tries.rs +++ b/bin/reth/src/commands/recover/storage_tries.rs @@ -1,4 +1,3 @@ -use crate::commands::common::{AccessRights, Environment, EnvironmentArgs}; use clap::Parser; use reth_cli_runner::CliContext; use reth_db::tables; @@ -10,6 +9,8 @@ use reth_provider::{BlockNumReader, HeaderProvider, ProviderError}; use reth_trie::StateRoot; use tracing::*; +use crate::commands::common::{AccessRights, Environment, EnvironmentArgs}; + /// `reth recover storage-tries` command #[derive(Debug, Parser)] pub struct Command { diff --git a/bin/reth/src/commands/stage/drop.rs b/bin/reth/src/commands/stage/drop.rs index ec32af330e973..a3a9933f026bf 100644 --- a/bin/reth/src/commands/stage/drop.rs +++ b/bin/reth/src/commands/stage/drop.rs @@ -1,9 +1,5 @@ //! Database debugging tool -use crate::{ - args::StageEnum, - commands::common::{AccessRights, Environment, EnvironmentArgs}, -}; use clap::Parser; use itertools::Itertools; use reth_db::{static_file::iter_static_files, tables, DatabaseEnv}; @@ -16,6 +12,11 @@ use reth_provider::{providers::StaticFileWriter, StaticFileProviderFactory}; use reth_stages::StageId; use reth_static_file_types::{find_fixed_range, StaticFileSegment}; +use crate::{ + args::StageEnum, + commands::common::{AccessRights, Environment, EnvironmentArgs}, +}; + /// `reth drop-stage` command #[derive(Debug, Parser)] pub struct Command { diff --git a/bin/reth/src/commands/stage/dump/execution.rs b/bin/reth/src/commands/stage/dump/execution.rs index 67b6d5a659c40..ed7c2ec12bf66 100644 --- a/bin/reth/src/commands/stage/dump/execution.rs +++ b/bin/reth/src/commands/stage/dump/execution.rs @@ -1,5 +1,3 @@ -use super::setup; -use crate::macros::block_executor; use reth_db::{tables, DatabaseEnv}; use reth_db_api::{ cursor::DbCursorRO, database::Database, table::TableImporter, transaction::DbTx, @@ -10,6 +8,9 @@ use reth_provider::{providers::StaticFileProvider, ChainSpecProvider, ProviderFa use reth_stages::{stages::ExecutionStage, Stage, StageCheckpoint, UnwindInput}; use tracing::info; +use super::setup; +use crate::macros::block_executor; + pub(crate) async fn dump_execution_stage( db_tool: &DbTool, from: u64, diff --git a/bin/reth/src/commands/stage/dump/hashing_account.rs b/bin/reth/src/commands/stage/dump/hashing_account.rs index 899b521fdc57b..dcf6dee1cae44 100644 --- a/bin/reth/src/commands/stage/dump/hashing_account.rs +++ b/bin/reth/src/commands/stage/dump/hashing_account.rs @@ -1,4 +1,3 @@ -use super::setup; use eyre::Result; use reth_db::{tables, DatabaseEnv}; use reth_db_api::{database::Database, table::TableImporter}; @@ -9,6 +8,8 @@ use reth_provider::{providers::StaticFileProvider, ProviderFactory}; use reth_stages::{stages::AccountHashingStage, Stage, StageCheckpoint, UnwindInput}; use tracing::info; +use super::setup; + pub(crate) async fn dump_hashing_account_stage( db_tool: &DbTool, from: BlockNumber, diff --git a/bin/reth/src/commands/stage/dump/hashing_storage.rs b/bin/reth/src/commands/stage/dump/hashing_storage.rs index f05ac390dc8e2..b32b2e0d9f38d 100644 --- a/bin/reth/src/commands/stage/dump/hashing_storage.rs +++ b/bin/reth/src/commands/stage/dump/hashing_storage.rs @@ -1,4 +1,3 @@ -use super::setup; use eyre::Result; use reth_db::{tables, DatabaseEnv}; use reth_db_api::{database::Database, table::TableImporter}; @@ -8,6 +7,8 @@ use reth_provider::{providers::StaticFileProvider, ProviderFactory}; use reth_stages::{stages::StorageHashingStage, Stage, StageCheckpoint, UnwindInput}; use tracing::info; +use super::setup; + pub(crate) async fn dump_hashing_storage_stage( db_tool: &DbTool, from: u64, diff --git a/bin/reth/src/commands/stage/dump/merkle.rs b/bin/reth/src/commands/stage/dump/merkle.rs index 85fd0bfcab57f..77deab93bdfce 100644 --- a/bin/reth/src/commands/stage/dump/merkle.rs +++ b/bin/reth/src/commands/stage/dump/merkle.rs @@ -1,5 +1,3 @@ -use super::setup; -use crate::macros::block_executor; use eyre::Result; use reth_config::config::EtlConfig; use reth_db::{tables, DatabaseEnv}; @@ -19,6 +17,9 @@ use reth_stages::{ }; use tracing::info; +use super::setup; +use crate::macros::block_executor; + pub(crate) async fn dump_merkle_stage( db_tool: &DbTool, from: BlockNumber, diff --git a/bin/reth/src/commands/stage/dump/mod.rs b/bin/reth/src/commands/stage/dump/mod.rs index f1fbdbbdecbdb..fd76fe4fb026a 100644 --- a/bin/reth/src/commands/stage/dump/mod.rs +++ b/bin/reth/src/commands/stage/dump/mod.rs @@ -1,10 +1,7 @@ //! Database debugging tool -use crate::{ - args::DatadirArgs, - commands::common::{AccessRights, Environment, EnvironmentArgs}, - dirs::DataDirPath, -}; +use std::path::PathBuf; + use clap::Parser; use reth_db::{init_db, mdbx::DatabaseArguments, tables, DatabaseEnv}; use reth_db_api::{ @@ -13,9 +10,14 @@ use reth_db_api::{ }; use reth_db_common::DbTool; use reth_node_core::dirs::PlatformPath; -use std::path::PathBuf; use tracing::info; +use crate::{ + args::DatadirArgs, + commands::common::{AccessRights, Environment, EnvironmentArgs}, + dirs::DataDirPath, +}; + mod hashing_storage; use hashing_storage::dump_hashing_storage_stage; diff --git a/bin/reth/src/commands/stage/run.rs b/bin/reth/src/commands/stage/run.rs index b8dcc7c9194dd..1ef6c5c81dad4 100644 --- a/bin/reth/src/commands/stage/run.rs +++ b/bin/reth/src/commands/stage/run.rs @@ -2,12 +2,8 @@ //! //! Stage debugging tool -use crate::{ - args::{get_secret_key, NetworkArgs, StageEnum}, - commands::common::{AccessRights, Environment, EnvironmentArgs}, - macros::block_executor, - prometheus_exporter, -}; +use std::{any::Any, net::SocketAddr, sync::Arc, time::Instant}; + use clap::Parser; use reth_beacon_consensus::EthBeaconConsensus; use reth_cli_runner::CliContext; @@ -26,9 +22,15 @@ use reth_stages::{ }, ExecInput, ExecOutput, Stage, StageExt, UnwindInput, UnwindOutput, }; -use std::{any::Any, net::SocketAddr, sync::Arc, time::Instant}; use tracing::*; +use crate::{ + args::{get_secret_key, NetworkArgs, StageEnum}, + commands::common::{AccessRights, Environment, EnvironmentArgs}, + macros::block_executor, + prometheus_exporter, +}; + /// `reth stage` command #[derive(Debug, Parser)] pub struct Command { diff --git a/bin/reth/src/commands/stage/unwind.rs b/bin/reth/src/commands/stage/unwind.rs index 57088eaf2e2df..3708421b4325d 100644 --- a/bin/reth/src/commands/stage/unwind.rs +++ b/bin/reth/src/commands/stage/unwind.rs @@ -1,5 +1,7 @@ //! Unwinding a certain block range +use std::{ops::RangeInclusive, sync::Arc}; + use clap::{Parser, Subcommand}; use reth_beacon_consensus::EthBeaconConsensus; use reth_config::Config; @@ -20,7 +22,6 @@ use reth_stages::{ Pipeline, StageSet, }; use reth_static_file::StaticFileProducer; -use std::{ops::RangeInclusive, sync::Arc}; use tokio::sync::watch; use tracing::info; diff --git a/bin/reth/src/commands/test_vectors/tables.rs b/bin/reth/src/commands/test_vectors/tables.rs index d7138444f69a7..51392e25233f2 100644 --- a/bin/reth/src/commands/test_vectors/tables.rs +++ b/bin/reth/src/commands/test_vectors/tables.rs @@ -1,3 +1,5 @@ +use std::collections::HashSet; + use arbitrary::Arbitrary; use eyre::Result; use proptest::{ @@ -9,7 +11,6 @@ use proptest_arbitrary_interop::arb; use reth_db::tables; use reth_db_api::table::{DupSort, Table, TableRow}; use reth_fs_util as fs; -use std::collections::HashSet; use tracing::error; const VECTORS_FOLDER: &str = "testdata/micro/db"; diff --git a/bin/reth/src/lib.rs b/bin/reth/src/lib.rs index 35cd1357a12c7..88f0f9c855f9d 100644 --- a/bin/reth/src/lib.rs +++ b/bin/reth/src/lib.rs @@ -36,7 +36,6 @@ mod macros; /// Re-exported utils. pub mod utils { pub use reth_db::open_db_read_only; - /// Re-exported from `reth_node_core`, also to prevent a breaking change. See the comment /// on the `reth_node_core::args` re-export for more details. pub use reth_node_core::utils::*; @@ -184,8 +183,7 @@ pub mod sigsegv_handler { pub fn install() {} } -#[cfg(all(feature = "jemalloc", unix))] -use tikv_jemallocator as _; - // for rendering diagrams use aquamarine as _; +#[cfg(all(feature = "jemalloc", unix))] +use tikv_jemallocator as _; diff --git a/bin/reth/src/optimism.rs b/bin/reth/src/optimism.rs index 58171879774a1..7797772e1b347 100644 --- a/bin/reth/src/optimism.rs +++ b/bin/reth/src/optimism.rs @@ -1,9 +1,10 @@ #![allow(missing_docs, rustdoc::missing_crate_level_docs)] +use std::sync::Arc; + use clap::Parser; use reth::cli::Cli; use reth_node_optimism::{args::RollupArgs, rpc::SequencerClient, OptimismNode}; -use std::sync::Arc; // We use jemalloc for performance reasons #[cfg(all(feature = "jemalloc", unix))] diff --git a/crates/blockchain-tree-api/src/lib.rs b/crates/blockchain-tree-api/src/lib.rs index b1f1240bb5b77..058f97a856d7f 100644 --- a/crates/blockchain-tree-api/src/lib.rs +++ b/crates/blockchain-tree-api/src/lib.rs @@ -7,14 +7,16 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -use self::error::CanonicalError; -use crate::error::InsertBlockError; +use std::collections::BTreeMap; + use reth_primitives::{ BlockHash, BlockNumHash, BlockNumber, Receipt, SealedBlock, SealedBlockWithSenders, SealedHeader, }; use reth_storage_errors::provider::{ProviderError, ProviderResult}; -use std::collections::BTreeMap; + +use self::error::CanonicalError; +use crate::error::InsertBlockError; pub mod error; diff --git a/crates/blockchain-tree/src/block_buffer.rs b/crates/blockchain-tree/src/block_buffer.rs index 6ad4bd3fa1e04..d6b287592467d 100644 --- a/crates/blockchain-tree/src/block_buffer.rs +++ b/crates/blockchain-tree/src/block_buffer.rs @@ -1,7 +1,9 @@ -use crate::metrics::BlockBufferMetrics; +use std::collections::{btree_map, hash_map, BTreeMap, HashMap, HashSet}; + use reth_network::cache::LruCache; use reth_primitives::{BlockHash, BlockNumber, SealedBlockWithSenders}; -use std::collections::{btree_map, hash_map, BTreeMap, HashMap, HashSet}; + +use crate::metrics::BlockBufferMetrics; /// Contains the tree of pending blocks that cannot be executed due to missing parent. /// It allows to store unconnected blocks for potential future inclusion. @@ -181,13 +183,15 @@ impl BlockBuffer { #[cfg(test)] mod tests { - use crate::BlockBuffer; + use std::collections::HashMap; + use reth_primitives::{BlockHash, BlockNumHash, SealedBlockWithSenders}; use reth_testing_utils::{ generators, generators::{random_block, Rng}, }; - use std::collections::HashMap; + + use crate::BlockBuffer; /// Create random block with specified number and parent hash. fn create_block(rng: &mut R, number: u64, parent: BlockHash) -> SealedBlockWithSenders { diff --git a/crates/blockchain-tree/src/block_indices.rs b/crates/blockchain-tree/src/block_indices.rs index b080f26bda333..1d9323d781c99 100644 --- a/crates/blockchain-tree/src/block_indices.rs +++ b/crates/blockchain-tree/src/block_indices.rs @@ -1,11 +1,13 @@ //! Implementation of [`BlockIndices`] related to [`super::BlockchainTree`] -use super::state::BlockchainId; -use crate::canonical_chain::CanonicalChain; +use std::collections::{btree_map, hash_map, BTreeMap, BTreeSet, HashMap, HashSet}; + use linked_hash_set::LinkedHashSet; use reth_execution_types::Chain; use reth_primitives::{BlockHash, BlockNumHash, BlockNumber, SealedBlockWithSenders}; -use std::collections::{btree_map, hash_map, BTreeMap, BTreeSet, HashMap, HashSet}; + +use super::state::BlockchainId; +use crate::canonical_chain::CanonicalChain; /// Internal indices of the blocks and chains. /// diff --git a/crates/blockchain-tree/src/blockchain_tree.rs b/crates/blockchain-tree/src/blockchain_tree.rs index 5d73a1a78e06f..6b3c76ede9781 100644 --- a/crates/blockchain-tree/src/blockchain_tree.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -1,10 +1,10 @@ //! Implementation of [`BlockchainTree`] -use crate::{ - metrics::{MakeCanonicalAction, MakeCanonicalDurationsRecorder, TreeMetrics}, - state::{BlockchainId, TreeState}, - AppendableChain, BlockIndices, BlockchainTreeConfig, ExecutionData, TreeExternals, +use std::{ + collections::{btree_map::Entry, BTreeMap, HashSet}, + sync::Arc, }; + use reth_blockchain_tree_api::{ error::{BlockchainTreeError, CanonicalError, InsertBlockError, InsertBlockErrorKind}, BlockAttachment, BlockStatus, BlockValidationKind, CanonicalOutcome, InsertPayloadOk, @@ -26,12 +26,14 @@ use reth_provider::{ use reth_prune_types::PruneModes; use reth_stages_api::{MetricEvent, MetricEventsSender}; use reth_storage_errors::provider::{ProviderResult, RootMismatch}; -use std::{ - collections::{btree_map::Entry, BTreeMap, HashSet}, - sync::Arc, -}; use tracing::{debug, error, info, instrument, trace, warn}; +use crate::{ + metrics::{MakeCanonicalAction, MakeCanonicalDurationsRecorder, TreeMetrics}, + state::{BlockchainId, TreeState}, + AppendableChain, BlockIndices, BlockchainTreeConfig, ExecutionData, TreeExternals, +}; + #[cfg_attr(doc, aquamarine::aquamarine)] /// A Tree of chains. /// @@ -1366,7 +1368,8 @@ where #[cfg(test)] mod tests { - use super::*; + use std::collections::HashMap; + use alloy_genesis::{Genesis, GenesisAccount}; use assert_matches::assert_matches; use linked_hash_set::LinkedHashSet; @@ -1394,7 +1397,8 @@ mod tests { }; use reth_stages_api::StageCheckpoint; use reth_trie::{root::state_root_unhashed, StateRoot}; - use std::collections::HashMap; + + use super::*; fn setup_externals( exec_res: Vec, diff --git a/crates/blockchain-tree/src/bundle.rs b/crates/blockchain-tree/src/bundle.rs index 01d1d717f2116..c6ade61007b6c 100644 --- a/crates/blockchain-tree/src/bundle.rs +++ b/crates/blockchain-tree/src/bundle.rs @@ -1,8 +1,9 @@ //! [`ExecutionDataProvider`] implementations used by the tree. +use std::collections::BTreeMap; + use reth_primitives::{BlockHash, BlockNumber, ForkBlock}; use reth_provider::{BlockExecutionForkProvider, ExecutionDataProvider, ExecutionOutcome}; -use std::collections::BTreeMap; /// Structure that combines references of required data to be a [`ExecutionDataProvider`]. #[derive(Clone, Debug)] diff --git a/crates/blockchain-tree/src/canonical_chain.rs b/crates/blockchain-tree/src/canonical_chain.rs index 8a9893a1807f0..70c975a2ad28c 100644 --- a/crates/blockchain-tree/src/canonical_chain.rs +++ b/crates/blockchain-tree/src/canonical_chain.rs @@ -1,6 +1,7 @@ -use reth_primitives::{BlockHash, BlockNumHash, BlockNumber}; use std::collections::BTreeMap; +use reth_primitives::{BlockHash, BlockNumHash, BlockNumber}; + /// This keeps track of (non-finalized) blocks of the canonical chain. /// /// This is a wrapper type around an ordered set of block numbers and hashes that belong to the diff --git a/crates/blockchain-tree/src/chain.rs b/crates/blockchain-tree/src/chain.rs index dbc0c1d04b5f7..e17080bb56278 100644 --- a/crates/blockchain-tree/src/chain.rs +++ b/crates/blockchain-tree/src/chain.rs @@ -3,8 +3,12 @@ //! A [`Chain`] contains the state of accounts for the chain after execution of its constituent //! blocks, as well as a list of the blocks the chain is composed of. -use super::externals::TreeExternals; -use crate::BundleStateDataRef; +use std::{ + collections::BTreeMap, + ops::{Deref, DerefMut}, + time::Instant, +}; + use reth_blockchain_tree_api::{ error::{BlockchainTreeError, InsertBlockErrorKind}, BlockAttachment, BlockValidationKind, @@ -24,11 +28,9 @@ use reth_provider::{ use reth_revm::database::StateProviderDatabase; use reth_trie::updates::TrieUpdates; use reth_trie_parallel::parallel_root::ParallelStateRoot; -use std::{ - collections::BTreeMap, - ops::{Deref, DerefMut}, - time::Instant, -}; + +use super::externals::TreeExternals; +use crate::BundleStateDataRef; /// A chain in the blockchain tree that has functionality to execute blocks and append them to /// itself. diff --git a/crates/blockchain-tree/src/externals.rs b/crates/blockchain-tree/src/externals.rs index eaa19f9193bc0..c2061999c101e 100644 --- a/crates/blockchain-tree/src/externals.rs +++ b/crates/blockchain-tree/src/externals.rs @@ -1,5 +1,7 @@ //! Blockchain tree externals. +use std::{collections::BTreeMap, sync::Arc}; + use reth_consensus::Consensus; use reth_db::{static_file::HeaderMask, tables}; use reth_db_api::{cursor::DbCursorRO, database::Database, transaction::DbTx}; @@ -9,7 +11,6 @@ use reth_provider::{ StatsReader, }; use reth_storage_errors::provider::ProviderResult; -use std::{collections::BTreeMap, sync::Arc}; /// A container for external components. /// diff --git a/crates/blockchain-tree/src/metrics.rs b/crates/blockchain-tree/src/metrics.rs index 5d44a63911789..8567999ef3956 100644 --- a/crates/blockchain-tree/src/metrics.rs +++ b/crates/blockchain-tree/src/metrics.rs @@ -1,9 +1,10 @@ +use std::time::{Duration, Instant}; + use metrics::Histogram; use reth_metrics::{ metrics::{Counter, Gauge}, Metrics, }; -use std::time::{Duration, Instant}; /// Metrics for the entire blockchain tree #[derive(Metrics)] diff --git a/crates/blockchain-tree/src/noop.rs b/crates/blockchain-tree/src/noop.rs index d92131dc8ac27..98d9f99f04395 100644 --- a/crates/blockchain-tree/src/noop.rs +++ b/crates/blockchain-tree/src/noop.rs @@ -1,3 +1,5 @@ +use std::collections::BTreeMap; + use reth_blockchain_tree_api::{ self, error::{BlockchainTreeError, CanonicalError, InsertBlockError, ProviderError}, @@ -13,7 +15,6 @@ use reth_provider::{ CanonStateSubscriptions, FullExecutionDataProvider, }; use reth_storage_errors::provider::ProviderResult; -use std::collections::BTreeMap; /// A `BlockchainTree` that does nothing. /// diff --git a/crates/blockchain-tree/src/shareable.rs b/crates/blockchain-tree/src/shareable.rs index 0f7903cf06954..20bac43754b8c 100644 --- a/crates/blockchain-tree/src/shareable.rs +++ b/crates/blockchain-tree/src/shareable.rs @@ -1,6 +1,7 @@ //! Wrapper around `BlockchainTree` that allows for it to be shared. -use super::BlockchainTree; +use std::{collections::BTreeMap, sync::Arc}; + use parking_lot::RwLock; use reth_blockchain_tree_api::{ error::{CanonicalError, InsertBlockError}, @@ -18,9 +19,10 @@ use reth_provider::{ ProviderError, }; use reth_storage_errors::provider::ProviderResult; -use std::{collections::BTreeMap, sync::Arc}; use tracing::trace; +use super::BlockchainTree; + /// Shareable blockchain tree that is behind a `RwLock` #[derive(Clone, Debug)] pub struct ShareableBlockchainTree { diff --git a/crates/blockchain-tree/src/state.rs b/crates/blockchain-tree/src/state.rs index e44e1aae552a7..7825fe6500cab 100644 --- a/crates/blockchain-tree/src/state.rs +++ b/crates/blockchain-tree/src/state.rs @@ -1,9 +1,11 @@ //! Blockchain tree state. -use crate::{AppendableChain, BlockBuffer, BlockIndices}; -use reth_primitives::{BlockHash, BlockNumber, Receipt, SealedBlock, SealedBlockWithSenders}; use std::collections::{BTreeMap, HashMap}; +use reth_primitives::{BlockHash, BlockNumber, Receipt, SealedBlock, SealedBlockWithSenders}; + +use crate::{AppendableChain, BlockBuffer, BlockIndices}; + /// Container to hold the state of the blockchain tree. #[derive(Debug)] pub(crate) struct TreeState { diff --git a/crates/chainspec/src/constants/mod.rs b/crates/chainspec/src/constants/mod.rs index 9af4f946b92d6..68dc01bbc7621 100644 --- a/crates/chainspec/src/constants/mod.rs +++ b/crates/chainspec/src/constants/mod.rs @@ -1,6 +1,7 @@ -use crate::spec::DepositContract; use alloy_primitives::{address, b256}; +use crate::spec::DepositContract; + /// Deposit contract address: `0x00000000219ab540356cbb839cbe05303d7705fa` pub(crate) const MAINNET_DEPOSIT_CONTRACT: DepositContract = DepositContract::new( address!("00000000219ab540356cbb839cbe05303d7705fa"), diff --git a/crates/chainspec/src/constants/optimism.rs b/crates/chainspec/src/constants/optimism.rs index d4a1de6d0ea4b..fab3531072266 100644 --- a/crates/chainspec/src/constants/optimism.rs +++ b/crates/chainspec/src/constants/optimism.rs @@ -47,9 +47,10 @@ pub(crate) const OP_CANYON_BASE_FEE_PARAMS: BaseFeeParams = BaseFeeParams { #[cfg(test)] mod tests { - use super::*; use alloy_eips::calc_next_block_base_fee; + use super::*; + #[test] fn calculate_optimism_base_fee_success() { let base_fee = [ diff --git a/crates/chainspec/src/lib.rs b/crates/chainspec/src/lib.rs index 8dd598abdfb49..1d7f1e9a6f37c 100644 --- a/crates/chainspec/src/lib.rs +++ b/crates/chainspec/src/lib.rs @@ -40,10 +40,12 @@ pub use reth_ethereum_forks::*; #[cfg(test)] mod tests { - use super::*; + use std::str::FromStr; + use alloy_primitives::U256; use alloy_rlp::Encodable; - use std::str::FromStr; + + use super::*; #[test] fn test_id() { diff --git a/crates/chainspec/src/net.rs b/crates/chainspec/src/net.rs index 922a7df574caa..f78faa3ac7dc6 100644 --- a/crates/chainspec/src/net.rs +++ b/crates/chainspec/src/net.rs @@ -1,8 +1,8 @@ -pub use reth_network_peers::{NodeRecord, NodeRecordParseError, TrustedPeer}; - #[cfg(not(feature = "std"))] use alloc::vec::Vec; +pub use reth_network_peers::{NodeRecord, NodeRecordParseError, TrustedPeer}; + // Ethereum bootnodes come from // OP bootnodes come from @@ -123,10 +123,12 @@ pub fn parse_nodes(nodes: impl IntoIterator>) -> Vec> = Lazy::new(|| { @@ -1232,13 +1234,15 @@ impl OptimismGenesisInfo { #[cfg(test)] mod tests { - use super::*; + use std::{collections::HashMap, str::FromStr}; + use alloy_chains::Chain; use alloy_genesis::{ChainConfig, GenesisAccount}; use alloy_primitives::{b256, hex}; use reth_ethereum_forks::{ForkCondition, ForkHash, ForkId, Head}; use reth_trie_common::TrieAccount; - use std::{collections::HashMap, str::FromStr}; + + use super::*; fn test_fork_ids(spec: &ChainSpec, cases: &[(Head, ForkId)]) { for (block, expected_id) in cases { diff --git a/crates/cli/runner/src/lib.rs b/crates/cli/runner/src/lib.rs index a848ad0b21d24..3a70fe4785108 100644 --- a/crates/cli/runner/src/lib.rs +++ b/crates/cli/runner/src/lib.rs @@ -10,8 +10,9 @@ //! Entrypoint for running commands. -use reth_tasks::{TaskExecutor, TaskManager}; use std::{future::Future, pin::pin, sync::mpsc, time::Duration}; + +use reth_tasks::{TaskExecutor, TaskManager}; use tracing::{debug, error, trace}; /// Executes CLI commands. diff --git a/crates/config/src/config.rs b/crates/config/src/config.rs index 5d79549d4e47a..d01096a5780d3 100644 --- a/crates/config/src/config.rs +++ b/crates/config/src/config.rs @@ -1,14 +1,15 @@ //! Configuration files. -use reth_network_types::{PeersConfig, SessionsConfig}; -use reth_prune_types::PruneModes; -use serde::{Deserialize, Deserializer, Serialize}; use std::{ ffi::OsStr, path::{Path, PathBuf}, time::Duration, }; +use reth_network_types::{PeersConfig, SessionsConfig}; +use reth_prune_types::PruneModes; +use serde::{Deserialize, Deserializer, Serialize}; + const EXTENSION: &str = "toml"; /// Configuration for the reth node. @@ -354,9 +355,10 @@ where #[cfg(test)] mod tests { - use super::{Config, EXTENSION}; use std::time::Duration; + use super::{Config, EXTENSION}; + fn with_tempdir(filename: &str, proc: fn(&std::path::Path)) { let temp_dir = tempfile::tempdir().unwrap(); let config_path = temp_dir.path().join(filename).with_extension(EXTENSION); diff --git a/crates/consensus/auto-seal/src/client.rs b/crates/consensus/auto-seal/src/client.rs index b9befa73857b7..f62428f304ee5 100644 --- a/crates/consensus/auto-seal/src/client.rs +++ b/crates/consensus/auto-seal/src/client.rs @@ -1,6 +1,7 @@ //! This includes download client implementations for auto sealing miners. -use crate::Storage; +use std::fmt::Debug; + use reth_network_p2p::{ bodies::client::{BodiesClient, BodiesFut}, download::DownloadClient, @@ -9,9 +10,10 @@ use reth_network_p2p::{ }; use reth_network_peers::{PeerId, WithPeerId}; use reth_primitives::{BlockBody, BlockHashOrNumber, Header, HeadersDirection, B256}; -use std::fmt::Debug; use tracing::{trace, warn}; +use crate::Storage; + /// A download client that polls the miner for transactions and assembles blocks to be returned in /// the download process. /// diff --git a/crates/consensus/auto-seal/src/lib.rs b/crates/consensus/auto-seal/src/lib.rs index ba6c67487e205..fbd4f79357164 100644 --- a/crates/consensus/auto-seal/src/lib.rs +++ b/crates/consensus/auto-seal/src/lib.rs @@ -15,6 +15,12 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +use std::{ + collections::HashMap, + sync::Arc, + time::{SystemTime, UNIX_EPOCH}, +}; + use reth_beacon_consensus::BeaconEngineMessage; use reth_chainspec::ChainSpec; use reth_consensus::{Consensus, ConsensusError, PostExecutionInput}; @@ -29,11 +35,6 @@ use reth_primitives::{ use reth_provider::{BlockReaderIdExt, StateProviderFactory, StateRootProvider}; use reth_revm::database::StateProviderDatabase; use reth_transaction_pool::TransactionPool; -use std::{ - collections::HashMap, - sync::Arc, - time::{SystemTime, UNIX_EPOCH}, -}; use tokio::sync::{mpsc::UnboundedSender, RwLock, RwLockReadGuard, RwLockWriteGuard}; use tracing::trace; @@ -41,11 +42,12 @@ mod client; mod mode; mod task; -pub use crate::client::AutoSealClient; pub use mode::{FixedBlockTimeMiner, MiningMode, ReadyTransactionMiner}; use reth_evm::execute::{BlockExecutionOutput, BlockExecutorProvider, Executor}; pub use task::MiningTask; +pub use crate::client::AutoSealClient; + /// A consensus implementation intended for local development and testing purposes. #[derive(Debug, Clone)] #[allow(dead_code)] diff --git a/crates/consensus/auto-seal/src/mode.rs b/crates/consensus/auto-seal/src/mode.rs index 2ff918af63dc2..5c1af0f2057e7 100644 --- a/crates/consensus/auto-seal/src/mode.rs +++ b/crates/consensus/auto-seal/src/mode.rs @@ -1,8 +1,5 @@ //! The mode the auto seal miner is operating in. -use futures_util::{stream::Fuse, StreamExt}; -use reth_primitives::TxHash; -use reth_transaction_pool::{TransactionPool, ValidPoolTransaction}; use std::{ fmt, pin::Pin, @@ -10,6 +7,10 @@ use std::{ task::{Context, Poll}, time::Duration, }; + +use futures_util::{stream::Fuse, StreamExt}; +use reth_primitives::TxHash; +use reth_transaction_pool::{TransactionPool, ValidPoolTransaction}; use tokio::{sync::mpsc::Receiver, time::Interval}; use tokio_stream::{wrappers::ReceiverStream, Stream}; diff --git a/crates/consensus/auto-seal/src/task.rs b/crates/consensus/auto-seal/src/task.rs index 856d02631cb02..5e3c3b516f756 100644 --- a/crates/consensus/auto-seal/src/task.rs +++ b/crates/consensus/auto-seal/src/task.rs @@ -1,4 +1,11 @@ -use crate::{mode::MiningMode, Storage}; +use std::{ + collections::VecDeque, + future::Future, + pin::Pin, + sync::Arc, + task::{Context, Poll}, +}; + use futures_util::{future::BoxFuture, FutureExt}; use reth_beacon_consensus::{BeaconEngineMessage, ForkchoiceStatus}; use reth_chainspec::ChainSpec; @@ -10,16 +17,11 @@ use reth_rpc_types::engine::ForkchoiceState; use reth_stages_api::PipelineEvent; use reth_tokio_util::EventStream; use reth_transaction_pool::{TransactionPool, ValidPoolTransaction}; -use std::{ - collections::VecDeque, - future::Future, - pin::Pin, - sync::Arc, - task::{Context, Poll}, -}; use tokio::sync::{mpsc::UnboundedSender, oneshot}; use tracing::{debug, error, warn}; +use crate::{mode::MiningMode, Storage}; + /// A Future that listens for new ready transactions and puts new blocks into storage pub struct MiningTask { /// The configured chain spec diff --git a/crates/consensus/beacon/src/engine/error.rs b/crates/consensus/beacon/src/engine/error.rs index 041a0c9445b55..0dd3ed62527d0 100644 --- a/crates/consensus/beacon/src/engine/error.rs +++ b/crates/consensus/beacon/src/engine/error.rs @@ -1,8 +1,9 @@ -use crate::engine::hooks::EngineHookError; use reth_errors::{DatabaseError, RethError}; use reth_rpc_types::engine::ForkchoiceUpdateError; use reth_stages_api::PipelineError; +use crate::engine::hooks::EngineHookError; + /// Beacon engine result. pub type BeaconEngineResult = Result; diff --git a/crates/consensus/beacon/src/engine/event.rs b/crates/consensus/beacon/src/engine/event.rs index 4b092bd2feb27..5f94bd5eecc29 100644 --- a/crates/consensus/beacon/src/engine/event.rs +++ b/crates/consensus/beacon/src/engine/event.rs @@ -1,7 +1,9 @@ -use crate::engine::forkchoice::ForkchoiceStatus; +use std::{sync::Arc, time::Duration}; + use reth_primitives::{SealedBlock, SealedHeader, B256}; use reth_rpc_types::engine::ForkchoiceState; -use std::{sync::Arc, time::Duration}; + +use crate::engine::forkchoice::ForkchoiceStatus; /// Events emitted by [`crate::BeaconConsensusEngine`]. #[derive(Clone, Debug)] diff --git a/crates/consensus/beacon/src/engine/handle.rs b/crates/consensus/beacon/src/engine/handle.rs index 0f0d9e1da80b8..00ec27df9ff4b 100644 --- a/crates/consensus/beacon/src/engine/handle.rs +++ b/crates/consensus/beacon/src/engine/handle.rs @@ -1,9 +1,5 @@ //! `BeaconConsensusEngine` external API -use crate::{ - engine::message::OnForkChoiceUpdated, BeaconConsensusEngineEvent, BeaconEngineMessage, - BeaconForkChoiceUpdateError, BeaconOnNewPayloadError, -}; use futures::TryFutureExt; use reth_engine_primitives::EngineTypes; use reth_errors::RethResult; @@ -13,6 +9,11 @@ use reth_rpc_types::engine::{ use reth_tokio_util::{EventSender, EventStream}; use tokio::sync::{mpsc::UnboundedSender, oneshot}; +use crate::{ + engine::message::OnForkChoiceUpdated, BeaconConsensusEngineEvent, BeaconEngineMessage, + BeaconForkChoiceUpdateError, BeaconOnNewPayloadError, +}; + /// A _shareable_ beacon consensus frontend type. Used to interact with the spawned beacon consensus /// engine task. /// diff --git a/crates/consensus/beacon/src/engine/hooks/controller.rs b/crates/consensus/beacon/src/engine/hooks/controller.rs index bd5c8a9e2b91c..2a3d9f71c7207 100644 --- a/crates/consensus/beacon/src/engine/hooks/controller.rs +++ b/crates/consensus/beacon/src/engine/hooks/controller.rs @@ -1,13 +1,15 @@ -use crate::hooks::{ - EngineHook, EngineHookContext, EngineHookDBAccessLevel, EngineHookError, EngineHookEvent, - EngineHooks, -}; use std::{ collections::VecDeque, task::{Context, Poll}, }; + use tracing::debug; +use crate::hooks::{ + EngineHook, EngineHookContext, EngineHookDBAccessLevel, EngineHookError, EngineHookEvent, + EngineHooks, +}; + #[derive(Debug)] pub(crate) struct PolledHook { pub(crate) name: &'static str, @@ -171,18 +173,20 @@ impl EngineHooksController { #[cfg(test)] mod tests { - use crate::hooks::{ - EngineHook, EngineHookContext, EngineHookDBAccessLevel, EngineHookEvent, EngineHooks, - EngineHooksController, - }; - use futures::poll; - use reth_errors::{RethError, RethResult}; use std::{ collections::VecDeque, future::poll_fn, task::{Context, Poll}, }; + use futures::poll; + use reth_errors::{RethError, RethResult}; + + use crate::hooks::{ + EngineHook, EngineHookContext, EngineHookDBAccessLevel, EngineHookEvent, EngineHooks, + EngineHooksController, + }; + struct TestHook { results: VecDeque>, name: &'static str, diff --git a/crates/consensus/beacon/src/engine/hooks/mod.rs b/crates/consensus/beacon/src/engine/hooks/mod.rs index 5d699921a6508..e408318d47971 100644 --- a/crates/consensus/beacon/src/engine/hooks/mod.rs +++ b/crates/consensus/beacon/src/engine/hooks/mod.rs @@ -1,10 +1,11 @@ -use reth_errors::{RethError, RethResult}; -use reth_primitives::BlockNumber; use std::{ fmt, task::{Context, Poll}, }; +use reth_errors::{RethError, RethResult}; +use reth_primitives::BlockNumber; + mod controller; pub(crate) use controller::{EngineHooksController, PolledHook}; diff --git a/crates/consensus/beacon/src/engine/hooks/prune.rs b/crates/consensus/beacon/src/engine/hooks/prune.rs index 7ea84ea935690..8ce7328d5ba5d 100644 --- a/crates/consensus/beacon/src/engine/hooks/prune.rs +++ b/crates/consensus/beacon/src/engine/hooks/prune.rs @@ -1,9 +1,10 @@ //! Prune hook for the engine implementation. -use crate::{ - engine::hooks::{EngineHook, EngineHookContext, EngineHookError, EngineHookEvent}, - hooks::EngineHookDBAccessLevel, +use std::{ + fmt, + task::{ready, Context, Poll}, }; + use futures::FutureExt; use metrics::Counter; use reth_db_api::database::Database; @@ -11,12 +12,13 @@ use reth_errors::{RethError, RethResult}; use reth_primitives::BlockNumber; use reth_prune::{Pruner, PrunerError, PrunerWithResult}; use reth_tasks::TaskSpawner; -use std::{ - fmt, - task::{ready, Context, Poll}, -}; use tokio::sync::oneshot; +use crate::{ + engine::hooks::{EngineHook, EngineHookContext, EngineHookError, EngineHookEvent}, + hooks::EngineHookDBAccessLevel, +}; + /// Manages pruning under the control of the engine. /// /// This type controls the [Pruner]. diff --git a/crates/consensus/beacon/src/engine/hooks/static_file.rs b/crates/consensus/beacon/src/engine/hooks/static_file.rs index 43c47ef41b02f..f1ce0216004bd 100644 --- a/crates/consensus/beacon/src/engine/hooks/static_file.rs +++ b/crates/consensus/beacon/src/engine/hooks/static_file.rs @@ -1,19 +1,21 @@ //! `StaticFile` hook for the engine implementation. -use crate::{ - engine::hooks::{EngineHook, EngineHookContext, EngineHookError, EngineHookEvent}, - hooks::EngineHookDBAccessLevel, -}; +use std::task::{ready, Context, Poll}; + use futures::FutureExt; use reth_db_api::database::Database; use reth_errors::RethResult; use reth_primitives::{static_file::HighestStaticFiles, BlockNumber}; use reth_static_file::{StaticFileProducer, StaticFileProducerWithResult}; use reth_tasks::TaskSpawner; -use std::task::{ready, Context, Poll}; use tokio::sync::oneshot; use tracing::trace; +use crate::{ + engine::hooks::{EngineHook, EngineHookContext, EngineHookError, EngineHookEvent}, + hooks::EngineHookDBAccessLevel, +}; + /// Manages producing static files under the control of the engine. /// /// This type controls the [`StaticFileProducer`]. diff --git a/crates/consensus/beacon/src/engine/invalid_headers.rs b/crates/consensus/beacon/src/engine/invalid_headers.rs index 2a37c60014daf..680fde3b439d9 100644 --- a/crates/consensus/beacon/src/engine/invalid_headers.rs +++ b/crates/consensus/beacon/src/engine/invalid_headers.rs @@ -1,10 +1,11 @@ +use std::sync::Arc; + use reth_metrics::{ metrics::{Counter, Gauge}, Metrics, }; use reth_primitives::{Header, SealedHeader, B256}; use schnellru::{ByLength, LruMap}; -use std::sync::Arc; use tracing::warn; /// The max hit counter for invalid headers in the cache before it is forcefully evicted. diff --git a/crates/consensus/beacon/src/engine/message.rs b/crates/consensus/beacon/src/engine/message.rs index 052b275c181dc..2377010ac22bf 100644 --- a/crates/consensus/beacon/src/engine/message.rs +++ b/crates/consensus/beacon/src/engine/message.rs @@ -1,4 +1,9 @@ -use crate::engine::{error::BeaconOnNewPayloadError, forkchoice::ForkchoiceStatus}; +use std::{ + future::Future, + pin::Pin, + task::{ready, Context, Poll}, +}; + use futures::{future::Either, FutureExt}; use reth_engine_primitives::EngineTypes; use reth_errors::RethResult; @@ -7,13 +12,10 @@ use reth_rpc_types::engine::{ CancunPayloadFields, ExecutionPayload, ForkChoiceUpdateResult, ForkchoiceState, ForkchoiceUpdateError, ForkchoiceUpdated, PayloadId, PayloadStatus, PayloadStatusEnum, }; -use std::{ - future::Future, - pin::Pin, - task::{ready, Context, Poll}, -}; use tokio::sync::oneshot; +use crate::engine::{error::BeaconOnNewPayloadError, forkchoice::ForkchoiceStatus}; + /// Represents the outcome of forkchoice update. /// /// This is a future that resolves to [`ForkChoiceUpdateResult`] diff --git a/crates/consensus/beacon/src/engine/mod.rs b/crates/consensus/beacon/src/engine/mod.rs index 3391a1de95e5a..0a5224754d6ba 100644 --- a/crates/consensus/beacon/src/engine/mod.rs +++ b/crates/consensus/beacon/src/engine/mod.rs @@ -1,3 +1,10 @@ +use std::{ + pin::Pin, + sync::Arc, + task::{Context, Poll}, + time::{Duration, Instant}, +}; + use futures::{stream::BoxStream, Future, StreamExt}; use itertools::Either; use reth_blockchain_tree_api::{ @@ -30,12 +37,6 @@ use reth_rpc_types::engine::{ use reth_stages_api::{ControlFlow, Pipeline, PipelineTarget, StageId}; use reth_tasks::TaskSpawner; use reth_tokio_util::EventSender; -use std::{ - pin::Pin, - sync::Arc, - task::{Context, Poll}, - time::{Duration, Instant}, -}; use tokio::sync::{ mpsc::{self, UnboundedSender}, oneshot, @@ -1969,11 +1970,8 @@ enum EngineEventOutcome { #[cfg(test)] mod tests { - use super::*; - use crate::{ - test_utils::{spawn_consensus_engine, TestConsensusEngineBuilder}, - BeaconForkChoiceUpdateError, - }; + use std::{collections::VecDeque, sync::Arc}; + use assert_matches::assert_matches; use reth_chainspec::{ChainSpecBuilder, MAINNET}; use reth_provider::{BlockWriter, ProviderFactory}; @@ -1982,9 +1980,14 @@ mod tests { use reth_stages::{ExecOutput, PipelineError, StageError}; use reth_stages_api::StageCheckpoint; use reth_testing_utils::generators::{self, Rng}; - use std::{collections::VecDeque, sync::Arc}; use tokio::sync::oneshot::error::TryRecvError; + use super::*; + use crate::{ + test_utils::{spawn_consensus_engine, TestConsensusEngineBuilder}, + BeaconForkChoiceUpdateError, + }; + // Pipeline error is propagated. #[tokio::test] async fn pipeline_error_is_propagated() { @@ -2169,7 +2172,6 @@ mod tests { } mod fork_choice_updated { - use super::*; use reth_db::{tables, test_utils::create_test_static_files_dir}; use reth_db_api::transaction::DbTxMut; use reth_primitives::U256; @@ -2177,6 +2179,8 @@ mod tests { use reth_rpc_types::engine::ForkchoiceUpdateError; use reth_testing_utils::generators::random_block; + use super::*; + #[tokio::test] async fn empty_head() { let chain_spec = Arc::new( @@ -2489,7 +2493,6 @@ mod tests { } mod new_payload { - use super::*; use alloy_genesis::Genesis; use reth_db::test_utils::create_test_static_files_dir; use reth_primitives::{Hardfork, U256}; @@ -2497,6 +2500,8 @@ mod tests { providers::StaticFileProvider, test_utils::blocks::BlockchainTestData, }; use reth_testing_utils::{generators::random_block, GenesisAllocator}; + + use super::*; #[tokio::test] async fn new_payload_before_forkchoice() { let mut rng = generators::rng(); diff --git a/crates/consensus/beacon/src/engine/sync.rs b/crates/consensus/beacon/src/engine/sync.rs index 76a6d0e815521..56d0e66e00082 100644 --- a/crates/consensus/beacon/src/engine/sync.rs +++ b/crates/consensus/beacon/src/engine/sync.rs @@ -1,9 +1,12 @@ //! Sync management for the engine implementation. -use crate::{ - engine::metrics::EngineSyncMetrics, BeaconConsensusEngineEvent, - ConsensusEngineLiveSyncProgress, EthBeaconConsensus, +use std::{ + cmp::{Ordering, Reverse}, + collections::{binary_heap::PeekMut, BinaryHeap}, + sync::Arc, + task::{ready, Context, Poll}, }; + use futures::FutureExt; use reth_chainspec::ChainSpec; use reth_db_api::database::Database; @@ -16,15 +19,14 @@ use reth_primitives::{BlockNumber, SealedBlock, B256}; use reth_stages_api::{ControlFlow, Pipeline, PipelineError, PipelineTarget, PipelineWithResult}; use reth_tasks::TaskSpawner; use reth_tokio_util::EventSender; -use std::{ - cmp::{Ordering, Reverse}, - collections::{binary_heap::PeekMut, BinaryHeap}, - sync::Arc, - task::{ready, Context, Poll}, -}; use tokio::sync::oneshot; use tracing::trace; +use crate::{ + engine::metrics::EngineSyncMetrics, BeaconConsensusEngineEvent, + ConsensusEngineLiveSyncProgress, EthBeaconConsensus, +}; + /// Manages syncing under the control of the engine. /// /// This type controls the [Pipeline] and supports (single) full block downloads. @@ -411,7 +413,8 @@ impl PipelineState { #[cfg(test)] mod tests { - use super::*; + use std::{collections::VecDeque, future::poll_fn, ops::Range}; + use assert_matches::assert_matches; use futures::poll; use reth_chainspec::{ChainSpecBuilder, MAINNET}; @@ -426,9 +429,10 @@ mod tests { use reth_stages_api::StageCheckpoint; use reth_static_file::StaticFileProducer; use reth_tasks::TokioTaskExecutor; - use std::{collections::VecDeque, future::poll_fn, ops::Range}; use tokio::sync::watch; + use super::*; + struct TestPipelineBuilder { pipeline_exec_outputs: VecDeque>, executor_results: Vec, diff --git a/crates/consensus/beacon/src/engine/test_utils.rs b/crates/consensus/beacon/src/engine/test_utils.rs index f58063d3ef58f..891c10c0abab6 100644 --- a/crates/consensus/beacon/src/engine/test_utils.rs +++ b/crates/consensus/beacon/src/engine/test_utils.rs @@ -1,8 +1,5 @@ -use crate::{ - engine::hooks::PruneHook, hooks::EngineHooks, BeaconConsensusEngine, - BeaconConsensusEngineError, BeaconConsensusEngineHandle, BeaconForkChoiceUpdateError, - BeaconOnNewPayloadError, EthBeaconConsensus, MIN_BLOCKS_FOR_PIPELINE_RUN, -}; +use std::{collections::VecDeque, sync::Arc}; + use reth_blockchain_tree::{ config::BlockchainTreeConfig, externals::TreeExternals, BlockchainTree, ShareableBlockchainTree, }; @@ -36,9 +33,14 @@ use reth_rpc_types::engine::{ use reth_stages::{sets::DefaultStages, test_utils::TestStages, ExecOutput, Pipeline, StageError}; use reth_static_file::StaticFileProducer; use reth_tasks::TokioTaskExecutor; -use std::{collections::VecDeque, sync::Arc}; use tokio::sync::{oneshot, watch}; +use crate::{ + engine::hooks::PruneHook, hooks::EngineHooks, BeaconConsensusEngine, + BeaconConsensusEngineError, BeaconConsensusEngineHandle, BeaconForkChoiceUpdateError, + BeaconOnNewPayloadError, EthBeaconConsensus, MIN_BLOCKS_FOR_PIPELINE_RUN, +}; + type DatabaseEnv = TempDatabase; type TestBeaconConsensusEngine = BeaconConsensusEngine< diff --git a/crates/consensus/common/src/calc.rs b/crates/consensus/common/src/calc.rs index 27320700b33ec..d5853a6f0de75 100644 --- a/crates/consensus/common/src/calc.rs +++ b/crates/consensus/common/src/calc.rs @@ -113,9 +113,10 @@ pub const fn ommer_reward( #[cfg(test)] mod tests { - use super::*; use reth_chainspec::MAINNET; + use super::*; + #[test] fn calc_base_block_reward() { // ((block number, td), reward) diff --git a/crates/consensus/common/src/validation.rs b/crates/consensus/common/src/validation.rs index 31bde166ece04..1ff56b7f3ee0c 100644 --- a/crates/consensus/common/src/validation.rs +++ b/crates/consensus/common/src/validation.rs @@ -268,7 +268,8 @@ pub fn validate_against_parent_4844( #[cfg(test)] mod tests { - use super::*; + use std::ops::RangeBounds; + use mockall::mock; use rand::Rng; use reth_chainspec::ChainSpecBuilder; @@ -280,7 +281,8 @@ mod tests { use reth_storage_api::{ errors::provider::ProviderResult, AccountReader, HeaderProvider, WithdrawalsProvider, }; - use std::ops::RangeBounds; + + use super::*; mock! { WithdrawalsProvider {} diff --git a/crates/consensus/consensus/src/lib.rs b/crates/consensus/consensus/src/lib.rs index 7aee9f15e7061..b65504bab501d 100644 --- a/crates/consensus/consensus/src/lib.rs +++ b/crates/consensus/consensus/src/lib.rs @@ -9,15 +9,15 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(feature = "std"), no_std)] +#[cfg(feature = "std")] +use std::fmt::Debug; + use reth_primitives::{ constants::MINIMUM_GAS_LIMIT, BlockHash, BlockNumber, BlockWithSenders, Bloom, GotExpected, GotExpectedBoxed, Header, InvalidTransactionError, Receipt, Request, SealedBlock, SealedHeader, B256, U256, }; -#[cfg(feature = "std")] -use std::fmt::Debug; - #[cfg(not(feature = "std"))] extern crate alloc; diff --git a/crates/consensus/consensus/src/noop.rs b/crates/consensus/consensus/src/noop.rs index 31c168eb0c83d..915de4e3fbdea 100644 --- a/crates/consensus/consensus/src/noop.rs +++ b/crates/consensus/consensus/src/noop.rs @@ -1,6 +1,7 @@ -use crate::{Consensus, ConsensusError, PostExecutionInput}; use reth_primitives::{BlockWithSenders, Header, SealedBlock, SealedHeader, U256}; +use crate::{Consensus, ConsensusError, PostExecutionInput}; + /// A Consensus implementation that does nothing. #[derive(Debug, Copy, Clone, Default)] #[non_exhaustive] diff --git a/crates/consensus/consensus/src/test_utils.rs b/crates/consensus/consensus/src/test_utils.rs index 546dffab1fd50..467b6bb941d2b 100644 --- a/crates/consensus/consensus/src/test_utils.rs +++ b/crates/consensus/consensus/src/test_utils.rs @@ -1,7 +1,9 @@ -use crate::{Consensus, ConsensusError, PostExecutionInput}; -use reth_primitives::{BlockWithSenders, Header, SealedBlock, SealedHeader, U256}; use std::sync::atomic::{AtomicBool, Ordering}; +use reth_primitives::{BlockWithSenders, Header, SealedBlock, SealedHeader, U256}; + +use crate::{Consensus, ConsensusError, PostExecutionInput}; + /// Consensus engine implementation for testing #[derive(Debug)] pub struct TestConsensus { diff --git a/crates/consensus/debug-client/src/client.rs b/crates/consensus/debug-client/src/client.rs index e72f58855eeb1..e6ad6eab3b6a6 100644 --- a/crates/consensus/debug-client/src/client.rs +++ b/crates/consensus/debug-client/src/client.rs @@ -1,3 +1,5 @@ +use std::future::Future; + use alloy_consensus::TxEnvelope; use alloy_eips::eip2718::Encodable2718; use reth_node_api::EngineTypes; @@ -9,7 +11,6 @@ use reth_rpc_builder::auth::AuthServerHandle; use reth_rpc_types::ExecutionPayloadV1; use reth_tracing::tracing::warn; use ringbuffer::{AllocRingBuffer, RingBuffer}; -use std::future::Future; use tokio::sync::mpsc; /// Supplies consensus client with new blocks sent in `tx` and a callback to find specific blocks diff --git a/crates/consensus/debug-client/src/providers/etherscan.rs b/crates/consensus/debug-client/src/providers/etherscan.rs index e189913d12646..bd24a6b383131 100644 --- a/crates/consensus/debug-client/src/providers/etherscan.rs +++ b/crates/consensus/debug-client/src/providers/etherscan.rs @@ -1,12 +1,14 @@ -use crate::BlockProvider; +use std::time::Duration; + use alloy_eips::BlockNumberOrTag; use reqwest::Client; use reth_node_core::rpc::types::RichBlock; use reth_tracing::tracing::warn; use serde::Deserialize; -use std::time::Duration; use tokio::{sync::mpsc, time::interval}; +use crate::BlockProvider; + /// Block provider that fetches new blocks from Etherscan API. #[derive(Debug, Clone)] pub struct EtherscanBlockProvider { diff --git a/crates/consensus/debug-client/src/providers/rpc.rs b/crates/consensus/debug-client/src/providers/rpc.rs index 3c0dcf9992e7d..55e37ac5777f4 100644 --- a/crates/consensus/debug-client/src/providers/rpc.rs +++ b/crates/consensus/debug-client/src/providers/rpc.rs @@ -1,4 +1,3 @@ -use crate::BlockProvider; use alloy_eips::BlockNumberOrTag; use alloy_provider::{Provider, ProviderBuilder}; use futures::StreamExt; @@ -6,6 +5,8 @@ use reth_node_core::rpc::types::RichBlock; use reth_rpc_types::BlockTransactionsKind; use tokio::sync::mpsc::Sender; +use crate::BlockProvider; + /// Block provider that fetches new blocks from an RPC endpoint using a websocket connection. #[derive(Debug, Clone)] pub struct RpcBlockProvider { diff --git a/crates/e2e-test-utils/src/engine_api.rs b/crates/e2e-test-utils/src/engine_api.rs index 66e8900323be4..0e4313d3745ec 100644 --- a/crates/e2e-test-utils/src/engine_api.rs +++ b/crates/e2e-test-utils/src/engine_api.rs @@ -1,4 +1,5 @@ -use crate::traits::PayloadEnvelopeExt; +use std::marker::PhantomData; + use jsonrpsee::{ core::client::ClientT, http_client::{transport::HttpBackend, HttpClient}, @@ -14,7 +15,8 @@ use reth::{ use reth_payload_builder::PayloadId; use reth_primitives::B256; use reth_rpc_layer::AuthClientService; -use std::marker::PhantomData; + +use crate::traits::PayloadEnvelopeExt; /// Helper for engine api operations pub struct EngineApiTestContext { diff --git a/crates/e2e-test-utils/src/lib.rs b/crates/e2e-test-utils/src/lib.rs index 925b09b912104..7a892d4803b96 100644 --- a/crates/e2e-test-utils/src/lib.rs +++ b/crates/e2e-test-utils/src/lib.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use node::NodeTestContext; use reth::{ args::{DiscoveryArgs, NetworkArgs, RpcServerArgs}, @@ -10,7 +12,6 @@ use reth_node_builder::{ components::NodeComponentsBuilder, FullNodeTypesAdapter, Node, NodeAdapter, RethFullAdapter, }; use reth_provider::providers::BlockchainProvider; -use std::sync::Arc; use tracing::{span, Level}; use wallet::Wallet; diff --git a/crates/e2e-test-utils/src/node.rs b/crates/e2e-test-utils/src/node.rs index 684e0f401c1b2..fa1697a821609 100644 --- a/crates/e2e-test-utils/src/node.rs +++ b/crates/e2e-test-utils/src/node.rs @@ -1,7 +1,4 @@ -use crate::{ - engine_api::EngineApiTestContext, network::NetworkTestContext, payload::PayloadTestContext, - rpc::RpcTestContext, traits::PayloadEnvelopeExt, -}; +use std::{marker::PhantomData, pin::Pin}; use alloy_rpc_types::BlockNumberOrTag; use eyre::Ok; @@ -16,9 +13,13 @@ use reth::{ use reth_node_builder::NodeTypes; use reth_primitives::{BlockHash, BlockNumber, Bytes, B256}; use reth_stages_types::StageId; -use std::{marker::PhantomData, pin::Pin}; use tokio_stream::StreamExt; +use crate::{ + engine_api::EngineApiTestContext, network::NetworkTestContext, payload::PayloadTestContext, + rpc::RpcTestContext, traits::PayloadEnvelopeExt, +}; + /// An helper struct to handle node actions pub struct NodeTestContext where diff --git a/crates/e2e-test-utils/src/transaction.rs b/crates/e2e-test-utils/src/transaction.rs index 0719c7733e6a0..10b1168edd8dc 100644 --- a/crates/e2e-test-utils/src/transaction.rs +++ b/crates/e2e-test-utils/src/transaction.rs @@ -6,9 +6,7 @@ use alloy_network::{eip2718::Encodable2718, EthereumWallet, TransactionBuilder}; use alloy_rpc_types::{TransactionInput, TransactionRequest}; use alloy_signer_local::PrivateKeySigner; use eyre::Ok; -use reth_primitives::{hex, Address, Bytes, U256}; - -use reth_primitives::B256; +use reth_primitives::{hex, Address, Bytes, B256, U256}; pub struct TransactionTestContext; diff --git a/crates/engine/util/src/engine_store.rs b/crates/engine/util/src/engine_store.rs index c6e2b65c5be04..925d6cd90023d 100644 --- a/crates/engine/util/src/engine_store.rs +++ b/crates/engine/util/src/engine_store.rs @@ -1,5 +1,13 @@ //! Stores engine API messages to disk for later inspection and replay. +use std::{ + collections::BTreeMap, + path::PathBuf, + pin::Pin, + task::{ready, Context, Poll}, + time::SystemTime, +}; + use futures::{Stream, StreamExt}; use reth_beacon_consensus::BeaconEngineMessage; use reth_engine_primitives::EngineTypes; @@ -9,13 +17,6 @@ use reth_rpc_types::{ ExecutionPayload, }; use serde::{Deserialize, Serialize}; -use std::{ - collections::BTreeMap, - path::PathBuf, - pin::Pin, - task::{ready, Context, Poll}, - time::SystemTime, -}; use tracing::*; /// A message from the engine API that has been stored to disk. diff --git a/crates/engine/util/src/lib.rs b/crates/engine/util/src/lib.rs index 38825b890bec7..2d56fa0b45753 100644 --- a/crates/engine/util/src/lib.rs +++ b/crates/engine/util/src/lib.rs @@ -1,9 +1,10 @@ //! Collection of various stream utilities for consensus engine. +use std::path::PathBuf; + use futures::Stream; use reth_beacon_consensus::BeaconEngineMessage; use reth_engine_primitives::EngineTypes; -use std::path::PathBuf; use tokio_util::either::Either; pub mod engine_store; diff --git a/crates/engine/util/src/skip_fcu.rs b/crates/engine/util/src/skip_fcu.rs index d63894a5c951d..1b27be9051057 100644 --- a/crates/engine/util/src/skip_fcu.rs +++ b/crates/engine/util/src/skip_fcu.rs @@ -1,13 +1,14 @@ //! Stream wrapper that skips specified number of FCUs. -use futures::{Stream, StreamExt}; -use reth_beacon_consensus::{BeaconEngineMessage, OnForkChoiceUpdated}; -use reth_engine_primitives::EngineTypes; use std::{ pin::Pin, task::{ready, Context, Poll}, }; +use futures::{Stream, StreamExt}; +use reth_beacon_consensus::{BeaconEngineMessage, OnForkChoiceUpdated}; +use reth_engine_primitives::EngineTypes; + /// Engine API stream wrapper that skips the specified number of forkchoice updated messages. #[derive(Debug)] #[pin_project::pin_project] diff --git a/crates/engine/util/src/skip_new_payload.rs b/crates/engine/util/src/skip_new_payload.rs index 04db70e0a6769..6f52014258c7e 100644 --- a/crates/engine/util/src/skip_new_payload.rs +++ b/crates/engine/util/src/skip_new_payload.rs @@ -1,14 +1,15 @@ //! Stream wrapper that skips specified number of new payload messages. -use futures::{Stream, StreamExt}; -use reth_beacon_consensus::BeaconEngineMessage; -use reth_engine_primitives::EngineTypes; -use reth_rpc_types::engine::{PayloadStatus, PayloadStatusEnum}; use std::{ pin::Pin, task::{ready, Context, Poll}, }; +use futures::{Stream, StreamExt}; +use reth_beacon_consensus::BeaconEngineMessage; +use reth_engine_primitives::EngineTypes; +use reth_rpc_types::engine::{PayloadStatus, PayloadStatusEnum}; + /// Engine API stream wrapper that skips the specified number of new payload messages. #[derive(Debug)] #[pin_project::pin_project] diff --git a/crates/errors/src/error.rs b/crates/errors/src/error.rs index e74d582759b79..82b8a59c349ed 100644 --- a/crates/errors/src/error.rs +++ b/crates/errors/src/error.rs @@ -1,9 +1,10 @@ +use std::fmt::Display; + use reth_blockchain_tree_api::error::{BlockchainTreeError, CanonicalError}; use reth_consensus::ConsensusError; use reth_execution_errors::BlockExecutionError; use reth_fs_util::FsPathError; use reth_storage_errors::{db::DatabaseError, provider::ProviderError}; -use std::fmt::Display; /// Result alias for [`RethError`]. pub type RethResult = Result; diff --git a/crates/errors/src/lib.rs b/crates/errors/src/lib.rs index 9dc0ce0ca5bc4..2c805e4aeffb3 100644 --- a/crates/errors/src/lib.rs +++ b/crates/errors/src/lib.rs @@ -14,7 +14,6 @@ mod error; pub use error::{RethError, RethResult}; - pub use reth_blockchain_tree_api::error::{BlockchainTreeError, CanonicalError}; pub use reth_consensus::ConsensusError; pub use reth_execution_errors::{BlockExecutionError, BlockValidationError}; diff --git a/crates/ethereum-forks/src/chains/dev.rs b/crates/ethereum-forks/src/chains/dev.rs index 866be0dd4260b..1f03135bbc1fa 100644 --- a/crates/ethereum-forks/src/chains/dev.rs +++ b/crates/ethereum-forks/src/chains/dev.rs @@ -1,6 +1,7 @@ -use crate::{ForkCondition, Hardfork}; use alloy_primitives::uint; +use crate::{ForkCondition, Hardfork}; + /// Dev hardforks pub const DEV_HARDFORKS: [(Hardfork, ForkCondition); 14] = [ (Hardfork::Frontier, ForkCondition::Block(0)), diff --git a/crates/ethereum-forks/src/chains/ethereum.rs b/crates/ethereum-forks/src/chains/ethereum.rs index 6db4d95fcade0..ef410411bb356 100644 --- a/crates/ethereum-forks/src/chains/ethereum.rs +++ b/crates/ethereum-forks/src/chains/ethereum.rs @@ -1,6 +1,7 @@ -use crate::{ForkCondition, Hardfork}; use alloy_primitives::{uint, U256}; +use crate::{ForkCondition, Hardfork}; + /// Ethereum mainnet hardforks pub const MAINNET_HARDFORKS: [(Hardfork, ForkCondition); 17] = [ (Hardfork::Frontier, ForkCondition::Block(0)), diff --git a/crates/ethereum-forks/src/chains/optimism.rs b/crates/ethereum-forks/src/chains/optimism.rs index 37af4a19ffe69..4ca91d620e41d 100644 --- a/crates/ethereum-forks/src/chains/optimism.rs +++ b/crates/ethereum-forks/src/chains/optimism.rs @@ -1,6 +1,7 @@ -use crate::{ForkCondition, Hardfork}; use alloy_primitives::U256; +use crate::{ForkCondition, Hardfork}; + /// Optimism mainnet hardforks pub const OP_MAINNET_HARDFORKS: [(Hardfork, ForkCondition); 21] = [ (Hardfork::Frontier, ForkCondition::Block(0)), diff --git a/crates/ethereum-forks/src/display.rs b/crates/ethereum-forks/src/display.rs index 3c14240836388..db8dc5856b446 100644 --- a/crates/ethereum-forks/src/display.rs +++ b/crates/ethereum-forks/src/display.rs @@ -5,11 +5,11 @@ use alloc::{ string::{String, ToString}, vec::Vec, }; - -use crate::{ForkCondition, Hardfork}; #[cfg(feature = "std")] use std::collections::BTreeMap; +use crate::{ForkCondition, Hardfork}; + /// A container to pretty-print a hardfork. /// /// The fork is formatted depending on its fork condition: diff --git a/crates/ethereum-forks/src/forkcondition.rs b/crates/ethereum-forks/src/forkcondition.rs index 80c7fff647bdb..e6c1acdfb6b87 100644 --- a/crates/ethereum-forks/src/forkcondition.rs +++ b/crates/ethereum-forks/src/forkcondition.rs @@ -1,6 +1,7 @@ -use crate::Head; use alloy_primitives::{BlockNumber, U256}; +use crate::Head; + /// The condition at which a fork is activated. #[derive(Debug, Copy, Clone, PartialEq, Eq, Default)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/crates/ethereum-forks/src/forkid.rs b/crates/ethereum-forks/src/forkid.rs index 48ef778fcfbf0..8db77d56fbfb0 100644 --- a/crates/ethereum-forks/src/forkid.rs +++ b/crates/ethereum-forks/src/forkid.rs @@ -2,28 +2,30 @@ //! //! Previously version of Apache licenced [`ethereum-forkid`](https://crates.io/crates/ethereum-forkid). -use crate::Head; #[cfg(not(feature = "std"))] use alloc::{ collections::{BTreeMap, BTreeSet}, vec::Vec, }; -use alloy_primitives::{hex, BlockNumber, B256}; -use alloy_rlp::{Error as RlpError, *}; -#[cfg(any(test, feature = "arbitrary"))] -use arbitrary::Arbitrary; use core::{ cmp::Ordering, fmt, ops::{Add, AddAssign}, }; +#[cfg(feature = "std")] +use std::collections::{BTreeMap, BTreeSet}; + +use alloy_primitives::{hex, BlockNumber, B256}; +use alloy_rlp::{Error as RlpError, *}; +#[cfg(any(test, feature = "arbitrary"))] +use arbitrary::Arbitrary; use crc::*; #[cfg(any(test, feature = "arbitrary"))] use proptest_derive::Arbitrary as PropTestArbitrary; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -#[cfg(feature = "std")] -use std::collections::{BTreeMap, BTreeSet}; + +use crate::Head; const CRC_32_IEEE: Crc = Crc::::new(&CRC_32_ISO_HDLC); const TIMESTAMP_BEFORE_ETHEREUM_MAINNET: u64 = 1_300_000_000; @@ -456,9 +458,10 @@ impl Cache { #[cfg(test)] mod tests { - use super::*; use alloy_primitives::b256; + use super::*; + const GENESIS_HASH: B256 = b256!("d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"); diff --git a/crates/ethereum-forks/src/hardfork.rs b/crates/ethereum-forks/src/hardfork.rs index fa095dea5a18b..686c11005b566 100644 --- a/crates/ethereum-forks/src/hardfork.rs +++ b/crates/ethereum-forks/src/hardfork.rs @@ -1,15 +1,15 @@ -use alloy_chains::Chain; +#[cfg(not(feature = "std"))] +use alloc::{format, string::String}; use core::{ fmt, fmt::{Display, Formatter}, str::FromStr, }; + +use alloy_chains::Chain; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -#[cfg(not(feature = "std"))] -use alloc::{format, string::String}; - /// Represents the consensus type of a blockchain fork. /// /// This enum defines two variants: `ProofOfWork` for hardforks that use a proof-of-work consensus diff --git a/crates/ethereum-forks/src/head.rs b/crates/ethereum-forks/src/head.rs index bd05cc3a772e6..9eea536841ab7 100644 --- a/crates/ethereum-forks/src/head.rs +++ b/crates/ethereum-forks/src/head.rs @@ -1,5 +1,6 @@ -use alloy_primitives::{BlockNumber, B256, U256}; use core::fmt; + +use alloy_primitives::{BlockNumber, B256, U256}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; diff --git a/crates/ethereum-forks/src/lib.rs b/crates/ethereum-forks/src/lib.rs index 37e9b87108232..8d9273f220ad5 100644 --- a/crates/ethereum-forks/src/lib.rs +++ b/crates/ethereum-forks/src/lib.rs @@ -24,15 +24,14 @@ mod forkid; mod hardfork; mod head; +pub use display::DisplayHardforks; +pub use forkcondition::ForkCondition; pub use forkid::{ EnrForkIdEntry, ForkFilter, ForkFilterKey, ForkHash, ForkId, ForkTransition, ValidationError, }; pub use hardfork::Hardfork; pub use head::Head; -pub use display::DisplayHardforks; -pub use forkcondition::ForkCondition; - /// Chains hardforks pub mod chains; diff --git a/crates/ethereum/consensus/src/lib.rs b/crates/ethereum/consensus/src/lib.rs index 210f544613940..d68ab164046ea 100644 --- a/crates/ethereum/consensus/src/lib.rs +++ b/crates/ethereum/consensus/src/lib.rs @@ -8,6 +8,8 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +use std::{sync::Arc, time::SystemTime}; + use reth_chainspec::{Chain, ChainSpec, Hardfork}; use reth_consensus::{Consensus, ConsensusError, PostExecutionInput}; use reth_consensus_common::validation::{ @@ -20,7 +22,6 @@ use reth_primitives::{ constants::MINIMUM_GAS_LIMIT, BlockWithSenders, Header, SealedBlock, SealedHeader, EMPTY_OMMER_ROOT_HASH, U256, }; -use std::{sync::Arc, time::SystemTime}; mod validation; pub use validation::validate_block_post_execution; @@ -224,10 +225,11 @@ impl Consensus for EthBeaconConsensus { #[cfg(test)] mod tests { - use super::*; use reth_chainspec::ChainSpecBuilder; use reth_primitives::{proofs, B256}; + use super::*; + fn header_with_gas_limit(gas_limit: u64) -> SealedHeader { let header = Header { gas_limit, ..Default::default() }; header.seal(B256::ZERO) diff --git a/crates/ethereum/engine-primitives/src/payload.rs b/crates/ethereum/engine-primitives/src/payload.rs index 8976f0caa5af8..eaadaf4633c92 100644 --- a/crates/ethereum/engine-primitives/src/payload.rs +++ b/crates/ethereum/engine-primitives/src/payload.rs @@ -1,5 +1,7 @@ //! Contains types required for building a payload. +use std::convert::Infallible; + use alloy_rlp::Encodable; use reth_chainspec::ChainSpec; use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes}; @@ -16,7 +18,6 @@ use reth_rpc_types_compat::engine::payload::{ convert_block_to_payload_field_v2, }; use revm_primitives::{BlobExcessGasAndPrice, BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, SpecId}; -use std::convert::Infallible; /// Contains the built payload. /// @@ -320,9 +321,10 @@ pub(crate) fn payload_id(parent: &B256, attributes: &PayloadAttributes) -> Paylo #[cfg(test)] mod tests { - use super::*; use reth_primitives::Genesis; + use super::*; + #[test] fn ensure_first_london_block_base_fee_is_set() { let hive_london = r#" diff --git a/crates/ethereum/evm/src/eip6110.rs b/crates/ethereum/evm/src/eip6110.rs index 722c38da76dc5..679e95a6563c4 100644 --- a/crates/ethereum/evm/src/eip6110.rs +++ b/crates/ethereum/evm/src/eip6110.rs @@ -1,4 +1,7 @@ //! EIP-6110 deposit requests parsing +#[cfg(not(feature = "std"))] +use alloc::{string::ToString, vec::Vec}; + use alloy_eips::eip6110::{DepositRequest, MAINNET_DEPOSIT_CONTRACT_ADDRESS}; use alloy_sol_types::{sol, SolEvent}; use reth_chainspec::ChainSpec; @@ -6,9 +9,6 @@ use reth_evm::execute::BlockValidationError; use reth_primitives::{Receipt, Request}; use revm_primitives::Log; -#[cfg(not(feature = "std"))] -use alloc::{string::ToString, vec::Vec}; - sol! { #[allow(missing_docs)] event DepositEvent( @@ -88,10 +88,11 @@ fn parse_deposit_from_log(log: &Log) -> DepositRequest { #[cfg(test)] mod tests { - use super::*; use reth_chainspec::MAINNET; use reth_primitives::TxType; + use super::*; + #[test] fn test_parse_deposit_from_log() { let receipts = vec![ diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index e4c89dd778dd9..1d5ce46871c87 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -1,11 +1,10 @@ //! Ethereum block executor. -use crate::{ - dao_fork::{DAO_HARDFORK_BENEFICIARY, DAO_HARDKFORK_ACCOUNTS}, - EthEvmConfig, -}; #[cfg(not(feature = "std"))] use alloc::{sync::Arc, vec, vec::Vec}; +#[cfg(feature = "std")] +use std::{fmt::Display, sync::Arc}; + use reth_chainspec::{ChainSpec, MAINNET}; use reth_ethereum_consensus::validate_block_post_execution; use reth_evm::{ @@ -34,8 +33,10 @@ use revm_primitives::{ BlockEnv, CfgEnvWithHandlerCfg, EVMError, EnvWithHandlerCfg, ResultAndState, }; -#[cfg(feature = "std")] -use std::{fmt::Display, sync::Arc}; +use crate::{ + dao_fork::{DAO_HARDFORK_BENEFICIARY, DAO_HARDKFORK_ACCOUNTS}, + EthEvmConfig, +}; /// Provides executors to execute regular ethereum blocks #[derive(Debug, Clone)] pub struct EthExecutorProvider { @@ -468,7 +469,8 @@ where #[cfg(test)] mod tests { - use super::*; + use std::collections::HashMap; + use alloy_eips::{ eip2935::HISTORY_STORAGE_ADDRESS, eip4788::{BEACON_ROOTS_ADDRESS, BEACON_ROOTS_CODE, SYSTEM_ADDRESS}, @@ -485,7 +487,8 @@ mod tests { use reth_testing_utils::generators::{self, sign_tx_with_key_pair}; use revm_primitives::{b256, fixed_bytes, Bytes, BLOCKHASH_SERVE_WINDOW}; use secp256k1::{Keypair, Secp256k1}; - use std::collections::HashMap; + + use super::*; fn create_state_provider_with_beacon_root_contract() -> StateProviderTest { let mut db = StateProviderTest::default(); diff --git a/crates/ethereum/evm/src/lib.rs b/crates/ethereum/evm/src/lib.rs index 4134849ea8f98..00606d82157bb 100644 --- a/crates/ethereum/evm/src/lib.rs +++ b/crates/ethereum/evm/src/lib.rs @@ -76,9 +76,10 @@ impl ConfigureEvm for EthEvmConfig { #[cfg(test)] mod tests { - use super::*; use reth_primitives::revm_primitives::{BlockEnv, CfgEnv, SpecId}; + use super::*; + #[test] #[ignore] fn test_fill_cfg_and_block_env() { diff --git a/crates/ethereum/node/src/node.rs b/crates/ethereum/node/src/node.rs index c3d8a9af55f4a..2c0ca437e49ef 100644 --- a/crates/ethereum/node/src/node.rs +++ b/crates/ethereum/node/src/node.rs @@ -1,6 +1,7 @@ //! Ethereum Node types config. -use crate::{EthEngineTypes, EthEvmConfig}; +use std::sync::Arc; + use reth_auto_seal_consensus::AutoSealConsensus; use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig}; use reth_beacon_consensus::EthBeaconConsensus; @@ -24,7 +25,8 @@ use reth_transaction_pool::{ blobstore::DiskFileBlobStore, EthTransactionPool, TransactionPool, TransactionValidationTaskExecutor, }; -use std::sync::Arc; + +use crate::{EthEngineTypes, EthEvmConfig}; /// Type configuration for a regular Ethereum node. #[derive(Debug, Default, Clone, Copy)] diff --git a/crates/ethereum/node/tests/e2e/dev.rs b/crates/ethereum/node/tests/e2e/dev.rs index 990c6f0bf2b01..03ef4d5e871db 100644 --- a/crates/ethereum/node/tests/e2e/dev.rs +++ b/crates/ethereum/node/tests/e2e/dev.rs @@ -1,4 +1,5 @@ -use crate::utils::EthNode; +use std::sync::Arc; + use alloy_genesis::Genesis; use alloy_primitives::{b256, hex}; use futures::StreamExt; @@ -6,7 +7,8 @@ use reth::rpc::eth::EthTransactions; use reth_chainspec::ChainSpec; use reth_e2e_test_utils::setup; use reth_provider::CanonStateSubscriptions; -use std::sync::Arc; + +use crate::utils::EthNode; #[tokio::test] async fn can_run_dev_node() -> eyre::Result<()> { diff --git a/crates/ethereum/node/tests/e2e/eth.rs b/crates/ethereum/node/tests/e2e/eth.rs index 8e6938b47fe42..e0ca293eb243f 100644 --- a/crates/ethereum/node/tests/e2e/eth.rs +++ b/crates/ethereum/node/tests/e2e/eth.rs @@ -1,4 +1,5 @@ -use crate::utils::eth_payload_attributes; +use std::sync::Arc; + use alloy_genesis::Genesis; use reth::{ args::RpcServerArgs, @@ -10,7 +11,8 @@ use reth_e2e_test_utils::{ node::NodeTestContext, setup, transaction::TransactionTestContext, wallet::Wallet, }; use reth_node_ethereum::EthereumNode; -use std::sync::Arc; + +use crate::utils::eth_payload_attributes; #[tokio::test] async fn can_run_eth_node() -> eyre::Result<()> { diff --git a/crates/ethereum/node/tests/e2e/p2p.rs b/crates/ethereum/node/tests/e2e/p2p.rs index a40c1b3f4b4e6..bc744fdb2baeb 100644 --- a/crates/ethereum/node/tests/e2e/p2p.rs +++ b/crates/ethereum/node/tests/e2e/p2p.rs @@ -1,8 +1,10 @@ -use crate::utils::eth_payload_attributes; +use std::sync::Arc; + use reth_chainspec::{ChainSpecBuilder, MAINNET}; use reth_e2e_test_utils::{setup, transaction::TransactionTestContext}; use reth_node_ethereum::EthereumNode; -use std::sync::Arc; + +use crate::utils::eth_payload_attributes; #[tokio::test] async fn can_sync() -> eyre::Result<()> { diff --git a/crates/ethereum/node/tests/it/exex.rs b/crates/ethereum/node/tests/it/exex.rs index 80366ba23db54..a1a513e6d2497 100644 --- a/crates/ethereum/node/tests/it/exex.rs +++ b/crates/ethereum/node/tests/it/exex.rs @@ -1,14 +1,15 @@ +use std::{ + future::Future, + pin::Pin, + task::{Context, Poll}, +}; + use futures::future; use reth_db::test_utils::create_test_rw_db; use reth_exex::ExExContext; use reth_node_api::FullNodeComponents; use reth_node_builder::{NodeBuilder, NodeConfig}; use reth_node_ethereum::EthereumNode; -use std::{ - future::Future, - pin::Pin, - task::{Context, Poll}, -}; struct DummyExEx { _ctx: ExExContext, diff --git a/crates/evm/execution-errors/src/lib.rs b/crates/evm/execution-errors/src/lib.rs index 9cc4d2ec12851..282c61c8d1acf 100644 --- a/crates/evm/execution-errors/src/lib.rs +++ b/crates/evm/execution-errors/src/lib.rs @@ -12,6 +12,9 @@ #[cfg(not(feature = "std"))] extern crate alloc; +#[cfg(not(feature = "std"))] +use alloc::{boxed::Box, string::String}; + use alloy_eips::BlockNumHash; use alloy_primitives::B256; use reth_consensus::ConsensusError; @@ -19,9 +22,6 @@ use reth_prune_types::PruneSegmentError; use reth_storage_errors::provider::ProviderError; use revm_primitives::EVMError; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, string::String}; - pub mod trie; pub use trie::{StateRootError, StorageRootError}; diff --git a/crates/evm/execution-types/src/chain.rs b/crates/evm/execution-types/src/chain.rs index 8833615bbc385..af96052b9b5fe 100644 --- a/crates/evm/execution-types/src/chain.rs +++ b/crates/evm/execution-types/src/chain.rs @@ -1,6 +1,7 @@ //! Contains [Chain], a chain of blocks and their final state. -use crate::ExecutionOutcome; +use std::{borrow::Cow, collections::BTreeMap, fmt, ops::RangeInclusive}; + use reth_execution_errors::BlockExecutionError; use reth_primitives::{ Address, BlockHash, BlockNumHash, BlockNumber, ForkBlock, Receipt, SealedBlock, @@ -8,7 +9,8 @@ use reth_primitives::{ }; use reth_trie::updates::TrieUpdates; use revm::db::BundleState; -use std::{borrow::Cow, collections::BTreeMap, fmt, ops::RangeInclusive}; + +use crate::ExecutionOutcome; /// A chain of blocks and their final state. /// @@ -500,10 +502,11 @@ pub enum ChainSplit { #[cfg(test)] mod tests { - use super::*; use reth_primitives::{Receipt, Receipts, TxType, B256}; use revm::primitives::{AccountInfo, HashMap}; + use super::*; + #[test] fn chain_append() { let block: SealedBlockWithSenders = SealedBlockWithSenders::default(); diff --git a/crates/evm/execution-types/src/execution_outcome.rs b/crates/evm/execution-types/src/execution_outcome.rs index 322e397a6be7d..d97b9f6d63fad 100644 --- a/crates/evm/execution-types/src/execution_outcome.rs +++ b/crates/evm/execution-types/src/execution_outcome.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use reth_primitives::{ logs_bloom, Account, Address, BlockNumber, Bloom, Bytecode, Log, Receipt, Receipts, Requests, StorageEntry, B256, U256, @@ -7,7 +9,6 @@ use revm::{ db::{states::BundleState, BundleAccount}, primitives::AccountInfo, }; -use std::collections::HashMap; /// Represents the outcome of block execution, including post-execution changes and reverts. /// @@ -328,11 +329,13 @@ impl ExecutionOutcome { #[cfg(test)] mod tests { - use super::*; + use std::collections::HashMap; + use alloy_eips::{eip6110::DepositRequest, eip7002::WithdrawalRequest}; use alloy_primitives::{FixedBytes, LogData}; use reth_primitives::{Address, Receipts, Request, Requests, TxType, B256}; - use std::collections::HashMap; + + use super::*; #[test] fn test_initialisation() { diff --git a/crates/evm/src/either.rs b/crates/evm/src/either.rs index 2f55f1668923c..f60cc26abc481 100644 --- a/crates/evm/src/either.rs +++ b/crates/evm/src/either.rs @@ -2,9 +2,8 @@ use std::fmt::Display; -use crate::execute::{ - BatchExecutor, BlockExecutionInput, BlockExecutionOutput, BlockExecutorProvider, Executor, -}; +// re-export Either +pub use futures_util::future::Either; use reth_execution_errors::BlockExecutionError; use reth_execution_types::ExecutionOutcome; use reth_primitives::{BlockNumber, BlockWithSenders, Receipt}; @@ -12,8 +11,9 @@ use reth_prune_types::PruneModes; use reth_storage_errors::provider::ProviderError; use revm_primitives::db::Database; -// re-export Either -pub use futures_util::future::Either; +use crate::execute::{ + BatchExecutor, BlockExecutionInput, BlockExecutionOutput, BlockExecutorProvider, Executor, +}; impl BlockExecutorProvider for Either where diff --git a/crates/evm/src/execute.rs b/crates/evm/src/execute.rs index 6d076fd45303b..a68cec0215fea 100644 --- a/crates/evm/src/execute.rs +++ b/crates/evm/src/execute.rs @@ -1,17 +1,16 @@ //! Traits for execution. -use reth_execution_types::ExecutionOutcome; -use reth_primitives::{BlockNumber, BlockWithSenders, Receipt, Request, U256}; -use reth_prune_types::PruneModes; -use revm::db::BundleState; -use revm_primitives::db::Database; -use std::fmt::Display; - #[cfg(not(feature = "std"))] use alloc::vec::Vec; +use std::fmt::Display; pub use reth_execution_errors::{BlockExecutionError, BlockValidationError}; +use reth_execution_types::ExecutionOutcome; +use reth_primitives::{BlockNumber, BlockWithSenders, Receipt, Request, U256}; +use reth_prune_types::PruneModes; pub use reth_storage_errors::provider::ProviderError; +use revm::db::BundleState; +use revm_primitives::db::Database; /// A general purpose executor trait that executes an input (e.g. block) and produces an output /// (e.g. state changes and receipts). @@ -179,10 +178,12 @@ pub trait BlockExecutorProvider: Send + Sync + Clone + Unpin + 'static { #[cfg(test)] mod tests { - use super::*; + use std::marker::PhantomData; + use reth_primitives::Block; use revm::db::{CacheDB, EmptyDBTyped}; - use std::marker::PhantomData; + + use super::*; #[derive(Clone, Default)] struct TestExecutorProvider; diff --git a/crates/evm/src/provider.rs b/crates/evm/src/provider.rs index abf04be8938c3..61af523429f4c 100644 --- a/crates/evm/src/provider.rs +++ b/crates/evm/src/provider.rs @@ -1,10 +1,11 @@ //! Provider trait for populating the EVM environment. -use crate::ConfigureEvmEnv; use reth_primitives::{BlockHashOrNumber, Header}; use reth_storage_errors::provider::ProviderResult; use revm::primitives::{BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, SpecId}; +use crate::ConfigureEvmEnv; + /// A provider type that knows chain specific information required to configure a /// [CfgEnvWithHandlerCfg]. /// diff --git a/crates/evm/src/test_utils.rs b/crates/evm/src/test_utils.rs index a4d098f0b3aa9..f670c5cc9e823 100644 --- a/crates/evm/src/test_utils.rs +++ b/crates/evm/src/test_utils.rs @@ -1,8 +1,7 @@ //! Helpers for testing. -use crate::execute::{ - BatchExecutor, BlockExecutionInput, BlockExecutionOutput, BlockExecutorProvider, Executor, -}; +use std::{fmt::Display, sync::Arc}; + use parking_lot::Mutex; use reth_execution_errors::BlockExecutionError; use reth_execution_types::ExecutionOutcome; @@ -10,7 +9,10 @@ use reth_primitives::{BlockNumber, BlockWithSenders, Receipt}; use reth_prune_types::PruneModes; use reth_storage_errors::provider::ProviderError; use revm_primitives::db::Database; -use std::{fmt::Display, sync::Arc}; + +use crate::execute::{ + BatchExecutor, BlockExecutionInput, BlockExecutionOutput, BlockExecutorProvider, Executor, +}; /// A [`BlockExecutorProvider`] that returns mocked execution results. #[derive(Clone, Debug, Default)] diff --git a/crates/exex/exex/src/context.rs b/crates/exex/exex/src/context.rs index 86939e3ba7679..08d335e80f500 100644 --- a/crates/exex/exex/src/context.rs +++ b/crates/exex/exex/src/context.rs @@ -1,11 +1,13 @@ -use crate::{ExExEvent, ExExNotification}; +use std::fmt::Debug; + use reth_node_api::FullNodeComponents; use reth_node_core::node_config::NodeConfig; use reth_primitives::Head; use reth_tasks::TaskExecutor; -use std::fmt::Debug; use tokio::sync::mpsc::{Receiver, UnboundedSender}; +use crate::{ExExEvent, ExExNotification}; + /// Captures the context that an `ExEx` has access to. pub struct ExExContext { /// The current head of the blockchain at launch. diff --git a/crates/exex/exex/src/lib.rs b/crates/exex/exex/src/lib.rs index a7661d855f418..ba3b9f887f5bc 100644 --- a/crates/exex/exex/src/lib.rs +++ b/crates/exex/exex/src/lib.rs @@ -45,7 +45,6 @@ pub use manager::*; mod notification; pub use notification::*; - // Re-export exex types #[doc(inline)] pub use reth_exex_types::*; diff --git a/crates/exex/exex/src/manager.rs b/crates/exex/exex/src/manager.rs index ce4994c34b038..38c0abc76e7e6 100644 --- a/crates/exex/exex/src/manager.rs +++ b/crates/exex/exex/src/manager.rs @@ -1,8 +1,3 @@ -use crate::{ExExEvent, ExExNotification, FinishedExExHeight}; -use metrics::Gauge; -use reth_metrics::{metrics::Counter, Metrics}; -use reth_primitives::BlockNumber; -use reth_tracing::tracing::debug; use std::{ collections::VecDeque, future::{poll_fn, Future}, @@ -13,12 +8,19 @@ use std::{ }, task::{ready, Context, Poll}, }; + +use metrics::Gauge; +use reth_metrics::{metrics::Counter, Metrics}; +use reth_primitives::BlockNumber; +use reth_tracing::tracing::debug; use tokio::sync::{ mpsc::{self, error::SendError, Receiver, UnboundedReceiver, UnboundedSender}, watch, }; use tokio_util::sync::{PollSendError, PollSender, ReusableBoxFuture}; +use crate::{ExExEvent, ExExNotification, FinishedExExHeight}; + /// Metrics for an `ExEx`. #[derive(Metrics)] #[metrics(scope = "exex")] diff --git a/crates/exex/test-utils/src/lib.rs b/crates/exex/test-utils/src/lib.rs index cba6e01246e65..2f43350c0e1ba 100644 --- a/crates/exex/test-utils/src/lib.rs +++ b/crates/exex/test-utils/src/lib.rs @@ -8,6 +8,13 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(test), warn(unused_crate_dependencies))] +use std::{ + fmt::Debug, + future::{poll_fn, Future}, + sync::Arc, + task::Poll, +}; + use futures_util::FutureExt; use reth_blockchain_tree::noop::NoopBlockchainTree; use reth_chainspec::{ChainSpec, MAINNET}; @@ -39,12 +46,6 @@ use reth_provider::{ }; use reth_tasks::TaskManager; use reth_transaction_pool::test_utils::{testing_pool, TestPool}; -use std::{ - fmt::Debug, - future::{poll_fn, Future}, - sync::Arc, - task::Poll, -}; use thiserror::Error; use tokio::sync::mpsc::{Sender, UnboundedReceiver}; diff --git a/crates/metrics/metrics-derive/tests/metrics.rs b/crates/metrics/metrics-derive/tests/metrics.rs index d5ed81a737227..e01cec543dca1 100644 --- a/crates/metrics/metrics-derive/tests/metrics.rs +++ b/crates/metrics/metrics-derive/tests/metrics.rs @@ -1,10 +1,11 @@ +use std::{collections::HashMap, sync::Mutex}; + use metrics::{ Counter, Gauge, Histogram, Key, KeyName, Label, Metadata, Recorder, SharedString, Unit, }; use once_cell::sync::Lazy; use reth_metrics_derive::Metrics; use serial_test::serial; -use std::{collections::HashMap, sync::Mutex}; #[allow(dead_code)] #[derive(Metrics)] diff --git a/crates/metrics/src/common/mpsc.rs b/crates/metrics/src/common/mpsc.rs index 6d45f0f0faee6..be857c7a7ba75 100644 --- a/crates/metrics/src/common/mpsc.rs +++ b/crates/metrics/src/common/mpsc.rs @@ -1,13 +1,14 @@ //! Support for metering senders. Facilitates debugging by exposing metrics for number of messages //! sent, number of errors, etc. -use futures::Stream; -use metrics::Counter; -use reth_metrics_derive::Metrics; use std::{ pin::Pin, task::{ready, Context, Poll}, }; + +use futures::Stream; +use metrics::Counter; +use reth_metrics_derive::Metrics; use tokio::sync::mpsc::{ self, error::{SendError, TryRecvError, TrySendError}, diff --git a/crates/net/discv4/src/config.rs b/crates/net/discv4/src/config.rs index 4fae31f585aec..22a9db310f623 100644 --- a/crates/net/discv4/src/config.rs +++ b/crates/net/discv4/src/config.rs @@ -3,6 +3,11 @@ //! This basis of this file has been taken from the discv5 codebase: //! +use std::{ + collections::{HashMap, HashSet}, + time::Duration, +}; + use alloy_primitives::bytes::Bytes; use alloy_rlp::Encodable; use reth_net_banlist::BanList; @@ -10,10 +15,6 @@ use reth_net_nat::{NatResolver, ResolveNatInterval}; use reth_network_peers::NodeRecord; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -use std::{ - collections::{HashMap, HashSet}, - time::Duration, -}; /// Configuration parameters that define the performance of the discovery network. #[derive(Clone, Debug)] diff --git a/crates/net/discv4/src/lib.rs b/crates/net/discv4/src/lib.rs index 6e18892fdd0c8..c058be54df75f 100644 --- a/crates/net/discv4/src/lib.rs +++ b/crates/net/discv4/src/lib.rs @@ -24,10 +24,20 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -use crate::{ - error::{DecodePacketError, Discv4Error}, - proto::{FindNode, Message, Neighbours, Packet, Ping, Pong}, +use std::{ + cell::RefCell, + collections::{btree_map, hash_map::Entry, BTreeMap, HashMap, VecDeque}, + fmt, + future::poll_fn, + io, + net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4}, + pin::Pin, + rc::Rc, + sync::Arc, + task::{ready, Context, Poll}, + time::{Duration, Instant, SystemTime, UNIX_EPOCH}, }; + use alloy_primitives::{bytes::Bytes, hex, B256}; use discv5::{ kbucket, @@ -43,19 +53,6 @@ use proto::{EnrRequest, EnrResponse}; use reth_ethereum_forks::ForkId; use reth_network_peers::{pk2id, PeerId}; use secp256k1::SecretKey; -use std::{ - cell::RefCell, - collections::{btree_map, hash_map::Entry, BTreeMap, HashMap, VecDeque}, - fmt, - future::poll_fn, - io, - net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4}, - pin::Pin, - rc::Rc, - sync::Arc, - task::{ready, Context, Poll}, - time::{Duration, Instant, SystemTime, UNIX_EPOCH}, -}; use tokio::{ net::UdpSocket, sync::{mpsc, mpsc::error::TrySendError, oneshot, oneshot::Sender as OneshotSender}, @@ -65,6 +62,11 @@ use tokio::{ use tokio_stream::{wrappers::ReceiverStream, Stream, StreamExt}; use tracing::{debug, trace}; +use crate::{ + error::{DecodePacketError, Discv4Error}, + proto::{FindNode, Message, Neighbours, Packet, Ping, Pong}, +}; + pub mod error; pub mod proto; @@ -82,11 +84,12 @@ pub use reth_network_peers::NodeRecord; #[cfg(any(test, feature = "test-utils"))] pub mod test_utils; -use crate::table::PongTable; use reth_net_nat::ResolveNatInterval; /// reexport to get public ip. pub use reth_net_nat::{external_ip, NatResolver}; +use crate::table::PongTable; + /// The default address for discv4 via UDP /// /// Note: the default TCP address is the same. @@ -213,12 +216,13 @@ impl Discv4 { /// /// ``` /// # use std::io; + /// use std::{net::SocketAddr, str::FromStr}; + /// /// use rand::thread_rng; /// use reth_chainspec::net::NodeRecord; /// use reth_discv4::{Discv4, Discv4Config}; /// use reth_network_peers::{pk2id, PeerId}; /// use secp256k1::SECP256K1; - /// use std::{net::SocketAddr, str::FromStr}; /// # async fn t() -> io::Result<()> { /// // generate a (random) keypair /// let mut rng = thread_rng(); @@ -2283,14 +2287,16 @@ pub enum DiscoveryUpdate { #[cfg(test)] mod tests { - use super::*; - use crate::test_utils::{create_discv4, create_discv4_with_config, rng_endpoint, rng_record}; + use std::future::poll_fn; + use alloy_primitives::hex; use alloy_rlp::{Decodable, Encodable}; use rand::{thread_rng, Rng}; use reth_chainspec::net::mainnet_nodes; use reth_ethereum_forks::{EnrForkIdEntry, ForkHash}; - use std::future::poll_fn; + + use super::*; + use crate::test_utils::{create_discv4, create_discv4_with_config, rng_endpoint, rng_record}; #[tokio::test] async fn test_configured_enr_forkid_entry() { diff --git a/crates/net/discv4/src/proto.rs b/crates/net/discv4/src/proto.rs index 6d2639f2d6f99..58b8195da0de8 100644 --- a/crates/net/discv4/src/proto.rs +++ b/crates/net/discv4/src/proto.rs @@ -1,6 +1,7 @@ //! Discovery v4 protocol implementation. -use crate::{error::DecodePacketError, MAX_PACKET_SIZE, MIN_PACKET_SIZE}; +use std::net::IpAddr; + use alloy_primitives::{ bytes::{Buf, BufMut, Bytes, BytesMut}, keccak256, B256, @@ -13,7 +14,8 @@ use secp256k1::{ ecdsa::{RecoverableSignature, RecoveryId}, SecretKey, SECP256K1, }; -use std::net::IpAddr; + +use crate::{error::DecodePacketError, MAX_PACKET_SIZE, MIN_PACKET_SIZE}; // Note: this is adapted from https://github.com/vorot93/discv4 @@ -537,17 +539,18 @@ impl Decodable for Pong { #[cfg(test)] mod tests { - use super::*; - use crate::{ - test_utils::{rng_endpoint, rng_ipv4_record, rng_ipv6_record, rng_message}, - DEFAULT_DISCOVERY_PORT, SAFE_MAX_DATAGRAM_NEIGHBOUR_RECORDS, - }; use alloy_primitives::hex; use assert_matches::assert_matches; use enr::EnrPublicKey; use rand::{thread_rng, Rng, RngCore}; use reth_ethereum_forks::ForkHash; + use super::*; + use crate::{ + test_utils::{rng_endpoint, rng_ipv4_record, rng_ipv6_record, rng_message}, + DEFAULT_DISCOVERY_PORT, SAFE_MAX_DATAGRAM_NEIGHBOUR_RECORDS, + }; + #[test] fn test_endpoint_ipv_v4() { let mut rng = thread_rng(); @@ -745,9 +748,10 @@ mod tests { #[test] fn encode_decode_enr_msg() { + use std::net::Ipv4Addr; + use alloy_rlp::Decodable; use enr::secp256k1::SecretKey; - use std::net::Ipv4Addr; let mut rng = rand::rngs::OsRng; let key = SecretKey::new(&mut rng); @@ -783,9 +787,10 @@ mod tests { #[test] fn encode_known_rlp_enr() { + use std::net::Ipv4Addr; + use alloy_rlp::Decodable; use enr::{secp256k1::SecretKey, EnrPublicKey}; - use std::net::Ipv4Addr; let valid_record = hex!("f884b8407098ad865b00a582051940cb9cf36836572411a47278783077011599ed5cd16b76f2635f4e234738f30813a89eb9137e3e3df5266e3a1f11df72ecf1145ccb9c01826964827634826970847f00000189736563703235366b31a103ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd31388375647082765f"); let signature = hex!("7098ad865b00a582051940cb9cf36836572411a47278783077011599ed5cd16b76f2635f4e234738f30813a89eb9137e3e3df5266e3a1f11df72ecf1145ccb9c"); @@ -813,9 +818,10 @@ mod tests { // #[test] fn decode_enr_rlp() { - use enr::secp256k1::SecretKey; use std::net::Ipv4Addr; + use enr::secp256k1::SecretKey; + let valid_record = hex!("f884b8407098ad865b00a582051940cb9cf36836572411a47278783077011599ed5cd16b76f2635f4e234738f30813a89eb9137e3e3df5266e3a1f11df72ecf1145ccb9c01826964827634826970847f00000189736563703235366b31a103ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd31388375647082765f"); let signature = hex!("7098ad865b00a582051940cb9cf36836572411a47278783077011599ed5cd16b76f2635f4e234738f30813a89eb9137e3e3df5266e3a1f11df72ecf1145ccb9c"); let expected_pubkey = @@ -841,9 +847,10 @@ mod tests { // #[test] fn encode_decode_enr_rlp() { - use enr::{secp256k1::SecretKey, EnrPublicKey}; use std::net::Ipv4Addr; + use enr::{secp256k1::SecretKey, EnrPublicKey}; + let key = SecretKey::new(&mut rand::rngs::OsRng); let ip = Ipv4Addr::new(127, 0, 0, 1); let tcp = 3000; diff --git a/crates/net/discv4/src/table.rs b/crates/net/discv4/src/table.rs index 315bd33bcd797..04711ee56b6e1 100644 --- a/crates/net/discv4/src/table.rs +++ b/crates/net/discv4/src/table.rs @@ -1,8 +1,9 @@ //! Additional support for tracking nodes. -use reth_network_peers::PeerId; use std::{collections::HashMap, net::IpAddr, time::Instant}; +use reth_network_peers::PeerId; + /// Keeps track of nodes from which we have received a `Pong` message. #[derive(Debug, Clone, Default)] pub(crate) struct PongTable { diff --git a/crates/net/discv4/src/test_utils.rs b/crates/net/discv4/src/test_utils.rs index 06133dba6790d..6e8cdb0996c1c 100644 --- a/crates/net/discv4/src/test_utils.rs +++ b/crates/net/discv4/src/test_utils.rs @@ -1,15 +1,5 @@ //! Mock discovery support -use crate::{ - proto::{FindNode, Message, Neighbours, NodeEndpoint, Packet, Ping, Pong}, - receive_loop, send_loop, Discv4, Discv4Config, Discv4Service, EgressSender, IngressEvent, - IngressReceiver, PeerId, SAFE_MAX_DATAGRAM_NEIGHBOUR_RECORDS, -}; -use alloy_primitives::{hex, B256}; -use rand::{thread_rng, Rng, RngCore}; -use reth_ethereum_forks::{ForkHash, ForkId}; -use reth_network_peers::{pk2id, NodeRecord}; -use secp256k1::{SecretKey, SECP256K1}; use std::{ collections::{HashMap, HashSet}, io, @@ -20,6 +10,12 @@ use std::{ task::{Context, Poll}, time::{Duration, SystemTime, UNIX_EPOCH}, }; + +use alloy_primitives::{hex, B256}; +use rand::{thread_rng, Rng, RngCore}; +use reth_ethereum_forks::{ForkHash, ForkId}; +use reth_network_peers::{pk2id, NodeRecord}; +use secp256k1::{SecretKey, SECP256K1}; use tokio::{ net::UdpSocket, sync::mpsc, @@ -28,6 +24,12 @@ use tokio::{ use tokio_stream::{Stream, StreamExt}; use tracing::debug; +use crate::{ + proto::{FindNode, Message, Neighbours, NodeEndpoint, Packet, Ping, Pong}, + receive_loop, send_loop, Discv4, Discv4Config, Discv4Service, EgressSender, IngressEvent, + IngressReceiver, PeerId, SAFE_MAX_DATAGRAM_NEIGHBOUR_RECORDS, +}; + /// Mock discovery node #[derive(Debug)] pub struct MockDiscovery { @@ -313,9 +315,10 @@ pub fn rng_message(rng: &mut impl RngCore) -> Message { #[cfg(test)] mod tests { + use std::net::Ipv4Addr; + use super::*; use crate::Discv4Event; - use std::net::Ipv4Addr; /// This test creates two local UDP sockets. The mocked discovery service responds to specific /// messages and we check the actual service receives answers diff --git a/crates/net/discv5/src/enr.rs b/crates/net/discv5/src/enr.rs index eb8b6be006b20..2a5e4091c41cf 100644 --- a/crates/net/discv5/src/enr.rs +++ b/crates/net/discv5/src/enr.rs @@ -55,12 +55,13 @@ impl From for Enr { #[cfg(test)] mod tests { - use super::*; use alloy_rlp::Encodable; use discv5::enr::{CombinedKey, EnrKey}; use reth_chainspec::{Hardfork, MAINNET}; use reth_network_peers::NodeRecord; + use super::*; + #[test] fn discv5_discv4_id_conversion() { let discv5_pk = CombinedKey::generate_secp256k1().public(); diff --git a/crates/net/discv5/src/filter.rs b/crates/net/discv5/src/filter.rs index 325544de6c180..55ce622c07401 100644 --- a/crates/net/discv5/src/filter.rs +++ b/crates/net/discv5/src/filter.rs @@ -92,9 +92,8 @@ mod tests { use alloy_rlp::Bytes; use discv5::enr::{CombinedKey, Enr}; - use crate::NetworkStackId; - use super::*; + use crate::NetworkStackId; #[test] fn must_not_include_key_filter() { diff --git a/crates/net/discv5/src/lib.rs b/crates/net/discv5/src/lib.rs index 5b0044a721f5c..df3152f22858b 100644 --- a/crates/net/discv5/src/lib.rs +++ b/crates/net/discv5/src/lib.rs @@ -36,19 +36,17 @@ pub mod filter; pub mod metrics; pub mod network_stack_id; -pub use discv5::{self, IpMode}; - pub use config::{ BootNode, Config, ConfigBuilder, DEFAULT_COUNT_BOOTSTRAP_LOOKUPS, DEFAULT_DISCOVERY_V5_ADDR, DEFAULT_DISCOVERY_V5_ADDR_IPV6, DEFAULT_DISCOVERY_V5_PORT, DEFAULT_SECONDS_BOOTSTRAP_LOOKUP_INTERVAL, DEFAULT_SECONDS_LOOKUP_INTERVAL, }; +pub use discv5::{self, IpMode}; pub use enr::enr_to_discv4_id; pub use error::Error; pub use filter::{FilterOutcome, MustNotIncludeKeys}; -pub use network_stack_id::NetworkStackId; - use metrics::{DiscoveredPeersMetrics, Discv5Metrics}; +pub use network_stack_id::NetworkStackId; /// Max kbucket index is 255. /// @@ -651,12 +649,13 @@ pub async fn lookup( #[cfg(test)] mod test { - use super::*; use ::enr::{CombinedKey, EnrKey}; use reth_chainspec::MAINNET; use secp256k1::rand::thread_rng; use tracing::trace; + use super::*; + fn discv5_noop() -> Discv5 { let sk = CombinedKey::generate_secp256k1(); Discv5 { diff --git a/crates/net/dns/src/config.rs b/crates/net/dns/src/config.rs index 1b85280f13b6f..643449532684f 100644 --- a/crates/net/dns/src/config.rs +++ b/crates/net/dns/src/config.rs @@ -1,4 +1,3 @@ -use crate::tree::LinkEntry; use std::{ collections::HashSet, num::{NonZeroU32, NonZeroUsize}, @@ -8,6 +7,8 @@ use std::{ #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; +use crate::tree::LinkEntry; + /// Settings for the [`DnsDiscoveryService`](crate::DnsDiscoveryService). #[derive(Debug, Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] diff --git a/crates/net/dns/src/lib.rs b/crates/net/dns/src/lib.rs index f07fde2e4a678..dcfb5aa7ff687 100644 --- a/crates/net/dns/src/lib.rs +++ b/crates/net/dns/src/lib.rs @@ -13,19 +13,6 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -pub use crate::resolver::{DnsResolver, MapResolver, Resolver}; -use crate::{ - query::{QueryOutcome, QueryPool, ResolveEntryResult, ResolveRootResult}, - sync::{ResolveKind, SyncAction}, - tree::{DnsEntry, LinkEntry}, -}; -pub use config::DnsDiscoveryConfig; -use enr::Enr; -use error::ParseDnsEntryError; -use reth_ethereum_forks::{EnrForkIdEntry, ForkId}; -use reth_network_peers::{pk2id, NodeRecord}; -use schnellru::{ByLength, LruMap}; -use secp256k1::SecretKey; use std::{ collections::{hash_map::Entry, HashMap, HashSet, VecDeque}, net::IpAddr, @@ -34,6 +21,14 @@ use std::{ task::{ready, Context, Poll}, time::{Duration, Instant}, }; + +pub use config::DnsDiscoveryConfig; +use enr::Enr; +use error::ParseDnsEntryError; +use reth_ethereum_forks::{EnrForkIdEntry, ForkId}; +use reth_network_peers::{pk2id, NodeRecord}; +use schnellru::{ByLength, LruMap}; +use secp256k1::SecretKey; use sync::SyncTree; use tokio::{ sync::{ @@ -49,6 +44,13 @@ use tokio_stream::{ }; use tracing::{debug, trace}; +pub use crate::resolver::{DnsResolver, MapResolver, Resolver}; +use crate::{ + query::{QueryOutcome, QueryPool, ResolveEntryResult, ResolveRootResult}, + sync::{ResolveKind, SyncAction}, + tree::{DnsEntry, LinkEntry}, +}; + mod config; mod error; mod query; @@ -118,8 +120,9 @@ impl DnsDiscoveryService { /// Creates a new instance of the [`DnsDiscoveryService`] using the given settings. /// /// ``` - /// use reth_dns_discovery::{DnsDiscoveryService, DnsResolver}; /// use std::sync::Arc; + /// + /// use reth_dns_discovery::{DnsDiscoveryService, DnsResolver}; /// # fn t() { /// let service = DnsDiscoveryService::new( /// Arc::new(DnsResolver::from_system_conf().unwrap()), @@ -409,15 +412,17 @@ fn convert_enr_node_record(enr: &Enr) -> Option #[cfg(test)] mod tests { - use super::*; - use crate::tree::TreeRootEntry; + use std::{future::poll_fn, net::Ipv4Addr}; + use alloy_chains::Chain; use alloy_rlp::{Decodable, Encodable}; use enr::EnrKey; use reth_chainspec::MAINNET; use reth_ethereum_forks::{ForkHash, Hardfork}; use secp256k1::rand::thread_rng; - use std::{future::poll_fn, net::Ipv4Addr}; + + use super::*; + use crate::tree::TreeRootEntry; #[test] fn test_convert_enr_node_record() { diff --git a/crates/net/dns/src/query.rs b/crates/net/dns/src/query.rs index 6023f82dcf263..d904f66b6e000 100644 --- a/crates/net/dns/src/query.rs +++ b/crates/net/dns/src/query.rs @@ -1,13 +1,5 @@ //! Handles query execution -use crate::{ - error::{LookupError, LookupResult}, - resolver::Resolver, - sync::ResolveKind, - tree::{DnsEntry, LinkEntry, TreeRootEntry}, -}; -use enr::EnrKeyUnambiguous; -use reth_tokio_util::ratelimit::{Rate, RateLimit}; use std::{ collections::VecDeque, future::Future, @@ -18,6 +10,16 @@ use std::{ time::Duration, }; +use enr::EnrKeyUnambiguous; +use reth_tokio_util::ratelimit::{Rate, RateLimit}; + +use crate::{ + error::{LookupError, LookupResult}, + resolver::Resolver, + sync::ResolveKind, + tree::{DnsEntry, LinkEntry, TreeRootEntry}, +}; + /// The `QueryPool` provides an aggregate state machine for driving queries to completion. pub(crate) struct QueryPool { /// The [Resolver] that's used to lookup queries. @@ -212,9 +214,10 @@ async fn lookup_with_timeout( #[cfg(test)] mod tests { + use std::future::poll_fn; + use super::*; use crate::{resolver::TimeoutResolver, DnsDiscoveryConfig, MapResolver}; - use std::future::poll_fn; #[tokio::test] async fn test_rate_limit() { diff --git a/crates/net/dns/src/resolver.rs b/crates/net/dns/src/resolver.rs index 42c444f89a75f..0d272e53f2671 100644 --- a/crates/net/dns/src/resolver.rs +++ b/crates/net/dns/src/resolver.rs @@ -1,7 +1,8 @@ //! Perform DNS lookups -use parking_lot::RwLock; use std::{collections::HashMap, future::Future}; + +use parking_lot::RwLock; use tracing::trace; pub use trust_dns_resolver::{error::ResolveError, TokioAsyncResolver}; use trust_dns_resolver::{name_server::ConnectionProvider, AsyncResolver}; diff --git a/crates/net/dns/src/sync.rs b/crates/net/dns/src/sync.rs index cfe6862c934d7..8a36fe8e00660 100644 --- a/crates/net/dns/src/sync.rs +++ b/crates/net/dns/src/sync.rs @@ -1,12 +1,14 @@ -use crate::tree::{LinkEntry, TreeRootEntry}; -use enr::EnrKeyUnambiguous; -use linked_hash_set::LinkedHashSet; -use secp256k1::SecretKey; use std::{ collections::HashMap, time::{Duration, Instant}, }; +use enr::EnrKeyUnambiguous; +use linked_hash_set::LinkedHashSet; +use secp256k1::SecretKey; + +use crate::tree::{LinkEntry, TreeRootEntry}; + /// A sync-able tree pub(crate) struct SyncTree { /// Root of the tree diff --git a/crates/net/dns/src/tree.rs b/crates/net/dns/src/tree.rs index 80182b694f80f..25cd9b8672d91 100644 --- a/crates/net/dns/src/tree.rs +++ b/crates/net/dns/src/tree.rs @@ -16,21 +16,23 @@ //! `signature` is a 65-byte secp256k1 EC signature over the keccak256 hash of the record //! content, excluding the sig= part, encoded as URL-safe base64 (RFC-4648). -use crate::error::{ - ParseDnsEntryError, - ParseDnsEntryError::{FieldNotFound, UnknownEntry}, - ParseEntryResult, +use std::{ + fmt, + hash::{Hash, Hasher}, + str::FromStr, }; + use alloy_primitives::{hex, Bytes}; use data_encoding::{BASE32_NOPAD, BASE64URL_NOPAD}; use enr::{Enr, EnrKey, EnrKeyUnambiguous, EnrPublicKey, Error as EnrError}; use secp256k1::SecretKey; #[cfg(feature = "serde")] use serde_with::{DeserializeFromStr, SerializeDisplay}; -use std::{ - fmt, - hash::{Hash, Hasher}, - str::FromStr, + +use crate::error::{ + ParseDnsEntryError, + ParseDnsEntryError::{FieldNotFound, UnknownEntry}, + ParseEntryResult, }; /// Prefix used for root entries in the ENR tree. diff --git a/crates/net/downloaders/src/bodies/bodies.rs b/crates/net/downloaders/src/bodies/bodies.rs index 9d651eee13a2c..0df672810f9c0 100644 --- a/crates/net/downloaders/src/bodies/bodies.rs +++ b/crates/net/downloaders/src/bodies/bodies.rs @@ -1,5 +1,13 @@ -use super::queue::BodiesRequestQueue; -use crate::{bodies::task::TaskDownloader, metrics::BodyDownloaderMetrics}; +use std::{ + cmp::Ordering, + collections::BinaryHeap, + mem, + ops::RangeInclusive, + pin::Pin, + sync::Arc, + task::{Context, Poll}, +}; + use futures::Stream; use futures_util::StreamExt; use reth_config::BodiesConfig; @@ -15,17 +23,11 @@ use reth_network_p2p::{ use reth_primitives::{BlockNumber, SealedHeader}; use reth_storage_api::HeaderProvider; use reth_tasks::{TaskSpawner, TokioTaskExecutor}; -use std::{ - cmp::Ordering, - collections::BinaryHeap, - mem, - ops::RangeInclusive, - pin::Pin, - sync::Arc, - task::{Context, Poll}, -}; use tracing::info; +use super::queue::BodiesRequestQueue; +use crate::{bodies::task::TaskDownloader, metrics::BodyDownloaderMetrics}; + /// Downloads bodies in batches. /// /// All blocks in a batch are fetched at the same time. @@ -598,11 +600,8 @@ impl BodiesDownloaderBuilder { #[cfg(test)] mod tests { - use super::*; - use crate::{ - bodies::test_utils::{insert_headers, zip_blocks}, - test_utils::{generate_bodies, TestBodiesClient}, - }; + use std::collections::HashMap; + use assert_matches::assert_matches; use reth_chainspec::MAINNET; use reth_consensus::test_utils::TestConsensus; @@ -610,7 +609,12 @@ mod tests { use reth_primitives::{BlockBody, B256}; use reth_provider::{providers::StaticFileProvider, ProviderFactory}; use reth_testing_utils::{generators, generators::random_block_range}; - use std::collections::HashMap; + + use super::*; + use crate::{ + bodies::test_utils::{insert_headers, zip_blocks}, + test_utils::{generate_bodies, TestBodiesClient}, + }; // Check that the blocks are emitted in order of block number, not in order of // first-downloaded diff --git a/crates/net/downloaders/src/bodies/noop.rs b/crates/net/downloaders/src/bodies/noop.rs index b1aa0e2eaa628..6f9a02415c596 100644 --- a/crates/net/downloaders/src/bodies/noop.rs +++ b/crates/net/downloaders/src/bodies/noop.rs @@ -1,10 +1,11 @@ +use std::ops::RangeInclusive; + use futures::Stream; use reth_network_p2p::{ bodies::{downloader::BodyDownloader, response::BlockResponse}, error::{DownloadError, DownloadResult}, }; use reth_primitives::BlockNumber; -use std::ops::RangeInclusive; /// A [`BodyDownloader`] implementation that does nothing. #[derive(Debug, Default)] diff --git a/crates/net/downloaders/src/bodies/queue.rs b/crates/net/downloaders/src/bodies/queue.rs index 35e5b4414e6a1..bd7359ee8c450 100644 --- a/crates/net/downloaders/src/bodies/queue.rs +++ b/crates/net/downloaders/src/bodies/queue.rs @@ -1,5 +1,9 @@ -use super::request::BodiesRequestFuture; -use crate::metrics::BodyDownloaderMetrics; +use std::{ + pin::Pin, + sync::Arc, + task::{Context, Poll}, +}; + use futures::{stream::FuturesUnordered, Stream}; use futures_util::StreamExt; use reth_consensus::Consensus; @@ -8,11 +12,9 @@ use reth_network_p2p::{ error::DownloadResult, }; use reth_primitives::{BlockNumber, SealedHeader}; -use std::{ - pin::Pin, - sync::Arc, - task::{Context, Poll}, -}; + +use super::request::BodiesRequestFuture; +use crate::metrics::BodyDownloaderMetrics; /// The wrapper around [`FuturesUnordered`] that keeps information /// about the blocks currently being requested. diff --git a/crates/net/downloaders/src/bodies/request.rs b/crates/net/downloaders/src/bodies/request.rs index f27801041e834..075d7f8832373 100644 --- a/crates/net/downloaders/src/bodies/request.rs +++ b/crates/net/downloaders/src/bodies/request.rs @@ -1,4 +1,11 @@ -use crate::metrics::{BodyDownloaderMetrics, ResponseMetrics}; +use std::{ + collections::VecDeque, + mem, + pin::Pin, + sync::Arc, + task::{ready, Context, Poll}, +}; + use futures::{Future, FutureExt}; use reth_consensus::Consensus; use reth_network_p2p::{ @@ -8,13 +15,8 @@ use reth_network_p2p::{ }; use reth_network_peers::{PeerId, WithPeerId}; use reth_primitives::{BlockBody, GotExpected, SealedBlock, SealedHeader, B256}; -use std::{ - collections::VecDeque, - mem, - pin::Pin, - sync::Arc, - task::{ready, Context, Poll}, -}; + +use crate::metrics::{BodyDownloaderMetrics, ResponseMetrics}; /// Body request implemented as a [Future]. /// @@ -249,13 +251,14 @@ where #[cfg(test)] mod tests { + use reth_consensus::test_utils::TestConsensus; + use reth_testing_utils::{generators, generators::random_header_range}; + use super::*; use crate::{ bodies::test_utils::zip_blocks, test_utils::{generate_bodies, TestBodiesClient}, }; - use reth_consensus::test_utils::TestConsensus; - use reth_testing_utils::{generators, generators::random_header_range}; /// Check if future returns empty bodies without dispatching any requests. #[tokio::test] diff --git a/crates/net/downloaders/src/bodies/task.rs b/crates/net/downloaders/src/bodies/task.rs index aa5bc27527e2b..632ac2493821c 100644 --- a/crates/net/downloaders/src/bodies/task.rs +++ b/crates/net/downloaders/src/bodies/task.rs @@ -1,3 +1,10 @@ +use std::{ + future::Future, + ops::RangeInclusive, + pin::Pin, + task::{ready, Context, Poll}, +}; + use futures::Stream; use futures_util::{FutureExt, StreamExt}; use pin_project::pin_project; @@ -7,12 +14,6 @@ use reth_network_p2p::{ }; use reth_primitives::BlockNumber; use reth_tasks::{TaskSpawner, TokioTaskExecutor}; -use std::{ - future::Future, - ops::RangeInclusive, - pin::Pin, - task::{ready, Context, Poll}, -}; use tokio::sync::{mpsc, mpsc::UnboundedSender}; use tokio_stream::wrappers::{ReceiverStream, UnboundedReceiverStream}; use tokio_util::sync::PollSender; @@ -42,11 +43,12 @@ impl TaskDownloader { /// # Example /// /// ``` + /// use std::sync::Arc; + /// /// use reth_consensus::Consensus; /// use reth_downloaders::bodies::{bodies::BodiesDownloaderBuilder, task::TaskDownloader}; /// use reth_network_p2p::bodies::client::BodiesClient; /// use reth_storage_api::HeaderProvider; - /// use std::sync::Arc; /// /// fn t( /// client: Arc, @@ -161,6 +163,13 @@ impl Future for SpawnedDownloader { #[cfg(test)] mod tests { + use std::sync::Arc; + + use assert_matches::assert_matches; + use reth_consensus::test_utils::TestConsensus; + use reth_network_p2p::error::DownloadError; + use reth_provider::test_utils::create_test_provider_factory; + use super::*; use crate::{ bodies::{ @@ -169,11 +178,6 @@ mod tests { }, test_utils::{generate_bodies, TestBodiesClient}, }; - use assert_matches::assert_matches; - use reth_consensus::test_utils::TestConsensus; - use reth_network_p2p::error::DownloadError; - use reth_provider::test_utils::create_test_provider_factory; - use std::sync::Arc; #[tokio::test(flavor = "multi_thread")] async fn download_one_by_one_on_task() { diff --git a/crates/net/downloaders/src/bodies/test_utils.rs b/crates/net/downloaders/src/bodies/test_utils.rs index b730510e8e74a..b45e233f90ee6 100644 --- a/crates/net/downloaders/src/bodies/test_utils.rs +++ b/crates/net/downloaders/src/bodies/test_utils.rs @@ -2,11 +2,12 @@ #![allow(dead_code)] +use std::collections::HashMap; + use reth_db::{tables, DatabaseEnv}; use reth_db_api::{database::Database, transaction::DbTxMut}; use reth_network_p2p::bodies::response::BlockResponse; use reth_primitives::{Block, BlockBody, SealedBlock, SealedHeader, B256}; -use std::collections::HashMap; pub(crate) fn zip_blocks<'a>( headers: impl Iterator, diff --git a/crates/net/downloaders/src/file_client.rs b/crates/net/downloaders/src/file_client.rs index 3464baf5d6ff7..8850f467e6ba2 100644 --- a/crates/net/downloaders/src/file_client.rs +++ b/crates/net/downloaders/src/file_client.rs @@ -1,4 +1,5 @@ -use super::file_codec::BlockFileCodec; +use std::{collections::HashMap, io, path::Path}; + use futures::Future; use itertools::Either; use reth_network_p2p::{ @@ -13,13 +14,14 @@ use reth_primitives::{ BlockBody, BlockHash, BlockHashOrNumber, BlockNumber, Header, HeadersDirection, SealedHeader, B256, }; -use std::{collections::HashMap, io, path::Path}; use thiserror::Error; use tokio::{fs::File, io::AsyncReadExt}; use tokio_stream::StreamExt; use tokio_util::codec::FramedRead; use tracing::{debug, trace, warn}; +use super::file_codec::BlockFileCodec; + /// Default byte length of chunk to read from chain file. /// /// Default is 1 GB. @@ -467,15 +469,8 @@ pub trait FromReader { #[cfg(test)] mod tests { - use super::*; - use crate::{ - bodies::{ - bodies::BodiesDownloaderBuilder, - test_utils::{insert_headers, zip_blocks}, - }, - headers::{reverse_headers::ReverseHeadersDownloaderBuilder, test_utils::child_header}, - test_utils::{generate_bodies, generate_bodies_file}, - }; + use std::sync::Arc; + use assert_matches::assert_matches; use futures_util::stream::StreamExt; use rand::Rng; @@ -485,7 +480,16 @@ mod tests { headers::downloader::{HeaderDownloader, SyncTarget}, }; use reth_provider::test_utils::create_test_provider_factory; - use std::sync::Arc; + + use super::*; + use crate::{ + bodies::{ + bodies::BodiesDownloaderBuilder, + test_utils::{insert_headers, zip_blocks}, + }, + headers::{reverse_headers::ReverseHeadersDownloaderBuilder, test_utils::child_header}, + test_utils::{generate_bodies, generate_bodies_file}, + }; #[tokio::test] async fn streams_bodies_from_buffer() { diff --git a/crates/net/downloaders/src/file_codec.rs b/crates/net/downloaders/src/file_codec.rs index 156f3316c431c..c3272a65ceec1 100644 --- a/crates/net/downloaders/src/file_codec.rs +++ b/crates/net/downloaders/src/file_codec.rs @@ -1,6 +1,5 @@ //! Codec for reading raw block bodies from a file. -use crate::file_client::FileClientError; use alloy_rlp::{Decodable, Encodable}; use reth_primitives::{ bytes::{Buf, BytesMut}, @@ -8,6 +7,8 @@ use reth_primitives::{ }; use tokio_util::codec::{Decoder, Encoder}; +use crate::file_client::FileClientError; + /// Codec for reading raw block bodies from a file. /// /// If using with [`FramedRead`](tokio_util::codec::FramedRead), the user should make sure the diff --git a/crates/net/downloaders/src/headers/reverse_headers.rs b/crates/net/downloaders/src/headers/reverse_headers.rs index e123ce71229a1..2949cbd11ea6f 100644 --- a/crates/net/downloaders/src/headers/reverse_headers.rs +++ b/crates/net/downloaders/src/headers/reverse_headers.rs @@ -1,7 +1,14 @@ //! A headers downloader that can handle multiple requests concurrently. -use super::task::TaskDownloader; -use crate::metrics::HeaderDownloaderMetrics; +use std::{ + cmp::{Ordering, Reverse}, + collections::{binary_heap::PeekMut, BinaryHeap}, + future::Future, + pin::Pin, + sync::Arc, + task::{ready, Context, Poll}, +}; + use futures::{stream::Stream, FutureExt}; use futures_util::{stream::FuturesUnordered, StreamExt}; use rayon::prelude::*; @@ -21,17 +28,12 @@ use reth_primitives::{ BlockHashOrNumber, BlockNumber, GotExpected, Header, HeadersDirection, SealedHeader, B256, }; use reth_tasks::{TaskSpawner, TokioTaskExecutor}; -use std::{ - cmp::{Ordering, Reverse}, - collections::{binary_heap::PeekMut, BinaryHeap}, - future::Future, - pin::Pin, - sync::Arc, - task::{ready, Context, Poll}, -}; use thiserror::Error; use tracing::{error, trace}; +use super::task::TaskDownloader; +use crate::metrics::HeaderDownloaderMetrics; + /// A heuristic that is used to determine the number of requests that should be prepared for a peer. /// This should ensure that there are always requests lined up for peers to handle while the /// downloader is yielding a next batch of headers that is being committed to the database. @@ -1207,12 +1209,13 @@ fn calc_next_request( #[cfg(test)] mod tests { - use super::*; - use crate::headers::test_utils::child_header; use assert_matches::assert_matches; use reth_consensus::test_utils::TestConsensus; use reth_network_p2p::test_utils::TestHeadersClient; + use super::*; + use crate::headers::test_utils::child_header; + /// Tests that `replace_number` works the same way as `Option::replace` #[test] fn test_replace_number_semantics() { diff --git a/crates/net/downloaders/src/headers/task.rs b/crates/net/downloaders/src/headers/task.rs index b3fa27fde59c4..7d80245830556 100644 --- a/crates/net/downloaders/src/headers/task.rs +++ b/crates/net/downloaders/src/headers/task.rs @@ -1,3 +1,9 @@ +use std::{ + future::Future, + pin::Pin, + task::{ready, Context, Poll}, +}; + use futures::{FutureExt, Stream}; use futures_util::StreamExt; use pin_project::pin_project; @@ -7,11 +13,6 @@ use reth_network_p2p::headers::{ }; use reth_primitives::SealedHeader; use reth_tasks::{TaskSpawner, TokioTaskExecutor}; -use std::{ - future::Future, - pin::Pin, - task::{ready, Context, Poll}, -}; use tokio::sync::{mpsc, mpsc::UnboundedSender}; use tokio_stream::wrappers::{ReceiverStream, UnboundedReceiverStream}; use tokio_util::sync::PollSender; @@ -179,13 +180,15 @@ enum DownloaderUpdates { #[cfg(test)] mod tests { + use std::sync::Arc; + + use reth_consensus::test_utils::TestConsensus; + use reth_network_p2p::test_utils::TestHeadersClient; + use super::*; use crate::headers::{ reverse_headers::ReverseHeadersDownloaderBuilder, test_utils::child_header, }; - use reth_consensus::test_utils::TestConsensus; - use reth_network_p2p::test_utils::TestHeadersClient; - use std::sync::Arc; #[tokio::test(flavor = "multi_thread")] async fn download_one_by_one_on_task() { diff --git a/crates/net/downloaders/src/receipt_file_client.rs b/crates/net/downloaders/src/receipt_file_client.rs index 9dd23489d3148..4039d3492a48e 100644 --- a/crates/net/downloaders/src/receipt_file_client.rs +++ b/crates/net/downloaders/src/receipt_file_client.rs @@ -223,6 +223,7 @@ mod test { use reth_primitives::hex; use reth_tracing::init_test_tracing; + use super::*; use crate::file_codec_ovm_receipt::{ test::{ receipt_block_1 as op_mainnet_receipt_block_1, @@ -235,8 +236,6 @@ mod test { HackReceiptFileCodec, }; - use super::*; - /// No receipts for genesis block const HACK_RECEIPT_BLOCK_NO_TRANSACTIONS: &[u8] = &hex!("c0"); diff --git a/crates/net/downloaders/src/test_utils/bodies_client.rs b/crates/net/downloaders/src/test_utils/bodies_client.rs index 7b655dae2891d..44f219d59f317 100644 --- a/crates/net/downloaders/src/test_utils/bodies_client.rs +++ b/crates/net/downloaders/src/test_utils/bodies_client.rs @@ -1,10 +1,3 @@ -use reth_network_p2p::{ - bodies::client::{BodiesClient, BodiesFut}, - download::DownloadClient, - priority::Priority, -}; -use reth_network_peers::PeerId; -use reth_primitives::{BlockBody, B256}; use std::{ collections::HashMap, fmt::Debug, @@ -14,6 +7,14 @@ use std::{ }, time::Duration, }; + +use reth_network_p2p::{ + bodies::client::{BodiesClient, BodiesFut}, + download::DownloadClient, + priority::Priority, +}; +use reth_network_peers::PeerId; +use reth_primitives::{BlockBody, B256}; use tokio::sync::Mutex; /// A [`BodiesClient`] for testing. diff --git a/crates/net/downloaders/src/test_utils/mod.rs b/crates/net/downloaders/src/test_utils/mod.rs index aff864ed53c67..0fd7653648dd0 100644 --- a/crates/net/downloaders/src/test_utils/mod.rs +++ b/crates/net/downloaders/src/test_utils/mod.rs @@ -2,14 +2,16 @@ #![allow(dead_code)] -use crate::{bodies::test_utils::create_raw_bodies, file_codec::BlockFileCodec}; +use std::{collections::HashMap, io::SeekFrom, ops::RangeInclusive}; + use futures::SinkExt; use reth_primitives::{BlockBody, SealedHeader, B256}; use reth_testing_utils::{generators, generators::random_block_range}; -use std::{collections::HashMap, io::SeekFrom, ops::RangeInclusive}; use tokio::{fs::File, io::AsyncSeekExt}; use tokio_util::codec::FramedWrite; +use crate::{bodies::test_utils::create_raw_bodies, file_codec::BlockFileCodec}; + mod bodies_client; pub use bodies_client::TestBodiesClient; diff --git a/crates/net/ecies/src/algorithm.rs b/crates/net/ecies/src/algorithm.rs index 83dcc657bce90..f65815b069252 100644 --- a/crates/net/ecies/src/algorithm.rs +++ b/crates/net/ecies/src/algorithm.rs @@ -1,11 +1,5 @@ #![allow(missing_docs)] -use crate::{ - error::ECIESErrorImpl, - mac::{HeaderBytes, MAC}, - util::{hmac_sha256, sha256}, - ECIESError, -}; use aes::{cipher::StreamCipher, Aes128, Aes256}; use alloy_primitives::{ bytes::{BufMut, Bytes, BytesMut}, @@ -24,6 +18,13 @@ use secp256k1::{ use sha2::Sha256; use sha3::Keccak256; +use crate::{ + error::ECIESErrorImpl, + mac::{HeaderBytes, MAC}, + util::{hmac_sha256, sha256}, + ECIESError, +}; + const PROTOCOL_VERSION: usize = 4; /// Computes the shared secret with ECDH and strips the y coordinate after computing the shared @@ -734,9 +735,10 @@ impl ECIES { #[cfg(test)] mod tests { - use super::*; use alloy_primitives::{b256, hex}; + use super::*; + #[test] fn ecdh() { let our_secret_key = SecretKey::from_slice(&hex!( diff --git a/crates/net/ecies/src/codec.rs b/crates/net/ecies/src/codec.rs index 54250e10210e1..a56f09edabe8c 100644 --- a/crates/net/ecies/src/codec.rs +++ b/crates/net/ecies/src/codec.rs @@ -1,10 +1,12 @@ -use crate::{algorithm::ECIES, ECIESError, EgressECIESValue, IngressECIESValue}; +use std::{fmt::Debug, io}; + use alloy_primitives::{bytes::BytesMut, B512 as PeerId}; use secp256k1::SecretKey; -use std::{fmt::Debug, io}; use tokio_util::codec::{Decoder, Encoder}; use tracing::{instrument, trace}; +use crate::{algorithm::ECIES, ECIESError, EgressECIESValue, IngressECIESValue}; + /// Tokio codec for ECIES #[derive(Debug)] pub(crate) struct ECIESCodec { diff --git a/crates/net/ecies/src/error.rs b/crates/net/ecies/src/error.rs index 424431119c9cb..8172b6349a36c 100644 --- a/crates/net/ecies/src/error.rs +++ b/crates/net/ecies/src/error.rs @@ -1,7 +1,9 @@ -use crate::IngressECIESValue; use std::fmt; + use thiserror::Error; +use crate::IngressECIESValue; + /// An error that occurs while reading or writing to an ECIES stream. #[derive(Debug, Error)] pub struct ECIESError { diff --git a/crates/net/ecies/src/stream.rs b/crates/net/ecies/src/stream.rs index dbd7577a35a85..4e1bf41601c3e 100644 --- a/crates/net/ecies/src/stream.rs +++ b/crates/net/ecies/src/stream.rs @@ -1,14 +1,5 @@ //! The ECIES Stream implementation which wraps over [`AsyncRead`] and [`AsyncWrite`]. -use crate::{ - codec::ECIESCodec, error::ECIESErrorImpl, ECIESError, EgressECIESValue, IngressECIESValue, -}; -use alloy_primitives::{ - bytes::{Bytes, BytesMut}, - B512 as PeerId, -}; -use futures::{ready, Sink, SinkExt}; -use secp256k1::SecretKey; use std::{ fmt::Debug, io, @@ -16,6 +7,13 @@ use std::{ task::{Context, Poll}, time::Duration, }; + +use alloy_primitives::{ + bytes::{Bytes, BytesMut}, + B512 as PeerId, +}; +use futures::{ready, Sink, SinkExt}; +use secp256k1::SecretKey; use tokio::{ io::{AsyncRead, AsyncWrite}, time::timeout, @@ -24,6 +22,10 @@ use tokio_stream::{Stream, StreamExt}; use tokio_util::codec::{Decoder, Framed}; use tracing::{instrument, trace}; +use crate::{ + codec::ECIESCodec, error::ECIESErrorImpl, ECIESError, EgressECIESValue, IngressECIESValue, +}; + const HANDSHAKE_TIMEOUT: Duration = Duration::from_secs(10); /// `ECIES` stream over TCP exchanging raw bytes @@ -172,11 +174,12 @@ where #[cfg(test)] mod tests { - use super::*; use reth_network_peers::pk2id; use secp256k1::SECP256K1; use tokio::net::{TcpListener, TcpStream}; + use super::*; + #[tokio::test] async fn can_write_and_read() { let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); diff --git a/crates/net/eth-wire-types/src/blocks.rs b/crates/net/eth-wire-types/src/blocks.rs index c8668c251f193..e4f9ba0cb3144 100644 --- a/crates/net/eth-wire-types/src/blocks.rs +++ b/crates/net/eth-wire-types/src/blocks.rs @@ -6,7 +6,6 @@ use reth_codecs_derive::{add_arbitrary_tests, derive_arbitrary}; #[cfg(any(test, feature = "arbitrary"))] use reth_primitives::generate_valid_header; use reth_primitives::{BlockBody, BlockHashOrNumber, Header, HeadersDirection, B256}; - #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -107,15 +106,16 @@ impl From> for BlockBodies { #[cfg(test)] mod tests { - use crate::{message::RequestPair, BlockBodies, BlockHeaders, GetBlockBodies, GetBlockHeaders}; + use std::str::FromStr; + use alloy_rlp::{Decodable, Encodable}; use reth_primitives::{ hex, BlockHashOrNumber, Header, HeadersDirection, Signature, Transaction, TransactionSigned, TxKind, TxLegacy, U256, }; - use std::str::FromStr; use super::BlockBody; + use crate::{message::RequestPair, BlockBodies, BlockHeaders, GetBlockBodies, GetBlockHeaders}; #[test] fn decode_hash() { diff --git a/crates/net/eth-wire-types/src/broadcast.rs b/crates/net/eth-wire-types/src/broadcast.rs index 1b5a3b4115bdd..46338749a706c 100644 --- a/crates/net/eth-wire-types/src/broadcast.rs +++ b/crates/net/eth-wire-types/src/broadcast.rs @@ -1,30 +1,28 @@ //! Types for broadcasting new data. -use crate::{EthMessage, EthVersion}; -use alloy_rlp::{ - Decodable, Encodable, RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper, -}; - -use derive_more::{Constructor, Deref, DerefMut, From, IntoIterator}; -use reth_codecs_derive::derive_arbitrary; -use reth_primitives::{ - Block, Bytes, PooledTransactionsElement, TransactionSigned, TxHash, B256, U128, -}; - use std::{ collections::{HashMap, HashSet}, mem, sync::Arc, }; +use alloy_rlp::{ + Decodable, Encodable, RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper, +}; +use derive_more::{Constructor, Deref, DerefMut, From, IntoIterator}; #[cfg(feature = "arbitrary")] use proptest::{collection::vec, prelude::*}; #[cfg(feature = "arbitrary")] use proptest_arbitrary_interop::arb; - +use reth_codecs_derive::derive_arbitrary; +use reth_primitives::{ + Block, Bytes, PooledTransactionsElement, TransactionSigned, TxHash, B256, U128, +}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; +use crate::{EthMessage, EthVersion}; + /// This informs peers of new blocks that have appeared on the network. #[derive_arbitrary(rlp)] #[derive(Clone, Debug, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper, Default)] @@ -737,10 +735,12 @@ impl FromIterator<(TxHash, Eth68TxMetadata)> for RequestTxHashes { #[cfg(test)] mod tests { - use super::*; - use reth_primitives::{b256, hex}; use std::str::FromStr; + use reth_primitives::{b256, hex}; + + use super::*; + /// Takes as input a struct / encoded hex message pair, ensuring that we encode to the exact hex /// message, and decode to the exact struct. fn test_encoding_vector( diff --git a/crates/net/eth-wire-types/src/message.rs b/crates/net/eth-wire-types/src/message.rs index cbd5ca536108e..39ca179aa3502 100644 --- a/crates/net/eth-wire-types/src/message.rs +++ b/crates/net/eth-wire-types/src/message.rs @@ -6,6 +6,13 @@ //! //! Reference: [Ethereum Wire Protocol](https://github.com/ethereum/wiki/wiki/Ethereum-Wire-Protocol). +use std::{fmt::Debug, sync::Arc}; + +use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; +use reth_primitives::bytes::{Buf, BufMut}; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + use super::{ broadcast::NewBlockHashes, BlockBodies, BlockHeaders, GetBlockBodies, GetBlockHeaders, GetNodeData, GetPooledTransactions, GetReceipts, NewBlock, NewPooledTransactionHashes66, @@ -13,12 +20,6 @@ use super::{ }; use crate::{EthVersion, SharedTransactions}; -use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; -use reth_primitives::bytes::{Buf, BufMut}; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; -use std::{fmt::Debug, sync::Arc}; - /// [`MAX_MESSAGE_SIZE`] is the maximum cap on the size of a protocol message. // https://github.com/ethereum/go-ethereum/blob/30602163d5d8321fbc68afdcbbaf2362b2641bde/eth/protocols/eth/protocol.go#L50 pub const MAX_MESSAGE_SIZE: usize = 10 * 1024 * 1024; @@ -494,12 +495,13 @@ where #[cfg(test)] mod tests { + use alloy_rlp::{Decodable, Encodable, Error}; + use reth_primitives::hex; + use super::MessageError; use crate::{ message::RequestPair, EthMessage, EthMessageID, GetNodeData, NodeData, ProtocolMessage, }; - use alloy_rlp::{Decodable, Encodable, Error}; - use reth_primitives::hex; fn encode(value: T) -> Vec { let mut buf = vec![]; diff --git a/crates/net/eth-wire-types/src/receipts.rs b/crates/net/eth-wire-types/src/receipts.rs index 4816f85548ceb..687d4ffdde2a4 100644 --- a/crates/net/eth-wire-types/src/receipts.rs +++ b/crates/net/eth-wire-types/src/receipts.rs @@ -3,7 +3,6 @@ use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper}; use reth_codecs_derive::derive_arbitrary; use reth_primitives::{ReceiptWithBloom, B256}; - #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -28,10 +27,11 @@ pub struct Receipts( #[cfg(test)] mod tests { - use crate::{message::RequestPair, GetReceipts, Receipts}; use alloy_rlp::{Decodable, Encodable}; use reth_primitives::{hex, Log, Receipt, ReceiptWithBloom, TxType}; + use crate::{message::RequestPair, GetReceipts, Receipts}; + #[test] fn roundtrip_eip1559() { let receipts = Receipts(vec![vec![ReceiptWithBloom { diff --git a/crates/net/eth-wire-types/src/state.rs b/crates/net/eth-wire-types/src/state.rs index 5f3dc833950f8..c4b629fd03521 100644 --- a/crates/net/eth-wire-types/src/state.rs +++ b/crates/net/eth-wire-types/src/state.rs @@ -3,7 +3,6 @@ use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper}; use reth_codecs_derive::derive_arbitrary; use reth_primitives::{Bytes, B256}; - #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -27,10 +26,10 @@ pub struct NodeData(pub Vec); #[cfg(test)] mod tests { + use alloy_rlp::{Decodable, Encodable}; use reth_primitives::hex; use crate::{message::RequestPair, GetNodeData, NodeData}; - use alloy_rlp::{Decodable, Encodable}; #[test] // Test vector from: https://eips.ethereum.org/EIPS/eip-2481 diff --git a/crates/net/eth-wire-types/src/status.rs b/crates/net/eth-wire-types/src/status.rs index 95e5aa84adf5a..e8c38a51ec0f9 100644 --- a/crates/net/eth-wire-types/src/status.rs +++ b/crates/net/eth-wire-types/src/status.rs @@ -1,4 +1,5 @@ -use crate::EthVersion; +use std::fmt::{Debug, Display}; + use alloy_genesis::Genesis; use alloy_rlp::{RlpDecodable, RlpEncodable}; use reth_chainspec::{Chain, ChainSpec, NamedChain, MAINNET}; @@ -6,7 +7,8 @@ use reth_codecs_derive::derive_arbitrary; use reth_primitives::{hex, ForkId, Hardfork, Head, B256, U256}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -use std::fmt::{Debug, Display}; + +use crate::EthVersion; /// The status message is used in the eth protocol handshake to ensure that peers are on the same /// network and are following the same fork. @@ -228,13 +230,15 @@ impl StatusBuilder { #[cfg(test)] mod tests { - use crate::{EthVersion, Status}; + use std::str::FromStr; + use alloy_genesis::Genesis; use alloy_rlp::{Decodable, Encodable}; use rand::Rng; use reth_chainspec::{Chain, ChainSpec, ForkCondition, NamedChain}; use reth_primitives::{hex, ForkHash, ForkId, Hardfork, Head, B256, U256}; - use std::str::FromStr; + + use crate::{EthVersion, Status}; #[test] fn encode_eth_status_message() { diff --git a/crates/net/eth-wire-types/src/transactions.rs b/crates/net/eth-wire-types/src/transactions.rs index d0a42d49beecc..b8f2f8987a573 100644 --- a/crates/net/eth-wire-types/src/transactions.rs +++ b/crates/net/eth-wire-types/src/transactions.rs @@ -6,7 +6,6 @@ use reth_codecs_derive::derive_arbitrary; use reth_primitives::{ transaction::TransactionConversionError, PooledTransactionsElement, TransactionSigned, B256, }; - #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -77,13 +76,15 @@ impl FromIterator for PooledTransactions { #[cfg(test)] mod tests { - use crate::{message::RequestPair, GetPooledTransactions, PooledTransactions}; + use std::str::FromStr; + use alloy_rlp::{Decodable, Encodable}; use reth_primitives::{ hex, PooledTransactionsElement, Signature, Transaction, TransactionSigned, TxEip1559, TxKind, TxLegacy, U256, }; - use std::str::FromStr; + + use crate::{message::RequestPair, GetPooledTransactions, PooledTransactions}; #[test] // Test vector from: https://eips.ethereum.org/EIPS/eip-2481 diff --git a/crates/net/eth-wire/src/capability.rs b/crates/net/eth-wire/src/capability.rs index 776cc375f9f9a..b1513f8b9d0f7 100644 --- a/crates/net/eth-wire/src/capability.rs +++ b/crates/net/eth-wire/src/capability.rs @@ -1,22 +1,24 @@ //! All capability related types -use crate::{ - errors::{P2PHandshakeError, P2PStreamError}, - p2pstream::MAX_RESERVED_MESSAGE_ID, - protocol::{ProtoVersion, Protocol}, - version::ParseVersionError, - EthMessage, EthMessageID, EthVersion, +use std::{ + borrow::Cow, + collections::{BTreeSet, HashMap}, + fmt, }; + use alloy_rlp::{Decodable, Encodable, RlpDecodable, RlpEncodable}; use derive_more::{Deref, DerefMut}; use reth_codecs::add_arbitrary_tests; use reth_primitives::bytes::{BufMut, Bytes}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -use std::{ - borrow::Cow, - collections::{BTreeSet, HashMap}, - fmt, + +use crate::{ + errors::{P2PHandshakeError, P2PStreamError}, + p2pstream::MAX_RESERVED_MESSAGE_ID, + protocol::{ProtoVersion, Protocol}, + version::ParseVersionError, + EthMessage, EthMessageID, EthVersion, }; /// A Capability message consisting of the message-id and the payload diff --git a/crates/net/eth-wire/src/disconnect.rs b/crates/net/eth-wire/src/disconnect.rs index 50ced132f2a61..afe93a9c9b195 100644 --- a/crates/net/eth-wire/src/disconnect.rs +++ b/crates/net/eth-wire/src/disconnect.rs @@ -1,18 +1,18 @@ //! Disconnect +use std::{fmt::Display, future::Future}; + use alloy_rlp::{Decodable, Encodable, Error as RlpError, Header}; use futures::{Sink, SinkExt}; use reth_codecs::derive_arbitrary; use reth_ecies::stream::ECIESStream; use reth_primitives::bytes::{Buf, BufMut}; -use std::{fmt::Display, future::Future}; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; use thiserror::Error; use tokio::io::AsyncWrite; use tokio_util::codec::{Encoder, Framed}; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; - /// RLPx disconnect reason. #[derive_arbitrary(rlp)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] @@ -183,10 +183,11 @@ where #[cfg(test)] mod tests { - use crate::{p2pstream::P2PMessage, DisconnectReason}; use alloy_rlp::{Decodable, Encodable}; use reth_primitives::hex; + use crate::{p2pstream::P2PMessage, DisconnectReason}; + fn all_reasons() -> Vec { vec![ DisconnectReason::DisconnectRequested, diff --git a/crates/net/eth-wire/src/errors/eth.rs b/crates/net/eth-wire/src/errors/eth.rs index 485a4ae2e7a46..88277dfc1b5c9 100644 --- a/crates/net/eth-wire/src/errors/eth.rs +++ b/crates/net/eth-wire/src/errors/eth.rs @@ -1,11 +1,13 @@ //! Error handling for (`EthStream`)[`crate::EthStream`] +use std::io; + +use reth_chainspec::Chain; +use reth_primitives::{GotExpected, GotExpectedBoxed, ValidationError, B256}; + use crate::{ errors::P2PStreamError, message::MessageError, version::ParseVersionError, DisconnectReason, }; -use reth_chainspec::Chain; -use reth_primitives::{GotExpected, GotExpectedBoxed, ValidationError, B256}; -use std::io; /// Errors when sending/receiving messages #[derive(thiserror::Error, Debug)] diff --git a/crates/net/eth-wire/src/errors/p2p.rs b/crates/net/eth-wire/src/errors/p2p.rs index a64385fe2b3c1..d184590d09ecb 100644 --- a/crates/net/eth-wire/src/errors/p2p.rs +++ b/crates/net/eth-wire/src/errors/p2p.rs @@ -1,11 +1,13 @@ //! Error handling for [`P2PStream`](crate::P2PStream). +use std::io; + +use reth_primitives::GotExpected; + use crate::{ capability::SharedCapabilityError, disconnect::UnknownDisconnectReason, DisconnectReason, ProtocolVersion, }; -use reth_primitives::GotExpected; -use std::io; /// Errors when sending/receiving p2p messages. These should result in kicking the peer. #[derive(thiserror::Error, Debug)] diff --git a/crates/net/eth-wire/src/ethstream.rs b/crates/net/eth-wire/src/ethstream.rs index fac5e05495a76..55bce68ece386 100644 --- a/crates/net/eth-wire/src/ethstream.rs +++ b/crates/net/eth-wire/src/ethstream.rs @@ -1,24 +1,26 @@ -use crate::{ - errors::{EthHandshakeError, EthStreamError}, - message::{EthBroadcastMessage, ProtocolBroadcastMessage}, - p2pstream::HANDSHAKE_TIMEOUT, - CanDisconnect, DisconnectReason, EthMessage, EthVersion, ProtocolMessage, Status, +use std::{ + pin::Pin, + task::{Context, Poll}, + time::Duration, }; + use futures::{ready, Sink, SinkExt, StreamExt}; use pin_project::pin_project; use reth_primitives::{ bytes::{Bytes, BytesMut}, ForkFilter, GotExpected, }; -use std::{ - pin::Pin, - task::{Context, Poll}, - time::Duration, -}; use tokio::time::timeout; use tokio_stream::Stream; use tracing::{debug, trace}; +use crate::{ + errors::{EthHandshakeError, EthStreamError}, + message::{EthBroadcastMessage, ProtocolBroadcastMessage}, + p2pstream::HANDSHAKE_TIMEOUT, + CanDisconnect, DisconnectReason, EthMessage, EthVersion, ProtocolMessage, Status, +}; + /// [`MAX_MESSAGE_SIZE`] is the maximum cap on the size of a protocol message. // https://github.com/ethereum/go-ethereum/blob/30602163d5d8321fbc68afdcbbaf2362b2641bde/eth/protocols/eth/protocol.go#L50 pub const MAX_MESSAGE_SIZE: usize = 10 * 1024 * 1024; @@ -344,13 +346,8 @@ where #[cfg(test)] mod tests { - use super::UnauthedEthStream; - use crate::{ - broadcast::BlockHashNumber, - errors::{EthHandshakeError, EthStreamError}, - p2pstream::{ProtocolVersion, UnauthedP2PStream}, - EthMessage, EthStream, EthVersion, HelloMessageWithProtocols, PassthroughCodec, Status, - }; + use std::time::Duration; + use futures::{SinkExt, StreamExt}; use reth_chainspec::NamedChain; use reth_discv4::DEFAULT_DISCOVERY_PORT; @@ -358,10 +355,17 @@ mod tests { use reth_network_peers::pk2id; use reth_primitives::{ForkFilter, Head, B256, U256}; use secp256k1::{SecretKey, SECP256K1}; - use std::time::Duration; use tokio::net::{TcpListener, TcpStream}; use tokio_util::codec::Decoder; + use super::UnauthedEthStream; + use crate::{ + broadcast::BlockHashNumber, + errors::{EthHandshakeError, EthStreamError}, + p2pstream::{ProtocolVersion, UnauthedP2PStream}, + EthMessage, EthStream, EthVersion, HelloMessageWithProtocols, PassthroughCodec, Status, + }; + #[tokio::test] async fn can_handshake() { let genesis = B256::random(); diff --git a/crates/net/eth-wire/src/hello.rs b/crates/net/eth-wire/src/hello.rs index fbdffecec38a9..3f7c3def1c301 100644 --- a/crates/net/eth-wire/src/hello.rs +++ b/crates/net/eth-wire/src/hello.rs @@ -1,14 +1,13 @@ -use crate::{capability::Capability, EthVersion, ProtocolVersion}; use alloy_rlp::{RlpDecodable, RlpEncodable}; use reth_codecs::derive_arbitrary; use reth_discv4::DEFAULT_DISCOVERY_PORT; use reth_network_peers::PeerId; use reth_primitives::constants::RETH_CLIENT_VERSION; - -use crate::protocol::Protocol; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; +use crate::{capability::Capability, protocol::Protocol, EthVersion, ProtocolVersion}; + /// This is a superset of [`HelloMessage`] that provides additional protocol [Protocol] information /// about the number of messages used by each capability in order to do proper message ID /// multiplexing. diff --git a/crates/net/eth-wire/src/lib.rs b/crates/net/eth-wire/src/lib.rs index e96a27077f8c9..e78eeeef53172 100644 --- a/crates/net/eth-wire/src/lib.rs +++ b/crates/net/eth-wire/src/lib.rs @@ -26,6 +26,9 @@ pub mod protocol; #[cfg(test)] pub mod test_utils; +// Re-export wire types +#[doc(inline)] +pub use reth_eth_wire_types::*; #[cfg(test)] pub use tokio_util::codec::{ LengthDelimitedCodec as PassthroughCodec, LengthDelimitedCodecError as PassthroughCodecError, @@ -41,7 +44,3 @@ pub use crate::{ MAX_RESERVED_MESSAGE_ID, }, }; - -// Re-export wire types -#[doc(inline)] -pub use reth_eth_wire_types::*; diff --git a/crates/net/eth-wire/src/multiplex.rs b/crates/net/eth-wire/src/multiplex.rs index 08e281f1a26c0..a38b36eb5cefc 100644 --- a/crates/net/eth-wire/src/multiplex.rs +++ b/crates/net/eth-wire/src/multiplex.rs @@ -16,17 +16,18 @@ use std::{ task::{ready, Context, Poll}, }; +use bytes::{Bytes, BytesMut}; +use futures::{Sink, SinkExt, Stream, StreamExt, TryStream, TryStreamExt}; +use reth_primitives::ForkFilter; +use tokio::sync::{mpsc, mpsc::UnboundedSender}; +use tokio_stream::wrappers::UnboundedReceiverStream; + use crate::{ capability::{Capability, SharedCapabilities, SharedCapability, UnsupportedCapabilityError}, errors::{EthStreamError, P2PStreamError}, p2pstream::DisconnectP2P, CanDisconnect, DisconnectReason, EthStream, P2PStream, Status, UnauthedEthStream, }; -use bytes::{Bytes, BytesMut}; -use futures::{Sink, SinkExt, Stream, StreamExt, TryStream, TryStreamExt}; -use reth_primitives::ForkFilter; -use tokio::sync::{mpsc, mpsc::UnboundedSender}; -use tokio_stream::wrappers::UnboundedReceiverStream; /// A Stream and Sink type that wraps a raw rlpx stream [`P2PStream`] and handles message ID /// multiplexing. @@ -666,6 +667,9 @@ impl fmt::Debug for ProtocolStream { #[cfg(test)] mod tests { + use tokio::{net::TcpListener, sync::oneshot}; + use tokio_util::codec::Decoder; + use super::*; use crate::{ test_utils::{ @@ -674,8 +678,6 @@ mod tests { }, UnauthedP2PStream, }; - use tokio::{net::TcpListener, sync::oneshot}; - use tokio_util::codec::Decoder; #[tokio::test] async fn eth_satellite() { diff --git a/crates/net/eth-wire/src/p2pstream.rs b/crates/net/eth-wire/src/p2pstream.rs index 23f106da9a421..d303d4cc380cc 100644 --- a/crates/net/eth-wire/src/p2pstream.rs +++ b/crates/net/eth-wire/src/p2pstream.rs @@ -1,10 +1,11 @@ -use crate::{ - capability::SharedCapabilities, - disconnect::CanDisconnect, - errors::{P2PHandshakeError, P2PStreamError}, - pinger::{Pinger, PingerEvent}, - DisconnectReason, HelloMessage, HelloMessageWithProtocols, +use std::{ + collections::VecDeque, + fmt, io, + pin::Pin, + task::{ready, Context, Poll}, + time::Duration, }; + use alloy_rlp::{Decodable, Encodable, Error as RlpError, EMPTY_LIST_CODE}; use futures::{Sink, SinkExt, StreamExt}; use pin_project::pin_project; @@ -14,18 +15,18 @@ use reth_primitives::{ bytes::{Buf, BufMut, Bytes, BytesMut}, hex, GotExpected, }; -use std::{ - collections::VecDeque, - fmt, io, - pin::Pin, - task::{ready, Context, Poll}, - time::Duration, -}; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; use tokio_stream::Stream; use tracing::{debug, trace}; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; +use crate::{ + capability::SharedCapabilities, + disconnect::CanDisconnect, + errors::{P2PHandshakeError, P2PStreamError}, + pinger::{Pinger, PingerEvent}, + DisconnectReason, HelloMessage, HelloMessageWithProtocols, +}; /// [`MAX_PAYLOAD_SIZE`] is the maximum size of an uncompressed message payload. /// This is defined in [EIP-706](https://eips.ethereum.org/EIPS/eip-706). @@ -825,11 +826,12 @@ impl Decodable for ProtocolVersion { #[cfg(test)] mod tests { - use super::*; - use crate::{capability::SharedCapability, test_utils::eth_hello, EthVersion}; use tokio::net::{TcpListener, TcpStream}; use tokio_util::codec::Decoder; + use super::*; + use crate::{capability::SharedCapability, test_utils::eth_hello, EthVersion}; + #[tokio::test] async fn test_can_disconnect() { reth_tracing::init_test_tracing(); diff --git a/crates/net/eth-wire/src/pinger.rs b/crates/net/eth-wire/src/pinger.rs index d93404c5f9746..df377de68e840 100644 --- a/crates/net/eth-wire/src/pinger.rs +++ b/crates/net/eth-wire/src/pinger.rs @@ -1,12 +1,14 @@ -use crate::errors::PingerError; use std::{ pin::Pin, task::{Context, Poll}, time::Duration, }; + use tokio::time::{Instant, Interval, Sleep}; use tokio_stream::Stream; +use crate::errors::PingerError; + /// The pinger is a state machine that is created with a maximum number of pongs that can be /// missed. #[derive(Debug)] @@ -126,9 +128,10 @@ pub(crate) enum PingerEvent { #[cfg(test)] mod tests { - use super::*; use futures::StreamExt; + use super::*; + #[tokio::test] async fn test_ping_timeout() { let interval = Duration::from_millis(300); diff --git a/crates/net/eth-wire/src/test_utils.rs b/crates/net/eth-wire/src/test_utils.rs index 466bc0f1cefa7..7ca3d03134aca 100644 --- a/crates/net/eth-wire/src/test_utils.rs +++ b/crates/net/eth-wire/src/test_utils.rs @@ -1,17 +1,19 @@ //! Utilities for testing p2p protocol. -use crate::{ - EthVersion, HelloMessageWithProtocols, P2PStream, ProtocolVersion, Status, UnauthedP2PStream, -}; +use std::net::SocketAddr; + use reth_chainspec::Chain; use reth_discv4::DEFAULT_DISCOVERY_PORT; use reth_network_peers::pk2id; use reth_primitives::{ForkFilter, Head, B256, U256}; use secp256k1::{SecretKey, SECP256K1}; -use std::net::SocketAddr; use tokio::net::TcpStream; use tokio_util::codec::{Decoder, Framed, LengthDelimitedCodec}; +use crate::{ + EthVersion, HelloMessageWithProtocols, P2PStream, ProtocolVersion, Status, UnauthedP2PStream, +}; + pub type P2pPassthroughTcpStream = P2PStream>; /// Returns a new testing `HelloMessage` and new secretkey @@ -59,9 +61,10 @@ pub async fn connect_passthrough( /// A Rplx subprotocol for testing pub mod proto { + use bytes::{Buf, BufMut, BytesMut}; + use super::*; use crate::{capability::Capability, protocol::Protocol}; - use bytes::{Buf, BufMut, BytesMut}; /// Returns a new testing `HelloMessage` with eth and the test protocol pub fn test_hello() -> (HelloMessageWithProtocols, SecretKey) { diff --git a/crates/net/eth-wire/tests/fuzz_roundtrip.rs b/crates/net/eth-wire/tests/fuzz_roundtrip.rs index ec55fc448ae08..61680fa53f39f 100644 --- a/crates/net/eth-wire/tests/fuzz_roundtrip.rs +++ b/crates/net/eth-wire/tests/fuzz_roundtrip.rs @@ -1,8 +1,9 @@ //! Round-trip encoding fuzzing for the `eth-wire` crate. +use std::fmt::Debug; + use alloy_rlp::{Decodable, Encodable}; use serde::Serialize; -use std::fmt::Debug; /// Creates a fuzz test for a type that should be [`Encodable`](alloy_rlp::Encodable) and /// [`Decodable`](alloy_rlp::Decodable). @@ -47,7 +48,6 @@ macro_rules! fuzz_type_and_name { #[cfg(test)] pub mod fuzz_rlp { - use crate::roundtrip_encoding; use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper}; use reth_codecs::derive_arbitrary; use reth_eth_wire::{ @@ -60,6 +60,8 @@ pub mod fuzz_rlp { use serde::{Deserialize, Serialize}; use test_fuzz::test_fuzz; + use crate::roundtrip_encoding; + // manually test Ping and Pong which are not covered by the above /// Tests the round-trip encoding of Ping diff --git a/crates/net/eth-wire/tests/new_block.rs b/crates/net/eth-wire/tests/new_block.rs index a1a6e043e3821..0aafa8c925aa7 100644 --- a/crates/net/eth-wire/tests/new_block.rs +++ b/crates/net/eth-wire/tests/new_block.rs @@ -1,9 +1,10 @@ //! Decoding tests for [`NewBlock`] +use std::{fs, path::PathBuf}; + use alloy_rlp::Decodable; use reth_eth_wire::NewBlock; use reth_primitives::hex; -use std::{fs, path::PathBuf}; #[test] fn decode_new_block_network() { diff --git a/crates/net/eth-wire/tests/new_pooled_transactions.rs b/crates/net/eth-wire/tests/new_pooled_transactions.rs index 48022185ce496..8e55bf2cbe91f 100644 --- a/crates/net/eth-wire/tests/new_pooled_transactions.rs +++ b/crates/net/eth-wire/tests/new_pooled_transactions.rs @@ -1,9 +1,10 @@ //! Decoding tests for [`NewPooledTransactions`] +use std::{fs, path::PathBuf}; + use alloy_rlp::Decodable; use reth_eth_wire::NewPooledTransactionHashes66; use reth_primitives::hex; -use std::{fs, path::PathBuf}; #[test] fn decode_new_pooled_transaction_hashes_network() { diff --git a/crates/net/eth-wire/tests/pooled_transactions.rs b/crates/net/eth-wire/tests/pooled_transactions.rs index 5f7431f3dd73b..94f736b991031 100644 --- a/crates/net/eth-wire/tests/pooled_transactions.rs +++ b/crates/net/eth-wire/tests/pooled_transactions.rs @@ -1,9 +1,10 @@ //! Decoding tests for [`PooledTransactions`] +use std::{fs, path::PathBuf}; + use alloy_rlp::{Decodable, Encodable}; use reth_eth_wire::{EthVersion, PooledTransactions, ProtocolMessage}; use reth_primitives::{hex, PooledTransactionsElement}; -use std::{fs, path::PathBuf}; use test_fuzz::test_fuzz; /// Helper function to ensure encode-decode roundtrip works for [`PooledTransactions`]. diff --git a/crates/net/nat/src/lib.rs b/crates/net/nat/src/lib.rs index 8f757908958fc..868b6faece5f0 100644 --- a/crates/net/nat/src/lib.rs +++ b/crates/net/nat/src/lib.rs @@ -203,9 +203,10 @@ async fn resolve_external_ip_url(url: &str) -> Option { #[cfg(test)] mod tests { - use super::*; use std::net::Ipv4Addr; + use super::*; + #[tokio::test] #[ignore] async fn get_external_ip() { diff --git a/crates/net/network-api/src/lib.rs b/crates/net/network-api/src/lib.rs index 6c6f8036daff1..78f9621c264f7 100644 --- a/crates/net/network-api/src/lib.rs +++ b/crates/net/network-api/src/lib.rs @@ -13,13 +13,14 @@ )] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +use std::{future::Future, net::SocketAddr, sync::Arc, time::Instant}; + pub use alloy_rpc_types_admin::EthProtocolInfo; pub use error::NetworkError; pub use reputation::{Reputation, ReputationChangeKind}; use reth_eth_wire::{capability::Capabilities, DisconnectReason, EthVersion, Status}; use reth_network_peers::NodeRecord; use serde::{Deserialize, Serialize}; -use std::{future::Future, net::SocketAddr, sync::Arc, time::Instant}; /// The `PeerId` type. pub type PeerId = alloy_primitives::B512; diff --git a/crates/net/network-api/src/noop.rs b/crates/net/network-api/src/noop.rs index 745613f406554..aef4f2aa48f32 100644 --- a/crates/net/network-api/src/noop.rs +++ b/crates/net/network-api/src/noop.rs @@ -3,15 +3,17 @@ //! This is useful for wiring components together that don't require network but still need to be //! generic over it. -use crate::{ - NetworkError, NetworkInfo, NetworkStatus, PeerId, PeerInfo, PeerKind, Peers, PeersInfo, - Reputation, ReputationChangeKind, -}; +use std::net::{IpAddr, SocketAddr}; + use alloy_rpc_types_admin::EthProtocolInfo; use enr::{secp256k1::SecretKey, Enr}; use reth_eth_wire::{DisconnectReason, ProtocolVersion}; use reth_network_peers::NodeRecord; -use std::net::{IpAddr, SocketAddr}; + +use crate::{ + NetworkError, NetworkInfo, NetworkStatus, PeerId, PeerInfo, PeerKind, Peers, PeersInfo, + Reputation, ReputationChangeKind, +}; /// A type that implements all network trait that does nothing. /// diff --git a/crates/net/network-types/src/peers/config.rs b/crates/net/network-types/src/peers/config.rs index 5143c4c6f2bfb..0039dad0d5d26 100644 --- a/crates/net/network-types/src/peers/config.rs +++ b/crates/net/network-types/src/peers/config.rs @@ -1,16 +1,18 @@ //! Configuration for peering. -use crate::{BackoffKind, ReputationChangeWeights}; -use reth_net_banlist::BanList; -use reth_network_peers::NodeRecord; use std::{ collections::HashSet, io::{self, ErrorKind}, path::Path, time::Duration, }; + +use reth_net_banlist::BanList; +use reth_network_peers::NodeRecord; use tracing::info; +use crate::{BackoffKind, ReputationChangeWeights}; + /// Maximum number of available slots for outbound sessions. pub const DEFAULT_MAX_COUNT_PEERS_OUTBOUND: u32 = 100; diff --git a/crates/net/network-types/src/session/config.rs b/crates/net/network-types/src/session/config.rs index 941448effd6bd..39f5a64a9bd30 100644 --- a/crates/net/network-types/src/session/config.rs +++ b/crates/net/network-types/src/session/config.rs @@ -1,8 +1,9 @@ //! Configuration types for peer sessions manager. -use crate::peers::config::{DEFAULT_MAX_COUNT_PEERS_INBOUND, DEFAULT_MAX_COUNT_PEERS_OUTBOUND}; use std::time::Duration; +use crate::peers::config::{DEFAULT_MAX_COUNT_PEERS_INBOUND, DEFAULT_MAX_COUNT_PEERS_OUTBOUND}; + /// Default request timeout for a single request. /// /// This represents the amount of time we wait for a response until we consider it timed out. diff --git a/crates/net/network/benches/bench.rs b/crates/net/network/benches/bench.rs index c41eb62029c75..a8b0b27a617fb 100644 --- a/crates/net/network/benches/bench.rs +++ b/crates/net/network/benches/bench.rs @@ -1,4 +1,6 @@ #![allow(missing_docs)] +use std::sync::Arc; + use criterion::*; use futures::StreamExt; use pprof::criterion::{Output, PProfProfiler}; @@ -8,7 +10,6 @@ use reth_network_api::Peers; use reth_primitives::U256; use reth_provider::test_utils::{ExtendedAccount, MockEthProvider}; use reth_transaction_pool::{test_utils::TransactionGenerator, PoolTransaction}; -use std::sync::Arc; use tokio::{runtime::Runtime as TokioRuntime, sync::mpsc::unbounded_channel}; criterion_group!( diff --git a/crates/net/network/src/builder.rs b/crates/net/network/src/builder.rs index b6e1dcf91925f..f0a4041d06c37 100644 --- a/crates/net/network/src/builder.rs +++ b/crates/net/network/src/builder.rs @@ -1,12 +1,13 @@ //! Builder support for configuring the entire setup. +use reth_transaction_pool::TransactionPool; +use tokio::sync::mpsc; + use crate::{ eth_requests::EthRequestHandler, transactions::{TransactionsManager, TransactionsManagerConfig}, NetworkHandle, NetworkManager, }; -use reth_transaction_pool::TransactionPool; -use tokio::sync::mpsc; /// We set the max channel capacity of the `EthRequestHandler` to 256 /// 256 requests with malicious 10MB body requests is 2.6GB which can be absorbed by the node. diff --git a/crates/net/network/src/cache.rs b/crates/net/network/src/cache.rs index 51337336fce08..84ad9e778f41c 100644 --- a/crates/net/network/src/cache.rs +++ b/crates/net/network/src/cache.rs @@ -1,11 +1,12 @@ //! Network cache support use core::hash::BuildHasher; +use std::{fmt, hash::Hash}; + use derive_more::{Deref, DerefMut}; use itertools::Itertools; // use linked_hash_set::LinkedHashSet; use schnellru::{ByLength, Limiter, RandomState, Unlimited}; -use std::{fmt, hash::Hash}; /// A minimal LRU cache based on a [`LruMap`](schnellru::LruMap) with limited capacity. /// @@ -184,10 +185,12 @@ where #[cfg(test)] mod test { - use super::*; - use derive_more::{Constructor, Display}; use std::hash::Hasher; + use derive_more::{Constructor, Display}; + + use super::*; + #[derive(Debug, Hash, PartialEq, Eq, Display, Clone, Copy)] struct Key(i8); diff --git a/crates/net/network/src/config.rs b/crates/net/network/src/config.rs index c42d204f5e296..e9dbe9044561f 100644 --- a/crates/net/network/src/config.rs +++ b/crates/net/network/src/config.rs @@ -1,11 +1,7 @@ //! Network config support -use crate::{ - error::NetworkError, - import::{BlockImport, ProofOfStakeBlockImport}, - transactions::TransactionsManagerConfig, - NetworkHandle, NetworkManager, -}; +use std::{collections::HashSet, net::SocketAddr, sync::Arc}; + use reth_chainspec::{ net::{mainnet_nodes, sepolia_nodes, TrustedPeer}, ChainSpec, MAINNET, @@ -19,12 +15,17 @@ use reth_network_types::{PeersConfig, SessionsConfig}; use reth_primitives::{ForkFilter, Head}; use reth_provider::{BlockReader, HeaderProvider}; use reth_tasks::{TaskSpawner, TokioTaskExecutor}; +pub use secp256k1::SecretKey; use secp256k1::SECP256K1; -use std::{collections::HashSet, net::SocketAddr, sync::Arc}; // re-export for convenience use crate::protocol::{IntoRlpxSubProtocol, RlpxSubProtocols}; -pub use secp256k1::SecretKey; +use crate::{ + error::NetworkError, + import::{BlockImport, ProofOfStakeBlockImport}, + transactions::TransactionsManagerConfig, + NetworkHandle, NetworkManager, +}; /// Convenience function to create a new random [`SecretKey`] pub fn rng_secret_key() -> SecretKey { @@ -578,13 +579,15 @@ impl NetworkMode { #[cfg(test)] mod tests { - use super::*; + use std::collections::BTreeMap; + use rand::thread_rng; use reth_chainspec::Chain; use reth_dns_discovery::tree::LinkEntry; use reth_primitives::ForkHash; use reth_provider::test_utils::NoopProvider; - use std::collections::BTreeMap; + + use super::*; fn builder() -> NetworkConfigBuilder { let secret_key = SecretKey::new(&mut thread_rng()); diff --git a/crates/net/network/src/discovery.rs b/crates/net/network/src/discovery.rs index c320c7fe15757..1e30ef26c18ec 100644 --- a/crates/net/network/src/discovery.rs +++ b/crates/net/network/src/discovery.rs @@ -1,10 +1,13 @@ //! Discovery support for the network. -use crate::{ - cache::LruMap, - error::{NetworkError, ServiceKind}, - manager::DiscoveredEvent, +use std::{ + collections::VecDeque, + net::{IpAddr, SocketAddr}, + pin::Pin, + sync::Arc, + task::{ready, Context, Poll}, }; + use enr::Enr; use futures::StreamExt; use reth_discv4::{DiscoveryUpdate, Discv4, Discv4Config}; @@ -15,17 +18,16 @@ use reth_dns_discovery::{ use reth_network_peers::{NodeRecord, PeerId}; use reth_primitives::{EnrForkIdEntry, ForkId}; use secp256k1::SecretKey; -use std::{ - collections::VecDeque, - net::{IpAddr, SocketAddr}, - pin::Pin, - sync::Arc, - task::{ready, Context, Poll}, -}; use tokio::{sync::mpsc, task::JoinHandle}; use tokio_stream::{wrappers::ReceiverStream, Stream}; use tracing::trace; +use crate::{ + cache::LruMap, + error::{NetworkError, ServiceKind}, + manager::DiscoveredEvent, +}; + /// Default max capacity for cache of discovered peers. /// /// Default is 10 000 peers. @@ -334,10 +336,12 @@ pub enum DiscoveryEvent { #[cfg(test)] mod tests { - use super::*; + use std::net::{Ipv4Addr, SocketAddrV4}; + use rand::thread_rng; use secp256k1::SECP256K1; - use std::net::{Ipv4Addr, SocketAddrV4}; + + use super::*; #[tokio::test(flavor = "multi_thread")] async fn test_discovery_setup() { diff --git a/crates/net/network/src/error.rs b/crates/net/network/src/error.rs index d5e0f453721db..76556d3509e54 100644 --- a/crates/net/network/src/error.rs +++ b/crates/net/network/src/error.rs @@ -1,13 +1,15 @@ //! Possible errors when interacting with the network. -use crate::session::PendingSessionHandshakeError; +use std::{fmt, io, io::ErrorKind, net::SocketAddr}; + use reth_dns_discovery::resolver::ResolveError; use reth_eth_wire::{ errors::{EthHandshakeError, EthStreamError, P2PHandshakeError, P2PStreamError}, DisconnectReason, }; use reth_network_types::BackoffKind; -use std::{fmt, io, io::ErrorKind, net::SocketAddr}; + +use crate::session::PendingSessionHandshakeError; /// Service kind. #[derive(Debug, PartialEq, Eq, Copy, Clone)] @@ -255,9 +257,10 @@ impl SessionError for io::Error { #[cfg(test)] mod tests { - use super::*; use std::net::{Ipv4Addr, SocketAddrV4}; + use super::*; + #[test] fn test_is_fatal_disconnect() { let err = PendingSessionHandshakeError::Eth(EthStreamError::P2PStreamError( diff --git a/crates/net/network/src/eth_requests.rs b/crates/net/network/src/eth_requests.rs index 2e403a517dc04..b0c2f256e6241 100644 --- a/crates/net/network/src/eth_requests.rs +++ b/crates/net/network/src/eth_requests.rs @@ -1,9 +1,12 @@ //! Blocks/Headers management for the p2p network. -use crate::{ - budget::DEFAULT_BUDGET_TRY_DRAIN_DOWNLOADERS, metered_poll_nested_stream_with_budget, - metrics::EthRequestHandlerMetrics, peers::PeersHandle, +use std::{ + future::Future, + pin::Pin, + task::{Context, Poll}, + time::Duration, }; + use alloy_rlp::Encodable; use futures::StreamExt; use reth_eth_wire::{ @@ -14,15 +17,14 @@ use reth_network_p2p::error::RequestResult; use reth_network_peers::PeerId; use reth_primitives::{BlockBody, BlockHashOrNumber, Header, HeadersDirection}; use reth_provider::{BlockReader, HeaderProvider, ReceiptProvider}; -use std::{ - future::Future, - pin::Pin, - task::{Context, Poll}, - time::Duration, -}; use tokio::sync::{mpsc::Receiver, oneshot}; use tokio_stream::wrappers::ReceiverStream; +use crate::{ + budget::DEFAULT_BUDGET_TRY_DRAIN_DOWNLOADERS, metered_poll_nested_stream_with_budget, + metrics::EthRequestHandlerMetrics, peers::PeersHandle, +}; + // Limits: /// Maximum number of receipts to serve. diff --git a/crates/net/network/src/fetch/client.rs b/crates/net/network/src/fetch/client.rs index 85ac8bb99cad5..ac8a6cfeb684c 100644 --- a/crates/net/network/src/fetch/client.rs +++ b/crates/net/network/src/fetch/client.rs @@ -1,8 +1,11 @@ //! A client implementation that can interact with the network and download data. -use crate::{fetch::DownloadRequest, flattened_response::FlattenedResponse, peers::PeersHandle}; -use futures::{future, future::Either}; +use std::sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, +}; +use futures::{future, future::Either}; use reth_network_api::ReputationChangeKind; use reth_network_p2p::{ bodies::client::{BodiesClient, BodiesFut}, @@ -13,12 +16,10 @@ use reth_network_p2p::{ }; use reth_network_peers::PeerId; use reth_primitives::{Header, B256}; -use std::sync::{ - atomic::{AtomicUsize, Ordering}, - Arc, -}; use tokio::sync::{mpsc::UnboundedSender, oneshot}; +use crate::{fetch::DownloadRequest, flattened_response::FlattenedResponse, peers::PeersHandle}; + #[cfg_attr(doc, aquamarine::aquamarine)] /// Front-end API for fetching data from the network. /// diff --git a/crates/net/network/src/fetch/mod.rs b/crates/net/network/src/fetch/mod.rs index 4825532e4856c..79b1098214495 100644 --- a/crates/net/network/src/fetch/mod.rs +++ b/crates/net/network/src/fetch/mod.rs @@ -1,6 +1,14 @@ //! Fetch data from the network. -use crate::{message::BlockRequest, peers::PeersHandle}; +use std::{ + collections::{HashMap, VecDeque}, + sync::{ + atomic::{AtomicU64, AtomicUsize, Ordering}, + Arc, + }, + task::{Context, Poll}, +}; + use futures::StreamExt; use reth_eth_wire::{GetBlockBodies, GetBlockHeaders}; use reth_network_api::ReputationChangeKind; @@ -11,17 +19,11 @@ use reth_network_p2p::{ }; use reth_network_peers::PeerId; use reth_primitives::{BlockBody, Header, B256}; -use std::{ - collections::{HashMap, VecDeque}, - sync::{ - atomic::{AtomicU64, AtomicUsize, Ordering}, - Arc, - }, - task::{Context, Poll}, -}; use tokio::sync::{mpsc, mpsc::UnboundedSender, oneshot}; use tokio_stream::wrappers::UnboundedReceiverStream; +use crate::{message::BlockRequest, peers::PeersHandle}; + mod client; pub use client::FetchClient; @@ -467,10 +469,12 @@ pub(crate) enum BlockResponseOutcome { #[cfg(test)] mod tests { + use std::future::poll_fn; + + use reth_primitives::{SealedHeader, B512}; + use super::*; use crate::{peers::PeersManager, PeersConfig}; - use reth_primitives::{SealedHeader, B512}; - use std::future::poll_fn; #[tokio::test(flavor = "multi_thread")] async fn test_poll_fetcher() { diff --git a/crates/net/network/src/flattened_response.rs b/crates/net/network/src/flattened_response.rs index df2a9db78ae42..78c3c35f59811 100644 --- a/crates/net/network/src/flattened_response.rs +++ b/crates/net/network/src/flattened_response.rs @@ -1,9 +1,10 @@ -use futures::Future; -use pin_project::pin_project; use std::{ pin::Pin, task::{Context, Poll}, }; + +use futures::Future; +use pin_project::pin_project; use tokio::sync::oneshot::{error::RecvError, Receiver}; /// Flatten a [Receiver] message in order to get rid of the [RecvError] result diff --git a/crates/net/network/src/import.rs b/crates/net/network/src/import.rs index 11acfd03b462f..201dc3e4f7862 100644 --- a/crates/net/network/src/import.rs +++ b/crates/net/network/src/import.rs @@ -1,9 +1,11 @@ //! This module provides an abstraction over block import in the form of the `BlockImport` trait. -use crate::message::NewBlockMessage; -use reth_network_peers::PeerId; use std::task::{Context, Poll}; +use reth_network_peers::PeerId; + +use crate::message::NewBlockMessage; + /// Abstraction over block import. pub trait BlockImport: std::fmt::Debug + Send + Sync { /// Invoked for a received `NewBlock` broadcast message from the peer. diff --git a/crates/net/network/src/lib.rs b/crates/net/network/src/lib.rs index f03889f98414e..5a223ac5b14ca 100644 --- a/crates/net/network/src/lib.rs +++ b/crates/net/network/src/lib.rs @@ -143,12 +143,11 @@ pub use fetch::FetchClient; pub use manager::{NetworkEvent, NetworkManager}; pub use message::PeerRequest; pub use network::{NetworkEvents, NetworkHandle, NetworkProtocols}; +pub use reth_eth_wire::{DisconnectReason, HelloMessageWithProtocols}; +pub use reth_network_types::{PeersConfig, SessionsConfig}; pub use session::{ ActiveSessionHandle, ActiveSessionMessage, Direction, PeerInfo, PendingSessionEvent, PendingSessionHandle, PendingSessionHandshakeError, SessionCommand, SessionEvent, SessionId, SessionManager, }; pub use transactions::{FilterAnnouncement, MessageFilter, ValidateTx68}; - -pub use reth_eth_wire::{DisconnectReason, HelloMessageWithProtocols}; -pub use reth_network_types::{PeersConfig, SessionsConfig}; diff --git a/crates/net/network/src/listener.rs b/crates/net/network/src/listener.rs index 9fcc15a104b5f..b19e2ae6c408f 100644 --- a/crates/net/network/src/listener.rs +++ b/crates/net/network/src/listener.rs @@ -1,12 +1,13 @@ //! Contains connection-oriented interfaces. -use futures::{ready, Stream}; use std::{ io, net::SocketAddr, pin::Pin, task::{Context, Poll}, }; + +use futures::{ready, Stream}; use tokio::net::{TcpListener, TcpStream}; /// A tcp connection listener. @@ -102,13 +103,15 @@ impl Stream for TcpListenerStream { #[cfg(test)] mod tests { - use super::*; use std::{ net::{Ipv4Addr, SocketAddrV4}, pin::pin, }; + use tokio::macros::support::poll_fn; + use super::*; + #[tokio::test(flavor = "multi_thread")] async fn test_incoming_listener() { let listener = diff --git a/crates/net/network/src/manager.rs b/crates/net/network/src/manager.rs index 17827444bc204..5ed9173ba1d5a 100644 --- a/crates/net/network/src/manager.rs +++ b/crates/net/network/src/manager.rs @@ -15,6 +15,35 @@ //! (IP+port) of our node is published via discovery, remote peers can initiate inbound connections //! to the local node. Once a (tcp) connection is established, both peers start to authenticate a [RLPx session](https://github.com/ethereum/devp2p/blob/master/rlpx.md) via a handshake. If the handshake was successful, both peers announce their capabilities and are now ready to exchange sub-protocol messages via the `RLPx` session. +use std::{ + net::SocketAddr, + pin::Pin, + sync::{ + atomic::{AtomicU64, AtomicUsize, Ordering}, + Arc, + }, + task::{Context, Poll}, + time::{Duration, Instant}, +}; + +use futures::{Future, StreamExt}; +use parking_lot::Mutex; +use reth_eth_wire::{ + capability::{Capabilities, CapabilityMessage}, + DisconnectReason, EthVersion, Status, +}; +use reth_metrics::common::mpsc::UnboundedMeteredSender; +use reth_network_api::{EthProtocolInfo, NetworkStatus, ReputationChangeKind}; +use reth_network_peers::{NodeRecord, PeerId}; +use reth_primitives::ForkId; +use reth_provider::{BlockNumReader, BlockReader}; +use reth_tasks::shutdown::GracefulShutdown; +use reth_tokio_util::EventSender; +use secp256k1::SecretKey; +use tokio::sync::mpsc::{self, error::TrySendError}; +use tokio_stream::wrappers::UnboundedReceiverStream; +use tracing::{debug, error, trace, warn}; + use crate::{ budget::{DEFAULT_BUDGET_TRY_DRAIN_NETWORK_HANDLE_CHANNEL, DEFAULT_BUDGET_TRY_DRAIN_SWARM}, config::NetworkConfig, @@ -35,33 +64,6 @@ use crate::{ transactions::NetworkTransactionEvent, FetchClient, NetworkBuilder, }; -use futures::{Future, StreamExt}; -use parking_lot::Mutex; -use reth_eth_wire::{ - capability::{Capabilities, CapabilityMessage}, - DisconnectReason, EthVersion, Status, -}; -use reth_metrics::common::mpsc::UnboundedMeteredSender; -use reth_network_api::{EthProtocolInfo, NetworkStatus, ReputationChangeKind}; -use reth_network_peers::{NodeRecord, PeerId}; -use reth_primitives::ForkId; -use reth_provider::{BlockNumReader, BlockReader}; -use reth_tasks::shutdown::GracefulShutdown; -use reth_tokio_util::EventSender; -use secp256k1::SecretKey; -use std::{ - net::SocketAddr, - pin::Pin, - sync::{ - atomic::{AtomicU64, AtomicUsize, Ordering}, - Arc, - }, - task::{Context, Poll}, - time::{Duration, Instant}, -}; -use tokio::sync::mpsc::{self, error::TrySendError}; -use tokio_stream::wrappers::UnboundedReceiverStream; -use tracing::{debug, error, trace, warn}; #[cfg_attr(doc, aquamarine::aquamarine)] /// Manages the _entire_ state of the network. diff --git a/crates/net/network/src/message.rs b/crates/net/network/src/message.rs index 9d55051e37486..296f634f0d170 100644 --- a/crates/net/network/src/message.rs +++ b/crates/net/network/src/message.rs @@ -3,6 +3,12 @@ //! An `RLPx` stream is multiplexed via the prepended message-id of a framed message. //! Capabilities are exchanged via the `RLPx` `Hello` message as pairs of `(id, version)`, +use std::{ + fmt, + sync::Arc, + task::{ready, Context, Poll}, +}; + use futures::FutureExt; use reth_eth_wire::{ capability::RawCapabilityMessage, message::RequestPair, BlockBodies, BlockHeaders, EthMessage, @@ -15,11 +21,6 @@ use reth_network_peers::PeerId; use reth_primitives::{ BlockBody, Bytes, Header, PooledTransactionsElement, ReceiptWithBloom, B256, }; -use std::{ - fmt, - sync::Arc, - task::{ready, Context, Poll}, -}; use tokio::sync::{mpsc, mpsc::error::TrySendError, oneshot}; /// Internal form of a `NewBlock` message diff --git a/crates/net/network/src/network.rs b/crates/net/network/src/network.rs index 632a6028795af..08d2c1162d12f 100644 --- a/crates/net/network/src/network.rs +++ b/crates/net/network/src/network.rs @@ -1,8 +1,11 @@ -use crate::{ - config::NetworkMode, discovery::DiscoveryEvent, manager::NetworkEvent, message::PeerRequest, - peers::PeersHandle, protocol::RlpxSubProtocol, swarm::NetworkConnectionState, - transactions::TransactionsHandle, FetchClient, +use std::{ + net::SocketAddr, + sync::{ + atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering}, + Arc, + }, }; + use enr::Enr; use parking_lot::Mutex; use reth_discv4::Discv4; @@ -16,19 +19,18 @@ use reth_network_peers::{NodeRecord, PeerId}; use reth_primitives::{Head, TransactionSigned, B256}; use reth_tokio_util::{EventSender, EventStream}; use secp256k1::SecretKey; -use std::{ - net::SocketAddr, - sync::{ - atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering}, - Arc, - }, -}; use tokio::sync::{ mpsc::{self, UnboundedSender}, oneshot, }; use tokio_stream::wrappers::UnboundedReceiverStream; +use crate::{ + config::NetworkMode, discovery::DiscoveryEvent, manager::NetworkEvent, message::PeerRequest, + peers::PeersHandle, protocol::RlpxSubProtocol, swarm::NetworkConnectionState, + transactions::TransactionsHandle, FetchClient, +}; + /// A _shareable_ network frontend. Used to interact with the network. /// /// See also [`NetworkManager`](crate::NetworkManager). diff --git a/crates/net/network/src/peers.rs b/crates/net/network/src/peers.rs index c7e6a05a57dce..960761eb63d7e 100644 --- a/crates/net/network/src/peers.rs +++ b/crates/net/network/src/peers.rs @@ -1,10 +1,14 @@ //! Peer related implementations -use crate::{ - error::SessionError, - session::{Direction, PendingSessionHandshakeError}, - swarm::NetworkConnectionState, +use std::{ + collections::{hash_map::Entry, HashMap, HashSet, VecDeque}, + fmt::Display, + io::{self}, + net::{IpAddr, SocketAddr}, + task::{Context, Poll}, + time::Duration, }; + use futures::StreamExt; use reth_eth_wire::{errors::EthStreamError, DisconnectReason}; use reth_net_banlist::BanList; @@ -20,14 +24,6 @@ use reth_network_types::{ ConnectionsConfig, PeersConfig, ReputationChangeWeights, }; use reth_primitives::ForkId; -use std::{ - collections::{hash_map::Entry, HashMap, HashSet, VecDeque}, - fmt::Display, - io::{self}, - net::{IpAddr, SocketAddr}, - task::{Context, Poll}, - time::Duration, -}; use thiserror::Error; use tokio::{ sync::{mpsc, oneshot}, @@ -36,6 +32,12 @@ use tokio::{ use tokio_stream::wrappers::UnboundedReceiverStream; use tracing::trace; +use crate::{ + error::SessionError, + session::{Direction, PendingSessionHandshakeError}, + swarm::NetworkConnectionState, +}; + /// A communication channel to the [`PeersManager`] to apply manual changes to the peer set. #[derive(Clone, Debug)] pub struct PeersHandle { @@ -1263,15 +1265,16 @@ impl Display for InboundConnectionError { #[cfg(test)] mod tests { - use super::PeersManager; - use crate::{ - peers::{ - ConnectionInfo, InboundConnectionError, PeerAction, PeerBackoffDurations, - PeerConnectionState, - }, - session::PendingSessionHandshakeError, - PeersConfig, + use std::{ + collections::HashSet, + future::{poll_fn, Future}, + io, + net::{IpAddr, Ipv4Addr, SocketAddr}, + pin::Pin, + task::{Context, Poll}, + time::Duration, }; + use reth_discv4::NodeRecord; use reth_eth_wire::{ errors::{EthHandshakeError, EthStreamError, P2PHandshakeError, P2PStreamError}, @@ -1282,14 +1285,15 @@ mod tests { use reth_network_peers::PeerId; use reth_network_types::{peers::reputation::DEFAULT_REPUTATION, BackoffKind}; use reth_primitives::B512; - use std::{ - collections::HashSet, - future::{poll_fn, Future}, - io, - net::{IpAddr, Ipv4Addr, SocketAddr}, - pin::Pin, - task::{Context, Poll}, - time::Duration, + + use super::PeersManager; + use crate::{ + peers::{ + ConnectionInfo, InboundConnectionError, PeerAction, PeerBackoffDurations, + PeerConnectionState, + }, + session::PendingSessionHandshakeError, + PeersConfig, }; struct PeerActionFuture<'a> { diff --git a/crates/net/network/src/protocol.rs b/crates/net/network/src/protocol.rs index 2ae1b132df3f3..8ea34fff1ed6c 100644 --- a/crates/net/network/src/protocol.rs +++ b/crates/net/network/src/protocol.rs @@ -2,12 +2,6 @@ //! //! See also -use futures::Stream; -use reth_eth_wire::{ - capability::SharedCapabilities, multiplex::ProtocolConnection, protocol::Protocol, -}; -use reth_network_api::{Direction, PeerId}; -use reth_primitives::BytesMut; use std::{ fmt, net::SocketAddr, @@ -15,6 +9,13 @@ use std::{ pin::Pin, }; +use futures::Stream; +use reth_eth_wire::{ + capability::SharedCapabilities, multiplex::ProtocolConnection, protocol::Protocol, +}; +use reth_network_api::{Direction, PeerId}; +use reth_primitives::BytesMut; + /// A trait that allows to offer additional RLPx-based application-level protocols when establishing /// a peer-to-peer connection. pub trait ProtocolHandler: fmt::Debug + Send + Sync + 'static { diff --git a/crates/net/network/src/session/active.rs b/crates/net/network/src/session/active.rs index 97ccaf2c6a787..7a5fb3ced9f57 100644 --- a/crates/net/network/src/session/active.rs +++ b/crates/net/network/src/session/active.rs @@ -1,14 +1,16 @@ //! Represents an established session. -use crate::{ - message::{NewBlockMessage, PeerMessage, PeerRequest, PeerResponse, PeerResponseResult}, - session::{ - conn::EthRlpxConnection, - handle::{ActiveSessionMessage, SessionCommand}, - SessionId, - }, -}; use core::sync::atomic::Ordering; +use std::{ + collections::VecDeque, + future::Future, + net::SocketAddr, + pin::Pin, + sync::{atomic::AtomicU64, Arc}, + task::{ready, Context, Poll}, + time::{Duration, Instant}, +}; + use futures::{stream::Fuse, SinkExt, StreamExt}; use reth_eth_wire::{ capability::Capabilities, @@ -21,15 +23,6 @@ use reth_network_p2p::error::RequestError; use reth_network_peers::PeerId; use reth_network_types::session::config::INITIAL_REQUEST_TIMEOUT; use rustc_hash::FxHashMap; -use std::{ - collections::VecDeque, - future::Future, - net::SocketAddr, - pin::Pin, - sync::{atomic::AtomicU64, Arc}, - task::{ready, Context, Poll}, - time::{Duration, Instant}, -}; use tokio::{ sync::{mpsc::error::TrySendError, oneshot}, time::Interval, @@ -38,6 +31,15 @@ use tokio_stream::wrappers::ReceiverStream; use tokio_util::sync::PollSender; use tracing::{debug, trace}; +use crate::{ + message::{NewBlockMessage, PeerMessage, PeerRequest, PeerResponse, PeerResponseResult}, + session::{ + conn::EthRlpxConnection, + handle::{ActiveSessionMessage, SessionCommand}, + SessionId, + }, +}; + // Constants for timeout updating. /// Minimum timeout value @@ -758,8 +760,6 @@ fn calculate_new_timeout(current_timeout: Duration, estimated_rtt: Duration) -> } #[cfg(test)] mod tests { - use super::*; - use crate::session::{handle::PendingSessionEvent, start_pending_incoming_session}; use reth_chainspec::MAINNET; use reth_ecies::stream::ECIESStream; use reth_eth_wire::{ @@ -775,6 +775,9 @@ mod tests { sync::mpsc, }; + use super::*; + use crate::session::{handle::PendingSessionEvent, start_pending_incoming_session}; + /// Returns a testing `HelloMessage` and new secretkey fn eth_hello(server_key: &SecretKey) -> HelloMessageWithProtocols { HelloMessageWithProtocols::builder(pk2id(&server_key.public_key(SECP256K1))).build() diff --git a/crates/net/network/src/session/conn.rs b/crates/net/network/src/session/conn.rs index 0da22e926275c..be2027b7b71e1 100644 --- a/crates/net/network/src/session/conn.rs +++ b/crates/net/network/src/session/conn.rs @@ -1,5 +1,10 @@ //! Connection types for a session +use std::{ + pin::Pin, + task::{Context, Poll}, +}; + use futures::{Sink, Stream}; use reth_ecies::stream::ECIESStream; use reth_eth_wire::{ @@ -8,10 +13,6 @@ use reth_eth_wire::{ multiplex::{ProtocolProxy, RlpxSatelliteStream}, EthMessage, EthStream, EthVersion, P2PStream, }; -use std::{ - pin::Pin, - task::{Context, Poll}, -}; use tokio::net::TcpStream; /// The type of the underlying peer network connection. diff --git a/crates/net/network/src/session/handle.rs b/crates/net/network/src/session/handle.rs index b28b1e27e390a..836ccae8d2001 100644 --- a/crates/net/network/src/session/handle.rs +++ b/crates/net/network/src/session/handle.rs @@ -1,10 +1,7 @@ //! Session handles. -use crate::{ - message::PeerMessage, - session::{conn::EthRlpxConnection, Direction, SessionId}, - PendingSessionHandshakeError, -}; +use std::{io, net::SocketAddr, sync::Arc, time::Instant}; + use reth_ecies::ECIESError; use reth_eth_wire::{ capability::{Capabilities, CapabilityMessage}, @@ -13,12 +10,17 @@ use reth_eth_wire::{ }; use reth_network_api::PeerInfo; use reth_network_peers::PeerId; -use std::{io, net::SocketAddr, sync::Arc, time::Instant}; use tokio::sync::{ mpsc::{self, error::SendError}, oneshot, }; +use crate::{ + message::PeerMessage, + session::{conn::EthRlpxConnection, Direction, SessionId}, + PendingSessionHandshakeError, +}; + /// A handler attached to a peer session that's not authenticated yet, pending Handshake and hello /// message which exchanges the `capabilities` of the peer. /// diff --git a/crates/net/network/src/session/mod.rs b/crates/net/network/src/session/mod.rs index 715ed59cf635f..35ca12649e126 100644 --- a/crates/net/network/src/session/mod.rs +++ b/crates/net/network/src/session/mod.rs @@ -1,6 +1,14 @@ //! Support for handling peer sessions. -use crate::{message::PeerMessage, metrics::SessionManagerMetrics, session::active::ActiveSession}; +use std::{ + collections::HashMap, + future::Future, + net::SocketAddr, + sync::{atomic::AtomicU64, Arc}, + task::{Context, Poll}, + time::{Duration, Instant}, +}; + use counter::SessionCounter; use futures::{future::Either, io, FutureExt, StreamExt}; use reth_ecies::{stream::ECIESStream, ECIESError}; @@ -17,14 +25,6 @@ use reth_primitives::{ForkFilter, ForkId, ForkTransition, Head}; use reth_tasks::TaskSpawner; use rustc_hash::FxHashMap; use secp256k1::SecretKey; -use std::{ - collections::HashMap, - future::Future, - net::SocketAddr, - sync::{atomic::AtomicU64, Arc}, - task::{Context, Poll}, - time::{Duration, Instant}, -}; use tokio::{ io::{AsyncRead, AsyncWrite}, net::TcpStream, @@ -34,12 +34,12 @@ use tokio_stream::wrappers::ReceiverStream; use tokio_util::sync::PollSender; use tracing::{debug, instrument, trace}; +use crate::{message::PeerMessage, metrics::SessionManagerMetrics, session::active::ActiveSession}; + mod active; mod conn; mod counter; mod handle; -pub use crate::message::PeerRequestSender; -use crate::protocol::{IntoRlpxSubProtocol, RlpxSubProtocolHandlers, RlpxSubProtocols}; pub use handle::{ ActiveSessionHandle, ActiveSessionMessage, PendingSessionEvent, PendingSessionHandle, SessionCommand, @@ -47,6 +47,9 @@ pub use handle::{ use reth_eth_wire::multiplex::RlpxProtocolMultiplexer; pub use reth_network_api::{Direction, PeerInfo}; +pub use crate::message::PeerRequestSender; +use crate::protocol::{IntoRlpxSubProtocol, RlpxSubProtocolHandlers, RlpxSubProtocols}; + /// Internal identifier for active sessions. #[derive(Debug, Clone, Copy, PartialOrd, PartialEq, Eq, Hash)] pub struct SessionId(usize); diff --git a/crates/net/network/src/state.rs b/crates/net/network/src/state.rs index afbf05dde6911..8892948324506 100644 --- a/crates/net/network/src/state.rs +++ b/crates/net/network/src/state.rs @@ -1,19 +1,16 @@ //! Keeps track of the state of the network. -use crate::{ - cache::LruCache, - discovery::{Discovery, DiscoveryEvent}, - fetch::{BlockResponseOutcome, FetchAction, StateFetcher}, - manager::DiscoveredEvent, - message::{ - BlockRequest, NewBlockMessage, PeerRequest, PeerRequestSender, PeerResponse, - PeerResponseResult, +use std::{ + collections::{HashMap, VecDeque}, + net::{IpAddr, SocketAddr}, + sync::{ + atomic::{AtomicU64, AtomicUsize}, + Arc, }, - peers::{PeerAction, PeersManager}, - FetchClient, + task::{Context, Poll}, }; -use rand::seq::SliceRandom; +use rand::seq::SliceRandom; use reth_eth_wire::{ capability::Capabilities, BlockHashNumber, DisconnectReason, NewBlockHashes, Status, }; @@ -21,18 +18,22 @@ use reth_network_api::PeerKind; use reth_network_peers::PeerId; use reth_primitives::{ForkId, B256}; use reth_provider::BlockNumReader; -use std::{ - collections::{HashMap, VecDeque}, - net::{IpAddr, SocketAddr}, - sync::{ - atomic::{AtomicU64, AtomicUsize}, - Arc, - }, - task::{Context, Poll}, -}; use tokio::sync::oneshot; use tracing::{debug, trace}; +use crate::{ + cache::LruCache, + discovery::{Discovery, DiscoveryEvent}, + fetch::{BlockResponseOutcome, FetchAction, StateFetcher}, + manager::DiscoveredEvent, + message::{ + BlockRequest, NewBlockMessage, PeerRequest, PeerRequestSender, PeerResponse, + PeerResponseResult, + }, + peers::{PeerAction, PeersManager}, + FetchClient, +}; + /// Cache limit of blocks to keep track of for a single peer. const PEER_BLOCK_CACHE_LIMIT: u32 = 512; @@ -525,10 +526,11 @@ pub(crate) enum StateAction { #[cfg(test)] mod tests { - use crate::{ - discovery::Discovery, fetch::StateFetcher, message::PeerRequestSender, peers::PeersManager, - state::NetworkState, PeerRequest, + use std::{ + future::poll_fn, + sync::{atomic::AtomicU64, Arc}, }; + use reth_eth_wire::{ capability::{Capabilities, Capability}, BlockBodies, EthVersion, @@ -537,13 +539,14 @@ mod tests { use reth_network_peers::PeerId; use reth_primitives::{BlockBody, Header, B256}; use reth_provider::test_utils::NoopProvider; - use std::{ - future::poll_fn, - sync::{atomic::AtomicU64, Arc}, - }; use tokio::sync::mpsc; use tokio_stream::{wrappers::ReceiverStream, StreamExt}; + use crate::{ + discovery::Discovery, fetch::StateFetcher, message::PeerRequestSender, peers::PeersManager, + state::NetworkState, PeerRequest, + }; + /// Returns a testing instance of the [`NetworkState`]. fn state() -> NetworkState { let peers = PeersManager::default(); diff --git a/crates/net/network/src/swarm.rs b/crates/net/network/src/swarm.rs index cfc1f841713c2..d5f6b60b1ceef 100644 --- a/crates/net/network/src/swarm.rs +++ b/crates/net/network/src/swarm.rs @@ -1,11 +1,11 @@ -use crate::{ - listener::{ConnectionListener, ListenerEvent}, - message::{PeerMessage, PeerRequestSender}, - peers::InboundConnectionError, - protocol::IntoRlpxSubProtocol, - session::{Direction, PendingSessionHandshakeError, SessionEvent, SessionId, SessionManager}, - state::{NetworkState, StateAction}, +use std::{ + io, + net::SocketAddr, + pin::Pin, + sync::Arc, + task::{Context, Poll}, }; + use futures::Stream; use reth_eth_wire::{ capability::{Capabilities, CapabilityMessage}, @@ -14,16 +14,17 @@ use reth_eth_wire::{ }; use reth_network_peers::PeerId; use reth_provider::{BlockNumReader, BlockReader}; -use std::{ - io, - net::SocketAddr, - pin::Pin, - sync::Arc, - task::{Context, Poll}, -}; - use tracing::trace; +use crate::{ + listener::{ConnectionListener, ListenerEvent}, + message::{PeerMessage, PeerRequestSender}, + peers::InboundConnectionError, + protocol::IntoRlpxSubProtocol, + session::{Direction, PendingSessionHandshakeError, SessionEvent, SessionId, SessionManager}, + state::{NetworkState, StateAction}, +}; + #[cfg_attr(doc, aquamarine::aquamarine)] /// Contains the connectivity related state of the network. /// diff --git a/crates/net/network/src/test_utils/init.rs b/crates/net/network/src/test_utils/init.rs index 87ccbb5f9d792..767f6818091a0 100644 --- a/crates/net/network/src/test_utils/init.rs +++ b/crates/net/network/src/test_utils/init.rs @@ -1,6 +1,7 @@ +use std::{net::SocketAddr, time::Duration}; + use enr::{k256::ecdsa::SigningKey, Enr, EnrPublicKey}; use reth_network_peers::PeerId; -use std::{net::SocketAddr, time::Duration}; /// The timeout for tests that create a `GethInstance` pub const GETH_TIMEOUT: Duration = Duration::from_secs(60); diff --git a/crates/net/network/src/test_utils/testnet.rs b/crates/net/network/src/test_utils/testnet.rs index c7642accd0d86..bffc5d1f2d550 100644 --- a/crates/net/network/src/test_utils/testnet.rs +++ b/crates/net/network/src/test_utils/testnet.rs @@ -1,15 +1,13 @@ //! A network implementation for testing purposes. -use crate::{ - builder::ETH_REQUEST_CHANNEL_CAPACITY, - error::NetworkError, - eth_requests::EthRequestHandler, - peers::PeersHandle, - protocol::IntoRlpxSubProtocol, - transactions::{TransactionsHandle, TransactionsManager, TransactionsManagerConfig}, - NetworkConfig, NetworkConfigBuilder, NetworkEvent, NetworkEvents, NetworkHandle, - NetworkManager, +use std::{ + fmt, + future::Future, + net::{Ipv4Addr, SocketAddr, SocketAddrV4}, + pin::Pin, + task::{Context, Poll}, }; + use futures::{FutureExt, StreamExt}; use pin_project::pin_project; use reth_chainspec::MAINNET; @@ -27,13 +25,6 @@ use reth_transaction_pool::{ EthTransactionPool, TransactionPool, TransactionValidationTaskExecutor, }; use secp256k1::SecretKey; -use std::{ - fmt, - future::Future, - net::{Ipv4Addr, SocketAddr, SocketAddrV4}, - pin::Pin, - task::{Context, Poll}, -}; use tokio::{ sync::{ mpsc::{channel, unbounded_channel}, @@ -42,6 +33,17 @@ use tokio::{ task::JoinHandle, }; +use crate::{ + builder::ETH_REQUEST_CHANNEL_CAPACITY, + error::NetworkError, + eth_requests::EthRequestHandler, + peers::PeersHandle, + protocol::IntoRlpxSubProtocol, + transactions::{TransactionsHandle, TransactionsManager, TransactionsManagerConfig}, + NetworkConfig, NetworkConfigBuilder, NetworkEvent, NetworkEvents, NetworkHandle, + NetworkManager, +}; + /// A test network consisting of multiple peers. pub struct Testnet { /// All running peers in the network. diff --git a/crates/net/network/src/transactions/config.rs b/crates/net/network/src/transactions/config.rs index 9ddb9ce9c87d3..083aefa8a637c 100644 --- a/crates/net/network/src/transactions/config.rs +++ b/crates/net/network/src/transactions/config.rs @@ -1,8 +1,9 @@ +use derive_more::Constructor; + use super::{ DEFAULT_SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESP_ON_PACK_GET_POOLED_TRANSACTIONS_REQ, SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE, }; -use derive_more::Constructor; /// Configuration for managing transactions within the network. #[derive(Debug, Default, Clone)] diff --git a/crates/net/network/src/transactions/constants.rs b/crates/net/network/src/transactions/constants.rs index 48fb8857cc352..66432c14712b8 100644 --- a/crates/net/network/src/transactions/constants.rs +++ b/crates/net/network/src/transactions/constants.rs @@ -57,7 +57,6 @@ pub mod tx_manager { /// Constants used by [`TransactionFetcher`](super::TransactionFetcher). pub mod tx_fetcher { - use crate::transactions::fetcher::TransactionFetcherInfo; use reth_network_types::peers::config::{ DEFAULT_MAX_COUNT_PEERS_INBOUND, DEFAULT_MAX_COUNT_PEERS_OUTBOUND, }; @@ -67,6 +66,7 @@ pub mod tx_fetcher { SOFT_LIMIT_COUNT_HASHES_IN_GET_POOLED_TRANSACTIONS_REQUEST, SOFT_LIMIT_COUNT_HASHES_IN_NEW_POOLED_TRANSACTIONS_BROADCAST_MESSAGE, }; + use crate::transactions::fetcher::TransactionFetcherInfo; /* ============== SCALARS OF MESSAGES ============== */ diff --git a/crates/net/network/src/transactions/fetcher.rs b/crates/net/network/src/transactions/fetcher.rs index 41081b1915155..cb3bdafa16c2e 100644 --- a/crates/net/network/src/transactions/fetcher.rs +++ b/crates/net/network/src/transactions/fetcher.rs @@ -25,16 +25,15 @@ //! before it's re-tried. Nonetheless, the capacity of the buffered hashes cache must be large //! enough to buffer many hashes during network failure, to allow for recovery. -use crate::{ - cache::{LruCache, LruMap}, - duration_metered_exec, - message::PeerRequest, - metrics::TransactionFetcherMetrics, - transactions::{validation, PartiallyFilterMessage}, +use std::{ + collections::HashMap, + pin::Pin, + task::{ready, Context, Poll}, + time::Duration, }; + use derive_more::{Constructor, Deref}; use futures::{stream::FuturesUnordered, Future, FutureExt, Stream, StreamExt}; - use pin_project::pin_project; use reth_eth_wire::{ DedupPayload, EthVersion, GetPooledTransactions, HandleMempoolData, HandleVersionedMempoolData, @@ -46,12 +45,6 @@ use reth_primitives::{PooledTransactionsElement, TxHash}; use schnellru::ByLength; #[cfg(debug_assertions)] use smallvec::{smallvec, SmallVec}; -use std::{ - collections::HashMap, - pin::Pin, - task::{ready, Context, Poll}, - time::Duration, -}; use tokio::sync::{mpsc::error::TrySendError, oneshot, oneshot::error::RecvError}; use tracing::{debug, trace}; use validation::FilterOutcome; @@ -62,6 +55,13 @@ use super::{ MessageFilter, PeerMetadata, PooledTransactions, SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE, }; +use crate::{ + cache::{LruCache, LruMap}, + duration_metered_exec, + message::PeerRequest, + metrics::TransactionFetcherMetrics, + transactions::{validation, PartiallyFilterMessage}, +}; /// The type responsible for fetching missing transactions from peers. /// @@ -1338,9 +1338,8 @@ mod test { use derive_more::IntoIterator; use reth_primitives::{hex, TransactionSigned, B256}; - use crate::transactions::tests::{default_cache, new_mock_session}; - use super::*; + use crate::transactions::tests::{default_cache, new_mock_session}; #[derive(IntoIterator)] struct TestValidAnnouncementData(Vec<(TxHash, Option<(u8, usize)>)>); diff --git a/crates/net/network/src/transactions/mod.rs b/crates/net/network/src/transactions/mod.rs index 14568590252f9..af8c0810567d1 100644 --- a/crates/net/network/src/transactions/mod.rs +++ b/crates/net/network/src/transactions/mod.rs @@ -1,19 +1,16 @@ //! Transactions management for the p2p network. -use crate::{ - budget::{ - DEFAULT_BUDGET_TRY_DRAIN_NETWORK_TRANSACTION_EVENTS, - DEFAULT_BUDGET_TRY_DRAIN_PENDING_POOL_IMPORTS, DEFAULT_BUDGET_TRY_DRAIN_POOL_IMPORTS, - DEFAULT_BUDGET_TRY_DRAIN_STREAM, +use std::{ + collections::{hash_map::Entry, HashMap, HashSet}, + pin::Pin, + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, }, - cache::LruCache, - duration_metered_exec, - manager::NetworkEvent, - message::{PeerRequest, PeerRequestSender}, - metered_poll_nested_stream_with_budget, - metrics::{TransactionsManagerMetrics, NETWORK_POOL_TRANSACTIONS_SCOPE}, - NetworkEvents, NetworkHandle, + task::{Context, Poll}, + time::{Duration, Instant}, }; + use futures::{stream::FuturesUnordered, Future, StreamExt}; use reth_eth_wire::{ EthVersion, GetPooledTransactions, HandleMempoolData, HandleVersionedMempoolData, @@ -36,20 +33,25 @@ use reth_transaction_pool::{ GetPooledTransactionLimit, PoolTransaction, PropagateKind, PropagatedTransactions, TransactionPool, ValidPoolTransaction, }; -use std::{ - collections::{hash_map::Entry, HashMap, HashSet}, - pin::Pin, - sync::{ - atomic::{AtomicUsize, Ordering}, - Arc, - }, - task::{Context, Poll}, - time::{Duration, Instant}, -}; use tokio::sync::{mpsc, oneshot, oneshot::error::RecvError}; use tokio_stream::wrappers::{ReceiverStream, UnboundedReceiverStream}; use tracing::{debug, trace}; +use crate::{ + budget::{ + DEFAULT_BUDGET_TRY_DRAIN_NETWORK_TRANSACTION_EVENTS, + DEFAULT_BUDGET_TRY_DRAIN_PENDING_POOL_IMPORTS, DEFAULT_BUDGET_TRY_DRAIN_POOL_IMPORTS, + DEFAULT_BUDGET_TRY_DRAIN_STREAM, + }, + cache::LruCache, + duration_metered_exec, + manager::NetworkEvent, + message::{PeerRequest, PeerRequestSender}, + metered_poll_nested_stream_with_budget, + metrics::{TransactionsManagerMetrics, NETWORK_POOL_TRANSACTIONS_SCOPE}, + NetworkEvents, NetworkHandle, +}; + /// Aggregation on configurable parameters for [`TransactionsManager`]. pub mod config; /// Default and spec'd bounds. @@ -58,7 +60,6 @@ pub mod constants; pub mod fetcher; pub mod validation; pub use config::{TransactionFetcherConfig, TransactionsManagerConfig}; - use constants::SOFT_LIMIT_COUNT_HASHES_IN_NEW_POOLED_TRANSACTIONS_BROADCAST_MESSAGE; pub(crate) use fetcher::{FetchEvent, TransactionFetcher}; pub use validation::*; @@ -1605,8 +1606,8 @@ struct TxManagerPollDurations { #[cfg(test)] mod tests { - use super::*; - use crate::{test_utils::Testnet, NetworkConfigBuilder, NetworkManager}; + use std::{fmt, future::poll_fn, hash}; + use alloy_rlp::Decodable; use constants::tx_fetcher::DEFAULT_MAX_COUNT_FALLBACK_PEERS; use futures::FutureExt; @@ -1619,10 +1620,12 @@ mod tests { use reth_provider::test_utils::NoopProvider; use reth_transaction_pool::test_utils::{testing_pool, MockTransaction}; use secp256k1::SecretKey; - use std::{fmt, future::poll_fn, hash}; use tests::fetcher::TxFetchMetadata; use tracing::error; + use super::*; + use crate::{test_utils::Testnet, NetworkConfigBuilder, NetworkManager}; + async fn new_tx_manager() -> TransactionsManager { let secret_key = SecretKey::new(&mut rand::thread_rng()); let client = NoopProvider::default(); diff --git a/crates/net/network/src/transactions/validation.rs b/crates/net/network/src/transactions/validation.rs index 931cfdb9e514e..a6c28d95dccf3 100644 --- a/crates/net/network/src/transactions/validation.rs +++ b/crates/net/network/src/transactions/validation.rs @@ -4,7 +4,6 @@ use std::{fmt, fmt::Display, mem}; -use crate::metrics::{AnnouncedTxTypesMetrics, TxTypesCounter}; use derive_more::{Deref, DerefMut}; use reth_eth_wire::{ DedupPayload, Eth68TxMetadata, HandleMempoolData, PartiallyValidData, ValidAnnouncementData, @@ -13,6 +12,8 @@ use reth_eth_wire::{ use reth_primitives::{Signature, TxHash, TxType}; use tracing::trace; +use crate::metrics::{AnnouncedTxTypesMetrics, TxTypesCounter}; + /// The size of a decoded signature in bytes. pub const SIGNATURE_DECODED_SIZE_BYTES: usize = mem::size_of::(); @@ -333,11 +334,12 @@ impl FilterAnnouncement for EthMessageFilter { #[cfg(test)] mod test { - use super::*; + use std::{collections::HashMap, str::FromStr}; use reth_eth_wire::{NewPooledTransactionHashes66, NewPooledTransactionHashes68}; use reth_primitives::B256; - use std::{collections::HashMap, str::FromStr}; + + use super::*; #[test] fn eth68_empty_announcement() { diff --git a/crates/net/network/tests/it/big_pooled_txs_req.rs b/crates/net/network/tests/it/big_pooled_txs_req.rs index 4ddc0cdd36eee..acb015d92d891 100644 --- a/crates/net/network/tests/it/big_pooled_txs_req.rs +++ b/crates/net/network/tests/it/big_pooled_txs_req.rs @@ -11,7 +11,6 @@ use reth_transaction_pool::{ test_utils::{testing_pool, MockTransaction}, TransactionPool, }; - use tokio::sync::oneshot; // peer0: `GetPooledTransactions` requester // peer1: `GetPooledTransactions` responder diff --git a/crates/net/network/tests/it/connect.rs b/crates/net/network/tests/it/connect.rs index a191443ed8cb7..ec1bf98900b2d 100644 --- a/crates/net/network/tests/it/connect.rs +++ b/crates/net/network/tests/it/connect.rs @@ -1,5 +1,7 @@ //! Connection tests +use std::{collections::HashSet, net::SocketAddr, time::Duration}; + use alloy_node_bindings::Geth; use alloy_provider::{ext::AdminApi, ProviderBuilder}; use futures::StreamExt; @@ -21,7 +23,6 @@ use reth_primitives::HeadersDirection; use reth_provider::test_utils::NoopProvider; use reth_transaction_pool::test_utils::testing_pool; use secp256k1::SecretKey; -use std::{collections::HashSet, net::SocketAddr, time::Duration}; use tokio::task; #[tokio::test(flavor = "multi_thread")] diff --git a/crates/net/network/tests/it/multiplex.rs b/crates/net/network/tests/it/multiplex.rs index ea63ace952b77..193688cfec54e 100644 --- a/crates/net/network/tests/it/multiplex.rs +++ b/crates/net/network/tests/it/multiplex.rs @@ -1,7 +1,12 @@ #![allow(unreachable_pub)] //! Testing gossiping of transactions. -use crate::multiplex::proto::{PingPongProtoMessage, PingPongProtoMessageKind}; +use std::{ + net::SocketAddr, + pin::Pin, + task::{ready, Context, Poll}, +}; + use futures::{Stream, StreamExt}; use reth_eth_wire::{ capability::SharedCapabilities, multiplex::ProtocolConnection, protocol::Protocol, @@ -13,20 +18,18 @@ use reth_network::{ use reth_network_api::{Direction, PeerId}; use reth_primitives::BytesMut; use reth_provider::test_utils::MockEthProvider; -use std::{ - net::SocketAddr, - pin::Pin, - task::{ready, Context, Poll}, -}; use tokio::sync::{mpsc, oneshot}; use tokio_stream::wrappers::UnboundedReceiverStream; +use crate::multiplex::proto::{PingPongProtoMessage, PingPongProtoMessageKind}; + /// A simple Rlpx subprotocol that sends pings and pongs mod proto { - use super::*; use reth_eth_wire::capability::Capability; use reth_primitives::{Buf, BufMut}; + use super::*; + #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum PingPongProtoMessageId { diff --git a/crates/net/network/tests/it/requests.rs b/crates/net/network/tests/it/requests.rs index 555acd08b2485..fc378d0b7fb09 100644 --- a/crates/net/network/tests/it/requests.rs +++ b/crates/net/network/tests/it/requests.rs @@ -1,6 +1,8 @@ #![allow(unreachable_pub)] //! Tests for eth related requests +use std::sync::Arc; + use rand::Rng; use reth_network::{ test_utils::{NetworkEventStream, Testnet}, @@ -16,7 +18,6 @@ use reth_primitives::{ TxEip2930, TxKind, U256, }; use reth_provider::test_utils::MockEthProvider; -use std::sync::Arc; /// Returns a new [`TransactionSigned`] with some random parameters pub fn rng_transaction(rng: &mut impl rand::RngCore) -> TransactionSigned { diff --git a/crates/net/network/tests/it/startup.rs b/crates/net/network/tests/it/startup.rs index 9317bef0fd4ab..269b352e4b10e 100644 --- a/crates/net/network/tests/it/startup.rs +++ b/crates/net/network/tests/it/startup.rs @@ -1,3 +1,8 @@ +use std::{ + io, + net::{Ipv4Addr, SocketAddr, SocketAddrV4}, +}; + use reth_discv4::Discv4Config; use reth_network::{ error::{NetworkError, ServiceKind}, @@ -6,10 +11,6 @@ use reth_network::{ use reth_network_api::{NetworkInfo, PeersInfo}; use reth_provider::test_utils::NoopProvider; use secp256k1::SecretKey; -use std::{ - io, - net::{Ipv4Addr, SocketAddr, SocketAddrV4}, -}; use tokio::net::TcpListener; fn is_addr_in_use_kind(err: &NetworkError, kind: ServiceKind) -> bool { diff --git a/crates/net/network/tests/it/txgossip.rs b/crates/net/network/tests/it/txgossip.rs index 68a7775f0e6a5..d5c5ccf6384c1 100644 --- a/crates/net/network/tests/it/txgossip.rs +++ b/crates/net/network/tests/it/txgossip.rs @@ -1,5 +1,7 @@ //! Testing gossiping of transactions. +use std::sync::Arc; + use futures::StreamExt; use rand::thread_rng; use reth_network::{test_utils::Testnet, NetworkEvent, NetworkEvents}; @@ -7,7 +9,6 @@ use reth_network_api::PeersInfo; use reth_primitives::{TransactionSigned, TxLegacy, U256}; use reth_provider::test_utils::{ExtendedAccount, MockEthProvider}; use reth_transaction_pool::{test_utils::TransactionGenerator, PoolTransaction, TransactionPool}; -use std::sync::Arc; #[tokio::test(flavor = "multi_thread")] async fn test_tx_gossip() { diff --git a/crates/net/p2p/src/bodies/client.rs b/crates/net/p2p/src/bodies/client.rs index 3a36da50016e5..cc7d661fdcb1a 100644 --- a/crates/net/p2p/src/bodies/client.rs +++ b/crates/net/p2p/src/bodies/client.rs @@ -3,10 +3,11 @@ use std::{ task::{ready, Context, Poll}, }; -use crate::{download::DownloadClient, error::PeerRequestResult, priority::Priority}; use futures::{Future, FutureExt}; use reth_primitives::{BlockBody, B256}; +use crate::{download::DownloadClient, error::PeerRequestResult, priority::Priority}; + /// The bodies future type pub type BodiesFut = Pin>> + Send + Sync>>; diff --git a/crates/net/p2p/src/bodies/downloader.rs b/crates/net/p2p/src/bodies/downloader.rs index 414a33fd4b1ed..fa2f12f68d6df 100644 --- a/crates/net/p2p/src/bodies/downloader.rs +++ b/crates/net/p2p/src/bodies/downloader.rs @@ -1,8 +1,10 @@ -use super::response::BlockResponse; -use crate::error::DownloadResult; +use std::ops::RangeInclusive; + use futures::Stream; use reth_primitives::BlockNumber; -use std::ops::RangeInclusive; + +use super::response::BlockResponse; +use crate::error::DownloadResult; /// Body downloader return type. pub type BodyDownloaderResult = DownloadResult>; diff --git a/crates/net/p2p/src/download.rs b/crates/net/p2p/src/download.rs index 07505144a7b89..2b5acff982da7 100644 --- a/crates/net/p2p/src/download.rs +++ b/crates/net/p2p/src/download.rs @@ -1,6 +1,7 @@ -use reth_network_peers::PeerId; use std::fmt::Debug; +use reth_network_peers::PeerId; + /// Generic download client for peer penalization #[auto_impl::auto_impl(&, Arc, Box)] pub trait DownloadClient: Send + Sync + Debug { diff --git a/crates/net/p2p/src/either.rs b/crates/net/p2p/src/either.rs index 5d0014e6fd2de..e5fad119e3bec 100644 --- a/crates/net/p2p/src/either.rs +++ b/crates/net/p2p/src/either.rs @@ -1,14 +1,14 @@ //! Support for different download types. +pub use futures::future::Either; +use reth_primitives::B256; + use crate::{ bodies::client::BodiesClient, download::DownloadClient, headers::client::{HeadersClient, HeadersRequest}, priority::Priority, }; -use reth_primitives::B256; - -pub use futures::future::Either; impl DownloadClient for Either where diff --git a/crates/net/p2p/src/error.rs b/crates/net/p2p/src/error.rs index e005f4ea92530..8e5aa416b693e 100644 --- a/crates/net/p2p/src/error.rs +++ b/crates/net/p2p/src/error.rs @@ -1,4 +1,5 @@ -use super::headers::client::HeadersRequest; +use std::ops::RangeInclusive; + use reth_consensus::ConsensusError; use reth_network_api::ReputationChangeKind; use reth_network_peers::WithPeerId; @@ -6,10 +7,11 @@ use reth_primitives::{ BlockHashOrNumber, BlockNumber, GotExpected, GotExpectedBoxed, Header, B256, }; use reth_storage_errors::{db::DatabaseError, provider::ProviderError}; -use std::ops::RangeInclusive; use thiserror::Error; use tokio::sync::{mpsc, oneshot}; +use super::headers::client::HeadersRequest; + /// Result alias for result of a request. pub type RequestResult = Result; diff --git a/crates/net/p2p/src/full_block.rs b/crates/net/p2p/src/full_block.rs index 93af03d5b076b..b1d34e892dedd 100644 --- a/crates/net/p2p/src/full_block.rs +++ b/crates/net/p2p/src/full_block.rs @@ -1,15 +1,3 @@ -use super::headers::client::HeadersRequest; -use crate::{ - bodies::client::{BodiesClient, SingleBodyRequest}, - error::PeerRequestResult, - headers::client::{HeadersClient, SingleHeaderRequest}, -}; -use futures::Stream; -use reth_consensus::{Consensus, ConsensusError}; -use reth_network_peers::WithPeerId; -use reth_primitives::{ - BlockBody, GotExpected, Header, HeadersDirection, SealedBlock, SealedHeader, B256, -}; use std::{ cmp::Reverse, collections::{HashMap, VecDeque}, @@ -19,8 +7,22 @@ use std::{ sync::Arc, task::{ready, Context, Poll}, }; + +use futures::Stream; +use reth_consensus::{Consensus, ConsensusError}; +use reth_network_peers::WithPeerId; +use reth_primitives::{ + BlockBody, GotExpected, Header, HeadersDirection, SealedBlock, SealedHeader, B256, +}; use tracing::debug; +use super::headers::client::HeadersRequest; +use crate::{ + bodies::client::{BodiesClient, SingleBodyRequest}, + error::PeerRequestResult, + headers::client::{HeadersClient, SingleHeaderRequest}, +}; + /// A Client that can fetch full blocks from the network. #[derive(Debug, Clone)] pub struct FullBlockClient { @@ -741,10 +743,12 @@ enum RangeResponseResult { #[cfg(test)] mod tests { + use std::ops::Range; + + use futures::StreamExt; + use super::*; use crate::test_utils::TestFullBlockClient; - use futures::StreamExt; - use std::ops::Range; #[tokio::test] async fn download_single_full_block() { diff --git a/crates/net/p2p/src/headers/client.rs b/crates/net/p2p/src/headers/client.rs index 5b70aa1e52827..15282613e6c83 100644 --- a/crates/net/p2p/src/headers/client.rs +++ b/crates/net/p2p/src/headers/client.rs @@ -1,13 +1,15 @@ -use crate::{download::DownloadClient, error::PeerRequestResult, priority::Priority}; -use futures::{Future, FutureExt}; -pub use reth_eth_wire_types::BlockHeaders; -use reth_primitives::{BlockHashOrNumber, Header, HeadersDirection}; use std::{ fmt::Debug, pin::Pin, task::{ready, Context, Poll}, }; +use futures::{Future, FutureExt}; +pub use reth_eth_wire_types::BlockHeaders; +use reth_primitives::{BlockHashOrNumber, Header, HeadersDirection}; + +use crate::{download::DownloadClient, error::PeerRequestResult, priority::Priority}; + /// The header request struct to be sent to connected peers, which /// will proceed to ask them to stream the requested headers to us. #[derive(Clone, Debug)] diff --git a/crates/net/p2p/src/headers/downloader.rs b/crates/net/p2p/src/headers/downloader.rs index a568c7313b6c4..8c6efb371f048 100644 --- a/crates/net/p2p/src/headers/downloader.rs +++ b/crates/net/p2p/src/headers/downloader.rs @@ -1,8 +1,9 @@ -use super::error::HeadersDownloaderResult; -use crate::error::{DownloadError, DownloadResult}; use futures::Stream; use reth_consensus::Consensus; use reth_primitives::{BlockHashOrNumber, SealedHeader, B256}; + +use super::error::HeadersDownloaderResult; +use crate::error::{DownloadError, DownloadResult}; /// A downloader capable of fetching and yielding block headers. /// /// A downloader represents a distinct strategy for submitting requests to download block headers, diff --git a/crates/net/p2p/src/test_utils/bodies.rs b/crates/net/p2p/src/test_utils/bodies.rs index 7f14133ab8469..bc7f76368cbca 100644 --- a/crates/net/p2p/src/test_utils/bodies.rs +++ b/crates/net/p2p/src/test_utils/bodies.rs @@ -1,13 +1,15 @@ +use std::fmt::{Debug, Formatter}; + +use futures::FutureExt; +use reth_primitives::{BlockBody, B256}; +use tokio::sync::oneshot; + use crate::{ bodies::client::{BodiesClient, BodiesFut}, download::DownloadClient, error::PeerRequestResult, priority::Priority, }; -use futures::FutureExt; -use reth_primitives::{BlockBody, B256}; -use std::fmt::{Debug, Formatter}; -use tokio::sync::oneshot; /// A test client for fetching bodies pub struct TestBodiesClient { diff --git a/crates/net/p2p/src/test_utils/full_block.rs b/crates/net/p2p/src/test_utils/full_block.rs index cfba59dbf745d..230aedc639e8d 100644 --- a/crates/net/p2p/src/test_utils/full_block.rs +++ b/crates/net/p2p/src/test_utils/full_block.rs @@ -1,3 +1,12 @@ +use std::{collections::HashMap, sync::Arc}; + +use parking_lot::Mutex; +use reth_network_peers::{PeerId, WithPeerId}; +use reth_primitives::{ + BlockBody, BlockHashOrNumber, BlockNumHash, Header, HeadersDirection, SealedBlock, + SealedHeader, B256, +}; + use crate::{ bodies::client::BodiesClient, download::DownloadClient, @@ -5,13 +14,6 @@ use crate::{ headers::client::{HeadersClient, HeadersRequest}, priority::Priority, }; -use parking_lot::Mutex; -use reth_network_peers::{PeerId, WithPeerId}; -use reth_primitives::{ - BlockBody, BlockHashOrNumber, BlockNumHash, Header, HeadersDirection, SealedBlock, - SealedHeader, B256, -}; -use std::{collections::HashMap, sync::Arc}; /// A headers+bodies client implementation that does nothing. #[derive(Debug, Default, Clone)] diff --git a/crates/net/p2p/src/test_utils/headers.rs b/crates/net/p2p/src/test_utils/headers.rs index 73dd04849d44f..b76274791e5b2 100644 --- a/crates/net/p2p/src/test_utils/headers.rs +++ b/crates/net/p2p/src/test_utils/headers.rs @@ -1,19 +1,5 @@ //! Testing support for headers related interfaces. -use crate::{ - download::DownloadClient, - error::{DownloadError, DownloadResult, PeerRequestResult, RequestError}, - headers::{ - client::{HeadersClient, HeadersRequest}, - downloader::{HeaderDownloader, SyncTarget}, - error::HeadersDownloaderResult, - }, - priority::Priority, -}; -use futures::{Future, FutureExt, Stream, StreamExt}; -use reth_consensus::{test_utils::TestConsensus, Consensus}; -use reth_network_peers::{PeerId, WithPeerId}; -use reth_primitives::{Header, HeadersDirection, SealedHeader}; use std::{ fmt, pin::Pin, @@ -23,8 +9,24 @@ use std::{ }, task::{ready, Context, Poll}, }; + +use futures::{Future, FutureExt, Stream, StreamExt}; +use reth_consensus::{test_utils::TestConsensus, Consensus}; +use reth_network_peers::{PeerId, WithPeerId}; +use reth_primitives::{Header, HeadersDirection, SealedHeader}; use tokio::sync::Mutex; +use crate::{ + download::DownloadClient, + error::{DownloadError, DownloadResult, PeerRequestResult, RequestError}, + headers::{ + client::{HeadersClient, HeadersRequest}, + downloader::{HeaderDownloader, SyncTarget}, + error::HeadersDownloaderResult, + }, + priority::Priority, +}; + /// A test downloader which just returns the values that have been pushed to it. #[derive(Debug)] pub struct TestHeaderDownloader { diff --git a/crates/net/peers/src/lib.rs b/crates/net/peers/src/lib.rs index f531f1eb8f090..2339c8c92f961 100644 --- a/crates/net/peers/src/lib.rs +++ b/crates/net/peers/src/lib.rs @@ -48,9 +48,9 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -use alloy_primitives::B512; use std::str::FromStr; +use alloy_primitives::B512; // Re-export PeerId for ease of use. pub use enr::Enr; diff --git a/crates/net/peers/src/node_record.rs b/crates/net/peers/src/node_record.rs index 3b6c38170d56b..eb072ddc406af 100644 --- a/crates/net/peers/src/node_record.rs +++ b/crates/net/peers/src/node_record.rs @@ -8,12 +8,12 @@ use std::{ str::FromStr, }; -use crate::PeerId; use alloy_rlp::{RlpDecodable, RlpEncodable}; -use serde_with::{DeserializeFromStr, SerializeDisplay}; - #[cfg(feature = "secp256k1")] use enr::Enr; +use serde_with::{DeserializeFromStr, SerializeDisplay}; + +use crate::PeerId; /// Represents a ENR in discovery. /// @@ -211,9 +211,10 @@ impl TryFrom<&Enr> for NodeRecord { #[cfg(test)] mod tests { + use std::net::Ipv6Addr; + use alloy_rlp::Decodable; use rand::{thread_rng, Rng, RngCore}; - use std::net::Ipv6Addr; use super::*; diff --git a/crates/net/peers/src/trusted_peer.rs b/crates/net/peers/src/trusted_peer.rs index 27096bcab3d83..3c3b15ed9c370 100644 --- a/crates/net/peers/src/trusted_peer.rs +++ b/crates/net/peers/src/trusted_peer.rs @@ -1,7 +1,5 @@ //! `NodeRecord` type that uses a domain instead of an IP. -use crate::{NodeRecord, PeerId}; -use serde_with::{DeserializeFromStr, SerializeDisplay}; use std::{ fmt::{self, Write}, io::Error, @@ -9,8 +7,12 @@ use std::{ num::ParseIntError, str::FromStr, }; + +use serde_with::{DeserializeFromStr, SerializeDisplay}; use url::Host; +use crate::{NodeRecord, PeerId}; + /// Represents the node record of a trusted peer. The only difference between this and a /// [`NodeRecord`] is that this does not contain the IP address of the peer, but rather a domain /// __or__ IP address. @@ -162,9 +164,10 @@ impl From for TrustedPeer { #[cfg(test)] mod tests { - use super::*; use std::net::Ipv6Addr; + use super::*; + #[test] fn test_url_parse() { let url = "enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@10.3.58.6:30303?discport=30301"; diff --git a/crates/node-core/build.rs b/crates/node-core/build.rs index 043505cdfb671..bb3af9d4aeca9 100644 --- a/crates/node-core/build.rs +++ b/crates/node-core/build.rs @@ -1,6 +1,7 @@ #![allow(missing_docs)] use std::{env, error::Error}; + use vergen::EmitBuilder; fn main() -> Result<(), Box> { diff --git a/crates/node-core/src/args/benchmark_args.rs b/crates/node-core/src/args/benchmark_args.rs index 1ff49c9c84d1c..9bf8f1844a8ac 100644 --- a/crates/node-core/src/args/benchmark_args.rs +++ b/crates/node-core/src/args/benchmark_args.rs @@ -1,8 +1,9 @@ //! clap [Args](clap::Args) for benchmark configuration -use clap::Args; use std::path::PathBuf; +use clap::Args; + /// Parameters for benchmark configuration #[derive(Debug, Args, PartialEq, Eq, Default, Clone)] #[command(next_help_heading = "Benchmark")] @@ -40,9 +41,10 @@ pub struct BenchmarkArgs { #[cfg(test)] mod tests { - use super::*; use clap::Parser; + use super::*; + /// A helper type to parse Args more easily #[derive(Parser)] struct CommandParser { diff --git a/crates/node-core/src/args/database.rs b/crates/node-core/src/args/database.rs index 09e9de82f52da..b7745e779b512 100644 --- a/crates/node-core/src/args/database.rs +++ b/crates/node-core/src/args/database.rs @@ -1,6 +1,5 @@ //! clap [Args](clap::Args) for database configuration -use crate::version::default_client_version; use clap::{ builder::{PossibleValue, TypedValueParser}, error::ErrorKind, @@ -8,6 +7,8 @@ use clap::{ }; use reth_storage_errors::db::LogLevel; +use crate::version::default_client_version; + /// Parameters for database configuration #[derive(Debug, Args, PartialEq, Eq, Default, Clone, Copy)] #[command(next_help_heading = "Database")] @@ -70,9 +71,10 @@ impl TypedValueParser for LogLevelValueParser { } #[cfg(test)] mod tests { - use super::*; use clap::Parser; + use super::*; + /// A helper type to parse Args more easily #[derive(Parser)] struct CommandParser { diff --git a/crates/node-core/src/args/datadir_args.rs b/crates/node-core/src/args/datadir_args.rs index 85adc49a4aed1..cbb288b8afcf5 100644 --- a/crates/node-core/src/args/datadir_args.rs +++ b/crates/node-core/src/args/datadir_args.rs @@ -1,9 +1,11 @@ //! clap [Args](clap::Args) for datadir config -use crate::dirs::{ChainPath, DataDirPath, MaybePlatformPath}; +use std::path::PathBuf; + use clap::Args; use reth_chainspec::Chain; -use std::path::PathBuf; + +use crate::dirs::{ChainPath, DataDirPath, MaybePlatformPath}; /// Parameters for datadir configuration #[derive(Debug, Args, PartialEq, Eq, Default, Clone)] @@ -34,9 +36,10 @@ impl DatadirArgs { #[cfg(test)] mod tests { - use super::*; use clap::Parser; + use super::*; + /// A helper type to parse Args more easily #[derive(Parser)] struct CommandParser { diff --git a/crates/node-core/src/args/debug.rs b/crates/node-core/src/args/debug.rs index 432bacf7d6831..9e643e305ce9b 100644 --- a/crates/node-core/src/args/debug.rs +++ b/crates/node-core/src/args/debug.rs @@ -1,8 +1,9 @@ //! clap [Args](clap::Args) for debugging purposes +use std::path::PathBuf; + use clap::Args; use reth_primitives::B256; -use std::path::PathBuf; /// Parameters for debugging purposes #[derive(Debug, Clone, Args, PartialEq, Eq, Default)] @@ -59,9 +60,10 @@ pub struct DebugArgs { #[cfg(test)] mod tests { - use super::*; use clap::Parser; + use super::*; + /// A helper type to parse Args more easily #[derive(Parser)] struct CommandParser { diff --git a/crates/node-core/src/args/dev.rs b/crates/node-core/src/args/dev.rs index b6a017452572f..3c778ba25949c 100644 --- a/crates/node-core/src/args/dev.rs +++ b/crates/node-core/src/args/dev.rs @@ -43,9 +43,10 @@ pub struct DevArgs { #[cfg(test)] mod tests { - use super::*; use clap::Parser; + use super::*; + /// A helper type to parse Args more easily #[derive(Parser)] struct CommandParser { diff --git a/crates/node-core/src/args/gas_price_oracle.rs b/crates/node-core/src/args/gas_price_oracle.rs index 5148fdca34b25..b48a9f602b815 100644 --- a/crates/node-core/src/args/gas_price_oracle.rs +++ b/crates/node-core/src/args/gas_price_oracle.rs @@ -1,4 +1,3 @@ -use crate::primitives::U256; use clap::Args; use reth_rpc::eth::gas_oracle::GasPriceOracleConfig; use reth_rpc_server_types::constants::gas_oracle::{ @@ -6,6 +5,8 @@ use reth_rpc_server_types::constants::gas_oracle::{ DEFAULT_MAX_GAS_PRICE, }; +use crate::primitives::U256; + /// Parameters to configure Gas Price Oracle #[derive(Debug, Clone, Copy, Args, PartialEq, Eq)] #[command(next_help_heading = "Gas Price Oracle")] @@ -54,8 +55,9 @@ impl Default for GasPriceOracleArgs { #[cfg(test)] mod tests { - use super::*; use clap::Parser; + + use super::*; /// A helper type to parse Args more easily #[derive(Parser)] struct CommandParser { diff --git a/crates/node-core/src/args/log.rs b/crates/node-core/src/args/log.rs index aa2e0cf5f1a38..39f9fee459746 100644 --- a/crates/node-core/src/args/log.rs +++ b/crates/node-core/src/args/log.rs @@ -1,13 +1,15 @@ //! clap [Args](clap::Args) for logging configuration. -use crate::dirs::{LogsDir, PlatformPath}; +use std::{fmt, fmt::Display}; + use clap::{ArgAction, Args, ValueEnum}; use reth_tracing::{ tracing_subscriber::filter::Directive, FileInfo, FileWorkerGuard, LayerInfo, LogFormat, RethTracer, Tracer, }; -use std::{fmt, fmt::Display}; use tracing::{level_filters::LevelFilter, Level}; + +use crate::dirs::{LogsDir, PlatformPath}; /// Constant to convert megabytes to bytes const MB_TO_BYTES: u64 = 1024 * 1024; diff --git a/crates/node-core/src/args/network.rs b/crates/node-core/src/args/network.rs index a5763495cd8dd..d9a2fc106dbe6 100644 --- a/crates/node-core/src/args/network.rs +++ b/crates/node-core/src/args/network.rs @@ -1,6 +1,12 @@ //! clap [Args](clap::Args) for network related arguments. -use crate::version::P2P_CLIENT_VERSION; +use std::{ + net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}, + ops::Not, + path::PathBuf, + sync::Arc, +}; + use clap::Args; use reth_chainspec::{net::mainnet_nodes, ChainSpec}; use reth_config::Config; @@ -20,12 +26,8 @@ use reth_network::{ }; use reth_network_peers::TrustedPeer; use secp256k1::SecretKey; -use std::{ - net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}, - ops::Not, - path::PathBuf, - sync::Arc, -}; + +use crate::version::P2P_CLIENT_VERSION; /// Parameters for configuring the network more granularity via CLI #[derive(Debug, Clone, Args, PartialEq, Eq)] @@ -356,8 +358,9 @@ impl Default for DiscoveryArgs { #[cfg(test)] mod tests { - use super::*; use clap::Parser; + + use super::*; /// A helper type to parse Args more easily #[derive(Parser)] struct CommandParser { diff --git a/crates/node-core/src/args/payload_builder.rs b/crates/node-core/src/args/payload_builder.rs index b6a937156de53..c687b04e19e35 100644 --- a/crates/node-core/src/args/payload_builder.rs +++ b/crates/node-core/src/args/payload_builder.rs @@ -1,7 +1,5 @@ -use crate::{ - args::utils::parse_duration_from_secs, cli::config::PayloadBuilderConfig, - version::default_extradata, -}; +use std::{borrow::Cow, ffi::OsStr, time::Duration}; + use clap::{ builder::{RangedU64ValueParser, TypedValueParser}, Arg, Args, Command, @@ -9,7 +7,11 @@ use clap::{ use reth_primitives::constants::{ ETHEREUM_BLOCK_GAS_LIMIT, MAXIMUM_EXTRA_DATA_SIZE, SLOT_DURATION, }; -use std::{borrow::Cow, ffi::OsStr, time::Duration}; + +use crate::{ + args::utils::parse_duration_from_secs, cli::config::PayloadBuilderConfig, + version::default_extradata, +}; /// Parameters for configuring the Payload Builder #[derive(Debug, Clone, Args, PartialEq, Eq)] @@ -99,9 +101,10 @@ impl TypedValueParser for ExtradataValueParser { #[cfg(test)] mod tests { - use super::*; use clap::Parser; + use super::*; + /// A helper type to parse Args more easily #[derive(Parser)] struct CommandParser { diff --git a/crates/node-core/src/args/pruning.rs b/crates/node-core/src/args/pruning.rs index 1621f2d8ed8b8..c4e51da75de60 100644 --- a/crates/node-core/src/args/pruning.rs +++ b/crates/node-core/src/args/pruning.rs @@ -47,9 +47,10 @@ impl PruningArgs { #[cfg(test)] mod tests { - use super::*; use clap::Parser; + use super::*; + /// A helper type to parse Args more easily #[derive(Parser)] struct CommandParser { diff --git a/crates/node-core/src/args/rpc_server.rs b/crates/node-core/src/args/rpc_server.rs index 7ab2dd268fa10..9fc3b63905d02 100644 --- a/crates/node-core/src/args/rpc_server.rs +++ b/crates/node-core/src/args/rpc_server.rs @@ -1,9 +1,11 @@ //! clap [Args](clap::Args) for RPC related arguments. -use crate::args::{ - types::{MaxU32, ZeroAsNoneU64}, - GasPriceOracleArgs, RpcStateCacheArgs, +use std::{ + ffi::OsStr, + net::{IpAddr, Ipv4Addr}, + path::PathBuf, }; + use alloy_rpc_types_engine::JwtSecret; use clap::{ builder::{PossibleValue, RangedU64ValueParser, TypedValueParser}, @@ -11,12 +13,11 @@ use clap::{ }; use rand::Rng; use reth_rpc::eth::RPC_DEFAULT_GAS_CAP; - use reth_rpc_server_types::{constants, RethRpcModule, RpcModuleSelection}; -use std::{ - ffi::OsStr, - net::{IpAddr, Ipv4Addr}, - path::PathBuf, + +use crate::args::{ + types::{MaxU32, ZeroAsNoneU64}, + GasPriceOracleArgs, RpcStateCacheArgs, }; /// Default max number of subscriptions per connection. @@ -326,9 +327,10 @@ impl TypedValueParser for RpcModuleSelectionValueParser { #[cfg(test)] mod tests { - use super::*; use clap::{Args, Parser}; + use super::*; + /// A helper type to parse Args more easily #[derive(Parser)] struct CommandParser { diff --git a/crates/node-core/src/args/secret_key.rs b/crates/node-core/src/args/secret_key.rs index a8b401bbb1cc0..0f4a36f946b75 100644 --- a/crates/node-core/src/args/secret_key.rs +++ b/crates/node-core/src/args/secret_key.rs @@ -1,11 +1,12 @@ -use reth_fs_util::{self as fs, FsPathError}; -use reth_network::config::rng_secret_key; -use reth_primitives::hex::encode as hex_encode; -use secp256k1::{Error as SecretKeyBaseError, SecretKey}; use std::{ io, path::{Path, PathBuf}, }; + +use reth_fs_util::{self as fs, FsPathError}; +use reth_network::config::rng_secret_key; +use reth_primitives::hex::encode as hex_encode; +use secp256k1::{Error as SecretKeyBaseError, SecretKey}; use thiserror::Error; /// Errors returned by loading a [`SecretKey`], including IO errors. diff --git a/crates/node-core/src/args/txpool.rs b/crates/node-core/src/args/txpool.rs index 12fc6bd79c0f7..fc9acc2f87b67 100644 --- a/crates/node-core/src/args/txpool.rs +++ b/crates/node-core/src/args/txpool.rs @@ -1,6 +1,5 @@ //! Transaction pool arguments -use crate::cli::config::RethTransactionPoolConfig; use clap::Args; use reth_primitives::Address; use reth_transaction_pool::{ @@ -9,6 +8,8 @@ use reth_transaction_pool::{ REPLACE_BLOB_PRICE_BUMP, TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER, TXPOOL_SUBPOOL_MAX_SIZE_MB_DEFAULT, TXPOOL_SUBPOOL_MAX_TXS_DEFAULT, }; + +use crate::cli::config::RethTransactionPoolConfig; /// Parameters for debugging purposes #[derive(Debug, Clone, Args, PartialEq, Eq)] #[command(next_help_heading = "TxPool")] @@ -122,9 +123,10 @@ impl RethTransactionPoolConfig for TxPoolArgs { #[cfg(test)] mod tests { - use super::*; use clap::Parser; + use super::*; + /// A helper type to parse Args more easily #[derive(Parser)] struct CommandParser { diff --git a/crates/node-core/src/args/utils.rs b/crates/node-core/src/args/utils.rs index 8a54a8942e1c6..cf59e79175a08 100644 --- a/crates/node-core/src/args/utils.rs +++ b/crates/node-core/src/args/utils.rs @@ -1,9 +1,5 @@ //! Clap parser utilities -use alloy_genesis::Genesis; -use reth_chainspec::ChainSpec; -use reth_fs_util as fs; -use reth_primitives::{BlockHashOrNumber, B256}; use std::{ net::{IpAddr, Ipv4Addr, SocketAddr, ToSocketAddrs}, path::PathBuf, @@ -12,13 +8,14 @@ use std::{ time::Duration, }; -use reth_chainspec::DEV; - +use alloy_genesis::Genesis; +use reth_chainspec::{ChainSpec, DEV}; #[cfg(feature = "optimism")] use reth_chainspec::{BASE_MAINNET, BASE_SEPOLIA, OP_MAINNET, OP_SEPOLIA}; - #[cfg(not(feature = "optimism"))] use reth_chainspec::{GOERLI, HOLESKY, MAINNET, SEPOLIA}; +use reth_fs_util as fs; +use reth_primitives::{BlockHashOrNumber, B256}; #[cfg(feature = "optimism")] /// Chains supported by op-reth. First value should be used as the default. @@ -138,10 +135,11 @@ pub fn parse_socket_address(value: &str) -> eyre::Result String { chain.to_string() @@ -92,9 +94,10 @@ pub trait XdgPath { /// # Example /// /// ``` -/// use reth_node_core::dirs::{DataDirPath, PlatformPath}; /// use std::str::FromStr; /// +/// use reth_node_core::dirs::{DataDirPath, PlatformPath}; +/// /// // Resolves to the platform-specific database path /// let default: PlatformPath = PlatformPath::default(); /// // Resolves to `$(pwd)/my/path/to/datadir` diff --git a/crates/node-core/src/exit.rs b/crates/node-core/src/exit.rs index 7957af1854fc7..66a8980c7efe3 100644 --- a/crates/node-core/src/exit.rs +++ b/crates/node-core/src/exit.rs @@ -1,12 +1,13 @@ //! Helper types for waiting for the node to exit. -use futures::FutureExt; -use reth_beacon_consensus::BeaconConsensusEngineError; use std::{ future::Future, pin::Pin, task::{ready, Context, Poll}, }; + +use futures::FutureExt; +use reth_beacon_consensus::BeaconConsensusEngineError; use tokio::sync::oneshot; /// A Future which resolves when the node exits @@ -56,9 +57,10 @@ impl Future for NodeExitFuture { #[cfg(test)] mod tests { - use super::*; use std::future::poll_fn; + use super::*; + #[tokio::test] async fn test_node_exit_future_terminate_true() { let (tx, rx) = oneshot::channel::>(); diff --git a/crates/node-core/src/metrics/prometheus_exporter.rs b/crates/node-core/src/metrics/prometheus_exporter.rs index b7a3ba7015c30..79f3c8e899925 100644 --- a/crates/node-core/src/metrics/prometheus_exporter.rs +++ b/crates/node-core/src/metrics/prometheus_exporter.rs @@ -1,6 +1,7 @@ //! Prometheus exporter -use crate::metrics::version_metrics::register_version_metrics; +use std::{convert::Infallible, net::SocketAddr, sync::Arc}; + use eyre::WrapErr; use futures::{future::FusedFuture, FutureExt}; use http::Response; @@ -11,7 +12,8 @@ use reth_db_api::database_metrics::DatabaseMetrics; use reth_metrics::metrics::Unit; use reth_provider::providers::StaticFileProvider; use reth_tasks::TaskExecutor; -use std::{convert::Infallible, net::SocketAddr, sync::Arc}; + +use crate::metrics::version_metrics::register_version_metrics; pub(crate) trait Hook: Fn() + Send + Sync {} impl Hook for T {} diff --git a/crates/node-core/src/metrics/version_metrics.rs b/crates/node-core/src/metrics/version_metrics.rs index f0b11c3b7e8b6..157d79335b4ec 100644 --- a/crates/node-core/src/metrics/version_metrics.rs +++ b/crates/node-core/src/metrics/version_metrics.rs @@ -1,8 +1,9 @@ //! This exposes reth's version information over prometheus. -use crate::version::build_profile_name; use metrics::gauge; +use crate::version::build_profile_name; + const LABELS: [(&str, &str); 6] = [ ("version", env!("CARGO_PKG_VERSION")), ("build_timestamp", env!("VERGEN_BUILD_TIMESTAMP")), diff --git a/crates/node-core/src/node_config.rs b/crates/node-core/src/node_config.rs index 932c12e704363..db2f41e98fef1 100644 --- a/crates/node-core/src/node_config.rs +++ b/crates/node-core/src/node_config.rs @@ -1,14 +1,7 @@ //! Support for customizing the node -use crate::{ - args::{ - DatabaseArgs, DatadirArgs, DebugArgs, DevArgs, NetworkArgs, PayloadBuilderArgs, - PruningArgs, RpcServerArgs, TxPoolArgs, - }, - dirs::{ChainPath, DataDirPath}, - metrics::prometheus_exporter, - utils::get_single_header, -}; +use std::{net::SocketAddr, path::PathBuf, sync::Arc}; + use metrics_exporter_prometheus::PrometheusHandle; use once_cell::sync::Lazy; use reth_chainspec::{ChainSpec, MAINNET}; @@ -25,9 +18,18 @@ use reth_provider::{ use reth_stages_types::StageId; use reth_storage_errors::provider::ProviderResult; use reth_tasks::TaskExecutor; -use std::{net::SocketAddr, path::PathBuf, sync::Arc}; use tracing::*; +use crate::{ + args::{ + DatabaseArgs, DatadirArgs, DebugArgs, DevArgs, NetworkArgs, PayloadBuilderArgs, + PruningArgs, RpcServerArgs, TxPoolArgs, + }, + dirs::{ChainPath, DataDirPath}, + metrics::prometheus_exporter, + utils::get_single_header, +}; + /// The default prometheus recorder handle. We use a global static to ensure that it is only /// installed once. pub static PROMETHEUS_RECORDER_HANDLE: Lazy = diff --git a/crates/node-core/src/utils.rs b/crates/node-core/src/utils.rs index 8393b50bef0a9..cb410728b038f 100644 --- a/crates/node-core/src/utils.rs +++ b/crates/node-core/src/utils.rs @@ -1,6 +1,12 @@ //! Utility functions for node startup and shutdown, for example path parsing and retrieving single //! blocks from the network. +use std::{ + env::VarError, + path::{Path, PathBuf}, + sync::Arc, +}; + use eyre::Result; use reth_chainspec::ChainSpec; use reth_consensus_common::validation::validate_block_pre_execution; @@ -14,11 +20,6 @@ use reth_network_p2p::{ use reth_primitives::{BlockHashOrNumber, HeadersDirection, SealedBlock, SealedHeader}; use reth_provider::BlockReader; use reth_rpc_types::engine::{JwtError, JwtSecret}; -use std::{ - env::VarError, - path::{Path, PathBuf}, - sync::Arc, -}; use tracing::{debug, info, trace, warn}; /// Parses a user-specified path with support for environment variables and common shorthands (e.g. diff --git a/crates/node/api/src/lib.rs b/crates/node/api/src/lib.rs index b01a2def0bdee..ee295df932c1f 100644 --- a/crates/node/api/src/lib.rs +++ b/crates/node/api/src/lib.rs @@ -11,18 +11,15 @@ /// Traits, validation methods, and helper types used to abstract over engine types. pub use reth_engine_primitives as engine; pub use reth_engine_primitives::*; - +/// Traits and helper types used to abstract over EVM methods and types. +pub use reth_evm::{ConfigureEvm, ConfigureEvmEnv}; /// Traits and helper types used to abstract over payload types. pub use reth_payload_primitives as payload; pub use reth_payload_primitives::*; -/// Traits and helper types used to abstract over EVM methods and types. -pub use reth_evm::{ConfigureEvm, ConfigureEvmEnv}; - pub mod primitives; pub mod node; pub use node::*; - // re-export for convenience pub use reth_provider::FullProvider; diff --git a/crates/node/api/src/node.rs b/crates/node/api/src/node.rs index 15345c49b6c09..62c477337442b 100644 --- a/crates/node/api/src/node.rs +++ b/crates/node/api/src/node.rs @@ -1,6 +1,7 @@ //! Traits for configuring a node. -use crate::{primitives::NodePrimitives, ConfigureEvm, EngineTypes}; +use std::marker::PhantomData; + use reth_db_api::{ database::Database, database_metrics::{DatabaseMetadata, DatabaseMetrics}, @@ -11,7 +12,8 @@ use reth_payload_builder::PayloadBuilderHandle; use reth_provider::FullProvider; use reth_tasks::TaskExecutor; use reth_transaction_pool::TransactionPool; -use std::marker::PhantomData; + +use crate::{primitives::NodePrimitives, ConfigureEvm, EngineTypes}; /// The type that configures the essential types of an ethereum like node. /// diff --git a/crates/node/builder/src/builder/mod.rs b/crates/node/builder/src/builder/mod.rs index f23fc873e8859..68b0b3458a7dc 100644 --- a/crates/node/builder/src/builder/mod.rs +++ b/crates/node/builder/src/builder/mod.rs @@ -2,13 +2,11 @@ #![allow(clippy::type_complexity, missing_debug_implementations)] -use crate::{ - common::WithConfigs, - components::NodeComponentsBuilder, - node::FullNode, - rpc::{RethRpcServerHandles, RpcContext}, - DefaultNodeLauncher, Node, NodeHandle, +use std::{ + net::{IpAddr, SocketAddr, SocketAddrV4, SocketAddrV6}, + sync::Arc, }; + use discv5::ListenConfig; use futures::Future; use reth_chainspec::ChainSpec; @@ -39,9 +37,13 @@ use reth_tasks::TaskExecutor; use reth_transaction_pool::{PoolConfig, TransactionPool}; use secp256k1::SecretKey; pub use states::*; -use std::{ - net::{IpAddr, SocketAddr, SocketAddrV4, SocketAddrV6}, - sync::Arc, + +use crate::{ + common::WithConfigs, + components::NodeComponentsBuilder, + node::FullNode, + rpc::{RethRpcServerHandles, RpcContext}, + DefaultNodeLauncher, Node, NodeHandle, }; mod states; diff --git a/crates/node/builder/src/builder/states.rs b/crates/node/builder/src/builder/states.rs index 8f09d5edd94ba..834248bff2a4a 100644 --- a/crates/node/builder/src/builder/states.rs +++ b/crates/node/builder/src/builder/states.rs @@ -5,6 +5,15 @@ //! The node builder process is essentially a state machine that transitions through various states //! before the node can be launched. +use std::{fmt, future::Future}; + +use reth_exex::ExExContext; +use reth_network::NetworkHandle; +use reth_node_api::{FullNodeComponents, FullNodeTypes, NodeTypes}; +use reth_node_core::node_config::NodeConfig; +use reth_payload_builder::PayloadBuilderHandle; +use reth_tasks::TaskExecutor; + use crate::{ components::{NodeComponents, NodeComponentsBuilder}, exex::BoxedLaunchExEx, @@ -13,13 +22,6 @@ use crate::{ rpc::{RethRpcServerHandles, RpcContext, RpcHooks}, FullNode, }; -use reth_exex::ExExContext; -use reth_network::NetworkHandle; -use reth_node_api::{FullNodeComponents, FullNodeTypes, NodeTypes}; -use reth_node_core::node_config::NodeConfig; -use reth_payload_builder::PayloadBuilderHandle; -use reth_tasks::TaskExecutor; -use std::{fmt, future::Future}; /// A node builder that also has the configured types. pub struct NodeBuilderWithTypes { diff --git a/crates/node/builder/src/components/builder.rs b/crates/node/builder/src/components/builder.rs index 72d2e6933da5a..650ab24abc13a 100644 --- a/crates/node/builder/src/components/builder.rs +++ b/crates/node/builder/src/components/builder.rs @@ -1,5 +1,11 @@ //! A generic [`NodeComponentsBuilder`] +use std::{future::Future, marker::PhantomData}; + +use reth_consensus::Consensus; +use reth_evm::execute::BlockExecutorProvider; +use reth_transaction_pool::TransactionPool; + use crate::{ components::{ Components, ConsensusBuilder, ExecutorBuilder, NetworkBuilder, NodeComponents, @@ -7,10 +13,6 @@ use crate::{ }, BuilderContext, ConfigureEvm, FullNodeTypes, }; -use reth_consensus::Consensus; -use reth_evm::execute::BlockExecutorProvider; -use reth_transaction_pool::TransactionPool; -use std::{future::Future, marker::PhantomData}; /// A generic, general purpose and customizable [`NodeComponentsBuilder`] implementation. /// diff --git a/crates/node/builder/src/components/consensus.rs b/crates/node/builder/src/components/consensus.rs index 6c90bda54752d..6a6735fb81125 100644 --- a/crates/node/builder/src/components/consensus.rs +++ b/crates/node/builder/src/components/consensus.rs @@ -1,7 +1,8 @@ //! Consensus component for the node builder. -use crate::{BuilderContext, FullNodeTypes}; use std::future::Future; +use crate::{BuilderContext, FullNodeTypes}; + /// A type that knows how to build the consensus implementation. pub trait ConsensusBuilder: Send { /// The consensus implementation to build. diff --git a/crates/node/builder/src/components/execute.rs b/crates/node/builder/src/components/execute.rs index 891f8e01feecb..a84d8516e4b35 100644 --- a/crates/node/builder/src/components/execute.rs +++ b/crates/node/builder/src/components/execute.rs @@ -1,8 +1,10 @@ //! EVM component for the node builder. -use crate::{BuilderContext, FullNodeTypes}; +use std::future::Future; + use reth_evm::execute::BlockExecutorProvider; use reth_node_api::ConfigureEvm; -use std::future::Future; + +use crate::{BuilderContext, FullNodeTypes}; /// A type that knows how to build the executor types. pub trait ExecutorBuilder: Send { diff --git a/crates/node/builder/src/components/mod.rs b/crates/node/builder/src/components/mod.rs index 0419f7a71c743..2055af5e5d7b2 100644 --- a/crates/node/builder/src/components/mod.rs +++ b/crates/node/builder/src/components/mod.rs @@ -7,7 +7,6 @@ //! //! Components depend on a fully type configured node: [FullNodeTypes](crate::node::FullNodeTypes). -use crate::{ConfigureEvm, FullNodeTypes}; pub use builder::*; pub use consensus::*; pub use execute::*; @@ -20,6 +19,8 @@ use reth_network::NetworkHandle; use reth_payload_builder::PayloadBuilderHandle; use reth_transaction_pool::TransactionPool; +use crate::{ConfigureEvm, FullNodeTypes}; + mod builder; mod consensus; mod execute; diff --git a/crates/node/builder/src/components/network.rs b/crates/node/builder/src/components/network.rs index f899162205818..5f473e408f690 100644 --- a/crates/node/builder/src/components/network.rs +++ b/crates/node/builder/src/components/network.rs @@ -1,9 +1,11 @@ //! Network component for the node builder. -use crate::{BuilderContext, FullNodeTypes}; +use std::future::Future; + use reth_network::NetworkHandle; use reth_transaction_pool::TransactionPool; -use std::future::Future; + +use crate::{BuilderContext, FullNodeTypes}; /// A type that knows how to build the network implementation. pub trait NetworkBuilder: Send { diff --git a/crates/node/builder/src/components/payload.rs b/crates/node/builder/src/components/payload.rs index b24026a2ccd45..55c7669efdb6e 100644 --- a/crates/node/builder/src/components/payload.rs +++ b/crates/node/builder/src/components/payload.rs @@ -1,9 +1,11 @@ //! Payload service component for the node builder. -use crate::{BuilderContext, FullNodeTypes}; +use std::future::Future; + use reth_payload_builder::PayloadBuilderHandle; use reth_transaction_pool::TransactionPool; -use std::future::Future; + +use crate::{BuilderContext, FullNodeTypes}; /// A type that knows how to spawn the payload service. pub trait PayloadServiceBuilder: Send { diff --git a/crates/node/builder/src/components/pool.rs b/crates/node/builder/src/components/pool.rs index 029079a99947c..21b38ce20f40d 100644 --- a/crates/node/builder/src/components/pool.rs +++ b/crates/node/builder/src/components/pool.rs @@ -1,8 +1,10 @@ //! Pool component for the node builder. -use crate::{BuilderContext, FullNodeTypes}; -use reth_transaction_pool::TransactionPool; use std::future::Future; +use reth_transaction_pool::TransactionPool; + +use crate::{BuilderContext, FullNodeTypes}; + /// A type that knows how to build the transaction pool. pub trait PoolBuilder: Send { /// The transaction pool to build. diff --git a/crates/node/builder/src/exex.rs b/crates/node/builder/src/exex.rs index abb82a3df59e8..13558ad98c437 100644 --- a/crates/node/builder/src/exex.rs +++ b/crates/node/builder/src/exex.rs @@ -1,8 +1,9 @@ //! Types for launching execution extensions (ExEx). +use std::future::Future; + use futures::{future::BoxFuture, FutureExt}; use reth_exex::ExExContext; use reth_node_api::FullNodeComponents; -use std::future::Future; /// A trait for launching an `ExEx`. pub trait LaunchExEx: Send { diff --git a/crates/node/builder/src/handle.rs b/crates/node/builder/src/handle.rs index cbdce0c8b59fb..71c87067be0b2 100644 --- a/crates/node/builder/src/handle.rs +++ b/crates/node/builder/src/handle.rs @@ -1,7 +1,9 @@ -use crate::node::FullNode; +use std::fmt; + use reth_node_api::FullNodeComponents; use reth_node_core::exit::NodeExitFuture; -use std::fmt; + +use crate::node::FullNode; /// A Handle to the launched node. #[must_use = "Needs to await the node exit future"] diff --git a/crates/node/builder/src/hooks.rs b/crates/node/builder/src/hooks.rs index 86c4b56c6d00b..e5ebafd3715ac 100644 --- a/crates/node/builder/src/hooks.rs +++ b/crates/node/builder/src/hooks.rs @@ -1,7 +1,9 @@ -use crate::node::FullNode; -use reth_node_api::FullNodeComponents; use std::fmt; +use reth_node_api::FullNodeComponents; + +use crate::node::FullNode; + /// Container for all the configurable hook functions. pub(crate) struct NodeHooks { pub(crate) on_component_initialized: Box>, diff --git a/crates/node/builder/src/launch/common.rs b/crates/node/builder/src/launch/common.rs index 1c48fd763041b..bfaf18221f1e8 100644 --- a/crates/node/builder/src/launch/common.rs +++ b/crates/node/builder/src/launch/common.rs @@ -1,10 +1,7 @@ //! Helper types that can be used by launchers. -use crate::{ - components::{NodeComponents, NodeComponentsBuilder}, - hooks::OnComponentInitializedHook, - BuilderContext, NodeAdapter, -}; +use std::{marker::PhantomData, sync::Arc, thread::available_parallelism}; + use backon::{ConstantBuilder, Retryable}; use eyre::Context; use rayon::ThreadPoolBuilder; @@ -39,12 +36,17 @@ use reth_stages::{sets::DefaultStages, MetricEvent, Pipeline, PipelineTarget}; use reth_static_file::StaticFileProducer; use reth_tasks::TaskExecutor; use reth_tracing::tracing::{debug, error, info, warn}; -use std::{marker::PhantomData, sync::Arc, thread::available_parallelism}; use tokio::sync::{ mpsc::{unbounded_channel, Receiver, UnboundedSender}, oneshot, watch, }; +use crate::{ + components::{NodeComponents, NodeComponentsBuilder}, + hooks::OnComponentInitializedHook, + BuilderContext, NodeAdapter, +}; + /// Reusable setup for launching a node. /// /// This provides commonly used boilerplate for launching a node. @@ -845,10 +847,11 @@ where #[cfg(test)] mod tests { - use super::{LaunchContext, NodeConfig}; use reth_config::Config; use reth_node_core::args::PruningArgs; + use super::{LaunchContext, NodeConfig}; + const EXTENSION: &str = "toml"; fn with_tempdir(filename: &str, proc: fn(&std::path::Path)) { diff --git a/crates/node/builder/src/launch/exex.rs b/crates/node/builder/src/launch/exex.rs index 103223357c7ce..e02a53a7a9fca 100644 --- a/crates/node/builder/src/launch/exex.rs +++ b/crates/node/builder/src/launch/exex.rs @@ -1,13 +1,15 @@ //! Support for launching execution extensions. -use crate::{common::WithConfigs, exex::BoxedLaunchExEx}; +use std::{fmt, fmt::Debug}; + use futures::future; use reth_exex::{ExExContext, ExExHandle, ExExManager, ExExManagerHandle}; use reth_node_api::FullNodeComponents; use reth_primitives::Head; use reth_provider::CanonStateSubscriptions; use reth_tracing::tracing::{debug, info}; -use std::{fmt, fmt::Debug}; + +use crate::{common::WithConfigs, exex::BoxedLaunchExEx}; /// Can launch execution extensions. pub struct ExExLauncher { diff --git a/crates/node/builder/src/launch/mod.rs b/crates/node/builder/src/launch/mod.rs index 532e87fecba55..aed682e1e36a5 100644 --- a/crates/node/builder/src/launch/mod.rs +++ b/crates/node/builder/src/launch/mod.rs @@ -1,12 +1,7 @@ //! Abstraction for launching a node. -use crate::{ - builder::{NodeAdapter, NodeAddOns, NodeTypesAdapter}, - components::{NodeComponents, NodeComponentsBuilder}, - hooks::NodeHooks, - node::FullNode, - NodeBuilderWithComponents, NodeHandle, -}; +use std::{future::Future, sync::Arc}; + use futures::{future::Either, stream, stream_select, StreamExt}; use reth_beacon_consensus::{ hooks::{EngineHooks, PruneHook, StaticFileHook}, @@ -30,10 +25,17 @@ use reth_rpc_types::engine::ClientVersionV1; use reth_tasks::TaskExecutor; use reth_tracing::tracing::{debug, info}; use reth_transaction_pool::TransactionPool; -use std::{future::Future, sync::Arc}; use tokio::sync::{mpsc::unbounded_channel, oneshot}; use tokio_stream::wrappers::UnboundedReceiverStream; +use crate::{ + builder::{NodeAdapter, NodeAddOns, NodeTypesAdapter}, + components::{NodeComponents, NodeComponentsBuilder}, + hooks::NodeHooks, + node::FullNode, + NodeBuilderWithComponents, NodeHandle, +}; + pub mod common; pub use common::LaunchContext; mod exex; diff --git a/crates/node/builder/src/lib.rs b/crates/node/builder/src/lib.rs index 6e85cef5d3893..c258a64750729 100644 --- a/crates/node/builder/src/lib.rs +++ b/crates/node/builder/src/lib.rs @@ -34,17 +34,13 @@ pub mod setup; /// Support for installing the ExExs (execution extensions) in a node. pub mod exex; +use aquamarine as _; +// re-export API types for convenience +pub use reth_node_api::*; /// Re-export the core configuration traits. pub use reth_node_core::cli::config::{ PayloadBuilderConfig, RethNetworkConfig, RethTransactionPoolConfig, }; - // re-export the core config for convenience pub use reth_node_core::node_config::NodeConfig; - -// re-export API types for convenience -pub use reth_node_api::*; - -use aquamarine as _; - use reth_rpc as _; diff --git a/crates/node/builder/src/node.rs b/crates/node/builder/src/node.rs index fe8d99ed60906..bfb97ba0c7a54 100644 --- a/crates/node/builder/src/node.rs +++ b/crates/node/builder/src/node.rs @@ -1,7 +1,9 @@ -use crate::rpc::{RethRpcServerHandles, RpcRegistry}; +use std::{marker::PhantomData, sync::Arc}; + use reth_chainspec::ChainSpec; use reth_network::NetworkHandle; use reth_node_api::FullNodeComponents; +pub use reth_node_api::{FullNodeTypes, NodeTypes}; use reth_node_core::{ dirs::{ChainPath, DataDirPath}, node_config::NodeConfig, @@ -11,11 +13,10 @@ use reth_payload_builder::PayloadBuilderHandle; use reth_provider::ChainSpecProvider; use reth_rpc_builder::{auth::AuthServerHandle, RpcServerHandle}; use reth_tasks::TaskExecutor; -use std::{marker::PhantomData, sync::Arc}; // re-export the node api types use crate::components::NodeComponentsBuilder; -pub use reth_node_api::{FullNodeTypes, NodeTypes}; +use crate::rpc::{RethRpcServerHandles, RpcRegistry}; /// A [`crate::Node`] is a [`NodeTypes`] that comes with preconfigured components. /// diff --git a/crates/node/builder/src/rpc.rs b/crates/node/builder/src/rpc.rs index 9a6ada8f916d0..4150f5f3eced6 100644 --- a/crates/node/builder/src/rpc.rs +++ b/crates/node/builder/src/rpc.rs @@ -1,5 +1,10 @@ //! Builder support for rpc components. +use std::{ + fmt, + ops::{Deref, DerefMut}, +}; + use futures::TryFutureExt; use reth_network::NetworkHandle; use reth_node_api::FullNodeComponents; @@ -13,10 +18,6 @@ use reth_rpc_builder::{ use reth_rpc_layer::JwtSecret; use reth_tasks::TaskExecutor; use reth_tracing::tracing::{debug, info}; -use std::{ - fmt, - ops::{Deref, DerefMut}, -}; /// Contains the handles to the spawned RPC servers. /// diff --git a/crates/node/builder/src/setup.rs b/crates/node/builder/src/setup.rs index cf4d090dcbe74..76009ba109767 100644 --- a/crates/node/builder/src/setup.rs +++ b/crates/node/builder/src/setup.rs @@ -1,5 +1,7 @@ //! Helpers for setting up parts of the node. +use std::sync::Arc; + use reth_config::{config::StageConfig, PruneConfig}; use reth_consensus::Consensus; use reth_db_api::database::Database; @@ -19,7 +21,6 @@ use reth_stages::{prelude::DefaultStages, stages::ExecutionStage, Pipeline, Stag use reth_static_file::StaticFileProducer; use reth_tasks::TaskExecutor; use reth_tracing::tracing::debug; -use std::sync::Arc; use tokio::sync::watch; /// Constructs a [Pipeline] that's wired to the network diff --git a/crates/node/events/src/cl.rs b/crates/node/events/src/cl.rs index 47f1de6683f04..9f3a1bbf1fcb3 100644 --- a/crates/node/events/src/cl.rs +++ b/crates/node/events/src/cl.rs @@ -1,13 +1,14 @@ //! Events related to Consensus Layer health. -use futures::Stream; -use reth_provider::CanonChainTracker; use std::{ fmt, pin::Pin, task::{ready, Context, Poll}, time::Duration, }; + +use futures::Stream; +use reth_provider::CanonChainTracker; use tokio::time::{Instant, Interval}; /// Interval of checking Consensus Layer client health. diff --git a/crates/node/events/src/node.rs b/crates/node/events/src/node.rs index 8a25c370037b9..4bd843c9887fc 100644 --- a/crates/node/events/src/node.rs +++ b/crates/node/events/src/node.rs @@ -1,6 +1,13 @@ //! Support for handling events emitted by node components. -use crate::cl::ConsensusLayerHealthEvent; +use std::{ + fmt::{Display, Formatter}, + future::Future, + pin::Pin, + task::{Context, Poll}, + time::{Duration, Instant, SystemTime, UNIX_EPOCH}, +}; + use alloy_rpc_types_engine::ForkchoiceState; use futures::Stream; use reth_beacon_consensus::{ @@ -13,16 +20,11 @@ use reth_primitives::{constants, BlockNumber, B256}; use reth_prune::PrunerEvent; use reth_stages::{EntitiesCheckpoint, ExecOutput, PipelineEvent, StageCheckpoint, StageId}; use reth_static_file::StaticFileProducerEvent; -use std::{ - fmt::{Display, Formatter}, - future::Future, - pin::Pin, - task::{Context, Poll}, - time::{Duration, Instant, SystemTime, UNIX_EPOCH}, -}; use tokio::time::Interval; use tracing::{debug, info, warn}; +use crate::cl::ConsensusLayerHealthEvent; + /// Interval of reporting node state. const INFO_MESSAGE_INTERVAL: Duration = Duration::from_secs(25); diff --git a/crates/optimism/consensus/src/lib.rs b/crates/optimism/consensus/src/lib.rs index 0c5439bf74485..6278acc133727 100644 --- a/crates/optimism/consensus/src/lib.rs +++ b/crates/optimism/consensus/src/lib.rs @@ -9,6 +9,8 @@ // The `optimism` feature must be enabled to use this crate. #![cfg(feature = "optimism")] +use std::{sync::Arc, time::SystemTime}; + use reth_chainspec::ChainSpec; use reth_consensus::{Consensus, ConsensusError, PostExecutionInput}; use reth_consensus_common::validation::{ @@ -20,7 +22,6 @@ use reth_consensus_common::validation::{ use reth_primitives::{ BlockWithSenders, Header, SealedBlock, SealedHeader, EMPTY_OMMER_ROOT_HASH, U256, }; -use std::{sync::Arc, time::SystemTime}; mod validation; pub use validation::validate_block_post_execution; diff --git a/crates/optimism/evm/src/execute.rs b/crates/optimism/evm/src/execute.rs index 12edb225fe437..ae2ed2dd6f9e5 100644 --- a/crates/optimism/evm/src/execute.rs +++ b/crates/optimism/evm/src/execute.rs @@ -1,6 +1,7 @@ //! Optimism block executor. -use crate::{l1::ensure_create2_deployer, OptimismBlockExecutionError, OptimismEvmConfig}; +use std::sync::Arc; + use reth_chainspec::{ChainSpec, Hardfork}; use reth_evm::{ execute::{ @@ -25,9 +26,10 @@ use revm_primitives::{ db::{Database, DatabaseCommit}, BlockEnv, CfgEnvWithHandlerCfg, EVMError, EnvWithHandlerCfg, ResultAndState, }; -use std::sync::Arc; use tracing::trace; +use crate::{l1::ensure_create2_deployer, OptimismBlockExecutionError, OptimismEvmConfig}; + /// Provides executors to execute regular ethereum blocks #[derive(Debug, Clone)] pub struct OpExecutorProvider { @@ -452,7 +454,8 @@ where #[cfg(test)] mod tests { - use super::*; + use std::{collections::HashMap, str::FromStr}; + use reth_chainspec::ChainSpecBuilder; use reth_primitives::{ b256, Account, Address, Block, Signature, StorageKey, StorageValue, Transaction, @@ -461,7 +464,8 @@ mod tests { use reth_revm::{ database::StateProviderDatabase, test_utils::StateProviderTest, L1_BLOCK_CONTRACT, }; - use std::{collections::HashMap, str::FromStr}; + + use super::*; fn create_op_state_provider() -> StateProviderTest { let mut db = StateProviderTest::default(); diff --git a/crates/optimism/evm/src/l1.rs b/crates/optimism/evm/src/l1.rs index a750c8f4f0a92..bdc32cd609ca4 100644 --- a/crates/optimism/evm/src/l1.rs +++ b/crates/optimism/evm/src/l1.rs @@ -1,6 +1,7 @@ //! Optimism-specific implementation and utilities for the executor -use crate::OptimismBlockExecutionError; +use std::sync::Arc; + use reth_chainspec::{ChainSpec, Hardfork}; use reth_execution_errors::BlockExecutionError; use reth_primitives::{address, b256, hex, Address, Block, Bytes, B256, U256}; @@ -8,9 +9,10 @@ use revm::{ primitives::{Bytecode, HashMap, SpecId}, DatabaseCommit, L1BlockInfo, }; -use std::sync::Arc; use tracing::trace; +use crate::OptimismBlockExecutionError; + /// The address of the create2 deployer const CREATE_2_DEPLOYER_ADDR: Address = address!("13b0D85CcB8bf860b6b79AF3029fCA081AE9beF2"); diff --git a/crates/optimism/evm/src/lib.rs b/crates/optimism/evm/src/lib.rs index d13168bfe0c6b..6ed137d1957c5 100644 --- a/crates/optimism/evm/src/lib.rs +++ b/crates/optimism/evm/src/lib.rs @@ -86,10 +86,11 @@ impl ConfigureEvm for OptimismEvmConfig { #[cfg(test)] mod tests { - use super::*; use reth_primitives::revm_primitives::{BlockEnv, CfgEnv}; use revm_primitives::SpecId; + use super::*; + #[test] #[ignore] fn test_fill_cfg_and_block_env() { diff --git a/crates/optimism/node/src/args.rs b/crates/optimism/node/src/args.rs index 8a3dddc810a43..ae976cac38d14 100644 --- a/crates/optimism/node/src/args.rs +++ b/crates/optimism/node/src/args.rs @@ -33,9 +33,10 @@ pub struct RollupArgs { #[cfg(test)] mod tests { - use super::*; use clap::{Args, Parser}; + use super::*; + /// A helper type to parse Args more easily #[derive(Parser)] struct CommandParser { diff --git a/crates/optimism/node/src/lib.rs b/crates/optimism/node/src/lib.rs index 68aebd0835fb0..53a360913b1d2 100644 --- a/crates/optimism/node/src/lib.rs +++ b/crates/optimism/node/src/lib.rs @@ -24,8 +24,7 @@ pub mod txpool; pub mod rpc; +pub use reth_evm_optimism::*; pub use reth_optimism_payload_builder::{ OptimismBuiltPayload, OptimismPayloadBuilder, OptimismPayloadBuilderAttributes, }; - -pub use reth_evm_optimism::*; diff --git a/crates/optimism/node/src/node.rs b/crates/optimism/node/src/node.rs index d8628dc6bf851..0a6562104242a 100644 --- a/crates/optimism/node/src/node.rs +++ b/crates/optimism/node/src/node.rs @@ -1,10 +1,7 @@ //! Optimism Node types config. -use crate::{ - args::RollupArgs, - txpool::{OpTransactionPool, OpTransactionValidator}, - OptimismEngineTypes, -}; +use std::sync::Arc; + use reth_basic_payload_builder::{BasicPayloadJobGenerator, BasicPayloadJobGeneratorConfig}; use reth_evm::ConfigureEvm; use reth_evm_optimism::{OpExecutorProvider, OptimismEvmConfig}; @@ -25,7 +22,12 @@ use reth_transaction_pool::{ blobstore::DiskFileBlobStore, CoinbaseTipOrdering, TransactionPool, TransactionValidationTaskExecutor, }; -use std::sync::Arc; + +use crate::{ + args::RollupArgs, + txpool::{OpTransactionPool, OpTransactionValidator}, + OptimismEngineTypes, +}; /// Type configuration for a regular Optimism node. #[derive(Debug, Default, Clone)] diff --git a/crates/optimism/node/src/rpc.rs b/crates/optimism/node/src/rpc.rs index 5ae1ba7b25387..97ea75771df07 100644 --- a/crates/optimism/node/src/rpc.rs +++ b/crates/optimism/node/src/rpc.rs @@ -1,5 +1,7 @@ //! Helpers for optimism specific RPC implementations. +use std::sync::{atomic::AtomicUsize, Arc}; + use jsonrpsee::types::ErrorObject; use reqwest::Client; use reth_rpc::eth::{ @@ -7,7 +9,6 @@ use reth_rpc::eth::{ traits::RawTransactionForwarder, }; use reth_rpc_types::ToRpcError; -use std::sync::{atomic::AtomicUsize, Arc}; /// Error type when interacting with the Sequencer #[derive(Debug, thiserror::Error)] diff --git a/crates/optimism/node/src/txpool.rs b/crates/optimism/node/src/txpool.rs index b29bc4bb03036..735615b3ae244 100644 --- a/crates/optimism/node/src/txpool.rs +++ b/crates/optimism/node/src/txpool.rs @@ -1,4 +1,9 @@ //! OP transaction pool types +use std::sync::{ + atomic::{AtomicU64, Ordering}, + Arc, +}; + use parking_lot::RwLock; use reth_chainspec::ChainSpec; use reth_evm_optimism::RethL1BlockInfo; @@ -10,10 +15,6 @@ use reth_transaction_pool::{ TransactionOrigin, TransactionValidationOutcome, TransactionValidationTaskExecutor, TransactionValidator, }; -use std::sync::{ - atomic::{AtomicU64, Ordering}, - Arc, -}; /// Type alias for default optimism transaction pool pub type OpTransactionPool = Pool< @@ -202,7 +203,6 @@ pub struct OpL1BlockInfo { #[cfg(test)] mod tests { - use crate::txpool::OpTransactionValidator; use reth_chainspec::MAINNET; use reth_primitives::{ Signature, Transaction, TransactionSigned, TransactionSignedEcRecovered, TxDeposit, TxKind, @@ -214,6 +214,8 @@ mod tests { EthPooledTransaction, TransactionOrigin, TransactionValidationOutcome, }; + use crate::txpool::OpTransactionValidator; + #[test] fn validate_optimism_transaction() { let client = MockEthProvider::default(); diff --git a/crates/optimism/node/tests/e2e/p2p.rs b/crates/optimism/node/tests/e2e/p2p.rs index e4993e8f3138c..8c9e8e157d25f 100644 --- a/crates/optimism/node/tests/e2e/p2p.rs +++ b/crates/optimism/node/tests/e2e/p2p.rs @@ -1,9 +1,11 @@ -use crate::utils::{advance_chain, setup}; +use std::sync::Arc; + use reth::blockchain_tree::error::BlockchainTreeError; use reth_rpc_types::engine::PayloadStatusEnum; -use std::sync::Arc; use tokio::sync::Mutex; +use crate::utils::{advance_chain, setup}; + #[tokio::test] async fn can_sync() -> eyre::Result<()> { reth_tracing::init_test_tracing(); diff --git a/crates/optimism/node/tests/e2e/utils.rs b/crates/optimism/node/tests/e2e/utils.rs index feacabfb2c29d..82986c09534c3 100644 --- a/crates/optimism/node/tests/e2e/utils.rs +++ b/crates/optimism/node/tests/e2e/utils.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use alloy_genesis::Genesis; use reth::{rpc::types::engine::PayloadAttributes, tasks::TaskManager}; use reth_chainspec::{ChainSpecBuilder, BASE_MAINNET}; @@ -5,7 +7,6 @@ use reth_e2e_test_utils::{transaction::TransactionTestContext, wallet::Wallet, N use reth_node_optimism::{OptimismBuiltPayload, OptimismNode, OptimismPayloadBuilderAttributes}; use reth_payload_builder::EthPayloadBuilderAttributes; use reth_primitives::{Address, B256}; -use std::sync::Arc; use tokio::sync::Mutex; /// Optimism Node Helper type diff --git a/crates/optimism/payload/src/builder.rs b/crates/optimism/payload/src/builder.rs index fa17982cb8c65..850be3d3a8609 100644 --- a/crates/optimism/payload/src/builder.rs +++ b/crates/optimism/payload/src/builder.rs @@ -1,9 +1,7 @@ //! Optimism payload builder implementation. -use crate::{ - error::OptimismPayloadBuilderError, - payload::{OptimismBuiltPayload, OptimismPayloadBuilderAttributes}, -}; +use std::sync::Arc; + use reth_basic_payload_builder::*; use reth_chainspec::ChainSpec; use reth_evm::ConfigureEvm; @@ -25,9 +23,13 @@ use revm::{ primitives::{EVMError, EnvWithHandlerCfg, InvalidTransaction, ResultAndState}, DatabaseCommit, State, }; -use std::sync::Arc; use tracing::{debug, trace, warn}; +use crate::{ + error::OptimismPayloadBuilderError, + payload::{OptimismBuiltPayload, OptimismPayloadBuilderAttributes}, +}; + /// Optimism's payload builder #[derive(Debug, Clone, PartialEq, Eq)] pub struct OptimismPayloadBuilder { diff --git a/crates/optimism/payload/src/payload.rs b/crates/optimism/payload/src/payload.rs index ae63246558dd8..0e4ed3145e4ad 100644 --- a/crates/optimism/payload/src/payload.rs +++ b/crates/optimism/payload/src/payload.rs @@ -2,6 +2,8 @@ //! Optimism builder support +use std::sync::Arc; + use alloy_rlp::Encodable; use reth_chainspec::ChainSpec; use reth_payload_builder::EthPayloadBuilderAttributes; @@ -12,6 +14,8 @@ use reth_primitives::{ Address, BlobTransactionSidecar, Header, SealedBlock, TransactionSigned, Withdrawals, B256, U256, }; +/// Re-export for use in downstream arguments. +pub use reth_rpc_types::engine::OptimismPayloadAttributes; use reth_rpc_types::engine::{ ExecutionPayloadEnvelopeV2, ExecutionPayloadV1, OptimismExecutionPayloadEnvelopeV3, OptimismExecutionPayloadEnvelopeV4, PayloadId, @@ -21,10 +25,6 @@ use reth_rpc_types_compat::engine::payload::{ convert_block_to_payload_field_v2, }; use revm::primitives::HandlerCfg; -use std::sync::Arc; - -/// Re-export for use in downstream arguments. -pub use reth_rpc_types::engine::OptimismPayloadAttributes; /// Optimism Payload Builder Attributes #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/crates/payload/basic/src/lib.rs b/crates/payload/basic/src/lib.rs index 26dc062934045..ebbb064146105 100644 --- a/crates/payload/basic/src/lib.rs +++ b/crates/payload/basic/src/lib.rs @@ -8,7 +8,16 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -use crate::metrics::PayloadBuilderMetrics; +use std::{ + fmt, + future::Future, + ops::Deref, + pin::Pin, + sync::{atomic::AtomicBool, Arc}, + task::{Context, Poll}, + time::{Duration, SystemTime, UNIX_EPOCH}, +}; + use futures_core::ready; use futures_util::FutureExt; use reth_chainspec::ChainSpec; @@ -34,21 +43,14 @@ use revm::{ primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg}, Database, DatabaseCommit, Evm, State, }; -use std::{ - fmt, - future::Future, - ops::Deref, - pin::Pin, - sync::{atomic::AtomicBool, Arc}, - task::{Context, Poll}, - time::{Duration, SystemTime, UNIX_EPOCH}, -}; use tokio::{ sync::{oneshot, Semaphore}, time::{Interval, Sleep}, }; use tracing::{debug, trace, warn}; +use crate::metrics::PayloadBuilderMetrics; + mod metrics; /// The [`PayloadJobGenerator`] that creates [`BasicPayloadJob`]s. diff --git a/crates/payload/builder/src/database.rs b/crates/payload/builder/src/database.rs index 340a8510a105a..99f38f6af4197 100644 --- a/crates/payload/builder/src/database.rs +++ b/crates/payload/builder/src/database.rs @@ -1,5 +1,10 @@ //! Database adapters for payload building. +use std::{ + cell::RefCell, + collections::{hash_map::Entry, HashMap}, +}; + use reth_primitives::{ revm_primitives::{ db::{Database, DatabaseRef}, @@ -7,10 +12,6 @@ use reth_primitives::{ }, U256, }; -use std::{ - cell::RefCell, - collections::{hash_map::Entry, HashMap}, -}; /// A container type that caches reads from an underlying [`DatabaseRef`]. /// diff --git a/crates/payload/builder/src/lib.rs b/crates/payload/builder/src/lib.rs index b3baf11991deb..fcc62d9aa1fd1 100644 --- a/crates/payload/builder/src/lib.rs +++ b/crates/payload/builder/src/lib.rs @@ -114,10 +114,9 @@ pub mod noop; pub mod test_utils; pub use events::Events; -pub use reth_rpc_types::engine::PayloadId; -pub use service::{PayloadBuilderHandle, PayloadBuilderService, PayloadStore}; -pub use traits::{KeepPayloadJobAlive, PayloadJob, PayloadJobGenerator}; - // re-export the Ethereum engine primitives for convenience #[doc(inline)] pub use reth_ethereum_engine_primitives::{EthBuiltPayload, EthPayloadBuilderAttributes}; +pub use reth_rpc_types::engine::PayloadId; +pub use service::{PayloadBuilderHandle, PayloadBuilderService, PayloadStore}; +pub use traits::{KeepPayloadJobAlive, PayloadJob, PayloadJobGenerator}; diff --git a/crates/payload/builder/src/noop.rs b/crates/payload/builder/src/noop.rs index 91ab90732166c..8b89596d3d63f 100644 --- a/crates/payload/builder/src/noop.rs +++ b/crates/payload/builder/src/noop.rs @@ -1,16 +1,18 @@ //! A payload builder service task that does nothing. -use crate::{service::PayloadServiceCommand, PayloadBuilderHandle}; -use futures_util::{ready, StreamExt}; -use reth_payload_primitives::{PayloadBuilderAttributes, PayloadTypes}; use std::{ future::Future, pin::Pin, task::{Context, Poll}, }; + +use futures_util::{ready, StreamExt}; +use reth_payload_primitives::{PayloadBuilderAttributes, PayloadTypes}; use tokio::sync::mpsc; use tokio_stream::wrappers::UnboundedReceiverStream; +use crate::{service::PayloadServiceCommand, PayloadBuilderHandle}; + /// A service task that does not build any payloads. #[derive(Debug)] pub struct NoopPayloadBuilderService { diff --git a/crates/payload/builder/src/service.rs b/crates/payload/builder/src/service.rs index 8946cd587506b..811d800700d89 100644 --- a/crates/payload/builder/src/service.rs +++ b/crates/payload/builder/src/service.rs @@ -3,23 +3,17 @@ //! The payload builder is responsible for building payloads. //! Once a new payload is created, it is continuously updated. -use crate::{ - error::PayloadBuilderError, - events::{Events, PayloadEvents}, - metrics::PayloadBuilderServiceMetrics, - traits::PayloadJobGenerator, - KeepPayloadJobAlive, PayloadJob, -}; -use futures_util::{future::FutureExt, Stream, StreamExt}; -use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes, PayloadTypes}; -use reth_provider::CanonStateNotification; -use reth_rpc_types::engine::PayloadId; use std::{ fmt, future::Future, pin::Pin, task::{Context, Poll}, }; + +use futures_util::{future::FutureExt, Stream, StreamExt}; +use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes, PayloadTypes}; +use reth_provider::CanonStateNotification; +use reth_rpc_types::engine::PayloadId; use tokio::sync::{ broadcast, mpsc, oneshot::{self, error::RecvError}, @@ -27,6 +21,14 @@ use tokio::sync::{ use tokio_stream::wrappers::UnboundedReceiverStream; use tracing::{debug, info, trace, warn}; +use crate::{ + error::PayloadBuilderError, + events::{Events, PayloadEvents}, + metrics::PayloadBuilderServiceMetrics, + traits::PayloadJobGenerator, + KeepPayloadJobAlive, PayloadJob, +}; + type PayloadFuture

= Pin> + Send + Sync>>; /// A communication channel to the [`PayloadBuilderService`] that can retrieve payloads. diff --git a/crates/payload/builder/src/test_utils.rs b/crates/payload/builder/src/test_utils.rs index 62f697ddd6cbc..54a034e9c12ec 100644 --- a/crates/payload/builder/src/test_utils.rs +++ b/crates/payload/builder/src/test_utils.rs @@ -1,19 +1,21 @@ //! Utils for testing purposes. -use crate::{ - error::PayloadBuilderError, traits::KeepPayloadJobAlive, EthBuiltPayload, - EthPayloadBuilderAttributes, PayloadBuilderHandle, PayloadBuilderService, PayloadJob, - PayloadJobGenerator, -}; -use reth_payload_primitives::PayloadTypes; -use reth_primitives::{Block, U256}; -use reth_provider::CanonStateNotification; use std::{ future::Future, pin::Pin, task::{Context, Poll}, }; +use reth_payload_primitives::PayloadTypes; +use reth_primitives::{Block, U256}; +use reth_provider::CanonStateNotification; + +use crate::{ + error::PayloadBuilderError, traits::KeepPayloadJobAlive, EthBuiltPayload, + EthPayloadBuilderAttributes, PayloadBuilderHandle, PayloadBuilderService, PayloadJob, + PayloadJobGenerator, +}; + /// Creates a new [`PayloadBuilderService`] for testing purposes. pub fn test_payload_service() -> ( PayloadBuilderService< diff --git a/crates/payload/builder/src/traits.rs b/crates/payload/builder/src/traits.rs index 895670d8b0eab..bbc370221b146 100644 --- a/crates/payload/builder/src/traits.rs +++ b/crates/payload/builder/src/traits.rs @@ -1,9 +1,11 @@ //! Trait abstractions used by the payload crate. -use crate::error::PayloadBuilderError; +use std::future::Future; + use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes}; use reth_provider::CanonStateNotification; -use std::future::Future; + +use crate::error::PayloadBuilderError; /// A type that can build a payload. /// diff --git a/crates/payload/primitives/src/lib.rs b/crates/payload/primitives/src/lib.rs index 52029a3c4a371..92bc7b24415c0 100644 --- a/crates/payload/primitives/src/lib.rs +++ b/crates/payload/primitives/src/lib.rs @@ -19,7 +19,6 @@ pub use traits::{BuiltPayload, PayloadAttributes, PayloadBuilderAttributes}; mod payload; pub use payload::PayloadOrAttributes; - use reth_chainspec::ChainSpec; /// The types that are used by the engine API. diff --git a/crates/payload/primitives/src/payload.rs b/crates/payload/primitives/src/payload.rs index 3bd53861bce00..cd7328541b4ed 100644 --- a/crates/payload/primitives/src/payload.rs +++ b/crates/payload/primitives/src/payload.rs @@ -1,7 +1,8 @@ -use crate::{MessageValidationKind, PayloadAttributes}; use reth_primitives::B256; use reth_rpc_types::engine::ExecutionPayload; +use crate::{MessageValidationKind, PayloadAttributes}; + /// Either an [`ExecutionPayload`] or a types that implements the [`PayloadAttributes`] trait. #[derive(Debug)] pub enum PayloadOrAttributes<'a, AttributesType> { diff --git a/crates/payload/validator/src/lib.rs b/crates/payload/validator/src/lib.rs index afc19037732d3..deaaa8a019518 100644 --- a/crates/payload/validator/src/lib.rs +++ b/crates/payload/validator/src/lib.rs @@ -8,11 +8,12 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +use std::sync::Arc; + use reth_chainspec::ChainSpec; use reth_primitives::SealedBlock; use reth_rpc_types::{engine::MaybeCancunPayloadFields, ExecutionPayload, PayloadError}; use reth_rpc_types_compat::engine::payload::try_into_block; -use std::sync::Arc; /// Execution payload validator. #[derive(Clone, Debug)] diff --git a/crates/primitives-traits/src/account.rs b/crates/primitives-traits/src/account.rs index 21a8d199b3a9a..7c39ce4bb9496 100644 --- a/crates/primitives-traits/src/account.rs +++ b/crates/primitives-traits/src/account.rs @@ -146,10 +146,11 @@ impl From for AccountInfo { #[cfg(test)] mod tests { - use super::*; use alloy_primitives::{hex_literal::hex, B256, U256}; use revm_primitives::LegacyAnalyzedBytecode; + use super::*; + #[test] fn test_account() { let mut buf = vec![]; diff --git a/crates/primitives-traits/src/alloy_compat.rs b/crates/primitives-traits/src/alloy_compat.rs index 4bf80e1f7c353..cdc5be2dc12a8 100644 --- a/crates/primitives-traits/src/alloy_compat.rs +++ b/crates/primitives-traits/src/alloy_compat.rs @@ -1,6 +1,7 @@ -use super::Header; use alloy_rpc_types_eth::{ConversionError, Header as RpcHeader}; +use super::Header; + impl TryFrom for Header { type Error = ConversionError; diff --git a/crates/primitives-traits/src/constants/mod.rs b/crates/primitives-traits/src/constants/mod.rs index 32d41ddcd8dda..1756c8bda4f46 100644 --- a/crates/primitives-traits/src/constants/mod.rs +++ b/crates/primitives-traits/src/constants/mod.rs @@ -1,8 +1,9 @@ //! Ethereum protocol-related constants -use alloy_primitives::{address, b256, Address, B256, U256}; use core::time::Duration; +use alloy_primitives::{address, b256, Address, B256, U256}; + /// Gas units, for example [`GIGAGAS`](gas_units::GIGAGAS). pub mod gas_units; diff --git a/crates/primitives-traits/src/error.rs b/crates/primitives-traits/src/error.rs index 8ae946c242086..60aa05b4cc7dc 100644 --- a/crates/primitives-traits/src/error.rs +++ b/crates/primitives-traits/src/error.rs @@ -1,11 +1,10 @@ +#[cfg(not(feature = "std"))] +use alloc::boxed::Box; use core::{ fmt, ops::{Deref, DerefMut}, }; -#[cfg(not(feature = "std"))] -use alloc::boxed::Box; - /// A pair of values, one of which is expected and one of which is actual. #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct GotExpected { diff --git a/crates/primitives-traits/src/header/mod.rs b/crates/primitives-traits/src/header/mod.rs index e817965a6d52a..e0fef436b01ad 100644 --- a/crates/primitives-traits/src/header/mod.rs +++ b/crates/primitives-traits/src/header/mod.rs @@ -7,6 +7,8 @@ pub use error::HeaderError; #[cfg(any(test, feature = "test-utils", feature = "arbitrary"))] pub mod test_utils; +use core::mem; + use alloy_consensus::constants::{EMPTY_OMMER_ROOT_HASH, EMPTY_ROOT_HASH}; use alloy_eips::{ calc_next_block_base_fee, eip1559::BaseFeeParams, merge::ALLOWED_FUTURE_BLOCK_TIME_SECONDS, @@ -15,7 +17,6 @@ use alloy_eips::{ use alloy_primitives::{keccak256, Address, BlockNumber, Bloom, Bytes, B256, B64, U256}; use alloy_rlp::{length_of_length, Decodable, Encodable}; use bytes::BufMut; -use core::mem; use reth_codecs::{add_arbitrary_tests, main_codec, Compact}; use revm_primitives::{calc_blob_gasprice, calc_excess_blob_gas}; diff --git a/crates/primitives-traits/src/header/sealed.rs b/crates/primitives-traits/src/header/sealed.rs index 355e4a9bc62a6..a009c1bb82cd7 100644 --- a/crates/primitives-traits/src/header/sealed.rs +++ b/crates/primitives-traits/src/header/sealed.rs @@ -1,14 +1,16 @@ -use super::Header; +use core::mem; + use alloy_eips::BlockNumHash; use alloy_primitives::{keccak256, BlockHash}; #[cfg(any(test, feature = "test-utils"))] use alloy_primitives::{BlockNumber, B256, U256}; use alloy_rlp::{Decodable, Encodable}; use bytes::BufMut; -use core::mem; use derive_more::{AsRef, Deref}; use reth_codecs::{add_arbitrary_tests, main_codec, Compact}; +use super::Header; + /// A [`Header`] that is sealed at a precalculated hash, use [`SealedHeader::unseal()`] if you want /// to modify header. #[main_codec(no_arbitrary)] diff --git a/crates/primitives-traits/src/header/test_utils.rs b/crates/primitives-traits/src/header/test_utils.rs index 982b779d4b5b6..719a5d747f5af 100644 --- a/crates/primitives-traits/src/header/test_utils.rs +++ b/crates/primitives-traits/src/header/test_utils.rs @@ -1,10 +1,11 @@ //! Test utilities to generate random valid headers. -use crate::Header; use alloy_primitives::B256; use proptest::{arbitrary::any, prop_compose}; use proptest_arbitrary_interop::arb; +use crate::Header; + /// Generates a header which is valid __with respect to past and future forks__. This means, for /// example, that if the withdrawals root is present, the base fee per gas is also present. /// diff --git a/crates/primitives-traits/src/integer_list.rs b/crates/primitives-traits/src/integer_list.rs index 8e258fd8b0606..9133043af5644 100644 --- a/crates/primitives-traits/src/integer_list.rs +++ b/crates/primitives-traits/src/integer_list.rs @@ -1,5 +1,8 @@ -use bytes::BufMut; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; use core::fmt; + +use bytes::BufMut; use derive_more::Deref; use roaring::RoaringTreemap; use serde::{ @@ -8,9 +11,6 @@ use serde::{ Deserialize, Deserializer, Serialize, Serializer, }; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// Uses Roaring Bitmaps to hold a list of integers. It provides really good compression with the /// capability to access its elements without decoding it. #[derive(Clone, PartialEq, Default, Deref)] diff --git a/crates/primitives-traits/src/request.rs b/crates/primitives-traits/src/request.rs index 99c2375e26065..08fcecb2ff019 100644 --- a/crates/primitives-traits/src/request.rs +++ b/crates/primitives-traits/src/request.rs @@ -1,5 +1,8 @@ //! EIP-7685 requests. +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + pub use alloy_consensus::Request; use alloy_eips::eip7685::{Decodable7685, Encodable7685}; use alloy_rlp::{Decodable, Encodable}; @@ -7,9 +10,6 @@ use derive_more::{Deref, DerefMut, From, IntoIterator}; use reth_codecs::{main_codec, Compact}; use revm_primitives::Bytes; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// A list of EIP-7685 requests. #[main_codec] #[derive(Debug, Clone, PartialEq, Eq, Default, Hash, Deref, DerefMut, From, IntoIterator)] diff --git a/crates/primitives-traits/src/withdrawal.rs b/crates/primitives-traits/src/withdrawal.rs index 679c80cab6a0b..a11160bbe2661 100644 --- a/crates/primitives-traits/src/withdrawal.rs +++ b/crates/primitives-traits/src/withdrawal.rs @@ -1,15 +1,14 @@ //! [EIP-4895](https://eips.ethereum.org/EIPS/eip-4895) Withdrawal types. -use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper}; -use derive_more::{AsRef, Deref, DerefMut, From, IntoIterator}; -use reth_codecs::{main_codec, Compact}; - #[cfg(not(feature = "std"))] use alloc::vec::Vec; /// Re-export from `alloy_eips`. #[doc(inline)] pub use alloy_eips::eip4895::Withdrawal; +use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper}; +use derive_more::{AsRef, Deref, DerefMut, From, IntoIterator}; +use reth_codecs::{main_codec, Compact}; /// Represents a collection of Withdrawals. #[main_codec] @@ -67,12 +66,13 @@ impl Withdrawals { #[cfg(test)] mod tests { - use super::*; use alloy_primitives::Address; use alloy_rlp::{RlpDecodable, RlpEncodable}; use proptest::proptest; use proptest_arbitrary_interop::arb; + use super::*; + /// This type is kept for compatibility tests after the codec support was added to alloy-eips /// Withdrawal type natively #[main_codec] diff --git a/crates/primitives/src/alloy_compat.rs b/crates/primitives/src/alloy_compat.rs index f257ee8bb89ad..74c90a6be26af 100644 --- a/crates/primitives/src/alloy_compat.rs +++ b/crates/primitives/src/alloy_compat.rs @@ -1,15 +1,16 @@ //! Common conversions from alloy types. +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + +use alloy_primitives::TxKind; +use alloy_rlp::Error as RlpError; + use crate::{ constants::EMPTY_TRANSACTIONS, transaction::extract_chain_id, Block, Signature, Transaction, TransactionSigned, TransactionSignedEcRecovered, TxEip1559, TxEip2930, TxEip4844, TxLegacy, TxType, }; -use alloy_primitives::TxKind; -use alloy_rlp::Error as RlpError; - -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; impl TryFrom for Block { type Error = alloy_rpc_types::ConversionError; @@ -271,11 +272,12 @@ impl TryFrom for Signature { #[cfg(test)] #[cfg(feature = "optimism")] mod tests { - use super::*; use alloy_primitives::{B256, U256}; use alloy_rpc_types::Transaction as AlloyTransaction; use revm_primitives::{address, Address}; + use super::*; + #[test] fn optimism_deposit_tx_conversion_no_mint() { let input = r#"{ diff --git a/crates/primitives/src/block.rs b/crates/primitives/src/block.rs index 9b5e172e8fc2c..72ed7519ecf2c 100644 --- a/crates/primitives/src/block.rs +++ b/crates/primitives/src/block.rs @@ -1,7 +1,6 @@ -use crate::{ - Address, Bytes, GotExpected, Header, SealedHeader, TransactionSigned, - TransactionSignedEcRecovered, Withdrawals, B256, -}; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + pub use alloy_eips::eip1898::{ BlockHashOrNumber, BlockId, BlockNumHash, BlockNumberOrTag, ForkBlock, RpcBlockHash, }; @@ -15,8 +14,10 @@ pub use reth_primitives_traits::test_utils::{generate_valid_header, valid_header use reth_primitives_traits::Requests; use serde::{Deserialize, Serialize}; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; +use crate::{ + Address, Bytes, GotExpected, Header, SealedHeader, TransactionSigned, + TransactionSignedEcRecovered, Withdrawals, B256, +}; // HACK(onbjerg): we need this to always set `requests` to `None` since we might otherwise generate // a block with `None` withdrawals and `Some` requests, in which case we end up trying to decode the @@ -632,11 +633,13 @@ impl<'a> arbitrary::Arbitrary<'a> for BlockBody { #[cfg(test)] mod tests { - use super::{BlockNumberOrTag::*, *}; - use crate::hex_literal::hex; + use std::str::FromStr; + use alloy_eips::eip1898::HexStringMissingPrefixError; use alloy_rlp::{Decodable, Encodable}; - use std::str::FromStr; + + use super::{BlockNumberOrTag::*, *}; + use crate::hex_literal::hex; /// Check parsing according to EIP-1898. #[test] diff --git a/crates/primitives/src/compression/mod.rs b/crates/primitives/src/compression/mod.rs index f7af0acbe4def..a1f84cea049a7 100644 --- a/crates/primitives/src/compression/mod.rs +++ b/crates/primitives/src/compression/mod.rs @@ -1,8 +1,8 @@ -use std::{cell::RefCell, thread_local}; -use zstd::bulk::{Compressor, Decompressor}; - #[cfg(not(feature = "std"))] use alloc::vec::Vec; +use std::{cell::RefCell, thread_local}; + +use zstd::bulk::{Compressor, Decompressor}; /// Compression/Decompression dictionary for `Receipt`. pub static RECEIPT_DICTIONARY: &[u8] = include_bytes!("./receipt_dictionary.bin"); diff --git a/crates/primitives/src/constants/eip4844.rs b/crates/primitives/src/constants/eip4844.rs index 48a3aebb3c32f..b2de2f0dc10fd 100644 --- a/crates/primitives/src/constants/eip4844.rs +++ b/crates/primitives/src/constants/eip4844.rs @@ -1,18 +1,18 @@ //! [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844#parameters) protocol constants and utils for shard Blob Transactions. -#[cfg(feature = "c-kzg")] -pub use trusted_setup::*; - pub use alloy_eips::eip4844::{ BLOB_GASPRICE_UPDATE_FRACTION, BLOB_TX_MIN_BLOB_GASPRICE, DATA_GAS_PER_BLOB, FIELD_ELEMENTS_PER_BLOB, FIELD_ELEMENT_BYTES, MAX_BLOBS_PER_BLOCK, MAX_DATA_GAS_PER_BLOCK, TARGET_BLOBS_PER_BLOCK, TARGET_DATA_GAS_PER_BLOCK, VERSIONED_HASH_VERSION_KZG, }; +#[cfg(feature = "c-kzg")] +pub use trusted_setup::*; #[cfg(feature = "c-kzg")] mod trusted_setup { - use crate::kzg::KzgSettings; use std::io::Write; + use crate::kzg::KzgSettings; + /// Loads the trusted setup parameters from the given bytes and returns the [`KzgSettings`]. /// /// This creates a temp file to store the bytes and then loads the [`KzgSettings`] from the file diff --git a/crates/primitives/src/eip4844.rs b/crates/primitives/src/eip4844.rs index 0d228528f78b3..8cd1ac102f8f4 100644 --- a/crates/primitives/src/eip4844.rs +++ b/crates/primitives/src/eip4844.rs @@ -1,9 +1,9 @@ //! Helpers for working with EIP-4844 blob fee. // re-exports from revm for calculating blob fee +#[doc(inline)] +pub use alloy_eips::eip4844::kzg_to_versioned_hash; + pub use crate::revm_primitives::{ calc_blob_gasprice, calc_excess_blob_gas as calculate_excess_blob_gas, }; - -#[doc(inline)] -pub use alloy_eips::eip4844::kzg_to_versioned_hash; diff --git a/crates/primitives/src/header.rs b/crates/primitives/src/header.rs index ea80328e75281..5987553a5cfbb 100644 --- a/crates/primitives/src/header.rs +++ b/crates/primitives/src/header.rs @@ -3,9 +3,8 @@ use alloy_rlp::{Decodable, Encodable}; use bytes::BufMut; use reth_codecs::derive_arbitrary; -use serde::{Deserialize, Serialize}; - pub use reth_primitives_traits::{Header, HeaderError, SealedHeader}; +use serde::{Deserialize, Serialize}; /// Represents the direction for a headers request depending on the `reverse` field of the request. /// > The response must contain a number of block headers, of rising number when reverse is 0, @@ -87,11 +86,13 @@ impl From for bool { #[cfg(test)] mod tests { + use std::str::FromStr; + + use alloy_rlp::{Decodable, Encodable}; + use crate::{ address, b256, bloom, bytes, hex, Address, Bytes, Header, HeadersDirection, B256, U256, }; - use alloy_rlp::{Decodable, Encodable}; - use std::str::FromStr; // Test vector from: https://eips.ethereum.org/EIPS/eip-2481 #[test] diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 35a3ee1893085..6edfe9a20c06d 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -36,6 +36,14 @@ mod receipt; pub mod revm; pub use reth_static_file_types as static_file; pub mod transaction; +pub use alloy_primitives::{ + self, address, b256, bloom, bytes, + bytes::{Buf, BufMut, BytesMut}, + eip191_hash_message, hex, hex_literal, keccak256, ruint, + utils::format_ether, + Address, BlockHash, BlockNumber, Bloom, BloomInput, Bytes, ChainId, Selector, StorageKey, + StorageValue, TxHash, TxIndex, TxKind, TxNumber, B128, B256, B512, B64, U128, U256, U64, U8, +}; #[cfg(any(test, feature = "arbitrary"))] pub use block::{generate_valid_header, valid_header_strategy}; pub use block::{ @@ -53,41 +61,27 @@ pub use header::{Header, HeadersDirection, SealedHeader}; pub use receipt::{ gas_spent_by_transactions, Receipt, ReceiptWithBloom, ReceiptWithBloomRef, Receipts, }; +pub use reth_ethereum_forks::*; pub use reth_primitives_traits::{ logs_bloom, Account, Bytecode, GotExpected, GotExpectedBoxed, Log, LogData, Request, Requests, StorageEntry, Withdrawal, Withdrawals, }; +pub use revm_primitives::{self, JumpTable}; pub use static_file::StaticFileSegment; - -pub use transaction::{ - BlobTransaction, BlobTransactionSidecar, FromRecoveredPooledTransaction, - PooledTransactionsElement, PooledTransactionsElementEcRecovered, -}; - #[cfg(feature = "c-kzg")] pub use transaction::BlobTransactionValidationError; - pub use transaction::{ util::secp256k1::{public_key_to_address, recover_signer_unchecked, sign_message}, - AccessList, AccessListItem, IntoRecoveredTransaction, InvalidTransactionError, Signature, - Transaction, TransactionMeta, TransactionSigned, TransactionSignedEcRecovered, - TransactionSignedNoHash, TryFromRecoveredTransaction, TxEip1559, TxEip2930, TxEip4844, - TxHashOrNumber, TxLegacy, TxType, EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, - LEGACY_TX_TYPE_ID, + AccessList, AccessListItem, BlobTransaction, BlobTransactionSidecar, + FromRecoveredPooledTransaction, IntoRecoveredTransaction, InvalidTransactionError, + PooledTransactionsElement, PooledTransactionsElementEcRecovered, Signature, Transaction, + TransactionMeta, TransactionSigned, TransactionSignedEcRecovered, TransactionSignedNoHash, + TryFromRecoveredTransaction, TxEip1559, TxEip2930, TxEip4844, TxHashOrNumber, TxLegacy, TxType, + EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, LEGACY_TX_TYPE_ID, }; // Re-exports pub use self::ruint::UintTryTo; -pub use alloy_primitives::{ - self, address, b256, bloom, bytes, - bytes::{Buf, BufMut, BytesMut}, - eip191_hash_message, hex, hex_literal, keccak256, ruint, - utils::format_ether, - Address, BlockHash, BlockNumber, Bloom, BloomInput, Bytes, ChainId, Selector, StorageKey, - StorageValue, TxHash, TxIndex, TxKind, TxNumber, B128, B256, B512, B64, U128, U256, U64, U8, -}; -pub use reth_ethereum_forks::*; -pub use revm_primitives::{self, JumpTable}; #[doc(hidden)] #[deprecated = "use B64 instead"] @@ -107,14 +101,12 @@ pub type H512 = B512; #[cfg(any(test, feature = "arbitrary"))] pub use arbitrary; - #[cfg(feature = "c-kzg")] pub use c_kzg as kzg; /// Optimism specific re-exports #[cfg(feature = "optimism")] mod optimism { - pub use crate::transaction::{TxDeposit, DEPOSIT_TX_TYPE_ID}; pub use reth_chainspec::{ net::{ base_nodes, base_testnet_nodes, op_nodes, op_testnet_nodes, OP_BOOTNODES, @@ -122,6 +114,8 @@ mod optimism { }, BASE_MAINNET, BASE_SEPOLIA, OP_MAINNET, OP_SEPOLIA, }; + + pub use crate::transaction::{TxDeposit, DEPOSIT_TX_TYPE_ID}; } #[cfg(feature = "optimism")] diff --git a/crates/primitives/src/proofs.rs b/crates/primitives/src/proofs.rs index 5521fedecf97f..f6f5b033a5c97 100644 --- a/crates/primitives/src/proofs.rs +++ b/crates/primitives/src/proofs.rs @@ -1,15 +1,15 @@ //! Helper function for calculating Merkle proofs and hashes. +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + +use alloy_eips::eip7685::Encodable7685; +use reth_trie_common::root::{ordered_trie_root, ordered_trie_root_with_encoder}; + use crate::{ constants::EMPTY_OMMER_ROOT_HASH, keccak256, Header, Receipt, ReceiptWithBloom, ReceiptWithBloomRef, Request, TransactionSigned, Withdrawal, B256, }; -use reth_trie_common::root::{ordered_trie_root, ordered_trie_root_with_encoder}; - -use alloy_eips::eip7685::Encodable7685; - -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; /// Calculate a transaction root. /// @@ -134,14 +134,16 @@ pub fn calculate_ommers_root(ommers: &[Header]) -> B256 { #[cfg(test)] mod tests { - use super::*; - use crate::{bloom, constants::EMPTY_ROOT_HASH, hex_literal::hex, Block, Log, TxType, U256}; + use std::collections::HashMap; + use alloy_genesis::GenesisAccount; use alloy_primitives::{b256, Address, LogData}; use alloy_rlp::Decodable; use reth_chainspec::{GOERLI, HOLESKY, MAINNET, SEPOLIA}; use reth_trie_common::root::{state_root_ref_unhashed, state_root_unhashed}; - use std::collections::HashMap; + + use super::*; + use crate::{bloom, constants::EMPTY_ROOT_HASH, hex_literal::hex, Block, Log, TxType, U256}; #[test] fn check_transaction_root() { diff --git a/crates/primitives/src/receipt.rs b/crates/primitives/src/receipt.rs index 1a9d917d62f71..dd4ed9b257d93 100644 --- a/crates/primitives/src/receipt.rs +++ b/crates/primitives/src/receipt.rs @@ -1,18 +1,19 @@ -#[cfg(feature = "zstd-codec")] -use crate::compression::{RECEIPT_COMPRESSOR, RECEIPT_DECOMPRESSOR}; -use crate::{logs_bloom, Bloom, Bytes, TxType, B256}; +#[cfg(not(feature = "std"))] +use alloc::{vec, vec::Vec}; +use core::{cmp::Ordering, ops::Deref}; + use alloy_primitives::Log; use alloy_rlp::{length_of_length, Decodable, Encodable, RlpDecodable, RlpEncodable}; use bytes::{Buf, BufMut}; -use core::{cmp::Ordering, ops::Deref}; use derive_more::{Deref, DerefMut, From, IntoIterator}; #[cfg(feature = "zstd-codec")] use reth_codecs::CompactZstd; use reth_codecs::{add_arbitrary_tests, main_codec, Compact}; use serde::{Deserialize, Serialize}; -#[cfg(not(feature = "std"))] -use alloc::{vec, vec::Vec}; +#[cfg(feature = "zstd-codec")] +use crate::compression::{RECEIPT_COMPRESSOR, RECEIPT_DECOMPRESSOR}; +use crate::{logs_bloom, Bloom, Bytes, TxType, B256}; /// Receipt containing result of transaction execution. #[cfg_attr(feature = "zstd-codec", main_codec(no_arbitrary, zstd))] @@ -505,9 +506,10 @@ impl<'a> Encodable for ReceiptWithBloomEncoder<'a> { #[cfg(test)] mod tests { + use alloy_primitives::{address, b256, bytes}; + use super::*; use crate::hex_literal::hex; - use alloy_primitives::{address, b256, bytes}; // Test vector from: https://eips.ethereum.org/EIPS/eip-2481 #[test] diff --git a/crates/primitives/src/revm/config.rs b/crates/primitives/src/revm/config.rs index 5914dbf593487..8f8dd1ee724d2 100644 --- a/crates/primitives/src/revm/config.rs +++ b/crates/primitives/src/revm/config.rs @@ -88,9 +88,10 @@ pub fn revm_spec(chain_spec: &ChainSpec, block: Head) -> revm_primitives::SpecId #[cfg(test)] mod tests { + use reth_chainspec::{ChainSpecBuilder, MAINNET}; + use super::*; use crate::U256; - use reth_chainspec::{ChainSpecBuilder, MAINNET}; #[test] fn test_revm_spec_by_timestamp_after_merge() { diff --git a/crates/primitives/src/revm/env.rs b/crates/primitives/src/revm/env.rs index bbd4cffd35fbc..517ee7d30c393 100644 --- a/crates/primitives/src/revm/env.rs +++ b/crates/primitives/src/revm/env.rs @@ -1,16 +1,16 @@ -use crate::{ - recover_signer_unchecked, - revm_primitives::{BlockEnv, Env, TxEnv}, - Address, Bytes, Header, Transaction, TransactionSignedEcRecovered, TxKind, B256, U256, -}; -use reth_chainspec::{Chain, ChainSpec}; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; use alloy_eips::{eip4788::BEACON_ROOTS_ADDRESS, eip7002::WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS}; +use reth_chainspec::{Chain, ChainSpec}; #[cfg(feature = "optimism")] use revm_primitives::OptimismFields; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; +use crate::{ + recover_signer_unchecked, + revm_primitives::{BlockEnv, Env, TxEnv}, + Address, Bytes, Header, Transaction, TransactionSignedEcRecovered, TxKind, B256, U256, +}; /// Fill block environment from Block. pub fn fill_block_env( @@ -370,9 +370,10 @@ pub fn fill_op_tx_env>( #[cfg(test)] mod tests { - use super::*; use reth_chainspec::GOERLI; + use super::*; + #[test] fn test_recover_genesis_goerli_signer() { // just ensures that `block_coinbase` does not panic on the genesis block diff --git a/crates/primitives/src/transaction/access_list.rs b/crates/primitives/src/transaction/access_list.rs index 22e113fbdc118..a0be948fcf78e 100644 --- a/crates/primitives/src/transaction/access_list.rs +++ b/crates/primitives/src/transaction/access_list.rs @@ -6,13 +6,14 @@ pub use alloy_eips::eip2930::{AccessList, AccessListItem}; #[cfg(test)] mod tests { - use super::*; - use crate::{Address, B256}; use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper}; use proptest::proptest; use proptest_arbitrary_interop::arb; use reth_codecs::{main_codec, Compact}; + use super::*; + use crate::{Address, B256}; + /// This type is kept for compatibility tests after the codec support was added to alloy-eips /// AccessList type natively #[main_codec(rlp)] diff --git a/crates/primitives/src/transaction/eip1559.rs b/crates/primitives/src/transaction/eip1559.rs index cce6f0ca22fc3..b95c7fadf0c08 100644 --- a/crates/primitives/src/transaction/eip1559.rs +++ b/crates/primitives/src/transaction/eip1559.rs @@ -1,9 +1,11 @@ -use super::access_list::AccessList; -use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256}; -use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use core::mem; + +use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use reth_codecs::{main_codec, Compact}; +use super::access_list::AccessList; +use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256}; + /// A transaction with a priority fee ([EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)). #[main_codec] #[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] @@ -223,12 +225,13 @@ impl TxEip1559 { #[cfg(test)] mod tests { + use std::str::FromStr; + use super::TxEip1559; use crate::{ transaction::{signature::Signature, TxKind}, AccessList, Address, Transaction, TransactionSigned, B256, U256, }; - use std::str::FromStr; #[test] fn recover_signer_eip1559() { diff --git a/crates/primitives/src/transaction/eip2930.rs b/crates/primitives/src/transaction/eip2930.rs index ebaa12785c1da..bd5ad445ac3b1 100644 --- a/crates/primitives/src/transaction/eip2930.rs +++ b/crates/primitives/src/transaction/eip2930.rs @@ -1,9 +1,11 @@ -use super::access_list::AccessList; -use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256}; -use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use core::mem; + +use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use reth_codecs::{main_codec, Compact}; +use super::access_list::AccessList; +use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256}; + /// Transaction with an [`AccessList`] ([EIP-2930](https://eips.ethereum.org/EIPS/eip-2930)). #[main_codec] #[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] @@ -186,12 +188,13 @@ impl TxEip2930 { #[cfg(test)] mod tests { + use alloy_rlp::{Decodable, Encodable}; + use super::TxEip2930; use crate::{ transaction::{signature::Signature, TxKind}, Address, Bytes, Transaction, TransactionSigned, U256, }; - use alloy_rlp::{Decodable, Encodable}; #[test] fn test_decode_create() { diff --git a/crates/primitives/src/transaction/eip4844.rs b/crates/primitives/src/transaction/eip4844.rs index f792d787afdd4..b5f9b778f1b3e 100644 --- a/crates/primitives/src/transaction/eip4844.rs +++ b/crates/primitives/src/transaction/eip4844.rs @@ -1,17 +1,17 @@ -use super::access_list::AccessList; -use crate::{ - constants::eip4844::DATA_GAS_PER_BLOB, keccak256, Address, Bytes, ChainId, Signature, TxType, - B256, U256, -}; -use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; use core::mem; + +use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use reth_codecs::{main_codec, Compact, CompactPlaceholder}; +use super::access_list::AccessList; #[cfg(feature = "c-kzg")] use crate::kzg::KzgSettings; - -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; +use crate::{ + constants::eip4844::DATA_GAS_PER_BLOB, keccak256, Address, Bytes, ChainId, Signature, TxType, + B256, U256, +}; /// [EIP-4844 Blob Transaction](https://eips.ethereum.org/EIPS/eip-4844#blob-transaction) /// @@ -290,9 +290,10 @@ impl TxEip4844 { #[cfg(test)] mod tests { - use super::*; use alloy_primitives::{address, bytes}; + use super::*; + #[test] fn backwards_compatible_txkind_test() { // TxEip4844 encoded with TxKind on to field diff --git a/crates/primitives/src/transaction/legacy.rs b/crates/primitives/src/transaction/legacy.rs index 09b661cf79950..d4e4e3621256d 100644 --- a/crates/primitives/src/transaction/legacy.rs +++ b/crates/primitives/src/transaction/legacy.rs @@ -1,8 +1,10 @@ -use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256}; -use alloy_rlp::{length_of_length, Encodable, Header}; use core::mem; + +use alloy_rlp::{length_of_length, Encodable, Header}; use reth_codecs::{main_codec, Compact}; +use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256}; + /// Legacy transaction. #[main_codec] #[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index c23d454f868dc..7cb7bbd5d1a54 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -1,43 +1,41 @@ //! Transaction types. -#[cfg(any(feature = "arbitrary", feature = "zstd-codec"))] -use crate::compression::{TRANSACTION_COMPRESSOR, TRANSACTION_DECOMPRESSOR}; -use crate::{keccak256, Address, BlockHashOrNumber, Bytes, TxHash, TxKind, B256, U256}; +use core::mem; +pub use access_list::{AccessList, AccessListItem}; use alloy_rlp::{ Decodable, Encodable, Error as RlpError, Header, EMPTY_LIST_CODE, EMPTY_STRING_CODE, }; use bytes::Buf; -use core::mem; use derive_more::{AsRef, Deref}; -use once_cell::sync::Lazy; -use rayon::prelude::{IntoParallelIterator, ParallelIterator}; -use reth_codecs::{add_arbitrary_tests, derive_arbitrary, Compact}; -use serde::{Deserialize, Serialize}; - -pub use access_list::{AccessList, AccessListItem}; pub use eip1559::TxEip1559; pub use eip2930::TxEip2930; pub use eip4844::TxEip4844; - pub use error::{ InvalidTransactionError, TransactionConversionError, TryFromRecoveredTransactionError, }; pub use legacy::TxLegacy; pub use meta::TransactionMeta; +use once_cell::sync::Lazy; pub use pooled::{PooledTransactionsElement, PooledTransactionsElementEcRecovered}; +use rayon::prelude::{IntoParallelIterator, ParallelIterator}; +use reth_codecs::{add_arbitrary_tests, derive_arbitrary, Compact}; +use serde::{Deserialize, Serialize}; #[cfg(all(feature = "c-kzg", any(test, feature = "arbitrary")))] pub use sidecar::generate_blob_sidecar; #[cfg(feature = "c-kzg")] pub use sidecar::BlobTransactionValidationError; pub use sidecar::{BlobTransaction, BlobTransactionSidecar}; - pub use signature::{extract_chain_id, Signature}; pub use tx_type::{ TxType, EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, LEGACY_TX_TYPE_ID, }; pub use variant::TransactionSignedVariant; +#[cfg(any(feature = "arbitrary", feature = "zstd-codec"))] +use crate::compression::{TRANSACTION_COMPRESSOR, TRANSACTION_DECOMPRESSOR}; +use crate::{keccak256, Address, BlockHashOrNumber, Bytes, TxHash, TxKind, B256, U256}; + mod access_list; mod eip1559; mod eip2930; @@ -55,14 +53,14 @@ mod variant; #[cfg(feature = "optimism")] mod optimism; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + #[cfg(feature = "optimism")] pub use optimism::TxDeposit; #[cfg(feature = "optimism")] pub use tx_type::DEPOSIT_TX_TYPE_ID; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// Either a transaction hash or number. pub type TxHashOrNumber = BlockHashOrNumber; @@ -1613,6 +1611,14 @@ impl IntoRecoveredTransaction for TransactionSignedEcRecovered { #[cfg(test)] mod tests { + use std::str::FromStr; + + use alloy_primitives::{address, b256, bytes}; + use alloy_rlp::{Decodable, Encodable, Error as RlpError}; + use proptest_arbitrary_interop::arb; + use reth_codecs::Compact; + use secp256k1::{Keypair, Secp256k1}; + use crate::{ hex, sign_message, transaction::{ @@ -1624,12 +1630,6 @@ mod tests { Address, Bytes, Transaction, TransactionSigned, TransactionSignedEcRecovered, TransactionSignedNoHash, TxEip2930, TxEip4844, B256, U256, }; - use alloy_primitives::{address, b256, bytes}; - use alloy_rlp::{Decodable, Encodable, Error as RlpError}; - use proptest_arbitrary_interop::arb; - use reth_codecs::Compact; - use secp256k1::{Keypair, Secp256k1}; - use std::str::FromStr; #[test] fn test_decode_empty_typed_tx() { @@ -1677,9 +1677,10 @@ mod tests { // Test vector from https://sepolia.etherscan.io/tx/0x9a22ccb0029bc8b0ddd073be1a1d923b7ae2b2ea52100bae0db4424f9107e9c0 // Blobscan: https://sepolia.blobscan.com/tx/0x9a22ccb0029bc8b0ddd073be1a1d923b7ae2b2ea52100bae0db4424f9107e9c0 fn test_decode_recover_sepolia_4844_tx() { - use crate::TxType; use alloy_primitives::{address, b256}; + use crate::TxType; + // https://sepolia.etherscan.io/getRawTx?tx=0x9a22ccb0029bc8b0ddd073be1a1d923b7ae2b2ea52100bae0db4424f9107e9c0 let raw_tx = alloy_primitives::hex::decode("0x03f9011d83aa36a7820fa28477359400852e90edd0008252089411e9ca82a3a762b4b5bd264d4173a242e7a770648080c08504a817c800f8a5a0012ec3d6f66766bedb002a190126b3549fce0047de0d4c25cffce0dc1c57921aa00152d8e24762ff22b1cfd9f8c0683786a7ca63ba49973818b3d1e9512cd2cec4a0013b98c6c83e066d5b14af2b85199e3d4fc7d1e778dd53130d180f5077e2d1c7a001148b495d6e859114e670ca54fb6e2657f0cbae5b08063605093a4b3dc9f8f1a0011ac212f13c5dff2b2c6b600a79635103d6f580a4221079951181b25c7e654901a0c8de4cced43169f9aa3d36506363b2d2c44f6c49fc1fd91ea114c86f3757077ea01e11fdd0d1934eda0492606ee0bb80a7bf8f35cc5f86ec60fe5031ba48bfd544").unwrap(); let decoded = TransactionSigned::decode_enveloped(&mut raw_tx.as_slice()).unwrap(); diff --git a/crates/primitives/src/transaction/optimism.rs b/crates/primitives/src/transaction/optimism.rs index 6bb8ec9b8c870..691b68b4a55fe 100644 --- a/crates/primitives/src/transaction/optimism.rs +++ b/crates/primitives/src/transaction/optimism.rs @@ -1,10 +1,12 @@ -use crate::{Address, Bytes, TxKind, TxType, B256, U256}; +use std::mem; + use alloy_rlp::{ length_of_length, Decodable, Encodable, Error as DecodeError, Header, EMPTY_STRING_CODE, }; use bytes::Buf; use reth_codecs::{main_codec, Compact}; -use std::mem; + +use crate::{Address, Bytes, TxKind, TxType, B256, U256}; /// Deposit transactions, also known as deposits are initiated on L1, and executed on L2. #[main_codec] @@ -144,9 +146,10 @@ impl TxDeposit { #[cfg(test)] mod tests { + use bytes::BytesMut; + use super::*; use crate::{revm_primitives::hex_literal::hex, TransactionSigned}; - use bytes::BytesMut; #[test] fn test_rlp_roundtrip() { diff --git a/crates/primitives/src/transaction/pooled.rs b/crates/primitives/src/transaction/pooled.rs index a72d22d9f9074..5750ecb3e800c 100644 --- a/crates/primitives/src/transaction/pooled.rs +++ b/crates/primitives/src/transaction/pooled.rs @@ -1,20 +1,21 @@ //! Defines the types for blob transactions, legacy, and other EIP-2718 transactions included in a //! response to `GetPooledTransactions`. -use super::error::TransactionConversionError; -use crate::{ - Address, BlobTransaction, BlobTransactionSidecar, Bytes, Signature, Transaction, - TransactionSigned, TransactionSignedEcRecovered, TxEip1559, TxEip2930, TxEip4844, TxHash, - TxLegacy, B256, EIP4844_TX_TYPE_ID, -}; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + use alloy_rlp::{Decodable, Encodable, Error as RlpError, Header, EMPTY_LIST_CODE}; use bytes::Buf; use derive_more::{AsRef, Deref}; use reth_codecs::add_arbitrary_tests; use serde::{Deserialize, Serialize}; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; +use super::error::TransactionConversionError; +use crate::{ + Address, BlobTransaction, BlobTransactionSidecar, Bytes, Signature, Transaction, + TransactionSigned, TransactionSignedEcRecovered, TxEip1559, TxEip2930, TxEip4844, TxHash, + TxLegacy, B256, EIP4844_TX_TYPE_ID, +}; /// A response to `GetPooledTransactions`. This can include either a blob transaction, or a /// non-4844 signed transaction. @@ -691,10 +692,11 @@ impl TryFrom for PooledTransactionsElementEcRecove #[cfg(test)] mod tests { - use super::*; use alloy_primitives::{address, hex}; use assert_matches::assert_matches; + use super::*; + #[test] fn invalid_legacy_pooled_decoding_input_too_short() { let input_too_short = [ diff --git a/crates/primitives/src/transaction/sidecar.rs b/crates/primitives/src/transaction/sidecar.rs index 2c6f4598a5139..55ff3deebc4c9 100644 --- a/crates/primitives/src/transaction/sidecar.rs +++ b/crates/primitives/src/transaction/sidecar.rs @@ -1,19 +1,18 @@ #![cfg_attr(docsrs, doc(cfg(feature = "c-kzg")))] -use crate::{ - keccak256, Signature, Transaction, TransactionSigned, TxEip4844, TxHash, EIP4844_TX_TYPE_ID, -}; -use alloy_rlp::{Decodable, Encodable, Error as RlpError, Header}; -use serde::{Deserialize, Serialize}; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; #[doc(inline)] pub use alloy_eips::eip4844::BlobTransactionSidecar; - #[cfg(feature = "c-kzg")] pub use alloy_eips::eip4844::BlobTransactionValidationError; +use alloy_rlp::{Decodable, Encodable, Error as RlpError, Header}; +use serde::{Deserialize, Serialize}; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; +use crate::{ + keccak256, Signature, Transaction, TransactionSigned, TxEip4844, TxHash, EIP4844_TX_TYPE_ID, +}; /// A response to `GetPooledTransactions` that includes blob data, their commitments, and their /// corresponding proofs. @@ -308,10 +307,12 @@ pub fn generate_blob_sidecar(blobs: Vec) -> BlobTransactionSidecar #[cfg(all(test, feature = "c-kzg"))] mod tests { + use std::{fs, path::PathBuf, str::FromStr}; + + use alloy_eips::eip4844::Bytes48; + use super::*; use crate::{hex, kzg::Blob}; - use alloy_eips::eip4844::Bytes48; - use std::{fs, path::PathBuf, str::FromStr}; #[test] fn test_blob_transaction_sidecar_generation() { diff --git a/crates/primitives/src/transaction/signature.rs b/crates/primitives/src/transaction/signature.rs index 077858a3c579a..2d94b863b26cf 100644 --- a/crates/primitives/src/transaction/signature.rs +++ b/crates/primitives/src/transaction/signature.rs @@ -1,10 +1,11 @@ -use crate::{transaction::util::secp256k1, Address, B256, U256}; use alloy_primitives::Bytes; use alloy_rlp::{Decodable, Encodable, Error as RlpError}; use bytes::Buf; use reth_codecs::{derive_arbitrary, Compact}; use serde::{Deserialize, Serialize}; +use crate::{transaction::util::secp256k1, Address, B256, U256}; + /// The order of the secp256k1 curve, divided by two. Signatures that should be checked according /// to EIP-2 should have an S value less than or equal to this. /// @@ -217,10 +218,12 @@ pub const fn extract_chain_id(v: u64) -> alloy_rlp::Result<(bool, Option)> #[cfg(test)] mod tests { - use crate::{transaction::signature::SECP256K1N_HALF, Address, Signature, B256, U256}; - use alloy_primitives::{hex, hex::FromHex, Bytes}; use std::str::FromStr; + use alloy_primitives::{hex, hex::FromHex, Bytes}; + + use crate::{transaction::signature::SECP256K1N_HALF, Address, Signature, B256, U256}; + #[test] fn test_payload_len_with_eip155_chain_id() { // Select 1 as an arbitrary nonzero value for R and S, as v() always returns 0 for (0, 0). diff --git a/crates/primitives/src/transaction/tx_type.rs b/crates/primitives/src/transaction/tx_type.rs index 7530fda086f82..da4bc8d694227 100644 --- a/crates/primitives/src/transaction/tx_type.rs +++ b/crates/primitives/src/transaction/tx_type.rs @@ -1,9 +1,10 @@ -use crate::{U64, U8}; use alloy_rlp::{Decodable, Encodable}; use bytes::Buf; use reth_codecs::{derive_arbitrary, Compact}; use serde::{Deserialize, Serialize}; +use crate::{U64, U8}; + /// Identifier for legacy transaction, however [`TxLegacy`](crate::TxLegacy) this is technically not /// typed. pub const LEGACY_TX_TYPE_ID: u8 = 0; @@ -204,9 +205,8 @@ impl Decodable for TxType { mod tests { use rand::Rng; - use crate::hex; - use super::*; + use crate::hex; #[test] fn test_u64_to_tx_type() { diff --git a/crates/primitives/src/transaction/util.rs b/crates/primitives/src/transaction/util.rs index b4a2db7f6b52e..62d8266167100 100644 --- a/crates/primitives/src/transaction/util.rs +++ b/crates/primitives/src/transaction/util.rs @@ -1,6 +1,4 @@ pub(crate) mod secp256k1 { - use super::*; - use crate::{keccak256, Address, Signature}; pub(crate) use ::secp256k1::Error; use ::secp256k1::{ ecdsa::{RecoverableSignature, RecoveryId}, @@ -8,6 +6,9 @@ pub(crate) mod secp256k1 { }; use revm_primitives::{B256, U256}; + use super::*; + use crate::{keccak256, Address, Signature}; + /// Recovers the address of the sender using secp256k1 pubkey recovery. /// /// Converts the public key into an ethereum address by hashing the public key with keccak256. diff --git a/crates/primitives/src/transaction/variant.rs b/crates/primitives/src/transaction/variant.rs index 5bff5215d7ac3..92e3e39202ff0 100644 --- a/crates/primitives/src/transaction/variant.rs +++ b/crates/primitives/src/transaction/variant.rs @@ -1,11 +1,12 @@ //! Helper enum functions for `Transaction`, `TransactionSigned` and //! `TransactionSignedEcRecovered` +use core::ops::Deref; + use crate::{ Address, Transaction, TransactionSigned, TransactionSignedEcRecovered, TransactionSignedNoHash, B256, }; -use core::ops::Deref; /// Represents various different transaction formats used in reth. /// diff --git a/crates/prune/prune/src/builder.rs b/crates/prune/prune/src/builder.rs index 233e80a71a9a9..468760dd781a2 100644 --- a/crates/prune/prune/src/builder.rs +++ b/crates/prune/prune/src/builder.rs @@ -1,13 +1,15 @@ -use crate::{segments::SegmentSet, Pruner}; +use std::time::Duration; + use reth_chainspec::MAINNET; use reth_config::PruneConfig; use reth_db_api::database::Database; use reth_exex_types::FinishedExExHeight; use reth_provider::ProviderFactory; use reth_prune_types::PruneModes; -use std::time::Duration; use tokio::sync::watch; +use crate::{segments::SegmentSet, Pruner}; + /// Contains the information required to build a pruner #[derive(Debug, Clone)] pub struct PrunerBuilder { diff --git a/crates/prune/prune/src/event.rs b/crates/prune/prune/src/event.rs index 7007e3f47568c..ca1ccd37aeea2 100644 --- a/crates/prune/prune/src/event.rs +++ b/crates/prune/prune/src/event.rs @@ -1,6 +1,7 @@ +use std::{collections::BTreeMap, time::Duration}; + use alloy_primitives::BlockNumber; use reth_prune_types::{PruneProgress, PruneSegment}; -use std::{collections::BTreeMap, time::Duration}; /// An event emitted by a [Pruner][crate::Pruner]. #[derive(Debug, PartialEq, Eq, Clone)] diff --git a/crates/prune/prune/src/lib.rs b/crates/prune/prune/src/lib.rs index 38453385ee69c..376a91282f374 100644 --- a/crates/prune/prune/src/lib.rs +++ b/crates/prune/prune/src/lib.rs @@ -16,12 +16,12 @@ mod metrics; mod pruner; pub mod segments; -use crate::metrics::Metrics; pub use builder::PrunerBuilder; pub use error::PrunerError; pub use event::PrunerEvent; pub use pruner::{Pruner, PrunerResult, PrunerWithResult}; - // Re-export prune types #[doc(inline)] pub use reth_prune_types::*; + +use crate::metrics::Metrics; diff --git a/crates/prune/prune/src/metrics.rs b/crates/prune/prune/src/metrics.rs index 246dc317b035f..263a5c0c3bcbc 100644 --- a/crates/prune/prune/src/metrics.rs +++ b/crates/prune/prune/src/metrics.rs @@ -1,9 +1,10 @@ +use std::collections::HashMap; + use reth_metrics::{ metrics::{Gauge, Histogram}, Metrics, }; use reth_prune_types::PruneSegment; -use std::collections::HashMap; #[derive(Metrics)] #[metrics(scope = "pruner")] diff --git a/crates/prune/prune/src/pruner.rs b/crates/prune/prune/src/pruner.rs index 656aa69adeb2e..7e5acd61c3ec2 100644 --- a/crates/prune/prune/src/pruner.rs +++ b/crates/prune/prune/src/pruner.rs @@ -1,10 +1,10 @@ //! Support for pruning. -use crate::{ - segments, - segments::{PruneInput, Segment}, - Metrics, PrunerError, PrunerEvent, +use std::{ + collections::BTreeMap, + time::{Duration, Instant}, }; + use alloy_primitives::BlockNumber; use reth_db_api::database::Database; use reth_exex_types::FinishedExExHeight; @@ -14,13 +14,15 @@ use reth_provider::{ use reth_prune_types::{PruneLimiter, PruneMode, PruneProgress, PrunePurpose, PruneSegment}; use reth_static_file_types::StaticFileSegment; use reth_tokio_util::{EventSender, EventStream}; -use std::{ - collections::BTreeMap, - time::{Duration, Instant}, -}; use tokio::sync::watch; use tracing::debug; +use crate::{ + segments, + segments::{PruneInput, Segment}, + Metrics, PrunerError, PrunerEvent, +}; + /// Result of [`Pruner::run`] execution. pub type PrunerResult = Result; @@ -332,12 +334,13 @@ impl Pruner { #[cfg(test)] mod tests { - use crate::Pruner; use reth_chainspec::MAINNET; use reth_db::test_utils::{create_test_rw_db, create_test_static_files_dir}; use reth_exex_types::FinishedExExHeight; use reth_provider::{providers::StaticFileProvider, ProviderFactory}; + use crate::Pruner; + #[test] fn is_pruning_needed() { let db = create_test_rw_db(); diff --git a/crates/prune/prune/src/segments/account_history.rs b/crates/prune/prune/src/segments/account_history.rs index ab2800a317183..fe57e8a836349 100644 --- a/crates/prune/prune/src/segments/account_history.rs +++ b/crates/prune/prune/src/segments/account_history.rs @@ -1,14 +1,15 @@ +use reth_db::tables; +use reth_db_api::{database::Database, models::ShardedKey}; +use reth_provider::DatabaseProviderRW; +use reth_prune_types::{PruneInterruptReason, PruneMode, PruneProgress, PruneSegment}; +use tracing::{instrument, trace}; + use crate::{ segments::{ history::prune_history_indices, PruneInput, PruneOutput, PruneOutputCheckpoint, Segment, }, PrunerError, }; -use reth_db::tables; -use reth_db_api::{database::Database, models::ShardedKey}; -use reth_provider::DatabaseProviderRW; -use reth_prune_types::{PruneInterruptReason, PruneMode, PruneProgress, PruneSegment}; -use tracing::{instrument, trace}; /// Number of account history tables to prune in one step. /// @@ -102,10 +103,8 @@ impl Segment for AccountHistory { #[cfg(test)] mod tests { - use crate::segments::{ - account_history::ACCOUNT_HISTORY_TABLES_TO_PRUNE, AccountHistory, PruneInput, PruneOutput, - Segment, - }; + use std::{collections::BTreeMap, ops::AddAssign}; + use alloy_primitives::{BlockNumber, B256}; use assert_matches::assert_matches; use reth_db::{tables, BlockNumberList}; @@ -118,7 +117,11 @@ mod tests { generators, generators::{random_block_range, random_changeset_range, random_eoa_accounts}, }; - use std::{collections::BTreeMap, ops::AddAssign}; + + use crate::segments::{ + account_history::ACCOUNT_HISTORY_TABLES_TO_PRUNE, AccountHistory, PruneInput, PruneOutput, + Segment, + }; #[test] fn prune() { diff --git a/crates/prune/prune/src/segments/headers.rs b/crates/prune/prune/src/segments/headers.rs index 1c49fe8c10866..f3f35e4e75ca9 100644 --- a/crates/prune/prune/src/segments/headers.rs +++ b/crates/prune/prune/src/segments/headers.rs @@ -1,9 +1,6 @@ use std::num::NonZeroUsize; -use crate::{ - segments::{PruneInput, PruneOutput, PruneOutputCheckpoint, Segment}, - PrunerError, -}; +use alloy_primitives::BlockNumber; use itertools::Itertools; use reth_db::tables; use reth_db_api::{ @@ -11,12 +8,15 @@ use reth_db_api::{ database::Database, transaction::DbTxMut, }; - -use alloy_primitives::BlockNumber; use reth_provider::DatabaseProviderRW; use reth_prune_types::{PruneLimiter, PruneMode, PruneProgress, PruneSegment}; use tracing::{instrument, trace}; +use crate::{ + segments::{PruneInput, PruneOutput, PruneOutputCheckpoint, Segment}, + PrunerError, +}; + /// Number of header tables to prune in one step const HEADER_TABLES_TO_PRUNE: usize = 3; diff --git a/crates/prune/prune/src/segments/mod.rs b/crates/prune/prune/src/segments/mod.rs index 9dc6892658de5..f61da9d4e2944 100644 --- a/crates/prune/prune/src/segments/mod.rs +++ b/crates/prune/prune/src/segments/mod.rs @@ -9,7 +9,8 @@ mod storage_history; mod transaction_lookup; mod transactions; -use crate::PrunerError; +use std::{fmt::Debug, ops::RangeInclusive}; + pub use account_history::AccountHistory; use alloy_primitives::{BlockNumber, TxNumber}; pub use headers::Headers; @@ -24,12 +25,13 @@ use reth_prune_types::{ }; pub use sender_recovery::SenderRecovery; pub use set::SegmentSet; -use std::{fmt::Debug, ops::RangeInclusive}; pub use storage_history::StorageHistory; use tracing::error; pub use transaction_lookup::TransactionLookup; pub use transactions::Transactions; +use crate::PrunerError; + /// A segment represents a pruning of some portion of the data. /// /// Segments are called from [Pruner](crate::Pruner) with the following lifecycle: diff --git a/crates/prune/prune/src/segments/receipts.rs b/crates/prune/prune/src/segments/receipts.rs index 5b8118778898d..441da838f40b2 100644 --- a/crates/prune/prune/src/segments/receipts.rs +++ b/crates/prune/prune/src/segments/receipts.rs @@ -1,7 +1,3 @@ -use crate::{ - segments::{PruneInput, PruneOutput, PruneOutputCheckpoint, Segment}, - PrunerError, -}; use reth_db::tables; use reth_db_api::database::Database; use reth_provider::{ @@ -11,6 +7,11 @@ use reth_provider::{ use reth_prune_types::{PruneCheckpoint, PruneMode, PruneProgress, PruneSegment}; use tracing::{instrument, trace}; +use crate::{ + segments::{PruneInput, PruneOutput, PruneOutputCheckpoint, Segment}, + PrunerError, +}; + #[derive(Debug)] pub struct Receipts { mode: PruneMode, @@ -93,7 +94,8 @@ impl Segment for Receipts { #[cfg(test)] mod tests { - use crate::segments::{PruneInput, PruneOutput, Receipts, Segment}; + use std::ops::Sub; + use alloy_primitives::{BlockNumber, TxNumber, B256}; use assert_matches::assert_matches; use itertools::{ @@ -110,7 +112,8 @@ mod tests { generators, generators::{random_block_range, random_receipt}, }; - use std::ops::Sub; + + use crate::segments::{PruneInput, PruneOutput, Receipts, Segment}; #[test] fn prune() { diff --git a/crates/prune/prune/src/segments/receipts_by_logs.rs b/crates/prune/prune/src/segments/receipts_by_logs.rs index 63b5941c34b50..252a68f373b60 100644 --- a/crates/prune/prune/src/segments/receipts_by_logs.rs +++ b/crates/prune/prune/src/segments/receipts_by_logs.rs @@ -1,7 +1,3 @@ -use crate::{ - segments::{PruneInput, PruneOutput, Segment}, - PrunerError, -}; use reth_db::tables; use reth_db_api::database::Database; use reth_provider::{BlockReader, DatabaseProviderRW, PruneCheckpointWriter, TransactionsProvider}; @@ -11,6 +7,11 @@ use reth_prune_types::{ }; use tracing::{instrument, trace}; +use crate::{ + segments::{PruneInput, PruneOutput, Segment}, + PrunerError, +}; + #[derive(Debug)] pub struct ReceiptsByLogs { config: ReceiptsLogPruneConfig, @@ -215,7 +216,8 @@ impl Segment for ReceiptsByLogs { #[cfg(test)] mod tests { - use crate::segments::{receipts_by_logs::ReceiptsByLogs, PruneInput, Segment}; + use std::collections::BTreeMap; + use alloy_primitives::B256; use assert_matches::assert_matches; use reth_db::tables; @@ -227,7 +229,8 @@ mod tests { generators, generators::{random_block_range, random_eoa_account, random_log, random_receipt}, }; - use std::collections::BTreeMap; + + use crate::segments::{receipts_by_logs::ReceiptsByLogs, PruneInput, Segment}; #[test] fn prune_receipts_by_logs() { diff --git a/crates/prune/prune/src/segments/sender_recovery.rs b/crates/prune/prune/src/segments/sender_recovery.rs index 94ef6ffb7c78d..0ec0033f78ee6 100644 --- a/crates/prune/prune/src/segments/sender_recovery.rs +++ b/crates/prune/prune/src/segments/sender_recovery.rs @@ -1,13 +1,14 @@ -use crate::{ - segments::{PruneInput, PruneOutput, PruneOutputCheckpoint, Segment}, - PrunerError, -}; use reth_db::tables; use reth_db_api::database::Database; use reth_provider::{DatabaseProviderRW, TransactionsProvider}; use reth_prune_types::{PruneMode, PruneProgress, PruneSegment}; use tracing::{instrument, trace}; +use crate::{ + segments::{PruneInput, PruneOutput, PruneOutputCheckpoint, Segment}, + PrunerError, +}; + #[derive(Debug)] pub struct SenderRecovery { mode: PruneMode, @@ -76,7 +77,8 @@ impl Segment for SenderRecovery { #[cfg(test)] mod tests { - use crate::segments::{PruneInput, PruneOutput, Segment, SenderRecovery}; + use std::ops::Sub; + use alloy_primitives::{BlockNumber, TxNumber, B256}; use assert_matches::assert_matches; use itertools::{ @@ -88,7 +90,8 @@ mod tests { use reth_prune_types::{PruneCheckpoint, PruneLimiter, PruneMode, PruneProgress, PruneSegment}; use reth_stages::test_utils::{StorageKind, TestStageDB}; use reth_testing_utils::{generators, generators::random_block_range}; - use std::ops::Sub; + + use crate::segments::{PruneInput, PruneOutput, Segment, SenderRecovery}; #[test] fn prune() { diff --git a/crates/prune/prune/src/segments/set.rs b/crates/prune/prune/src/segments/set.rs index f5b60f2695aa4..b748acd0757e5 100644 --- a/crates/prune/prune/src/segments/set.rs +++ b/crates/prune/prune/src/segments/set.rs @@ -1,9 +1,10 @@ +use reth_db_api::database::Database; +use reth_prune_types::PruneModes; + use crate::segments::{ AccountHistory, Receipts, ReceiptsByLogs, Segment, SenderRecovery, StorageHistory, TransactionLookup, }; -use reth_db_api::database::Database; -use reth_prune_types::PruneModes; /// Collection of [Segment]. Thread-safe, allocated on the heap. #[derive(Debug)] diff --git a/crates/prune/prune/src/segments/storage_history.rs b/crates/prune/prune/src/segments/storage_history.rs index 3e7ad86a7da46..b8d32bbb4c728 100644 --- a/crates/prune/prune/src/segments/storage_history.rs +++ b/crates/prune/prune/src/segments/storage_history.rs @@ -1,9 +1,3 @@ -use crate::{ - segments::{ - history::prune_history_indices, PruneInput, PruneOutput, PruneOutputCheckpoint, Segment, - }, - PrunerError, -}; use reth_db::tables; use reth_db_api::{ database::Database, @@ -13,6 +7,13 @@ use reth_provider::DatabaseProviderRW; use reth_prune_types::{PruneInterruptReason, PruneMode, PruneProgress, PruneSegment}; use tracing::{instrument, trace}; +use crate::{ + segments::{ + history::prune_history_indices, PruneInput, PruneOutput, PruneOutputCheckpoint, Segment, + }, + PrunerError, +}; + /// Number of storage history tables to prune in one step /// /// Storage History consists of two tables: [`tables::StorageChangeSets`] and @@ -105,10 +106,8 @@ impl Segment for StorageHistory { #[cfg(test)] mod tests { - use crate::segments::{ - storage_history::STORAGE_HISTORY_TABLES_TO_PRUNE, PruneInput, PruneOutput, Segment, - StorageHistory, - }; + use std::{collections::BTreeMap, ops::AddAssign}; + use alloy_primitives::{BlockNumber, B256}; use assert_matches::assert_matches; use reth_db::{tables, BlockNumberList}; @@ -119,7 +118,11 @@ mod tests { generators, generators::{random_block_range, random_changeset_range, random_eoa_accounts}, }; - use std::{collections::BTreeMap, ops::AddAssign}; + + use crate::segments::{ + storage_history::STORAGE_HISTORY_TABLES_TO_PRUNE, PruneInput, PruneOutput, Segment, + StorageHistory, + }; #[test] fn prune() { diff --git a/crates/prune/prune/src/segments/transaction_lookup.rs b/crates/prune/prune/src/segments/transaction_lookup.rs index 457f551c167ba..7fab452368b27 100644 --- a/crates/prune/prune/src/segments/transaction_lookup.rs +++ b/crates/prune/prune/src/segments/transaction_lookup.rs @@ -1,7 +1,3 @@ -use crate::{ - segments::{PruneInput, PruneOutput, PruneOutputCheckpoint, Segment}, - PrunerError, -}; use rayon::prelude::*; use reth_db::tables; use reth_db_api::database::Database; @@ -9,6 +5,11 @@ use reth_provider::{DatabaseProviderRW, TransactionsProvider}; use reth_prune_types::{PruneMode, PruneProgress, PruneSegment}; use tracing::{instrument, trace}; +use crate::{ + segments::{PruneInput, PruneOutput, PruneOutputCheckpoint, Segment}, + PrunerError, +}; + #[derive(Debug)] pub struct TransactionLookup { mode: PruneMode, @@ -103,7 +104,8 @@ impl Segment for TransactionLookup { #[cfg(test)] mod tests { - use crate::segments::{PruneInput, PruneOutput, Segment, TransactionLookup}; + use std::ops::Sub; + use alloy_primitives::{BlockNumber, TxNumber, B256}; use assert_matches::assert_matches; use itertools::{ @@ -117,7 +119,8 @@ mod tests { }; use reth_stages::test_utils::{StorageKind, TestStageDB}; use reth_testing_utils::{generators, generators::random_block_range}; - use std::ops::Sub; + + use crate::segments::{PruneInput, PruneOutput, Segment, TransactionLookup}; #[test] fn prune() { diff --git a/crates/prune/prune/src/segments/transactions.rs b/crates/prune/prune/src/segments/transactions.rs index fd24a380de5b8..35c41aae3fd35 100644 --- a/crates/prune/prune/src/segments/transactions.rs +++ b/crates/prune/prune/src/segments/transactions.rs @@ -1,13 +1,14 @@ -use crate::{ - segments::{PruneInput, PruneOutput, PruneOutputCheckpoint, Segment}, - PrunerError, -}; use reth_db::tables; use reth_db_api::database::Database; use reth_provider::{DatabaseProviderRW, TransactionsProvider}; use reth_prune_types::{PruneMode, PruneProgress, PruneSegment}; use tracing::{instrument, trace}; +use crate::{ + segments::{PruneInput, PruneOutput, PruneOutputCheckpoint, Segment}, + PrunerError, +}; + #[derive(Debug)] pub struct Transactions { mode: PruneMode, @@ -75,7 +76,8 @@ impl Segment for Transactions { #[cfg(test)] mod tests { - use crate::segments::{PruneInput, PruneOutput, Segment, Transactions}; + use std::ops::Sub; + use alloy_primitives::{BlockNumber, TxNumber, B256}; use assert_matches::assert_matches; use itertools::{ @@ -89,7 +91,8 @@ mod tests { }; use reth_stages::test_utils::{StorageKind, TestStageDB}; use reth_testing_utils::{generators, generators::random_block_range}; - use std::ops::Sub; + + use crate::segments::{PruneInput, PruneOutput, Segment, Transactions}; #[test] fn prune() { diff --git a/crates/prune/types/src/checkpoint.rs b/crates/prune/types/src/checkpoint.rs index 0e27dd1465e9f..9d36e2c4c4e4a 100644 --- a/crates/prune/types/src/checkpoint.rs +++ b/crates/prune/types/src/checkpoint.rs @@ -1,7 +1,8 @@ -use crate::PruneMode; use alloy_primitives::{BlockNumber, TxNumber}; use reth_codecs::{main_codec, Compact}; +use crate::PruneMode; + /// Saves the pruning progress of a stage. #[main_codec] #[derive(Debug, PartialEq, Eq, Clone, Copy)] diff --git a/crates/prune/types/src/lib.rs b/crates/prune/types/src/lib.rs index 82563010f165e..affb55d1081eb 100644 --- a/crates/prune/types/src/lib.rs +++ b/crates/prune/types/src/lib.rs @@ -14,16 +14,16 @@ mod mode; mod segment; mod target; +use std::collections::BTreeMap; + +use alloy_primitives::{Address, BlockNumber}; pub use checkpoint::PruneCheckpoint; pub use limiter::PruneLimiter; pub use mode::PruneMode; pub use segment::{PrunePurpose, PruneSegment, PruneSegmentError}; use serde::{Deserialize, Serialize}; -use std::collections::BTreeMap; pub use target::{PruneModes, MINIMUM_PRUNING_DISTANCE}; -use alloy_primitives::{Address, BlockNumber}; - /// Configuration for pruning receipts not associated with logs emitted by the specified contracts. #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] pub struct ReceiptsLogPruneConfig(pub BTreeMap); diff --git a/crates/prune/types/src/mode.rs b/crates/prune/types/src/mode.rs index 514e96b8305c3..8004114064b00 100644 --- a/crates/prune/types/src/mode.rs +++ b/crates/prune/types/src/mode.rs @@ -1,7 +1,8 @@ -use crate::{segment::PrunePurpose, PruneSegment, PruneSegmentError}; use alloy_primitives::BlockNumber; use reth_codecs::{main_codec, Compact}; +use crate::{segment::PrunePurpose, PruneSegment, PruneSegmentError}; + /// Prune mode. #[main_codec] #[derive(Debug, PartialEq, Eq, Clone, Copy)] @@ -74,11 +75,12 @@ impl Default for PruneMode { #[cfg(test)] mod tests { + use assert_matches::assert_matches; + use serde::Deserialize; + use crate::{ PruneMode, PrunePurpose, PruneSegment, PruneSegmentError, MINIMUM_PRUNING_DISTANCE, }; - use assert_matches::assert_matches; - use serde::Deserialize; #[test] fn test_prune_target_block() { diff --git a/crates/prune/types/src/segment.rs b/crates/prune/types/src/segment.rs index 867fc4ca18634..951e197519e58 100644 --- a/crates/prune/types/src/segment.rs +++ b/crates/prune/types/src/segment.rs @@ -1,8 +1,9 @@ -use crate::MINIMUM_PRUNING_DISTANCE; use derive_more::Display; use reth_codecs::{main_codec, Compact}; use thiserror::Error; +use crate::MINIMUM_PRUNING_DISTANCE; + /// Segment of the data that can be pruned. #[main_codec] #[derive(Debug, Display, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] diff --git a/crates/prune/types/src/target.rs b/crates/prune/types/src/target.rs index 9ff9034b917e4..4de0427f1080a 100644 --- a/crates/prune/types/src/target.rs +++ b/crates/prune/types/src/target.rs @@ -1,6 +1,7 @@ -use crate::{PruneMode, ReceiptsLogPruneConfig}; use serde::{Deserialize, Deserializer, Serialize}; +use crate::{PruneMode, ReceiptsLogPruneConfig}; + /// Minimum distance from the tip necessary for the node to work correctly: /// 1. Minimum 2 epochs (32 blocks per epoch) required to handle any reorg according to the /// consensus protocol. @@ -100,10 +101,11 @@ fn deserialize_opt_prune_mode_with_min_blocks<'de, const MIN_BLOCKS: u64, D: Des #[cfg(test)] mod tests { - use super::*; use assert_matches::assert_matches; use serde::Deserialize; + use super::*; + #[test] fn test_deserialize_opt_prune_mode_with_min_blocks() { #[derive(Debug, Deserialize, PartialEq, Eq)] diff --git a/crates/revm/src/batch.rs b/crates/revm/src/batch.rs index f2903a4f47cfd..baabaa94756df 100644 --- a/crates/revm/src/batch.rs +++ b/crates/revm/src/batch.rs @@ -1,16 +1,17 @@ //! Helper for handling execution of multiple blocks. -use crate::{precompile::Address, primitives::alloy_primitives::BlockNumber}; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; use core::time::Duration; +use std::collections::HashSet; + use reth_execution_errors::BlockExecutionError; use reth_primitives::{Receipt, Receipts, Request, Requests}; use reth_prune_types::{PruneMode, PruneModes, PruneSegmentError, MINIMUM_PRUNING_DISTANCE}; use revm::db::states::bundle_state::BundleRetention; -use std::collections::HashSet; use tracing::debug; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; +use crate::{precompile::Address, primitives::alloy_primitives::BlockNumber}; /// Takes care of: /// - recording receipts during execution of multiple blocks. diff --git a/crates/revm/src/database.rs b/crates/revm/src/database.rs index 3b31788dbdaf7..3e52fd0df8b22 100644 --- a/crates/revm/src/database.rs +++ b/crates/revm/src/database.rs @@ -1,5 +1,5 @@ -use crate::primitives::alloy_primitives::{BlockNumber, StorageKey, StorageValue}; use core::ops::{Deref, DerefMut}; + use reth_primitives::{Account, Address, B256, KECCAK_EMPTY, U256}; use reth_storage_errors::provider::{ProviderError, ProviderResult}; use revm::{ @@ -8,6 +8,8 @@ use revm::{ Database, }; +use crate::primitives::alloy_primitives::{BlockNumber, StorageKey, StorageValue}; + /// A helper trait responsible for providing that necessary state for the EVM execution. /// /// This servers as the data layer for [Database]. diff --git a/crates/revm/src/state_change.rs b/crates/revm/src/state_change.rs index 4505d2ee97612..c5745d1b1724f 100644 --- a/crates/revm/src/state_change.rs +++ b/crates/revm/src/state_change.rs @@ -1,3 +1,8 @@ +#[cfg(not(feature = "std"))] +use alloc::{boxed::Box, format, string::ToString, vec::Vec}; +#[cfg(feature = "std")] +use std::collections::HashMap; + use alloy_eips::{ eip2935::{HISTORY_STORAGE_ADDRESS, HISTORY_STORAGE_CODE}, eip7002::WithdrawalRequest, @@ -26,11 +31,6 @@ use revm::{ // reuse revm's hashbrown implementation for no-std #[cfg(not(feature = "std"))] use crate::precompile::HashMap; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, string::ToString, vec::Vec}; - -#[cfg(feature = "std")] -use std::collections::HashMap; /// Collect all balance changes at the end of the block. /// diff --git a/crates/revm/src/test_utils.rs b/crates/revm/src/test_utils.rs index 90ac4ea0466e1..3f57c6cba055e 100644 --- a/crates/revm/src/test_utils.rs +++ b/crates/revm/src/test_utils.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use reth_primitives::{ keccak256, Account, Address, BlockNumber, Bytecode, Bytes, StorageKey, B256, U256, }; @@ -5,7 +7,6 @@ use reth_storage_api::{AccountReader, BlockHashReader, StateProvider, StateRootP use reth_storage_errors::provider::ProviderResult; use reth_trie::{updates::TrieUpdates, AccountProof}; use revm::db::BundleState; -use std::collections::HashMap; /// Mock state for testing #[derive(Debug, Default, Clone, Eq, PartialEq)] diff --git a/crates/rpc/ipc/src/client/mod.rs b/crates/rpc/ipc/src/client/mod.rs index e8eff9c8f454f..cae7a5a30982f 100644 --- a/crates/rpc/ipc/src/client/mod.rs +++ b/crates/rpc/ipc/src/client/mod.rs @@ -1,6 +1,7 @@ //! [`jsonrpsee`] transport adapter implementation for IPC. -use crate::stream_codec::StreamCodec; +use std::io; + use futures::{StreamExt, TryFutureExt}; use interprocess::local_socket::{ tokio::{prelude::*, RecvHalf, SendHalf}, @@ -10,10 +11,11 @@ use jsonrpsee::{ async_client::{Client, ClientBuilder}, core::client::{ReceivedMessage, TransportReceiverT, TransportSenderT}, }; -use std::io; use tokio::io::AsyncWriteExt; use tokio_util::codec::FramedRead; +use crate::stream_codec::StreamCodec; + /// Sending end of IPC transport. #[derive(Debug)] pub(crate) struct Sender { diff --git a/crates/rpc/ipc/src/server/connection.rs b/crates/rpc/ipc/src/server/connection.rs index 2aadc6e2bca0d..b48060a5c3736 100644 --- a/crates/rpc/ipc/src/server/connection.rs +++ b/crates/rpc/ipc/src/server/connection.rs @@ -1,7 +1,5 @@ //! A IPC connection. -use crate::stream_codec::StreamCodec; -use futures::{stream::FuturesUnordered, FutureExt, Sink, Stream}; use std::{ collections::VecDeque, future::Future, @@ -9,10 +7,14 @@ use std::{ pin::Pin, task::{Context, Poll}, }; + +use futures::{stream::FuturesUnordered, FutureExt, Sink, Stream}; use tokio::io::{AsyncRead, AsyncWrite}; use tokio_util::codec::Framed; use tower::Service; +use crate::stream_codec::StreamCodec; + pub(crate) type JsonRpcStream = Framed; #[pin_project::pin_project] diff --git a/crates/rpc/ipc/src/server/ipc.rs b/crates/rpc/ipc/src/server/ipc.rs index 33ed8d2d5531d..093d7c45af401 100644 --- a/crates/rpc/ipc/src/server/ipc.rs +++ b/crates/rpc/ipc/src/server/ipc.rs @@ -1,5 +1,7 @@ //! IPC request handling adapted from [`jsonrpsee`] http request handling +use std::sync::Arc; + use futures::{stream::FuturesOrdered, StreamExt}; use jsonrpsee::{ batch_response_error, @@ -15,7 +17,6 @@ use jsonrpsee::{ }, BatchResponseBuilder, MethodResponse, ResponsePayload, }; -use std::sync::Arc; use tokio::sync::OwnedSemaphorePermit; use tokio_util::either::Either; use tracing::instrument; diff --git a/crates/rpc/ipc/src/server/mod.rs b/crates/rpc/ipc/src/server/mod.rs index 6dff8a8afae09..04b37a89c9d97 100644 --- a/crates/rpc/ipc/src/server/mod.rs +++ b/crates/rpc/ipc/src/server/mod.rs @@ -1,6 +1,13 @@ //! JSON-RPC IPC server implementation -use crate::server::connection::{IpcConn, JsonRpcStream}; +use std::{ + future::Future, + io, + pin::{pin, Pin}, + sync::Arc, + task::{Context, Poll}, +}; + use futures::StreamExt; use futures_util::future::Either; use interprocess::local_socket::{ @@ -17,19 +24,21 @@ use jsonrpsee::{ }, BoundedSubscriptions, MethodSink, Methods, }; -use std::{ - future::Future, - io, - pin::{pin, Pin}, - sync::Arc, - task::{Context, Poll}, -}; use tokio::{ io::{AsyncRead, AsyncWrite, AsyncWriteExt}, - sync::oneshot, + sync::{mpsc, oneshot}, +}; +use tokio_stream::wrappers::ReceiverStream; +use tower::{ + layer::{ + util::{Identity, Stack}, + LayerFn, + }, + Layer, Service, }; -use tower::{layer::util::Identity, Layer, Service}; use tracing::{debug, instrument, trace, warn, Instrument}; + +use crate::server::connection::{IpcConn, JsonRpcStream}; // re-export so can be used during builder setup use crate::{ server::{ @@ -38,9 +47,6 @@ use crate::{ }, stream_codec::StreamCodec, }; -use tokio::sync::mpsc; -use tokio_stream::wrappers::ReceiverStream; -use tower::layer::{util::Stack, LayerFn}; mod connection; mod ipc; @@ -802,8 +808,8 @@ pub fn dummy_name() -> String { #[cfg(test)] mod tests { - use super::*; - use crate::client::IpcClientBuilder; + use std::pin::pin; + use futures::future::select; use jsonrpsee::{ core::{ @@ -816,10 +822,12 @@ mod tests { PendingSubscriptionSink, RpcModule, SubscriptionMessage, }; use reth_tracing::init_test_tracing; - use std::pin::pin; use tokio::sync::broadcast; use tokio_stream::wrappers::BroadcastStream; + use super::*; + use crate::client::IpcClientBuilder; + async fn pipe_from_stream_with_bounded_buffer( pending: PendingSubscriptionSink, stream: BroadcastStream, diff --git a/crates/rpc/ipc/src/server/rpc_service.rs b/crates/rpc/ipc/src/server/rpc_service.rs index 2f645605da72c..57428240509e7 100644 --- a/crates/rpc/ipc/src/server/rpc_service.rs +++ b/crates/rpc/ipc/src/server/rpc_service.rs @@ -1,4 +1,6 @@ //! JSON-RPC service middleware. +use std::sync::Arc; + use futures_util::future::BoxFuture; use jsonrpsee::{ server::{ @@ -9,7 +11,6 @@ use jsonrpsee::{ BoundedSubscriptions, ConnectionId, Extensions, MethodCallback, MethodResponse, MethodSink, Methods, SubscriptionState, }; -use std::sync::Arc; /// JSON-RPC service middleware. #[derive(Clone, Debug)] diff --git a/crates/rpc/ipc/src/stream_codec.rs b/crates/rpc/ipc/src/stream_codec.rs index e6e035f1d512b..4392f9df2e656 100644 --- a/crates/rpc/ipc/src/stream_codec.rs +++ b/crates/rpc/ipc/src/stream_codec.rs @@ -27,9 +27,10 @@ // This basis of this file has been taken from the deprecated jsonrpc codebase: // https://github.com/paritytech/jsonrpc -use bytes::BytesMut; use std::{io, str}; +use bytes::BytesMut; + /// Separator for enveloping messages in streaming codecs #[derive(Debug, Clone)] pub enum Separator { @@ -140,10 +141,11 @@ impl tokio_util::codec::Encoder for StreamCodec { #[cfg(test)] mod tests { - use super::*; use bytes::BufMut; use tokio_util::codec::Decoder; + use super::*; + #[test] fn simple_encode() { let mut buf = BytesMut::with_capacity(2048); diff --git a/crates/rpc/rpc-api/src/anvil.rs b/crates/rpc/rpc-api/src/anvil.rs index 56416d094136f..cd2cfff662fb0 100644 --- a/crates/rpc/rpc-api/src/anvil.rs +++ b/crates/rpc/rpc-api/src/anvil.rs @@ -1,5 +1,4 @@ use jsonrpsee::{core::RpcResult, proc_macros::rpc}; - use reth_primitives::{Address, Bytes, B256, U256}; use reth_rpc_types::{ anvil::{Forking, Metadata, MineOptions, NodeInfo}, diff --git a/crates/rpc/rpc-api/src/optimism.rs b/crates/rpc/rpc-api/src/optimism.rs index 783bd1760bc47..c48c62a91064b 100644 --- a/crates/rpc/rpc-api/src/optimism.rs +++ b/crates/rpc/rpc-api/src/optimism.rs @@ -1,10 +1,11 @@ #![allow(missing_docs)] #![allow(unreachable_pub)] +use std::{collections::HashMap, net::IpAddr}; + use jsonrpsee::{core::RpcResult, proc_macros::rpc}; use reth_primitives::{Address, BlockNumber, ChainId, B256}; use reth_rpc_types::{BlockId, BlockNumberOrTag}; use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, net::IpAddr}; // https://github.com/ethereum-optimism/optimism/blob/develop/op-service/eth/id.go#L33 #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] @@ -308,9 +309,10 @@ pub trait OpAdminApi { #[cfg(test)] mod tests { - use super::*; use serde_json::json; + use super::*; + fn test_helper<'a, T>(json_str: &'a str) where T: Serialize + Deserialize<'a>, diff --git a/crates/rpc/rpc-api/src/reth.rs b/crates/rpc/rpc-api/src/reth.rs index 1e9c4314ab141..9879b3f990eab 100644 --- a/crates/rpc/rpc-api/src/reth.rs +++ b/crates/rpc/rpc-api/src/reth.rs @@ -1,6 +1,7 @@ +use std::collections::HashMap; + use jsonrpsee::{core::RpcResult, proc_macros::rpc}; use reth_primitives::{Address, BlockId, U256}; -use std::collections::HashMap; /// Reth API namespace for reth-specific methods #[cfg_attr(not(feature = "client"), rpc(server, namespace = "reth"))] diff --git a/crates/rpc/rpc-api/src/trace.rs b/crates/rpc/rpc-api/src/trace.rs index aa2a5693a8651..a3968522c9f0b 100644 --- a/crates/rpc/rpc-api/src/trace.rs +++ b/crates/rpc/rpc-api/src/trace.rs @@ -1,3 +1,5 @@ +use std::collections::HashSet; + use jsonrpsee::{core::RpcResult, proc_macros::rpc}; use reth_primitives::{BlockId, Bytes, B256}; use reth_rpc_types::{ @@ -9,7 +11,6 @@ use reth_rpc_types::{ }, BlockOverrides, Index, TransactionRequest, }; -use std::collections::HashSet; /// Ethereum trace API #[cfg_attr(not(feature = "client"), rpc(server, namespace = "trace"))] diff --git a/crates/rpc/rpc-builder/src/auth.rs b/crates/rpc/rpc-builder/src/auth.rs index 1e8ef8f56a180..5e3155e498ac5 100644 --- a/crates/rpc/rpc-builder/src/auth.rs +++ b/crates/rpc/rpc-builder/src/auth.rs @@ -1,5 +1,7 @@ -use crate::error::{RpcError, ServerKind}; +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; + use http::header::AUTHORIZATION; +pub use jsonrpsee::server::ServerBuilder; use jsonrpsee::{ core::RegisterMethodError, http_client::{transport::HttpBackend, HeaderMap}, @@ -7,6 +9,7 @@ use jsonrpsee::{ Methods, }; use reth_engine_primitives::EngineTypes; +pub use reth_ipc::server::Builder as IpcServerBuilder; use reth_rpc::EthSubscriptionIdProvider; use reth_rpc_api::servers::*; use reth_rpc_layer::{ @@ -14,11 +17,9 @@ use reth_rpc_layer::{ JwtSecret, }; use reth_rpc_server_types::constants; -use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use tower::layer::util::Identity; -pub use jsonrpsee::server::ServerBuilder; -pub use reth_ipc::server::Builder as IpcServerBuilder; +use crate::error::{RpcError, ServerKind}; /// Server configuration for the auth server. #[derive(Debug)] diff --git a/crates/rpc/rpc-builder/src/config.rs b/crates/rpc/rpc-builder/src/config.rs index 45cad81cd7f04..3dca2098bdf6c 100644 --- a/crates/rpc/rpc-builder/src/config.rs +++ b/crates/rpc/rpc-builder/src/config.rs @@ -1,16 +1,18 @@ -use crate::{ - auth::AuthServerConfig, error::RpcError, EthConfig, IpcServerBuilder, RpcModuleConfig, - RpcServerConfig, TransportRpcModuleConfig, -}; +use std::{net::SocketAddr, path::PathBuf}; + use jsonrpsee::server::ServerBuilder; use reth_node_core::{args::RpcServerArgs, utils::get_or_create_jwt_secret_from_path}; use reth_rpc::eth::{cache::EthStateCacheConfig, gas_oracle::GasPriceOracleConfig}; use reth_rpc_layer::{JwtError, JwtSecret}; use reth_rpc_server_types::RpcModuleSelection; -use std::{net::SocketAddr, path::PathBuf}; use tower::layer::util::Identity; use tracing::debug; +use crate::{ + auth::AuthServerConfig, error::RpcError, EthConfig, IpcServerBuilder, RpcModuleConfig, + RpcServerConfig, TransportRpcModuleConfig, +}; + /// A trait that provides a configured RPC server. /// /// This provides all basic config values for the RPC server and is implemented by the @@ -214,11 +216,12 @@ impl RethRpcServerConfig for RpcServerArgs { #[cfg(test)] mod tests { + use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; + use clap::{Args, Parser}; use reth_node_core::args::RpcServerArgs; use reth_rpc::eth::RPC_DEFAULT_GAS_CAP; use reth_rpc_server_types::{constants, RethRpcModule, RpcModuleSelection}; - use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; use crate::config::RethRpcServerConfig; diff --git a/crates/rpc/rpc-builder/src/error.rs b/crates/rpc/rpc-builder/src/error.rs index cc55d232c9053..ab198b5c30e85 100644 --- a/crates/rpc/rpc-builder/src/error.rs +++ b/crates/rpc/rpc-builder/src/error.rs @@ -1,11 +1,13 @@ -use crate::{cors::CorsDomainError, RethRpcModule}; -use reth_ipc::server::IpcServerStartError; use std::{ collections::HashSet, io::{self, ErrorKind}, net::SocketAddr, }; +use reth_ipc::server::IpcServerStartError; + +use crate::{cors::CorsDomainError, RethRpcModule}; + /// Rpc server kind. #[derive(Debug, PartialEq, Eq, Copy, Clone)] pub enum ServerKind { @@ -131,8 +133,9 @@ pub enum WsHttpSamePortError { #[cfg(test)] mod tests { - use super::*; use std::net::{Ipv4Addr, SocketAddrV4}; + + use super::*; #[test] fn test_address_in_use_message() { let addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 1234)); diff --git a/crates/rpc/rpc-builder/src/eth.rs b/crates/rpc/rpc-builder/src/eth.rs index 224301966b235..5ee3b40dd9908 100644 --- a/crates/rpc/rpc-builder/src/eth.rs +++ b/crates/rpc/rpc-builder/src/eth.rs @@ -1,4 +1,5 @@ -use crate::RpcModuleConfig; +use std::sync::Arc; + use reth_evm::ConfigureEvm; use reth_network_api::{NetworkInfo, Peers}; use reth_provider::{ @@ -21,7 +22,8 @@ use reth_rpc_server_types::constants::{ use reth_tasks::{pool::BlockingTaskPool, TaskSpawner}; use reth_transaction_pool::TransactionPool; use serde::{Deserialize, Serialize}; -use std::sync::Arc; + +use crate::RpcModuleConfig; /// All handlers for the `eth` namespace #[derive(Debug, Clone)] diff --git a/crates/rpc/rpc-builder/src/lib.rs b/crates/rpc/rpc-builder/src/lib.rs index 7257b3be35ab3..ac91b1d658b93 100644 --- a/crates/rpc/rpc-builder/src/lib.rs +++ b/crates/rpc/rpc-builder/src/lib.rs @@ -155,15 +155,18 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -use crate::{ - auth::AuthRpcModule, - cors::CorsDomainError, - error::WsHttpSamePortError, - eth::{EthHandlersBuilder, EthHandlersConfig}, - metrics::RpcRequestMetrics, +use std::{ + collections::HashMap, + fmt, + net::{Ipv4Addr, SocketAddr, SocketAddrV4}, + sync::Arc, + time::{Duration, SystemTime, UNIX_EPOCH}, }; + use error::{ConflictingModules, RpcError, ServerKind}; use http::{header::AUTHORIZATION, HeaderMap}; +// re-export for convenience +pub use jsonrpsee::server::ServerBuilder; use jsonrpsee::{ core::RegisterMethodError, server::{AlreadyStoppedError, IdProvider, RpcServiceBuilder, Server, ServerHandle}, @@ -172,6 +175,9 @@ use jsonrpsee::{ use reth_engine_primitives::EngineTypes; use reth_evm::ConfigureEvm; use reth_ipc::server::IpcServer; +pub use reth_ipc::server::{ + Builder as IpcServerBuilder, RpcServiceBuilder as IpcRpcServiceBuilder, +}; use reth_network_api::{noop::NoopNetwork, NetworkInfo, Peers}; use reth_provider::{ AccountReader, BlockReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider, @@ -184,26 +190,21 @@ use reth_rpc::{ }; use reth_rpc_api::servers::*; use reth_rpc_layer::{AuthLayer, Claims, JwtAuthValidator, JwtSecret}; +pub use reth_rpc_server_types::{constants, RethRpcModule, RpcModuleSelection}; use reth_tasks::{pool::BlockingTaskGuard, TaskSpawner, TokioTaskExecutor}; use reth_transaction_pool::{noop::NoopTransactionPool, TransactionPool}; use serde::{Deserialize, Serialize}; -use std::{ - collections::HashMap, - fmt, - net::{Ipv4Addr, SocketAddr, SocketAddrV4}, - sync::Arc, - time::{Duration, SystemTime, UNIX_EPOCH}, -}; +pub use tower::layer::util::{Identity, Stack}; use tower_http::cors::CorsLayer; use tracing::{instrument, trace}; -// re-export for convenience -pub use jsonrpsee::server::ServerBuilder; -pub use reth_ipc::server::{ - Builder as IpcServerBuilder, RpcServiceBuilder as IpcRpcServiceBuilder, +use crate::{ + auth::AuthRpcModule, + cors::CorsDomainError, + error::WsHttpSamePortError, + eth::{EthHandlersBuilder, EthHandlersConfig}, + metrics::RpcRequestMetrics, }; -pub use reth_rpc_server_types::{constants, RethRpcModule, RpcModuleSelection}; -pub use tower::layer::util::{Identity, Stack}; /// Auth server utilities. pub mod auth; diff --git a/crates/rpc/rpc-builder/src/metrics.rs b/crates/rpc/rpc-builder/src/metrics.rs index 4b638a7b36d76..4a2447b130dc1 100644 --- a/crates/rpc/rpc-builder/src/metrics.rs +++ b/crates/rpc/rpc-builder/src/metrics.rs @@ -1,8 +1,3 @@ -use jsonrpsee::{server::middleware::rpc::RpcServiceT, types::Request, MethodResponse, RpcModule}; -use reth_metrics::{ - metrics::{Counter, Histogram}, - Metrics, -}; use std::{ collections::HashMap, future::Future, @@ -11,6 +6,12 @@ use std::{ task::{Context, Poll}, time::Instant, }; + +use jsonrpsee::{server::middleware::rpc::RpcServiceT, types::Request, MethodResponse, RpcModule}; +use reth_metrics::{ + metrics::{Counter, Histogram}, + Metrics, +}; use tower::Layer; /// Metrics for the RPC server. diff --git a/crates/rpc/rpc-builder/tests/it/auth.rs b/crates/rpc/rpc-builder/tests/it/auth.rs index 631ea813578db..a7f62c71de869 100644 --- a/crates/rpc/rpc-builder/tests/it/auth.rs +++ b/crates/rpc/rpc-builder/tests/it/auth.rs @@ -1,6 +1,5 @@ //! Auth server tests -use crate::utils::launch_auth; use jsonrpsee::core::client::{ClientT, SubscriptionClientT}; use reth_ethereum_engine_primitives::EthEngineTypes; use reth_primitives::{Block, U64}; @@ -10,6 +9,8 @@ use reth_rpc_types::engine::{ForkchoiceState, PayloadId, TransitionConfiguration use reth_rpc_types_compat::engine::payload::{ block_to_payload_v1, convert_block_to_payload_input_v2, }; + +use crate::utils::launch_auth; #[allow(unused_must_use)] async fn test_basic_engine_calls(client: &C) where diff --git a/crates/rpc/rpc-builder/tests/it/http.rs b/crates/rpc/rpc-builder/tests/it/http.rs index caf16ebf6fce2..a481041c4497a 100644 --- a/crates/rpc/rpc-builder/tests/it/http.rs +++ b/crates/rpc/rpc-builder/tests/it/http.rs @@ -1,7 +1,8 @@ #![allow(unreachable_pub)] //! Standalone http tests -use crate::utils::{launch_http, launch_http_ws, launch_ws}; +use std::collections::HashSet; + use jsonrpsee::{ core::{ client::{ClientT, SubscriptionClientT}, @@ -27,7 +28,8 @@ use reth_rpc_types::{ }; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use serde_json::Value; -use std::collections::HashSet; + +use crate::utils::{launch_http, launch_http_ws, launch_ws}; fn is_unimplemented(err: jsonrpsee::core::client::Error) -> bool { match err { diff --git a/crates/rpc/rpc-builder/tests/it/serde.rs b/crates/rpc/rpc-builder/tests/it/serde.rs index 5df41b2d19b71..19c757d7dbce8 100644 --- a/crates/rpc/rpc-builder/tests/it/serde.rs +++ b/crates/rpc/rpc-builder/tests/it/serde.rs @@ -1,6 +1,5 @@ //! various serde test -use crate::utils::launch_http; use jsonrpsee::{ core::{client::ClientT, traits::ToRpcParams}, types::Request, @@ -9,6 +8,8 @@ use reth_primitives::U256; use reth_rpc_server_types::RethRpcModule; use serde_json::value::RawValue; +use crate::utils::launch_http; + struct RawRpcParams(Box); impl ToRpcParams for RawRpcParams { diff --git a/crates/rpc/rpc-builder/tests/it/startup.rs b/crates/rpc/rpc-builder/tests/it/startup.rs index 91800166f1d99..6e88b83fe2a38 100644 --- a/crates/rpc/rpc-builder/tests/it/startup.rs +++ b/crates/rpc/rpc-builder/tests/it/startup.rs @@ -1,14 +1,16 @@ //! Startup tests -use crate::utils::{ - launch_http, launch_http_ws_same_port, launch_ws, test_address, test_rpc_builder, -}; +use std::io; + use reth_rpc_builder::{ error::{RpcError, ServerKind, WsHttpSamePortError}, RpcServerConfig, TransportRpcModuleConfig, }; use reth_rpc_server_types::RethRpcModule; -use std::io; + +use crate::utils::{ + launch_http, launch_http_ws_same_port, launch_ws, test_address, test_rpc_builder, +}; fn is_addr_in_use_kind(err: &RpcError, kind: ServerKind) -> bool { match err { diff --git a/crates/rpc/rpc-builder/tests/it/utils.rs b/crates/rpc/rpc-builder/tests/it/utils.rs index d751b2d331a2f..9dc32425be1bc 100644 --- a/crates/rpc/rpc-builder/tests/it/utils.rs +++ b/crates/rpc/rpc-builder/tests/it/utils.rs @@ -1,3 +1,5 @@ +use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; + use reth_beacon_consensus::BeaconConsensusEngineHandle; use reth_chainspec::MAINNET; use reth_ethereum_engine_primitives::EthEngineTypes; @@ -15,7 +17,6 @@ use reth_rpc_server_types::RpcModuleSelection; use reth_rpc_types::engine::{ClientCode, ClientVersionV1}; use reth_tasks::TokioTaskExecutor; use reth_transaction_pool::test_utils::{TestPool, TestPoolBuilder}; -use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; use tokio::sync::mpsc::unbounded_channel; /// Localhost with port 0 so a free port is used. diff --git a/crates/rpc/rpc-engine-api/src/engine_api.rs b/crates/rpc/rpc-engine-api/src/engine_api.rs index 8185bbe8cc045..d36e9fcae5b81 100644 --- a/crates/rpc/rpc-engine-api/src/engine_api.rs +++ b/crates/rpc/rpc-engine-api/src/engine_api.rs @@ -1,4 +1,5 @@ -use crate::{metrics::EngineApiMetrics, EngineApiError, EngineApiResult}; +use std::{sync::Arc, time::Instant}; + use async_trait::async_trait; use jsonrpsee_core::RpcResult; use reth_beacon_consensus::BeaconConsensusEngineHandle; @@ -23,10 +24,11 @@ use reth_rpc_types_compat::engine::payload::{ }; use reth_storage_api::{BlockReader, HeaderProvider, StateProviderFactory}; use reth_tasks::TaskSpawner; -use std::{sync::Arc, time::Instant}; use tokio::sync::oneshot; use tracing::{trace, warn}; +use crate::{metrics::EngineApiMetrics, EngineApiError, EngineApiResult}; + /// The Engine API response sender. pub type EngineApiSender = oneshot::Sender>; @@ -837,22 +839,22 @@ where #[cfg(test)] mod tests { - use super::*; use assert_matches::assert_matches; use reth_beacon_consensus::{BeaconConsensusEngineEvent, BeaconEngineMessage}; - use reth_ethereum_engine_primitives::EthEngineTypes; - use reth_testing_utils::generators::random_block; - use reth_chainspec::MAINNET; + use reth_ethereum_engine_primitives::EthEngineTypes; use reth_payload_builder::test_utils::spawn_test_payload_service; use reth_primitives::{SealedBlock, B256}; use reth_provider::test_utils::MockEthProvider; use reth_rpc_types::engine::{ClientCode, ClientVersionV1}; use reth_rpc_types_compat::engine::payload::execution_payload_from_sealed_block; use reth_tasks::TokioTaskExecutor; + use reth_testing_utils::generators::random_block; use reth_tokio_util::EventSender; use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver}; + use super::*; + fn setup_engine_api() -> (EngineApiTestHandle, EngineApi, EthEngineTypes>) { let client = ClientVersionV1 { @@ -913,9 +915,10 @@ mod tests { // tests covering `engine_getPayloadBodiesByRange` and `engine_getPayloadBodiesByHash` mod get_payload_bodies { - use super::*; use reth_testing_utils::{generators, generators::random_block_range}; + use super::*; + #[tokio::test] async fn invalid_params() { let (_, api) = setup_engine_api(); @@ -1027,10 +1030,11 @@ mod tests { // https://github.com/ethereum/execution-apis/blob/main/src/engine/paris.md#specification-3 mod exchange_transition_configuration { - use super::*; use reth_primitives::U256; use reth_testing_utils::generators; + use super::*; + #[tokio::test] async fn terminal_td_mismatch() { let (handle, api) = setup_engine_api(); diff --git a/crates/rpc/rpc-engine-api/src/error.rs b/crates/rpc/rpc-engine-api/src/error.rs index 6fb7a197238dd..4369c1e95f322 100644 --- a/crates/rpc/rpc-engine-api/src/error.rs +++ b/crates/rpc/rpc-engine-api/src/error.rs @@ -210,9 +210,10 @@ impl From for jsonrpsee_types::error::ErrorObject<'static> { #[cfg(test)] mod tests { - use super::*; use reth_rpc_types::engine::ForkchoiceUpdateError; + use super::*; + #[track_caller] fn ensure_engine_rpc_error( code: i32, diff --git a/crates/rpc/rpc-engine-api/src/lib.rs b/crates/rpc/rpc-engine-api/src/lib.rs index 0f9323c0074b7..aa210ac390da1 100644 --- a/crates/rpc/rpc-engine-api/src/lib.rs +++ b/crates/rpc/rpc-engine-api/src/lib.rs @@ -24,7 +24,6 @@ mod metrics; pub use engine_api::{EngineApi, EngineApiSender}; pub use error::*; pub use message::EngineApiMessageVersion; - // re-export server trait for convenience pub use reth_rpc_api::EngineApiServer; diff --git a/crates/rpc/rpc-engine-api/src/metrics.rs b/crates/rpc/rpc-engine-api/src/metrics.rs index 73489b7557b6e..196f323dea335 100644 --- a/crates/rpc/rpc-engine-api/src/metrics.rs +++ b/crates/rpc/rpc-engine-api/src/metrics.rs @@ -1,10 +1,11 @@ use std::time::Duration; -use crate::EngineApiError; use metrics::{Counter, Histogram}; use reth_metrics::Metrics; use reth_rpc_types::engine::{ForkchoiceUpdated, PayloadStatus, PayloadStatusEnum}; +use crate::EngineApiError; + /// All beacon consensus engine metrics #[derive(Default)] pub(crate) struct EngineApiMetrics { diff --git a/crates/rpc/rpc-layer/src/auth_client_layer.rs b/crates/rpc/rpc-layer/src/auth_client_layer.rs index 5eda04aa0f378..a72cb8d4552b8 100644 --- a/crates/rpc/rpc-layer/src/auth_client_layer.rs +++ b/crates/rpc/rpc-layer/src/auth_client_layer.rs @@ -1,11 +1,13 @@ -use crate::{Claims, JwtSecret}; -use http::{header::AUTHORIZATION, HeaderValue}; use std::{ task::{Context, Poll}, time::{Duration, SystemTime, UNIX_EPOCH}, }; + +use http::{header::AUTHORIZATION, HeaderValue}; use tower::{Layer, Service}; +use crate::{Claims, JwtSecret}; + /// A layer that adds a new JWT token to every request using `AuthClientService`. #[derive(Debug)] pub struct AuthClientLayer { diff --git a/crates/rpc/rpc-layer/src/auth_layer.rs b/crates/rpc/rpc-layer/src/auth_layer.rs index 0a11ae8024f61..0dea72a274377 100644 --- a/crates/rpc/rpc-layer/src/auth_layer.rs +++ b/crates/rpc/rpc-layer/src/auth_layer.rs @@ -1,13 +1,15 @@ -use super::AuthValidator; -use jsonrpsee_http_client::{HttpRequest, HttpResponse}; -use pin_project::pin_project; use std::{ future::Future, pin::Pin, task::{Context, Poll}, }; + +use jsonrpsee_http_client::{HttpRequest, HttpResponse}; +use pin_project::pin_project; use tower::{Layer, Service}; +use super::AuthValidator; + /// This is an Http middleware layer that acts as an /// interceptor for `Authorization` headers. Incoming requests are dispatched to /// an inner [`AuthValidator`]. Invalid requests are blocked and the validator's error response is @@ -16,9 +18,10 @@ use tower::{Layer, Service}; /// # How to integrate /// ```rust /// async fn build_layered_rpc_server() { +/// use std::net::SocketAddr; +/// /// use jsonrpsee::server::ServerBuilder; /// use reth_rpc_layer::{AuthLayer, JwtAuthValidator, JwtSecret}; -/// use std::net::SocketAddr; /// /// const AUTH_PORT: u32 = 8551; /// const AUTH_ADDR: &str = "0.0.0.0"; @@ -149,18 +152,20 @@ where #[cfg(test)] mod tests { - use super::*; - use crate::JwtAuthValidator; + use std::{ + net::SocketAddr, + time::{SystemTime, UNIX_EPOCH}, + }; + use alloy_rpc_types_engine::{Claims, JwtError, JwtSecret}; use jsonrpsee::{ server::{RandomStringIdProvider, ServerBuilder, ServerHandle}, RpcModule, }; use reqwest::{header, StatusCode}; - use std::{ - net::SocketAddr, - time::{SystemTime, UNIX_EPOCH}, - }; + + use super::*; + use crate::JwtAuthValidator; const AUTH_PORT: u32 = 8551; const AUTH_ADDR: &str = "0.0.0.0"; diff --git a/crates/rpc/rpc-layer/src/jwt_validator.rs b/crates/rpc/rpc-layer/src/jwt_validator.rs index 5fe3beaba0a84..8cf82cf36732d 100644 --- a/crates/rpc/rpc-layer/src/jwt_validator.rs +++ b/crates/rpc/rpc-layer/src/jwt_validator.rs @@ -1,8 +1,9 @@ -use crate::{AuthValidator, JwtError, JwtSecret}; use http::{header, HeaderMap, Response, StatusCode}; use jsonrpsee_http_client::{HttpBody, HttpResponse}; use tracing::error; +use crate::{AuthValidator, JwtError, JwtSecret}; + /// Implements JWT validation logics and integrates /// to an Http [`AuthLayer`][crate::AuthLayer] /// by implementing the [`AuthValidator`] trait. @@ -65,9 +66,10 @@ fn err_response(err: JwtError) -> HttpResponse { #[cfg(test)] mod tests { - use crate::jwt_validator::get_bearer; use http::{header, HeaderMap}; + use crate::jwt_validator::get_bearer; + #[test] fn auth_header_available() { let jwt = "foo"; diff --git a/crates/rpc/rpc-layer/src/lib.rs b/crates/rpc/rpc-layer/src/lib.rs index e4f7dbe06f168..db71f0c7d4e27 100644 --- a/crates/rpc/rpc-layer/src/lib.rs +++ b/crates/rpc/rpc-layer/src/lib.rs @@ -17,7 +17,6 @@ mod jwt_validator; // Export alloy JWT types pub use alloy_rpc_types_engine::{Claims, JwtError, JwtSecret}; - pub use auth_client_layer::{secret_to_bearer_header, AuthClientLayer, AuthClientService}; pub use auth_layer::AuthLayer; pub use jwt_validator::JwtAuthValidator; diff --git a/crates/rpc/rpc-testing-util/src/debug.rs b/crates/rpc/rpc-testing-util/src/debug.rs index 91a9bf2ee8fd2..301454ce27f27 100644 --- a/crates/rpc/rpc-testing-util/src/debug.rs +++ b/crates/rpc/rpc-testing-util/src/debug.rs @@ -1,5 +1,11 @@ //! Helpers for testing debug trace calls. +use std::{ + future::Future, + pin::Pin, + task::{Context, Poll}, +}; + use futures::{Stream, StreamExt}; use jsonrpsee::core::client::Error as RpcError; use reth_primitives::{BlockId, TxHash, B256}; @@ -11,11 +17,6 @@ use reth_rpc_types::{ }, TransactionRequest, }; -use std::{ - future::Future, - pin::Pin, - task::{Context, Poll}, -}; const NOOP_TRACER: &str = include_str!("../assets/noop-tracer.js"); const JS_TRACER_TEMPLATE: &str = include_str!("../assets/tracer-template.js"); @@ -371,13 +372,14 @@ impl From for Option { #[cfg(test)] mod tests { + use futures::StreamExt; + use jsonrpsee::http_client::HttpClientBuilder; + use reth_rpc_types::trace::geth::{CallConfig, GethDebugTracingOptions}; + use crate::{ debug::{DebugApiExt, JsTracerBuilder, NoopJsTracer}, utils::parse_env_url, }; - use futures::StreamExt; - use jsonrpsee::http_client::HttpClientBuilder; - use reth_rpc_types::trace::geth::{CallConfig, GethDebugTracingOptions}; // random tx const TX_1: &str = "0x5525c63a805df2b83c113ebcc8c7672a3b290673c4e81335b410cd9ebc64e085"; diff --git a/crates/rpc/rpc-testing-util/src/trace.rs b/crates/rpc/rpc-testing-util/src/trace.rs index db8933c0ad9c0..623241f0dde40 100644 --- a/crates/rpc/rpc-testing-util/src/trace.rs +++ b/crates/rpc/rpc-testing-util/src/trace.rs @@ -1,5 +1,11 @@ //! Helpers for testing trace calls. +use std::{ + collections::HashSet, + pin::Pin, + task::{Context, Poll}, +}; + use futures::{Stream, StreamExt}; use jsonrpsee::core::client::Error as RpcError; use reth_primitives::{BlockId, Bytes, TxHash, B256}; @@ -12,11 +18,6 @@ use reth_rpc_types::{ }, Index, TransactionRequest, }; -use std::{ - collections::HashSet, - pin::Pin, - task::{Context, Poll}, -}; /// A type alias that represents the result of a raw transaction trace stream. type RawTransactionTraceResult<'a> = @@ -514,11 +515,12 @@ where } #[cfg(test)] mod tests { - use super::*; use jsonrpsee::http_client::HttpClientBuilder; use reth_primitives::BlockNumberOrTag; use reth_rpc_types::trace::filter::TraceFilterMode; + use super::*; + const fn assert_is_stream(_: &St) {} #[tokio::test] diff --git a/crates/rpc/rpc-testing-util/tests/it/trace.rs b/crates/rpc/rpc-testing-util/tests/it/trace.rs index a6439f0744c4f..4efd0507e7b0d 100644 --- a/crates/rpc/rpc-testing-util/tests/it/trace.rs +++ b/crates/rpc/rpc-testing-util/tests/it/trace.rs @@ -1,3 +1,5 @@ +use std::{collections::HashSet, time::Instant}; + use futures::StreamExt; use jsonrpsee::http_client::HttpClientBuilder; use reth_rpc_api::EthApiClient; @@ -5,7 +7,6 @@ use reth_rpc_api_testing_util::{debug::DebugApiExt, trace::TraceApiExt, utils::p use reth_rpc_types::trace::{ filter::TraceFilter, parity::TraceType, tracerequest::TraceCallRequest, }; -use std::{collections::HashSet, time::Instant}; /// This is intended to be run locally against a running node. /// diff --git a/crates/rpc/rpc-types-compat/src/block.rs b/crates/rpc/rpc-types-compat/src/block.rs index 7cfd57e8aaf88..f5be9ab2faa7e 100644 --- a/crates/rpc/rpc-types-compat/src/block.rs +++ b/crates/rpc/rpc-types-compat/src/block.rs @@ -1,12 +1,13 @@ //! Compatibility functions for rpc `Block` type. -use crate::transaction::from_recovered_with_block_context; use alloy_rlp::Encodable; use reth_primitives::{ Block as PrimitiveBlock, BlockWithSenders, Header as PrimitiveHeader, Withdrawals, B256, U256, }; use reth_rpc_types::{Block, BlockError, BlockTransactions, BlockTransactionsKind, Header}; +use crate::transaction::from_recovered_with_block_context; + /// Converts the given primitive block into a [Block] response with the given /// [`BlockTransactionsKind`] /// diff --git a/crates/rpc/rpc-types-compat/src/engine/payload.rs b/crates/rpc/rpc-types-compat/src/engine/payload.rs index dacfab06418e6..4b5b42a4aeae3 100644 --- a/crates/rpc/rpc-types-compat/src/engine/payload.rs +++ b/crates/rpc/rpc-types-compat/src/engine/payload.rs @@ -391,16 +391,17 @@ pub fn execution_payload_from_sealed_block(value: SealedBlock) -> ExecutionPaylo #[cfg(test)] mod tests { - use super::{ - block_to_payload_v3, try_into_block, try_payload_v3_to_block, try_payload_v4_to_block, - validate_block_hash, - }; use reth_primitives::{b256, hex, Bytes, U256}; use reth_rpc_types::{ engine::{CancunPayloadFields, ExecutionPayloadV3, ExecutionPayloadV4}, ExecutionPayload, ExecutionPayloadV1, ExecutionPayloadV2, }; + use super::{ + block_to_payload_v3, try_into_block, try_payload_v3_to_block, try_payload_v4_to_block, + validate_block_hash, + }; + #[test] fn roundtrip_payload_to_block() { let first_transaction_raw = Bytes::from_static(&hex!("02f9017a8501a1f0ff438211cc85012a05f2008512a05f2000830249f094d5409474fd5a725eab2ac9a8b26ca6fb51af37ef80b901040cc7326300000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000001bdd2ed4b616c800000000000000000000000000001e9ee781dd4b97bdef92e5d1785f73a1f931daa20000000000000000000000007a40026a3b9a41754a95eec8c92c6b99886f440c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000009ae80eb647dd09968488fa1d7e412bf8558a0b7a0000000000000000000000000f9815537d361cb02befd9918c95c97d4d8a4a2bc001a0ba8f1928bb0efc3fcd01524a2039a9a2588fa567cd9a7cc18217e05c615e9d69a0544bfd11425ac7748e76b3795b57a5563e2b0eff47b5428744c62ff19ccfc305")[..]); diff --git a/crates/rpc/rpc-types/src/lib.rs b/crates/rpc/rpc-types/src/lib.rs index 5df802da09fa4..fa46e8fa6e3d2 100644 --- a/crates/rpc/rpc-types/src/lib.rs +++ b/crates/rpc/rpc-types/src/lib.rs @@ -17,10 +17,8 @@ mod rpc; // re-export for convenience pub use alloy_rpc_types::serde_helpers; - // Ethereum specific rpc types coming from alloy. pub use alloy_rpc_types::*; - // Ethereum specific serde types coming from alloy. pub use alloy_serde::*; @@ -30,17 +28,13 @@ pub mod trace { } // Anvil specific rpc types coming from alloy. +// re-export admin +pub use alloy_rpc_types_admin as admin; pub use alloy_rpc_types_anvil as anvil; - // re-export beacon pub use alloy_rpc_types_beacon as beacon; - -// re-export admin -pub use alloy_rpc_types_admin as admin; - // re-export txpool pub use alloy_rpc_types_txpool as txpool; - // Ethereum specific rpc types related to typed transaction requests and the engine API. pub use eth::{ engine, @@ -50,7 +44,6 @@ pub use eth::{ error::ToRpcError, transaction::{self, TransactionRequest, TypedTransactionRequest}, }; - pub use mev::*; pub use peer::*; pub use rpc::*; diff --git a/crates/rpc/rpc-types/src/mev.rs b/crates/rpc/rpc-types/src/mev.rs index 20c92f1a6cd8f..ab8a58ab39dc6 100644 --- a/crates/rpc/rpc-types/src/mev.rs +++ b/crates/rpc/rpc-types/src/mev.rs @@ -1,11 +1,12 @@ //! MEV bundle type bindings -use crate::{BlockId, BlockNumberOrTag, Log}; use alloy_primitives::{Address, Bytes, TxHash, B256, U256}; use serde::{ ser::{SerializeSeq, Serializer}, Deserialize, Deserializer, Serialize, }; + +use crate::{BlockId, BlockNumberOrTag, Log}; /// A bundle of transactions to send to the matchmaker. /// /// Note: this is for `mev_sendBundle` and not `eth_sendBundle`. @@ -743,9 +744,10 @@ pub struct EthCallBundleTransactionResult { } mod u256_numeric_string { + use std::str::FromStr; + use alloy_primitives::U256; use serde::{de, Deserialize, Serializer}; - use std::str::FromStr; pub(crate) fn deserialize<'de, D>(deserializer: D) -> Result where @@ -777,9 +779,10 @@ mod u256_numeric_string { #[cfg(test)] mod tests { - use super::*; use std::str::FromStr; + use super::*; + #[test] fn can_deserialize_simple() { let str = r#" diff --git a/crates/rpc/rpc-types/src/rpc.rs b/crates/rpc/rpc-types/src/rpc.rs index bb5ae5d77fbbb..0f525e57ac2e9 100644 --- a/crates/rpc/rpc-types/src/rpc.rs +++ b/crates/rpc/rpc-types/src/rpc.rs @@ -1,6 +1,7 @@ -use serde::{Deserialize, Serialize}; use std::collections::HashMap; +use serde::{Deserialize, Serialize}; + /// Represents the `rpc_modules` response, which returns the /// list of all available modules on that transport and their version #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)] diff --git a/crates/rpc/rpc/src/admin.rs b/crates/rpc/rpc/src/admin.rs index 71f95fedec9a6..0e1e13a0c013a 100644 --- a/crates/rpc/rpc/src/admin.rs +++ b/crates/rpc/rpc/src/admin.rs @@ -1,4 +1,5 @@ -use crate::result::ToRpcResult; +use std::sync::Arc; + use alloy_genesis::ChainConfig; use alloy_primitives::B256; use async_trait::async_trait; @@ -11,7 +12,8 @@ use reth_rpc_types::{ admin::{EthProtocolInfo, NodeInfo, Ports, ProtocolInfo}, PeerEthProtocolInfo, PeerInfo, PeerNetworkInfo, PeerProtocolsInfo, }; -use std::sync::Arc; + +use crate::result::ToRpcResult; /// `admin` API implementation. /// diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index b2d524a6325b5..94d93a0954f28 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -1,12 +1,5 @@ -use crate::{ - eth::{ - error::{EthApiError, EthResult}, - revm_utils::prepare_call_env, - EthTransactions, - }, - result::{internal_rpc_err, ToRpcResult}, - EthApiSpec, -}; +use std::sync::Arc; + use alloy_rlp::{Decodable, Encodable}; use async_trait::async_trait; use jsonrpsee::core::RpcResult; @@ -36,9 +29,18 @@ use revm_inspectors::tracing::{ js::{JsInspector, TransactionContext}, FourByteInspector, MuxInspector, TracingInspector, TracingInspectorConfig, }; -use std::sync::Arc; use tokio::sync::{AcquireError, OwnedSemaphorePermit}; +use crate::{ + eth::{ + error::{EthApiError, EthResult}, + revm_utils::prepare_call_env, + EthTransactions, + }, + result::{internal_rpc_err, ToRpcResult}, + EthApiSpec, +}; + /// `debug` API implementation. /// /// This type provides the functionality for handling `debug` related requests. diff --git a/crates/rpc/rpc/src/eth/api/block.rs b/crates/rpc/rpc/src/eth/api/block.rs index 18a547faf9e61..d872b04740744 100644 --- a/crates/rpc/rpc/src/eth/api/block.rs +++ b/crates/rpc/rpc/src/eth/api/block.rs @@ -1,12 +1,7 @@ //! Contains RPC handler implementations specific to blocks. -use crate::{ - eth::{ - api::transactions::build_transaction_receipt_with_block_receipts, - error::{EthApiError, EthResult}, - }, - EthApi, -}; +use std::sync::Arc; + use reth_evm::ConfigureEvm; use reth_network_api::NetworkInfo; use reth_primitives::{BlockId, TransactionMeta}; @@ -14,7 +9,14 @@ use reth_provider::{BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, StatePr use reth_rpc_types::{AnyTransactionReceipt, Header, Index, RichBlock}; use reth_rpc_types_compat::block::{from_block, uncle_block_from_header}; use reth_transaction_pool::TransactionPool; -use std::sync::Arc; + +use crate::{ + eth::{ + api::transactions::build_transaction_receipt_with_block_receipts, + error::{EthApiError, EthResult}, + }, + EthApi, +}; impl EthApi where diff --git a/crates/rpc/rpc/src/eth/api/call.rs b/crates/rpc/rpc/src/eth/api/call.rs index 907065e476d41..d5a2467c46e35 100644 --- a/crates/rpc/rpc/src/eth/api/call.rs +++ b/crates/rpc/rpc/src/eth/api/call.rs @@ -1,16 +1,5 @@ //! Contains RPC handler implementations specific to endpoints that call/execute within evm. -use crate::{ - eth::{ - error::{ensure_success, EthApiError, EthResult, RevertError, RpcInvalidTransactionError}, - revm_utils::{ - apply_state_overrides, build_call_evm_env, caller_gas_allowance, - cap_tx_gas_limit_with_caller_allowance, get_precompiles, prepare_call_env, - }, - EthTransactions, - }, - EthApi, -}; use reth_evm::ConfigureEvm; use reth_network_api::NetworkInfo; use reth_primitives::{revm::env::tx_env_with_recovered, BlockId, Bytes, TxKind, U256}; @@ -31,6 +20,18 @@ use revm::{ use revm_inspectors::access_list::AccessListInspector; use tracing::trace; +use crate::{ + eth::{ + error::{ensure_success, EthApiError, EthResult, RevertError, RpcInvalidTransactionError}, + revm_utils::{ + apply_state_overrides, build_call_evm_env, caller_gas_allowance, + cap_tx_gas_limit_with_caller_allowance, get_precompiles, prepare_call_env, + }, + EthTransactions, + }, + EthApi, +}; + // Gas per transaction not creating a contract. const MIN_TRANSACTION_GAS: u64 = 21_000u64; /// Allowed error ratio for gas estimation diff --git a/crates/rpc/rpc/src/eth/api/fee_history.rs b/crates/rpc/rpc/src/eth/api/fee_history.rs index 626c670376c86..cc92e1df6fa33 100644 --- a/crates/rpc/rpc/src/eth/api/fee_history.rs +++ b/crates/rpc/rpc/src/eth/api/fee_history.rs @@ -1,6 +1,11 @@ //! Consist of types adjacent to the fee history cache and its configs -use crate::eth::{cache::EthStateCache, error::EthApiError}; +use std::{ + collections::{BTreeMap, VecDeque}, + fmt::Debug, + sync::{atomic::Ordering::SeqCst, Arc}, +}; + use futures::{ future::{Fuse, FusedFuture}, FutureExt, Stream, StreamExt, @@ -16,13 +21,10 @@ use reth_provider::{BlockReaderIdExt, CanonStateNotification, ChainSpecProvider} use reth_rpc_server_types::constants::gas_oracle::MAX_HEADER_HISTORY; use reth_rpc_types::TxGasAndReward; use serde::{Deserialize, Serialize}; -use std::{ - collections::{BTreeMap, VecDeque}, - fmt::Debug, - sync::{atomic::Ordering::SeqCst, Arc}, -}; use tracing::trace; +use crate::eth::{cache::EthStateCache, error::EthApiError}; + /// Contains cached fee history entries for blocks. /// /// Purpose for this is to provide cached data for `eth_feeHistory`. diff --git a/crates/rpc/rpc/src/eth/api/fees.rs b/crates/rpc/rpc/src/eth/api/fees.rs index 2493d60557780..fc810124a24dc 100644 --- a/crates/rpc/rpc/src/eth/api/fees.rs +++ b/crates/rpc/rpc/src/eth/api/fees.rs @@ -1,12 +1,5 @@ //! Contains RPC handler implementations for fee history. -use crate::{ - eth::{ - api::fee_history::{calculate_reward_percentiles_for_block, FeeHistoryEntry}, - error::{EthApiError, EthResult}, - }, - EthApi, -}; use reth_evm::ConfigureEvm; use reth_network_api::NetworkInfo; use reth_primitives::{BlockNumberOrTag, U256}; @@ -15,6 +8,14 @@ use reth_rpc_types::FeeHistory; use reth_transaction_pool::TransactionPool; use tracing::debug; +use crate::{ + eth::{ + api::fee_history::{calculate_reward_percentiles_for_block, FeeHistoryEntry}, + error::{EthApiError, EthResult}, + }, + EthApi, +}; + impl EthApi where Pool: TransactionPool + Clone + 'static, diff --git a/crates/rpc/rpc/src/eth/api/mod.rs b/crates/rpc/rpc/src/eth/api/mod.rs index 364a55842d3c4..c843ade7ee23e 100644 --- a/crates/rpc/rpc/src/eth/api/mod.rs +++ b/crates/rpc/rpc/src/eth/api/mod.rs @@ -1,17 +1,13 @@ //! The entire implementation of the namespace is quite large, hence it is divided across several //! files. -use crate::eth::{ - api::{ - fee_history::FeeHistoryCache, - pending_block::{PendingBlock, PendingBlockEnv, PendingBlockEnvOrigin}, - }, - cache::EthStateCache, - error::{EthApiError, EthResult}, - gas_oracle::GasPriceOracle, - signer::EthSigner, - traits::RawTransactionForwarder, +use std::{ + fmt::Debug, + future::Future, + sync::Arc, + time::{Duration, Instant}, }; + use async_trait::async_trait; use reth_chainspec::ChainInfo; use reth_errors::{RethError, RethResult}; @@ -28,14 +24,20 @@ use reth_rpc_types::{SyncInfo, SyncStatus}; use reth_tasks::{pool::BlockingTaskPool, TaskSpawner, TokioTaskExecutor}; use reth_transaction_pool::TransactionPool; use revm_primitives::{CfgEnv, SpecId}; -use std::{ - fmt::Debug, - future::Future, - sync::Arc, - time::{Duration, Instant}, -}; use tokio::sync::{oneshot, Mutex}; +use crate::eth::{ + api::{ + fee_history::FeeHistoryCache, + pending_block::{PendingBlock, PendingBlockEnv, PendingBlockEnvOrigin}, + }, + cache::EthStateCache, + error::{EthApiError, EthResult}, + gas_oracle::GasPriceOracle, + signer::EthSigner, + traits::RawTransactionForwarder, +}; + mod block; mod call; pub(crate) mod fee_history; diff --git a/crates/rpc/rpc/src/eth/api/pending_block.rs b/crates/rpc/rpc/src/eth/api/pending_block.rs index 4f9a616dece87..ae02a7b6076e5 100644 --- a/crates/rpc/rpc/src/eth/api/pending_block.rs +++ b/crates/rpc/rpc/src/eth/api/pending_block.rs @@ -1,6 +1,7 @@ //! Support for building a pending block via local txpool. -use crate::eth::error::{EthApiError, EthResult}; +use std::time::Instant; + use reth_chainspec::ChainSpec; use reth_errors::ProviderError; use reth_execution_types::ExecutionOutcome; @@ -25,7 +26,8 @@ use reth_revm::{ use reth_transaction_pool::{BestTransactionsAttributes, TransactionPool}; use revm::{db::states::bundle_state::BundleRetention, Database, DatabaseCommit, State}; use revm_primitives::EnvWithHandlerCfg; -use std::time::Instant; + +use crate::eth::error::{EthApiError, EthResult}; /// Configured [`BlockEnv`] and [`CfgEnvWithHandlerCfg`] for a pending block #[derive(Debug, Clone)] diff --git a/crates/rpc/rpc/src/eth/api/server.rs b/crates/rpc/rpc/src/eth/api/server.rs index f238b4da079aa..1c4aac3e936d3 100644 --- a/crates/rpc/rpc/src/eth/api/server.rs +++ b/crates/rpc/rpc/src/eth/api/server.rs @@ -1,14 +1,6 @@ //! Implementation of the [`jsonrpsee`] generated [`reth_rpc_api::EthApiServer`] trait //! Handles RPC requests for the `eth_` namespace. -use super::EthApiSpec; -use crate::{ - eth::{ - api::{EthApi, EthTransactions}, - error::EthApiError, - }, - result::{internal_rpc_err, ToRpcResult}, -}; use alloy_dyn_abi::TypedData; use jsonrpsee::core::RpcResult as Result; use reth_evm::ConfigureEvm; @@ -29,6 +21,15 @@ use reth_rpc_types::{ use reth_transaction_pool::TransactionPool; use tracing::trace; +use super::EthApiSpec; +use crate::{ + eth::{ + api::{EthApi, EthTransactions}, + error::EthApiError, + }, + result::{internal_rpc_err, ToRpcResult}, +}; + #[async_trait::async_trait] impl EthApiServer for EthApi where @@ -425,13 +426,6 @@ where #[cfg(test)] mod tests { - use crate::{ - eth::{ - cache::EthStateCache, gas_oracle::GasPriceOracle, FeeHistoryCache, - FeeHistoryCacheConfig, - }, - EthApi, - }; use jsonrpsee::types::error::INVALID_PARAMS_CODE; use reth_chainspec::BaseFeeParams; use reth_evm_ethereum::EthEvmConfig; @@ -450,6 +444,14 @@ mod tests { use reth_testing_utils::{generators, generators::Rng}; use reth_transaction_pool::test_utils::{testing_pool, TestPool}; + use crate::{ + eth::{ + cache::EthStateCache, gas_oracle::GasPriceOracle, FeeHistoryCache, + FeeHistoryCacheConfig, + }, + EthApi, + }; + fn build_test_eth_api< P: BlockReaderIdExt + BlockReader diff --git a/crates/rpc/rpc/src/eth/api/sign.rs b/crates/rpc/rpc/src/eth/api/sign.rs index 5256de4a4dae3..e02f2c2c269fd 100644 --- a/crates/rpc/rpc/src/eth/api/sign.rs +++ b/crates/rpc/rpc/src/eth/api/sign.rs @@ -1,5 +1,8 @@ //! Contains RPC handler implementations specific to sign endpoints +use alloy_dyn_abi::TypedData; +use reth_primitives::{Address, Bytes}; + use crate::{ eth::{ error::{EthResult, SignError}, @@ -7,8 +10,6 @@ use crate::{ }, EthApi, }; -use alloy_dyn_abi::TypedData; -use reth_primitives::{Address, Bytes}; impl EthApi { pub(crate) async fn sign(&self, account: Address, message: &[u8]) -> EthResult { diff --git a/crates/rpc/rpc/src/eth/api/state.rs b/crates/rpc/rpc/src/eth/api/state.rs index d7c1bafacf9fc..17bb40698c30f 100644 --- a/crates/rpc/rpc/src/eth/api/state.rs +++ b/crates/rpc/rpc/src/eth/api/state.rs @@ -1,9 +1,5 @@ //! Contains RPC handler implementations specific to state. -use crate::{ - eth::error::{EthApiError, EthResult, RpcInvalidTransactionError}, - EthApi, -}; use reth_evm::ConfigureEvm; use reth_primitives::{Address, BlockId, BlockNumberOrTag, Bytes, B256, U256}; use reth_provider::{ @@ -13,6 +9,11 @@ use reth_rpc_types::{serde_helpers::JsonStorageKey, EIP1186AccountProofResponse} use reth_rpc_types_compat::proof::from_primitive_account_proof; use reth_transaction_pool::{PoolTransaction, TransactionPool}; +use crate::{ + eth::error::{EthApiError, EthResult, RpcInvalidTransactionError}, + EthApi, +}; + impl EthApi where Provider: @@ -115,16 +116,18 @@ where #[cfg(test)] mod tests { - use super::*; - use crate::eth::{ - cache::EthStateCache, gas_oracle::GasPriceOracle, FeeHistoryCache, FeeHistoryCacheConfig, - }; + use std::collections::HashMap; + use reth_evm_ethereum::EthEvmConfig; use reth_primitives::{constants::ETHEREUM_BLOCK_GAS_LIMIT, StorageKey, StorageValue}; use reth_provider::test_utils::{ExtendedAccount, MockEthProvider, NoopProvider}; use reth_tasks::pool::BlockingTaskPool; use reth_transaction_pool::test_utils::testing_pool; - use std::collections::HashMap; + + use super::*; + use crate::eth::{ + cache::EthStateCache, gas_oracle::GasPriceOracle, FeeHistoryCache, FeeHistoryCacheConfig, + }; #[tokio::test] async fn test_storage() { diff --git a/crates/rpc/rpc/src/eth/api/transactions.rs b/crates/rpc/rpc/src/eth/api/transactions.rs index 8829a0434e493..1176c6a9f098f 100644 --- a/crates/rpc/rpc/src/eth/api/transactions.rs +++ b/crates/rpc/rpc/src/eth/api/transactions.rs @@ -1,13 +1,6 @@ //! Contains RPC handler implementations specific to transactions -use crate::{ - eth::{ - api::pending_block::PendingBlockEnv, - error::{EthApiError, EthResult, RpcInvalidTransactionError, SignError}, - revm_utils::prepare_call_env, - utils::recover_raw_transaction, - }, - EthApi, EthApiSpec, -}; +use std::future::Future; + use alloy_primitives::TxKind as RpcTransactionKind; use async_trait::async_trait; use reth_evm::ConfigureEvm; @@ -25,6 +18,8 @@ use reth_provider::{ BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, StateProviderBox, StateProviderFactory, }; use reth_revm::database::StateProviderDatabase; +#[cfg(feature = "optimism")] +use reth_rpc_types::OptimismTransactionReceiptFields; use reth_rpc_types::{ state::EvmOverrides, transaction::{ @@ -46,13 +41,18 @@ use revm::{ GetInspector, Inspector, }; use revm_inspectors::tracing::{TracingInspector, TracingInspectorConfig}; -use std::future::Future; - -use crate::eth::revm_utils::FillableTransaction; -#[cfg(feature = "optimism")] -use reth_rpc_types::OptimismTransactionReceiptFields; use revm_primitives::db::{Database, DatabaseRef}; +use crate::{ + eth::{ + api::pending_block::PendingBlockEnv, + error::{EthApiError, EthResult, RpcInvalidTransactionError, SignError}, + revm_utils::{prepare_call_env, FillableTransaction}, + utils::recover_raw_transaction, + }, + EthApi, EthApiSpec, +}; + /// Helper alias type for the state's [`CacheDB`] pub(crate) type StateCacheDB = CacheDB>; @@ -1561,9 +1561,10 @@ where l1_block_info: Option, block_timestamp: u64, ) -> EthResult { - use crate::eth::{api::optimism::OptimismTxMeta, optimism::OptimismEthApiError}; use reth_evm_optimism::RethL1BlockInfo; + use crate::eth::{api::optimism::OptimismTxMeta, optimism::OptimismEthApiError}; + let Some(l1_block_info) = l1_block_info else { return Ok(OptimismTxMeta::default()) }; let (l1_fee, l1_data_gas) = if !tx.is_deposit() { @@ -1798,10 +1799,6 @@ pub(crate) fn build_transaction_receipt_with_block_receipts( #[cfg(test)] mod tests { - use super::*; - use crate::eth::{ - cache::EthStateCache, gas_oracle::GasPriceOracle, FeeHistoryCache, FeeHistoryCacheConfig, - }; use reth_evm_ethereum::EthEvmConfig; use reth_network_api::noop::NoopNetwork; use reth_primitives::{constants::ETHEREUM_BLOCK_GAS_LIMIT, hex_literal::hex}; @@ -1809,6 +1806,11 @@ mod tests { use reth_tasks::pool::BlockingTaskPool; use reth_transaction_pool::test_utils::testing_pool; + use super::*; + use crate::eth::{ + cache::EthStateCache, gas_oracle::GasPriceOracle, FeeHistoryCache, FeeHistoryCacheConfig, + }; + #[tokio::test] async fn send_raw_transaction() { let noop_provider = NoopProvider::default(); diff --git a/crates/rpc/rpc/src/eth/bundle.rs b/crates/rpc/rpc/src/eth/bundle.rs index 97ea4bb4c0fea..b7447ebd14b21 100644 --- a/crates/rpc/rpc/src/eth/bundle.rs +++ b/crates/rpc/rpc/src/eth/bundle.rs @@ -1,11 +1,7 @@ //! `Eth` bundle implementation and helpers. -use crate::eth::{ - error::{EthApiError, EthResult, RpcInvalidTransactionError}, - revm_utils::FillableTransaction, - utils::recover_raw_transaction, - EthTransactions, -}; +use std::sync::Arc; + use jsonrpsee::core::RpcResult; use reth_primitives::{ keccak256, @@ -21,7 +17,13 @@ use revm::{ primitives::{ResultAndState, TxEnv}, }; use revm_primitives::{EnvKzgSettings, EnvWithHandlerCfg, MAX_BLOB_GAS_PER_BLOCK}; -use std::sync::Arc; + +use crate::eth::{ + error::{EthApiError, EthResult, RpcInvalidTransactionError}, + revm_utils::FillableTransaction, + utils::recover_raw_transaction, + EthTransactions, +}; /// `Eth` bundle implementation. pub struct EthBundle { diff --git a/crates/rpc/rpc/src/eth/cache/mod.rs b/crates/rpc/rpc/src/eth/cache/mod.rs index cfbe68311ee3a..801316ce72d15 100644 --- a/crates/rpc/rpc/src/eth/cache/mod.rs +++ b/crates/rpc/rpc/src/eth/cache/mod.rs @@ -1,5 +1,12 @@ //! Async caching support for eth RPC +use std::{ + future::Future, + pin::Pin, + sync::Arc, + task::{ready, Context, Poll}, +}; + use futures::{future::Either, Stream, StreamExt}; use reth_errors::{ProviderError, ProviderResult}; use reth_evm::ConfigureEvm; @@ -14,12 +21,6 @@ use reth_provider::{ use reth_tasks::{TaskSpawner, TokioTaskExecutor}; use revm::primitives::{BlockEnv, CfgEnv, CfgEnvWithHandlerCfg, SpecId}; use schnellru::{ByLength, Limiter}; -use std::{ - future::Future, - pin::Pin, - sync::Arc, - task::{ready, Context, Poll}, -}; use tokio::sync::{ mpsc::{unbounded_channel, UnboundedSender}, oneshot, Semaphore, diff --git a/crates/rpc/rpc/src/eth/cache/multi_consumer.rs b/crates/rpc/rpc/src/eth/cache/multi_consumer.rs index cd02ecc5672f3..933eaa389a0d4 100644 --- a/crates/rpc/rpc/src/eth/cache/multi_consumer.rs +++ b/crates/rpc/rpc/src/eth/cache/multi_consumer.rs @@ -1,11 +1,13 @@ -use super::metrics::CacheMetrics; -use schnellru::{ByLength, Limiter, LruMap}; use std::{ collections::{hash_map::Entry, HashMap}, fmt::{self, Debug, Formatter}, hash::Hash, }; +use schnellru::{ByLength, Limiter, LruMap}; + +use super::metrics::CacheMetrics; + /// A multi-consumer LRU cache. pub struct MultiConsumerLruCache where diff --git a/crates/rpc/rpc/src/eth/error.rs b/crates/rpc/rpc/src/eth/error.rs index 84c1504015a32..508eca12ef7a4 100644 --- a/crates/rpc/rpc/src/eth/error.rs +++ b/crates/rpc/rpc/src/eth/error.rs @@ -1,6 +1,7 @@ //! Implementation specific Errors for the `eth_` namespace. -use crate::result::{internal_rpc_err, invalid_params_rpc_err, rpc_err, rpc_error_with_code}; +use std::time::Duration; + use alloy_sol_types::decode_revert_reason; use jsonrpsee::types::{error::CALL_EXECUTION_FAILED_CODE, ErrorObject}; use reth_errors::RethError; @@ -14,7 +15,8 @@ use reth_transaction_pool::error::{ }; use revm::primitives::{EVMError, ExecutionResult, HaltReason, OutOfGasError}; use revm_inspectors::tracing::{js::JsInspectorError, MuxError}; -use std::time::Duration; + +use crate::result::{internal_rpc_err, invalid_params_rpc_err, rpc_err, rpc_error_with_code}; /// Result alias pub type EthResult = Result; diff --git a/crates/rpc/rpc/src/eth/filter.rs b/crates/rpc/rpc/src/eth/filter.rs index 1fea2df4a4b41..9db599b67b52d 100644 --- a/crates/rpc/rpc/src/eth/filter.rs +++ b/crates/rpc/rpc/src/eth/filter.rs @@ -1,13 +1,11 @@ -use super::cache::EthStateCache; -use crate::{ - eth::{ - error::EthApiError, - logs_utils::{self, append_matching_block_logs}, - }, - result::{rpc_error_with_code, ToRpcResult}, - EthSubscriptionIdProvider, -}; use core::fmt; +use std::{ + collections::HashMap, + iter::StepBy, + ops::RangeInclusive, + sync::Arc, + time::{Duration, Instant}, +}; use async_trait::async_trait; use jsonrpsee::{core::RpcResult, server::IdProvider}; @@ -19,22 +17,24 @@ use reth_rpc_types::{ BlockNumHash, Filter, FilterBlockOption, FilterChanges, FilterId, FilteredParams, Log, PendingTransactionFilterKind, }; - use reth_tasks::TaskSpawner; use reth_transaction_pool::{NewSubpoolTransactionStream, PoolTransaction, TransactionPool}; -use std::{ - collections::HashMap, - iter::StepBy, - ops::RangeInclusive, - sync::Arc, - time::{Duration, Instant}, -}; use tokio::{ sync::{mpsc::Receiver, Mutex}, time::MissedTickBehavior, }; use tracing::trace; +use super::cache::EthStateCache; +use crate::{ + eth::{ + error::EthApiError, + logs_utils::{self, append_matching_block_logs}, + }, + result::{rpc_error_with_code, ToRpcResult}, + EthSubscriptionIdProvider, +}; + /// The maximum number of headers we read at once when handling a range filter. const MAX_HEADERS_RANGE: u64 = 1_000; // with ~530bytes per header this is ~500kb @@ -756,9 +756,10 @@ impl Iterator for BlockRangeInclusiveIter { #[cfg(test)] mod tests { - use super::*; use rand::{thread_rng, Rng}; + use super::*; + #[test] fn test_block_range_iter() { for _ in 0..100 { diff --git a/crates/rpc/rpc/src/eth/gas_oracle.rs b/crates/rpc/rpc/src/eth/gas_oracle.rs index bb44af67b5f75..b2343aa751cb7 100644 --- a/crates/rpc/rpc/src/eth/gas_oracle.rs +++ b/crates/rpc/rpc/src/eth/gas_oracle.rs @@ -1,20 +1,22 @@ //! An implementation of the eth gas price oracle, used for providing gas price estimates based on //! previous blocks. -use crate::eth::{ - cache::EthStateCache, - error::{EthApiError, EthResult, RpcInvalidTransactionError}, -}; +use std::fmt::{self, Debug, Formatter}; + use derive_more::{Deref, DerefMut}; use reth_primitives::{constants::GWEI_TO_WEI, BlockNumberOrTag, B256, U256}; use reth_provider::BlockReaderIdExt; use reth_rpc_server_types::constants::gas_oracle::*; use schnellru::{ByLength, LruMap}; use serde::{Deserialize, Serialize}; -use std::fmt::{self, Debug, Formatter}; use tokio::sync::Mutex; use tracing::warn; +use crate::eth::{ + cache::EthStateCache, + error::{EthApiError, EthResult, RpcInvalidTransactionError}, +}; + /// Settings for the [`GasPriceOracle`] #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] diff --git a/crates/rpc/rpc/src/eth/id_provider.rs b/crates/rpc/rpc/src/eth/id_provider.rs index 6691e13a9f4bc..44caf877c8ef1 100644 --- a/crates/rpc/rpc/src/eth/id_provider.rs +++ b/crates/rpc/rpc/src/eth/id_provider.rs @@ -1,6 +1,7 @@ -use jsonrpsee::types::SubscriptionId; use std::fmt::Write; +use jsonrpsee::types::SubscriptionId; + /// An [`IdProvider`](jsonrpsee::core::traits::IdProvider) for ethereum subscription ids. /// /// Returns new hex-string [QUANTITY](https://ethereum.org/en/developers/docs/apis/json-rpc/#quantities-encoding) ids @@ -40,9 +41,10 @@ fn to_quantity(val: u128) -> SubscriptionId<'static> { #[cfg(test)] mod tests { - use super::*; use reth_primitives::U128; + use super::*; + #[test] fn test_id_provider_quantity() { let id = to_quantity(0); diff --git a/crates/rpc/rpc/src/eth/logs_utils.rs b/crates/rpc/rpc/src/eth/logs_utils.rs index c57ce5fcb986d..2d318005a4194 100644 --- a/crates/rpc/rpc/src/eth/logs_utils.rs +++ b/crates/rpc/rpc/src/eth/logs_utils.rs @@ -1,10 +1,11 @@ -use super::filter::FilterError; use alloy_primitives::TxHash; use reth_chainspec::ChainInfo; use reth_primitives::{BlockNumHash, Receipt}; use reth_provider::{BlockReader, ProviderError}; use reth_rpc_types::{FilteredParams, Log}; +use super::filter::FilterError; + /// Returns all matching of a block's receipts when the transaction hashes are known. pub(crate) fn matching_block_logs_with_tx_hashes<'a, I>( filter: &FilteredParams, diff --git a/crates/rpc/rpc/src/eth/mod.rs b/crates/rpc/rpc/src/eth/mod.rs index 8d8e982c2c79e..44a104c784a5b 100644 --- a/crates/rpc/rpc/src/eth/mod.rs +++ b/crates/rpc/rpc/src/eth/mod.rs @@ -21,7 +21,6 @@ pub use api::{ fee_history::{fee_history_cache_new_blocks_task, FeeHistoryCache, FeeHistoryCacheConfig}, EthApi, EthApiSpec, EthTransactions, TransactionSource, RPC_DEFAULT_GAS_CAP, }; - pub use bundle::EthBundle; pub use filter::{EthFilter, EthFilterConfig}; pub use id_provider::EthSubscriptionIdProvider; diff --git a/crates/rpc/rpc/src/eth/pubsub.rs b/crates/rpc/rpc/src/eth/pubsub.rs index fdfa836b91ff4..ebe5e96e9f586 100644 --- a/crates/rpc/rpc/src/eth/pubsub.rs +++ b/crates/rpc/rpc/src/eth/pubsub.rs @@ -1,9 +1,7 @@ //! `eth_` `PubSub` RPC handler implementation -use crate::{ - eth::logs_utils, - result::{internal_rpc_err, invalid_params_rpc_err}, -}; +use std::sync::Arc; + use futures::StreamExt; use jsonrpsee::{ server::SubscriptionMessage, types::ErrorObject, PendingSubscriptionSink, SubscriptionSink, @@ -22,12 +20,16 @@ use reth_rpc_types::{ use reth_tasks::{TaskSpawner, TokioTaskExecutor}; use reth_transaction_pool::{NewTransactionEvent, TransactionPool}; use serde::Serialize; -use std::sync::Arc; use tokio_stream::{ wrappers::{BroadcastStream, ReceiverStream}, Stream, }; +use crate::{ + eth::logs_utils, + result::{internal_rpc_err, invalid_params_rpc_err}, +}; + /// `Eth` pubsub RPC implementation. /// /// This handles `eth_subscribe` RPC calls. diff --git a/crates/rpc/rpc/src/eth/revm_utils.rs b/crates/rpc/rpc/src/eth/revm_utils.rs index 4f4b9d7f02e4c..0af4d2b5463a4 100644 --- a/crates/rpc/rpc/src/eth/revm_utils.rs +++ b/crates/rpc/rpc/src/eth/revm_utils.rs @@ -1,6 +1,7 @@ //! utilities for working with revm -use crate::eth::error::{EthApiError, EthResult, RpcInvalidTransactionError}; +use std::cmp::min; + #[cfg(feature = "optimism")] use reth_primitives::revm::env::fill_op_tx_env; #[cfg(not(feature = "optimism"))] @@ -23,9 +24,10 @@ use revm::{ }, Database, }; -use std::cmp::min; use tracing::trace; +use crate::eth::error::{EthApiError, EthResult, RpcInvalidTransactionError}; + /// Helper type to work with different transaction types when configuring the EVM env. /// /// This makes it easier to handle errors. @@ -510,9 +512,10 @@ where #[cfg(test)] mod tests { - use super::*; use reth_primitives::constants::GWEI_TO_WEI; + use super::*; + #[test] fn test_ensure_0_fallback() { let CallFees { gas_price, .. } = diff --git a/crates/rpc/rpc/src/eth/signer.rs b/crates/rpc/rpc/src/eth/signer.rs index 50c06159c4f09..b7b95aa7aaeec 100644 --- a/crates/rpc/rpc/src/eth/signer.rs +++ b/crates/rpc/rpc/src/eth/signer.rs @@ -1,16 +1,17 @@ //! An abstraction over ethereum signers. -use crate::eth::error::SignError; +use std::collections::HashMap; + use alloy_dyn_abi::TypedData; +use dyn_clone::DynClone; use reth_primitives::{ eip191_hash_message, sign_message, Address, Signature, TransactionSigned, B256, }; use reth_rpc_types::TypedTransactionRequest; - -use dyn_clone::DynClone; use reth_rpc_types_compat::transaction::to_primitive_transaction; use secp256k1::SecretKey; -use std::collections::HashMap; + +use crate::eth::error::SignError; type Result = std::result::Result; @@ -121,9 +122,11 @@ impl EthSigner for DevSigner { #[cfg(test)] mod tests { - use super::*; - use reth_primitives::U256; use std::str::FromStr; + + use reth_primitives::U256; + + use super::*; fn build_signer() -> DevSigner { let addresses = vec![]; let secret = diff --git a/crates/rpc/rpc/src/eth/traits.rs b/crates/rpc/rpc/src/eth/traits.rs index 0f73ded3c82f1..96539b143f3d0 100644 --- a/crates/rpc/rpc/src/eth/traits.rs +++ b/crates/rpc/rpc/src/eth/traits.rs @@ -1,8 +1,9 @@ //! Additional helper traits that allow for more customization. -use crate::eth::error::EthResult; use std::fmt; +use crate::eth::error::EthResult; + /// A trait that allows for forwarding raw transactions. /// /// For example to a sequencer. diff --git a/crates/rpc/rpc/src/eth/utils.rs b/crates/rpc/rpc/src/eth/utils.rs index a4291c4b933d3..5e2cce1e891ac 100644 --- a/crates/rpc/rpc/src/eth/utils.rs +++ b/crates/rpc/rpc/src/eth/utils.rs @@ -1,8 +1,9 @@ //! Commonly used code snippets -use crate::eth::error::{EthApiError, EthResult}; use reth_primitives::{Bytes, PooledTransactionsElement, PooledTransactionsElementEcRecovered}; +use crate::eth::error::{EthApiError, EthResult}; + /// Recovers a [`PooledTransactionsElementEcRecovered`] from an enveloped encoded byte stream. /// /// See [`PooledTransactionsElement::decode_enveloped`] diff --git a/crates/rpc/rpc/src/net.rs b/crates/rpc/rpc/src/net.rs index 8e6615a281bf1..793affd8bb706 100644 --- a/crates/rpc/rpc/src/net.rs +++ b/crates/rpc/rpc/src/net.rs @@ -1,10 +1,11 @@ -use crate::eth::EthApiSpec; use jsonrpsee::core::RpcResult as Result; use reth_network_api::PeersInfo; use reth_primitives::U64; use reth_rpc_api::NetApiServer; use reth_rpc_types::PeerCount; +use crate::eth::EthApiSpec; + /// `Net` API implementation. /// /// This type provides the functionality for handling `net` related requests. diff --git a/crates/rpc/rpc/src/otterscan.rs b/crates/rpc/rpc/src/otterscan.rs index e658402f3a94a..b7639ade9ecb4 100644 --- a/crates/rpc/rpc/src/otterscan.rs +++ b/crates/rpc/rpc/src/otterscan.rs @@ -1,9 +1,6 @@ use alloy_primitives::Bytes; use async_trait::async_trait; use jsonrpsee::core::RpcResult; -use revm_inspectors::transfer::{TransferInspector, TransferKind}; -use revm_primitives::ExecutionResult; - use reth_primitives::{Address, BlockId, BlockNumberOrTag, TxHash, B256}; use reth_rpc_api::{EthApiServer, OtterscanServer}; use reth_rpc_types::{ @@ -13,6 +10,8 @@ use reth_rpc_types::{ }, BlockTransactions, Transaction, }; +use revm_inspectors::transfer::{TransferInspector, TransferKind}; +use revm_primitives::ExecutionResult; use crate::{eth::EthTransactions, result::internal_rpc_err}; diff --git a/crates/rpc/rpc/src/result.rs b/crates/rpc/rpc/src/result.rs index f00c9e279939f..6d15f51e77474 100644 --- a/crates/rpc/rpc/src/result.rs +++ b/crates/rpc/rpc/src/result.rs @@ -1,8 +1,9 @@ //! Additional helpers for converting errors. +use std::fmt::Display; + use jsonrpsee::core::RpcResult; use reth_rpc_types::engine::PayloadError; -use std::fmt::Display; /// Helper trait to easily convert various `Result` types into [`RpcResult`] pub trait ToRpcResult: Sized { @@ -151,9 +152,10 @@ pub(crate) fn rpc_err( #[cfg(test)] mod tests { - use super::*; use reth_errors::{RethError, RethResult}; + use super::*; + const fn assert_rpc_result>() {} #[test] diff --git a/crates/rpc/rpc/src/reth.rs b/crates/rpc/rpc/src/reth.rs index 17925b5ab8bf0..4fc0fa90f395c 100644 --- a/crates/rpc/rpc/src/reth.rs +++ b/crates/rpc/rpc/src/reth.rs @@ -1,4 +1,5 @@ -use crate::eth::error::{EthApiError, EthResult}; +use std::{collections::HashMap, future::Future, sync::Arc}; + use async_trait::async_trait; use jsonrpsee::core::RpcResult; use reth_errors::RethResult; @@ -6,9 +7,10 @@ use reth_primitives::{Address, BlockId, U256}; use reth_provider::{BlockReaderIdExt, ChangeSetReader, StateProviderFactory}; use reth_rpc_api::RethApiServer; use reth_tasks::TaskSpawner; -use std::{collections::HashMap, future::Future, sync::Arc}; use tokio::sync::oneshot; +use crate::eth::error::{EthApiError, EthResult}; + /// `reth` API implementation. /// /// This type provides the functionality for handling `reth` prototype RPC requests. diff --git a/crates/rpc/rpc/src/rpc.rs b/crates/rpc/rpc/src/rpc.rs index 0f74730f78ea7..77e91258ce64b 100644 --- a/crates/rpc/rpc/src/rpc.rs +++ b/crates/rpc/rpc/src/rpc.rs @@ -1,7 +1,8 @@ +use std::{collections::HashMap, sync::Arc}; + use jsonrpsee::core::RpcResult; use reth_rpc_api::RpcApiServer; use reth_rpc_types::RpcModules; -use std::{collections::HashMap, sync::Arc}; /// `rpc` API implementation. /// diff --git a/crates/rpc/rpc/src/trace.rs b/crates/rpc/rpc/src/trace.rs index e959a367e3f37..34239002825b2 100644 --- a/crates/rpc/rpc/src/trace.rs +++ b/crates/rpc/rpc/src/trace.rs @@ -1,9 +1,5 @@ -use crate::eth::{ - error::{EthApiError, EthResult}, - revm_utils::prepare_call_env, - utils::recover_raw_transaction, - EthTransactions, -}; +use std::{collections::HashSet, sync::Arc}; + use async_trait::async_trait; use jsonrpsee::core::RpcResult as Result; use reth_consensus_common::calc::{ @@ -32,9 +28,15 @@ use revm_inspectors::{ opcode::OpcodeGasInspector, tracing::{parity::populate_state_diff, TracingInspector, TracingInspectorConfig}, }; -use std::{collections::HashSet, sync::Arc}; use tokio::sync::{AcquireError, OwnedSemaphorePermit}; +use crate::eth::{ + error::{EthApiError, EthResult}, + revm_utils::prepare_call_env, + utils::recover_raw_transaction, + EthTransactions, +}; + /// `trace` API implementation. /// /// This type provides the functionality for handling `trace` related requests. diff --git a/crates/rpc/rpc/src/txpool.rs b/crates/rpc/rpc/src/txpool.rs index 71c342225165b..963497e1d8176 100644 --- a/crates/rpc/rpc/src/txpool.rs +++ b/crates/rpc/rpc/src/txpool.rs @@ -1,3 +1,5 @@ +use std::collections::BTreeMap; + use async_trait::async_trait; use jsonrpsee::core::RpcResult as Result; use reth_primitives::Address; @@ -7,7 +9,6 @@ use reth_rpc_types::{ Transaction, }; use reth_transaction_pool::{AllPoolTransactions, PoolTransaction, TransactionPool}; -use std::collections::BTreeMap; use tracing::trace; /// `txpool` API implementation. diff --git a/crates/rpc/rpc/src/web3.rs b/crates/rpc/rpc/src/web3.rs index 4ed94ac85523d..78464327aa2c7 100644 --- a/crates/rpc/rpc/src/web3.rs +++ b/crates/rpc/rpc/src/web3.rs @@ -1,10 +1,11 @@ -use crate::result::ToRpcResult; use async_trait::async_trait; use jsonrpsee::core::RpcResult; use reth_network_api::NetworkInfo; use reth_primitives::{keccak256, Bytes, B256}; use reth_rpc_api::Web3ApiServer; +use crate::result::ToRpcResult; + /// `web3` API implementation. /// /// This type provides the functionality for handling `web3` related requests. diff --git a/crates/stages/api/src/error.rs b/crates/stages/api/src/error.rs index 2f113f2fa8132..44155fe95a24a 100644 --- a/crates/stages/api/src/error.rs +++ b/crates/stages/api/src/error.rs @@ -1,4 +1,3 @@ -use crate::PipelineEvent; use alloy_primitives::{BlockNumber, TxNumber}; use reth_consensus::ConsensusError; use reth_errors::{BlockExecutionError, DatabaseError, RethError}; @@ -9,6 +8,8 @@ use reth_static_file_types::StaticFileSegment; use thiserror::Error; use tokio::sync::broadcast::error::SendError; +use crate::PipelineEvent; + /// Represents the specific error type within a block error. #[derive(Error, Debug)] pub enum BlockErrorKind { diff --git a/crates/stages/api/src/lib.rs b/crates/stages/api/src/lib.rs index ec01876c9951b..d4357d91b4b7f 100644 --- a/crates/stages/api/src/lib.rs +++ b/crates/stages/api/src/lib.rs @@ -20,12 +20,11 @@ mod stage; pub mod test_utils; mod util; -pub use crate::metrics::*; +use aquamarine as _; pub use error::*; pub use pipeline::*; -pub use stage::*; - -use aquamarine as _; - // re-export the stages types for convenience pub use reth_stages_types::*; +pub use stage::*; + +pub use crate::metrics::*; diff --git a/crates/stages/api/src/metrics/listener.rs b/crates/stages/api/src/metrics/listener.rs index e703367bcd672..af3cde0ebc3ac 100644 --- a/crates/stages/api/src/metrics/listener.rs +++ b/crates/stages/api/src/metrics/listener.rs @@ -1,14 +1,16 @@ -use crate::{metrics::SyncMetrics, StageCheckpoint, StageId}; -use alloy_primitives::BlockNumber; -use reth_primitives_traits::constants::MGAS_TO_GAS; use std::{ future::Future, pin::Pin, task::{ready, Context, Poll}, }; + +use alloy_primitives::BlockNumber; +use reth_primitives_traits::constants::MGAS_TO_GAS; use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender}; use tracing::trace; +use crate::{metrics::SyncMetrics, StageCheckpoint, StageId}; + /// Alias type for metric producers to use. pub type MetricEventsSender = UnboundedSender; diff --git a/crates/stages/api/src/metrics/sync_metrics.rs b/crates/stages/api/src/metrics/sync_metrics.rs index 3ee2964ea715c..829fd299fb3c2 100644 --- a/crates/stages/api/src/metrics/sync_metrics.rs +++ b/crates/stages/api/src/metrics/sync_metrics.rs @@ -1,9 +1,11 @@ -use crate::StageId; +use std::collections::HashMap; + use reth_metrics::{ metrics::{Counter, Gauge}, Metrics, }; -use std::collections::HashMap; + +use crate::StageId; #[derive(Debug, Default)] pub(crate) struct SyncMetrics { diff --git a/crates/stages/api/src/pipeline/builder.rs b/crates/stages/api/src/pipeline/builder.rs index 1e83af4c3c825..16d9a112d5c50 100644 --- a/crates/stages/api/src/pipeline/builder.rs +++ b/crates/stages/api/src/pipeline/builder.rs @@ -1,10 +1,11 @@ -use crate::{pipeline::BoxedStage, MetricEventsSender, Pipeline, Stage, StageId, StageSet}; use alloy_primitives::{BlockNumber, B256}; use reth_db_api::database::Database; use reth_provider::ProviderFactory; use reth_static_file::StaticFileProducer; use tokio::sync::watch; +use crate::{pipeline::BoxedStage, MetricEventsSender, Pipeline, Stage, StageId, StageSet}; + /// Builds a [`Pipeline`]. #[must_use = "call `build` to construct the pipeline"] pub struct PipelineBuilder diff --git a/crates/stages/api/src/pipeline/event.rs b/crates/stages/api/src/pipeline/event.rs index 879725886cf94..d9c502d4a2502 100644 --- a/crates/stages/api/src/pipeline/event.rs +++ b/crates/stages/api/src/pipeline/event.rs @@ -1,9 +1,11 @@ +use std::fmt::{Display, Formatter}; + +use alloy_primitives::BlockNumber; + use crate::{ stage::{ExecOutput, UnwindInput, UnwindOutput}, StageCheckpoint, StageId, }; -use alloy_primitives::BlockNumber; -use std::fmt::{Display, Formatter}; /// An event emitted by a [Pipeline][crate::Pipeline]. /// diff --git a/crates/stages/api/src/pipeline/mod.rs b/crates/stages/api/src/pipeline/mod.rs index 1be468702e432..984c2e422dff0 100644 --- a/crates/stages/api/src/pipeline/mod.rs +++ b/crates/stages/api/src/pipeline/mod.rs @@ -1,7 +1,7 @@ mod ctrl; mod event; -pub use crate::pipeline::ctrl::ControlFlow; -use crate::{PipelineTarget, StageCheckpoint, StageId}; +use std::pin::Pin; + use alloy_primitives::{BlockNumber, B256}; pub use event::*; use futures_util::Future; @@ -14,23 +14,26 @@ use reth_provider::{ use reth_prune::PrunerBuilder; use reth_static_file::StaticFileProducer; use reth_tokio_util::{EventSender, EventStream}; -use std::pin::Pin; use tokio::sync::watch; use tracing::*; +pub use crate::pipeline::ctrl::ControlFlow; +use crate::{PipelineTarget, StageCheckpoint, StageId}; + mod builder; mod progress; mod set; -use crate::{ - BlockErrorKind, ExecInput, ExecOutput, MetricEvent, MetricEventsSender, PipelineError, Stage, - StageError, StageExt, UnwindInput, -}; pub use builder::*; use progress::*; use reth_errors::RethResult; pub use set::*; +use crate::{ + BlockErrorKind, ExecInput, ExecOutput, MetricEvent, MetricEventsSender, PipelineError, Stage, + StageError, StageExt, UnwindInput, +}; + /// A container for a queued stage. pub(crate) type BoxedStage = Box>; @@ -586,8 +589,6 @@ impl std::fmt::Debug for Pipeline { #[cfg(test)] mod tests { - use super::*; - use crate::{test_utils::TestStage, UnwindOutput}; use assert_matches::assert_matches; use reth_consensus::ConsensusError; use reth_errors::ProviderError; @@ -596,6 +597,9 @@ mod tests { use reth_testing_utils::{generators, generators::random_header}; use tokio_stream::StreamExt; + use super::*; + use crate::{test_utils::TestStage, UnwindOutput}; + #[test] fn record_progress_calculates_outliers() { let mut progress = PipelineProgress::default(); diff --git a/crates/stages/api/src/pipeline/progress.rs b/crates/stages/api/src/pipeline/progress.rs index 4138f95ddf593..ea8f47c8deb6e 100644 --- a/crates/stages/api/src/pipeline/progress.rs +++ b/crates/stages/api/src/pipeline/progress.rs @@ -1,6 +1,7 @@ -use crate::{util::opt, ControlFlow}; use alloy_primitives::BlockNumber; +use crate::{util::opt, ControlFlow}; + #[derive(Debug, Default)] pub(crate) struct PipelineProgress { /// Block number reached by the stage. diff --git a/crates/stages/api/src/pipeline/set.rs b/crates/stages/api/src/pipeline/set.rs index 527d9a99a4687..134c687d0e016 100644 --- a/crates/stages/api/src/pipeline/set.rs +++ b/crates/stages/api/src/pipeline/set.rs @@ -1,10 +1,12 @@ -use crate::{Stage, StageId}; -use reth_db_api::database::Database; use std::{ collections::HashMap, fmt::{Debug, Formatter}, }; +use reth_db_api::database::Database; + +use crate::{Stage, StageId}; + /// Combines multiple [`Stage`]s into a single unit. /// /// A [`StageSet`] is a logical chunk of stages that depend on each other. It is up to the diff --git a/crates/stages/api/src/stage.rs b/crates/stages/api/src/stage.rs index b8178df46d515..9ae5cb7f386a9 100644 --- a/crates/stages/api/src/stage.rs +++ b/crates/stages/api/src/stage.rs @@ -1,7 +1,3 @@ -use crate::{error::StageError, StageCheckpoint, StageId}; -use alloy_primitives::{BlockNumber, TxNumber}; -use reth_db_api::database::Database; -use reth_provider::{BlockReader, DatabaseProviderRW, ProviderError, TransactionsProvider}; use std::{ cmp::{max, min}, future::{poll_fn, Future}, @@ -9,6 +5,12 @@ use std::{ task::{Context, Poll}, }; +use alloy_primitives::{BlockNumber, TxNumber}; +use reth_db_api::database::Database; +use reth_provider::{BlockReader, DatabaseProviderRW, ProviderError, TransactionsProvider}; + +use crate::{error::StageError, StageCheckpoint, StageId}; + /// Stage execution input, see [`Stage::execute`]. #[derive(Debug, Default, PartialEq, Eq, Clone, Copy)] pub struct ExecInput { diff --git a/crates/stages/api/src/test_utils.rs b/crates/stages/api/src/test_utils.rs index 8d76cee31bef3..bb5806d01faeb 100644 --- a/crates/stages/api/src/test_utils.rs +++ b/crates/stages/api/src/test_utils.rs @@ -1,9 +1,11 @@ #![allow(missing_docs)] -use crate::{ExecInput, ExecOutput, Stage, StageError, StageId, UnwindInput, UnwindOutput}; +use std::collections::VecDeque; + use reth_db_api::database::Database; use reth_provider::DatabaseProviderRW; -use std::collections::VecDeque; + +use crate::{ExecInput, ExecOutput, Stage, StageError, StageId, UnwindInput, UnwindOutput}; /// A test stage that can be used for testing. /// diff --git a/crates/stages/stages/benches/criterion.rs b/crates/stages/stages/benches/criterion.rs index 0e13437553b52..19ae613fe6a9e 100644 --- a/crates/stages/stages/benches/criterion.rs +++ b/crates/stages/stages/benches/criterion.rs @@ -1,10 +1,11 @@ #![allow(missing_docs)] +use std::{ops::RangeInclusive, sync::Arc}; + use criterion::{criterion_main, measurement::WallTime, BenchmarkGroup, Criterion}; #[cfg(not(target_os = "windows"))] use pprof::criterion::{Output, PProfProfiler}; use reth_config::config::{EtlConfig, TransactionLookupConfig}; use reth_db::{test_utils::TempDatabase, DatabaseEnv}; - use reth_primitives::BlockNumber; use reth_stages::{ stages::{MerkleStage, SenderRecoveryStage, TransactionLookupStage}, @@ -12,7 +13,6 @@ use reth_stages::{ StageCheckpoint, }; use reth_stages_api::{ExecInput, Stage, StageExt, UnwindInput}; -use std::{ops::RangeInclusive, sync::Arc}; use tokio::runtime::Runtime; mod setup; diff --git a/crates/stages/stages/benches/setup/account_hashing.rs b/crates/stages/stages/benches/setup/account_hashing.rs index 86831418e53f0..9eac2ec33560e 100644 --- a/crates/stages/stages/benches/setup/account_hashing.rs +++ b/crates/stages/stages/benches/setup/account_hashing.rs @@ -1,6 +1,7 @@ #![allow(unreachable_pub)] -use super::constants; +use std::{fs, ops::RangeInclusive, path::Path}; + use reth_db::tables; use reth_db_api::{ cursor::DbCursorRO, database::Database, transaction::DbTx, DatabaseError as DbError, @@ -11,7 +12,8 @@ use reth_stages::{ test_utils::TestStageDB, StageCheckpoint, }; -use std::{fs, ops::RangeInclusive, path::Path}; + +use super::constants; /// Prepares a database for [`AccountHashingStage`] /// If the environment variable [`constants::ACCOUNT_HASHING_DB`] is set, it will use that one and diff --git a/crates/stages/stages/benches/setup/mod.rs b/crates/stages/stages/benches/setup/mod.rs index de08526bec4a3..c20f5bb8c94b5 100644 --- a/crates/stages/stages/benches/setup/mod.rs +++ b/crates/stages/stages/benches/setup/mod.rs @@ -1,4 +1,6 @@ #![allow(unreachable_pub)] +use std::{collections::BTreeMap, fs, path::Path, sync::Arc}; + use itertools::concat; use reth_db::{tables, test_utils::TempDatabase, DatabaseEnv}; use reth_db_api::{ @@ -18,7 +20,6 @@ use reth_testing_utils::{ }, }; use reth_trie::StateRoot; -use std::{collections::BTreeMap, fs, path::Path, sync::Arc}; use tokio::runtime::Handle; mod constants; diff --git a/crates/stages/stages/src/sets.rs b/crates/stages/stages/src/sets.rs index d5d132810daae..0e3cee0ddc7e1 100644 --- a/crates/stages/stages/src/sets.rs +++ b/crates/stages/stages/src/sets.rs @@ -33,14 +33,8 @@ //! //! # } //! ``` -use crate::{ - stages::{ - AccountHashingStage, BodyStage, ExecutionStage, FinishStage, HeaderStage, - IndexAccountHistoryStage, IndexStorageHistoryStage, MerkleStage, SenderRecoveryStage, - StorageHashingStage, TransactionLookupStage, - }, - StageSet, StageSetBuilder, -}; +use std::sync::Arc; + use reth_config::config::StageConfig; use reth_consensus::Consensus; use reth_db_api::database::Database; @@ -49,9 +43,17 @@ use reth_network_p2p::{bodies::downloader::BodyDownloader, headers::downloader:: use reth_primitives::B256; use reth_provider::HeaderSyncGapProvider; use reth_prune_types::PruneModes; -use std::sync::Arc; use tokio::sync::watch; +use crate::{ + stages::{ + AccountHashingStage, BodyStage, ExecutionStage, FinishStage, HeaderStage, + IndexAccountHistoryStage, IndexStorageHistoryStage, MerkleStage, SenderRecoveryStage, + StorageHashingStage, TransactionLookupStage, + }, + StageSet, StageSetBuilder, +}; + /// A set containing all stages to run a fully syncing instance of reth. /// /// A combination of (in order) diff --git a/crates/stages/stages/src/stages/bodies.rs b/crates/stages/stages/src/stages/bodies.rs index 6776597a6065c..1c8c75a8d47b8 100644 --- a/crates/stages/stages/src/stages/bodies.rs +++ b/crates/stages/stages/src/stages/bodies.rs @@ -4,8 +4,6 @@ use std::{ }; use futures_util::TryStreamExt; -use tracing::*; - use reth_db::tables; use reth_db_api::{ cursor::{DbCursorRO, DbCursorRW}, @@ -24,6 +22,7 @@ use reth_stages_api::{ UnwindInput, UnwindOutput, }; use reth_storage_errors::provider::ProviderResult; +use tracing::*; // TODO(onbjerg): Metrics and events (gradual status for e.g. CLI) /// The body stage downloads block bodies. @@ -394,17 +393,15 @@ fn stage_checkpoint( #[cfg(test)] mod tests { use assert_matches::assert_matches; - use reth_provider::StaticFileProviderFactory; use reth_stages_api::StageUnitCheckpoint; use test_utils::*; + use super::*; use crate::test_utils::{ stage_test_suite_ext, ExecuteStageTestRunner, StageTestRunner, UnwindStageTestRunner, }; - use super::*; - stage_test_suite_ext!(BodyTestRunner, body); /// Checks that the stage downloads at most `batch_size` blocks. @@ -612,13 +609,14 @@ mod tests { } mod test_utils { - use crate::{ - stages::bodies::BodyStage, - test_utils::{ - ExecuteStageTestRunner, StageTestRunner, TestRunnerError, TestStageDB, - UnwindStageTestRunner, - }, + use std::{ + collections::{HashMap, VecDeque}, + ops::RangeInclusive, + pin::Pin, + sync::Arc, + task::{Context, Poll}, }; + use futures_util::Stream; use reth_db::{static_file::HeaderMask, tables, test_utils::TempDatabase, DatabaseEnv}; use reth_db_api::{ @@ -646,12 +644,13 @@ mod tests { generators, generators::{random_block_range, random_signed_tx}, }; - use std::{ - collections::{HashMap, VecDeque}, - ops::RangeInclusive, - pin::Pin, - sync::Arc, - task::{Context, Poll}, + + use crate::{ + stages::bodies::BodyStage, + test_utils::{ + ExecuteStageTestRunner, StageTestRunner, TestRunnerError, TestStageDB, + UnwindStageTestRunner, + }, }; /// The block hash of the genesis block. diff --git a/crates/stages/stages/src/stages/execution.rs b/crates/stages/stages/src/stages/execution.rs index a37c081b4da75..2d23705e685e2 100644 --- a/crates/stages/stages/src/stages/execution.rs +++ b/crates/stages/stages/src/stages/execution.rs @@ -1,4 +1,11 @@ -use crate::stages::MERKLE_STAGE_DEFAULT_CLEAN_THRESHOLD; +use std::{ + cmp::Ordering, + ops::RangeInclusive, + sync::Arc, + task::{ready, Context, Poll}, + time::{Duration, Instant}, +}; + use num_traits::Zero; use reth_config::config::ExecutionConfig; use reth_db::{static_file::HeaderMask, tables}; @@ -22,15 +29,10 @@ use reth_stages_api::{ ExecutionCheckpoint, MetricEvent, MetricEventsSender, Stage, StageCheckpoint, StageError, StageId, UnwindInput, UnwindOutput, }; -use std::{ - cmp::Ordering, - ops::RangeInclusive, - sync::Arc, - task::{ready, Context, Poll}, - time::{Duration, Instant}, -}; use tracing::*; +use crate::stages::MERKLE_STAGE_DEFAULT_CLEAN_THRESHOLD; + /// The execution stage executes all transactions and /// update history indexes. /// @@ -703,8 +705,8 @@ where #[cfg(test)] mod tests { - use super::*; - use crate::test_utils::TestStageDB; + use std::collections::BTreeMap; + use alloy_rlp::Decodable; use assert_matches::assert_matches; use reth_chainspec::ChainSpecBuilder; @@ -721,7 +723,9 @@ mod tests { }; use reth_prune_types::{PruneMode, ReceiptsLogPruneConfig}; use reth_stages_api::StageUnitCheckpoint; - use std::collections::BTreeMap; + + use super::*; + use crate::test_utils::TestStageDB; fn stage() -> ExecutionStage { let executor_provider = EthExecutorProvider::ethereum(Arc::new( diff --git a/crates/stages/stages/src/stages/finish.rs b/crates/stages/stages/src/stages/finish.rs index 9eb3a6d762b8d..14524cbe3aeca 100644 --- a/crates/stages/stages/src/stages/finish.rs +++ b/crates/stages/stages/src/stages/finish.rs @@ -36,11 +36,6 @@ impl Stage for FinishStage { #[cfg(test)] mod tests { - use super::*; - use crate::test_utils::{ - stage_test_suite_ext, ExecuteStageTestRunner, StageTestRunner, TestRunnerError, - TestStageDB, UnwindStageTestRunner, - }; use reth_primitives::SealedHeader; use reth_provider::providers::StaticFileWriter; use reth_testing_utils::{ @@ -48,6 +43,12 @@ mod tests { generators::{random_header, random_header_range}, }; + use super::*; + use crate::test_utils::{ + stage_test_suite_ext, ExecuteStageTestRunner, StageTestRunner, TestRunnerError, + TestStageDB, UnwindStageTestRunner, + }; + stage_test_suite_ext!(FinishTestRunner, finish); #[derive(Default)] diff --git a/crates/stages/stages/src/stages/hashing_account.rs b/crates/stages/stages/src/stages/hashing_account.rs index fe8bc8547a58f..8fa824ea88d42 100644 --- a/crates/stages/stages/src/stages/hashing_account.rs +++ b/crates/stages/stages/src/stages/hashing_account.rs @@ -1,3 +1,9 @@ +use std::{ + fmt::Debug, + ops::{Range, RangeInclusive}, + sync::mpsc::{self, Receiver}, +}; + use itertools::Itertools; use reth_config::config::{EtlConfig, HashingConfig}; use reth_db::{tables, RawKey, RawTable, RawValue}; @@ -14,11 +20,6 @@ use reth_stages_api::{ StageError, StageId, UnwindInput, UnwindOutput, }; use reth_storage_errors::provider::ProviderResult; -use std::{ - fmt::Debug, - ops::{Range, RangeInclusive}, - sync::mpsc::{self, Receiver}, -}; use tracing::*; /// Maximum number of channels that can exist in memory. @@ -289,17 +290,18 @@ fn stage_checkpoint_progress( #[cfg(test)] mod tests { - use super::*; - use crate::test_utils::{ - stage_test_suite_ext, ExecuteStageTestRunner, StageTestRunner, TestRunnerError, - UnwindStageTestRunner, - }; use assert_matches::assert_matches; use reth_primitives::{Account, U256}; use reth_provider::providers::StaticFileWriter; use reth_stages_api::StageUnitCheckpoint; use test_utils::*; + use super::*; + use crate::test_utils::{ + stage_test_suite_ext, ExecuteStageTestRunner, StageTestRunner, TestRunnerError, + UnwindStageTestRunner, + }; + stage_test_suite_ext!(AccountHashingTestRunner, account_hashing); #[tokio::test] @@ -343,9 +345,10 @@ mod tests { } mod test_utils { + use reth_primitives::Address; + use super::*; use crate::test_utils::TestStageDB; - use reth_primitives::Address; pub(crate) struct AccountHashingTestRunner { pub(crate) db: TestStageDB, diff --git a/crates/stages/stages/src/stages/hashing_storage.rs b/crates/stages/stages/src/stages/hashing_storage.rs index 662f1d1a77285..0873369e748ef 100644 --- a/crates/stages/stages/src/stages/hashing_storage.rs +++ b/crates/stages/stages/src/stages/hashing_storage.rs @@ -1,3 +1,8 @@ +use std::{ + fmt::Debug, + sync::mpsc::{self, Receiver}, +}; + use itertools::Itertools; use reth_config::config::{EtlConfig, HashingConfig}; use reth_db::tables; @@ -16,10 +21,6 @@ use reth_stages_api::{ StorageHashingCheckpoint, UnwindInput, UnwindOutput, }; use reth_storage_errors::provider::ProviderResult; -use std::{ - fmt::Debug, - sync::mpsc::{self, Receiver}, -}; use tracing::*; /// Maximum number of channels that can exist in memory. @@ -210,11 +211,6 @@ fn stage_checkpoint_progress( #[cfg(test)] mod tests { - use super::*; - use crate::test_utils::{ - stage_test_suite_ext, ExecuteStageTestRunner, StageTestRunner, TestRunnerError, - TestStageDB, UnwindStageTestRunner, - }; use assert_matches::assert_matches; use rand::Rng; use reth_db_api::{ @@ -228,6 +224,12 @@ mod tests { generators::{random_block_range, random_contract_account_range}, }; + use super::*; + use crate::test_utils::{ + stage_test_suite_ext, ExecuteStageTestRunner, StageTestRunner, TestRunnerError, + TestStageDB, UnwindStageTestRunner, + }; + stage_test_suite_ext!(StorageHashingTestRunner, storage_hashing); /// Execute with low clean threshold so as to hash whole storage diff --git a/crates/stages/stages/src/stages/headers.rs b/crates/stages/stages/src/stages/headers.rs index 3d05ea52d960d..97d5e0f79451f 100644 --- a/crates/stages/stages/src/stages/headers.rs +++ b/crates/stages/stages/src/stages/headers.rs @@ -1,3 +1,8 @@ +use std::{ + sync::Arc, + task::{ready, Context, Poll}, +}; + use futures_util::StreamExt; use reth_codecs::Compact; use reth_config::config::EtlConfig; @@ -20,10 +25,6 @@ use reth_stages_api::{ HeadersCheckpoint, Stage, StageCheckpoint, StageError, StageId, UnwindInput, UnwindOutput, }; use reth_storage_errors::provider::ProviderError; -use std::{ - sync::Arc, - task::{ready, Context, Poll}, -}; use tokio::sync::watch; use tracing::*; @@ -371,10 +372,6 @@ where #[cfg(test)] mod tests { - use super::*; - use crate::test_utils::{ - stage_test_suite, ExecuteStageTestRunner, StageTestRunner, UnwindStageTestRunner, - }; use assert_matches::assert_matches; use reth_execution_types::ExecutionOutcome; use reth_primitives::{BlockBody, SealedBlock, SealedBlockWithSenders, B256}; @@ -384,9 +381,12 @@ mod tests { use reth_trie::{updates::TrieUpdates, HashedPostState}; use test_runner::HeadersTestRunner; + use super::*; + use crate::test_utils::{ + stage_test_suite, ExecuteStageTestRunner, StageTestRunner, UnwindStageTestRunner, + }; + mod test_runner { - use super::*; - use crate::test_utils::{TestRunnerError, TestStageDB}; use reth_consensus::test_utils::TestConsensus; use reth_db::{test_utils::TempDatabase, DatabaseEnv}; use reth_downloaders::headers::reverse_headers::{ @@ -396,6 +396,9 @@ mod tests { use reth_provider::BlockNumReader; use tokio::sync::watch; + use super::*; + use crate::test_utils::{TestRunnerError, TestStageDB}; + pub(crate) struct HeadersTestRunner { pub(crate) client: TestHeadersClient, channel: (watch::Sender, watch::Receiver), diff --git a/crates/stages/stages/src/stages/index_account_history.rs b/crates/stages/stages/src/stages/index_account_history.rs index 7f83185277c62..cb1802bbf2078 100644 --- a/crates/stages/stages/src/stages/index_account_history.rs +++ b/crates/stages/stages/src/stages/index_account_history.rs @@ -1,4 +1,5 @@ -use super::{collect_history_indices, load_history_indices}; +use std::fmt::Debug; + use reth_config::config::{EtlConfig, IndexHistoryConfig}; use reth_db::tables; use reth_db_api::{database::Database, models::ShardedKey, table::Decode, transaction::DbTxMut}; @@ -10,9 +11,10 @@ use reth_prune_types::{PruneCheckpoint, PruneMode, PrunePurpose, PruneSegment}; use reth_stages_api::{ ExecInput, ExecOutput, Stage, StageCheckpoint, StageError, StageId, UnwindInput, UnwindOutput, }; -use std::fmt::Debug; use tracing::info; +use super::{collect_history_indices, load_history_indices}; + /// Stage is indexing history the account changesets generated in /// [`ExecutionStage`][crate::stages::ExecutionStage]. For more information /// on index sharding take a look at [`tables::AccountsHistory`] @@ -141,11 +143,8 @@ impl Stage for IndexAccountHistoryStage { #[cfg(test)] mod tests { - use super::*; - use crate::test_utils::{ - stage_test_suite_ext, ExecuteStageTestRunner, StageTestRunner, TestRunnerError, - TestStageDB, UnwindStageTestRunner, - }; + use std::collections::BTreeMap; + use itertools::Itertools; use reth_db::BlockNumberList; use reth_db_api::{ @@ -162,7 +161,12 @@ mod tests { generators, generators::{random_block_range, random_changeset_range, random_contract_account_range}, }; - use std::collections::BTreeMap; + + use super::*; + use crate::test_utils::{ + stage_test_suite_ext, ExecuteStageTestRunner, StageTestRunner, TestRunnerError, + TestStageDB, UnwindStageTestRunner, + }; const ADDRESS: Address = address!("0000000000000000000000000000000000000001"); diff --git a/crates/stages/stages/src/stages/index_storage_history.rs b/crates/stages/stages/src/stages/index_storage_history.rs index 23332f2d6ee86..a618346b88e5c 100644 --- a/crates/stages/stages/src/stages/index_storage_history.rs +++ b/crates/stages/stages/src/stages/index_storage_history.rs @@ -1,5 +1,5 @@ -use super::{collect_history_indices, load_history_indices}; -use crate::{StageCheckpoint, StageId}; +use std::fmt::Debug; + use reth_config::config::{EtlConfig, IndexHistoryConfig}; use reth_db::tables; use reth_db_api::{ @@ -13,9 +13,11 @@ use reth_provider::{ }; use reth_prune_types::{PruneCheckpoint, PruneMode, PrunePurpose, PruneSegment}; use reth_stages_api::{ExecInput, ExecOutput, Stage, StageError, UnwindInput, UnwindOutput}; -use std::fmt::Debug; use tracing::info; +use super::{collect_history_indices, load_history_indices}; +use crate::{StageCheckpoint, StageId}; + /// Stage is indexing history the account changesets generated in /// [`ExecutionStage`][crate::stages::ExecutionStage]. For more information /// on index sharding take a look at [`tables::StoragesHistory`]. @@ -147,11 +149,8 @@ impl Stage for IndexStorageHistoryStage { #[cfg(test)] mod tests { - use super::*; - use crate::test_utils::{ - stage_test_suite_ext, ExecuteStageTestRunner, StageTestRunner, TestRunnerError, - TestStageDB, UnwindStageTestRunner, - }; + use std::collections::BTreeMap; + use itertools::Itertools; use reth_db::BlockNumberList; use reth_db_api::{ @@ -168,7 +167,12 @@ mod tests { generators, generators::{random_block_range, random_changeset_range, random_contract_account_range}, }; - use std::collections::BTreeMap; + + use super::*; + use crate::test_utils::{ + stage_test_suite_ext, ExecuteStageTestRunner, StageTestRunner, TestRunnerError, + TestStageDB, UnwindStageTestRunner, + }; const ADDRESS: Address = address!("0000000000000000000000000000000000000001"); const STORAGE_KEY: B256 = diff --git a/crates/stages/stages/src/stages/merkle.rs b/crates/stages/stages/src/stages/merkle.rs index 5a3d31a404368..c28e200493c42 100644 --- a/crates/stages/stages/src/stages/merkle.rs +++ b/crates/stages/stages/src/stages/merkle.rs @@ -1,3 +1,5 @@ +use std::fmt::Debug; + use reth_codecs::Compact; use reth_consensus::ConsensusError; use reth_db::tables; @@ -15,7 +17,6 @@ use reth_stages_api::{ StageCheckpoint, StageError, StageId, UnwindInput, UnwindOutput, }; use reth_trie::{IntermediateStateRootState, StateRoot, StateRootProgress, StoredSubNode}; -use std::fmt::Debug; use tracing::*; // TODO: automate the process outlined below so the user can just send in a debugging package @@ -358,11 +359,8 @@ fn validate_state_root( #[cfg(test)] mod tests { - use super::*; - use crate::test_utils::{ - stage_test_suite_ext, ExecuteStageTestRunner, StageTestRunner, StorageKind, - TestRunnerError, TestStageDB, UnwindStageTestRunner, - }; + use std::collections::BTreeMap; + use assert_matches::assert_matches; use reth_db_api::cursor::{DbCursorRO, DbCursorRW, DbDupCursorRO}; use reth_primitives::{keccak256, SealedBlock, StaticFileSegment, StorageEntry, U256}; @@ -375,7 +373,12 @@ mod tests { }, }; use reth_trie::test_utils::{state_root, state_root_prehashed}; - use std::collections::BTreeMap; + + use super::*; + use crate::test_utils::{ + stage_test_suite_ext, ExecuteStageTestRunner, StageTestRunner, StorageKind, + TestRunnerError, TestStageDB, UnwindStageTestRunner, + }; stage_test_suite_ext!(MerkleTestRunner, merkle); diff --git a/crates/stages/stages/src/stages/mod.rs b/crates/stages/stages/src/stages/mod.rs index 8d850b8ba13af..2d2dc92e11503 100644 --- a/crates/stages/stages/src/stages/mod.rs +++ b/crates/stages/stages/src/stages/mod.rs @@ -30,7 +30,6 @@ pub use headers::*; pub use index_account_history::*; pub use index_storage_history::*; pub use merkle::*; - pub use sender_recovery::*; pub use tx_lookup::*; @@ -39,8 +38,8 @@ use utils::*; #[cfg(test)] mod tests { - use super::*; - use crate::test_utils::{StorageKind, TestStageDB}; + use std::{io::Write, sync::Arc}; + use alloy_rlp::Decodable; use reth_chainspec::ChainSpecBuilder; use reth_db::{ @@ -68,7 +67,9 @@ mod tests { use reth_prune_types::{PruneMode, PruneModes}; use reth_stages_api::{ExecInput, PipelineTarget, Stage, StageCheckpoint, StageId}; use reth_testing_utils::generators::{self, random_block, random_block_range, random_receipt}; - use std::{io::Write, sync::Arc}; + + use super::*; + use crate::test_utils::{StorageKind, TestStageDB}; #[tokio::test] #[ignore] diff --git a/crates/stages/stages/src/stages/sender_recovery.rs b/crates/stages/stages/src/stages/sender_recovery.rs index 41df7795c3c4e..fcb846bf24291 100644 --- a/crates/stages/stages/src/stages/sender_recovery.rs +++ b/crates/stages/stages/src/stages/sender_recovery.rs @@ -1,3 +1,5 @@ +use std::{fmt::Debug, ops::Range, sync::mpsc}; + use reth_config::config::SenderRecoveryConfig; use reth_consensus::ConsensusError; use reth_db::{static_file::TransactionMask, tables, RawValue}; @@ -16,7 +18,6 @@ use reth_stages_api::{ BlockErrorKind, EntitiesCheckpoint, ExecInput, ExecOutput, Stage, StageCheckpoint, StageError, StageId, UnwindInput, UnwindOutput, }; -use std::{fmt::Debug, ops::Range, sync::mpsc}; use thiserror::Error; use tracing::*; diff --git a/crates/stages/stages/src/stages/tx_lookup.rs b/crates/stages/stages/src/stages/tx_lookup.rs index 4cb422e3392d2..eb18d6131c309 100644 --- a/crates/stages/stages/src/stages/tx_lookup.rs +++ b/crates/stages/stages/src/stages/tx_lookup.rs @@ -236,11 +236,8 @@ fn stage_checkpoint( #[cfg(test)] mod tests { - use super::*; - use crate::test_utils::{ - stage_test_suite_ext, ExecuteStageTestRunner, StageTestRunner, StorageKind, - TestRunnerError, TestStageDB, UnwindStageTestRunner, - }; + use std::ops::Sub; + use assert_matches::assert_matches; use reth_primitives::{BlockNumber, SealedBlock, B256}; use reth_provider::{providers::StaticFileWriter, StaticFileProviderFactory}; @@ -249,7 +246,12 @@ mod tests { generators, generators::{random_block, random_block_range}, }; - use std::ops::Sub; + + use super::*; + use crate::test_utils::{ + stage_test_suite_ext, ExecuteStageTestRunner, StageTestRunner, StorageKind, + TestRunnerError, TestStageDB, UnwindStageTestRunner, + }; // Implement stage test suite. stage_test_suite_ext!(TransactionLookupTestRunner, transaction_lookup); diff --git a/crates/stages/stages/src/stages/utils.rs b/crates/stages/stages/src/stages/utils.rs index 6665d2278cd63..254262401b5f0 100644 --- a/crates/stages/stages/src/stages/utils.rs +++ b/crates/stages/stages/src/stages/utils.rs @@ -1,4 +1,6 @@ //! Utils for `stages`. +use std::{collections::HashMap, hash::Hash, ops::RangeBounds}; + use reth_config::config::EtlConfig; use reth_db::BlockNumberList; use reth_db_api::{ @@ -11,7 +13,6 @@ use reth_db_api::{ use reth_etl::Collector; use reth_primitives::BlockNumber; use reth_stages_api::StageError; -use std::{collections::HashMap, hash::Hash, ops::RangeBounds}; use tracing::info; /// Number of blocks before pushing indices from cache to [`Collector`] diff --git a/crates/stages/stages/src/test_utils/runner.rs b/crates/stages/stages/src/test_utils/runner.rs index d0003ff12d904..f81765e26e226 100644 --- a/crates/stages/stages/src/test_utils/runner.rs +++ b/crates/stages/stages/src/test_utils/runner.rs @@ -1,13 +1,15 @@ -use super::TestStageDB; +use std::sync::Arc; + use reth_db::{test_utils::TempDatabase, DatabaseEnv}; use reth_provider::ProviderError; use reth_stages_api::{ ExecInput, ExecOutput, Stage, StageError, StageExt, UnwindInput, UnwindOutput, }; use reth_storage_errors::db::DatabaseError; -use std::sync::Arc; use tokio::sync::oneshot; +use super::TestStageDB; + #[derive(thiserror::Error, Debug)] pub(crate) enum TestRunnerError { #[error(transparent)] diff --git a/crates/stages/stages/src/test_utils/set.rs b/crates/stages/stages/src/test_utils/set.rs index d17695168e2cd..74c8aa2b78114 100644 --- a/crates/stages/stages/src/test_utils/set.rs +++ b/crates/stages/stages/src/test_utils/set.rs @@ -1,8 +1,10 @@ -use super::TEST_STAGE_ID; -use crate::{StageSet, StageSetBuilder}; +use std::collections::VecDeque; + use reth_db_api::database::Database; use reth_stages_api::{test_utils::TestStage, ExecOutput, StageError, UnwindOutput}; -use std::collections::VecDeque; + +use super::TEST_STAGE_ID; +use crate::{StageSet, StageSetBuilder}; #[derive(Default, Debug)] pub struct TestStages { diff --git a/crates/stages/stages/src/test_utils/test_db.rs b/crates/stages/stages/src/test_utils/test_db.rs index 8f72b5aab2254..98a7cd19f40e9 100644 --- a/crates/stages/stages/src/test_utils/test_db.rs +++ b/crates/stages/stages/src/test_utils/test_db.rs @@ -1,3 +1,5 @@ +use std::{collections::BTreeMap, path::Path, sync::Arc}; + use reth_chainspec::MAINNET; use reth_db::{ tables, @@ -25,7 +27,6 @@ use reth_provider::{ }; use reth_storage_errors::provider::ProviderResult; use reth_testing_utils::generators::ChangeSet; -use std::{collections::BTreeMap, path::Path, sync::Arc}; use tempfile::TempDir; /// Test database that is used for testing stage implementations. diff --git a/crates/stages/types/src/checkpoints.rs b/crates/stages/types/src/checkpoints.rs index d7188de1be9f2..e0b7094e14080 100644 --- a/crates/stages/types/src/checkpoints.rs +++ b/crates/stages/types/src/checkpoints.rs @@ -1,8 +1,9 @@ +use std::ops::RangeInclusive; + use alloy_primitives::{Address, BlockNumber, B256}; use bytes::Buf; use reth_codecs::{main_codec, Compact}; use reth_trie_common::{hash_builder::HashBuilderState, StoredSubNode}; -use std::ops::RangeInclusive; use super::StageId; @@ -374,9 +375,10 @@ stage_unit_checkpoints!( #[cfg(test)] mod tests { - use super::*; use rand::Rng; + use super::*; + #[test] fn merkle_checkpoint_roundtrip() { let mut rng = rand::thread_rng(); diff --git a/crates/static-file/static-file/src/event.rs b/crates/static-file/static-file/src/event.rs index a11333ce53a27..be5d8330880aa 100644 --- a/crates/static-file/static-file/src/event.rs +++ b/crates/static-file/static-file/src/event.rs @@ -1,6 +1,7 @@ -use crate::StaticFileTargets; use std::time::Duration; +use crate::StaticFileTargets; + /// An event emitted by a [`StaticFileProducer`][crate::StaticFileProducer]. #[derive(Debug, PartialEq, Eq, Clone)] pub enum StaticFileProducerEvent { diff --git a/crates/static-file/static-file/src/lib.rs b/crates/static-file/static-file/src/lib.rs index 1bfe4134e954f..246ccf15a6e07 100644 --- a/crates/static-file/static-file/src/lib.rs +++ b/crates/static-file/static-file/src/lib.rs @@ -12,10 +12,9 @@ pub mod segments; mod static_file_producer; pub use event::StaticFileProducerEvent; +// Re-export for convenience. +pub use reth_static_file_types::*; pub use static_file_producer::{ StaticFileProducer, StaticFileProducerInner, StaticFileProducerResult, StaticFileProducerWithResult, StaticFileTargets, }; - -// Re-export for convenience. -pub use reth_static_file_types::*; diff --git a/crates/static-file/static-file/src/segments/headers.rs b/crates/static-file/static-file/src/segments/headers.rs index e87c1fdc58e8e..35d218599b3cc 100644 --- a/crates/static-file/static-file/src/segments/headers.rs +++ b/crates/static-file/static-file/src/segments/headers.rs @@ -1,4 +1,5 @@ -use crate::segments::{dataset_for_compression, prepare_jar, Segment, SegmentHeader}; +use std::{ops::RangeInclusive, path::Path}; + use alloy_primitives::BlockNumber; use reth_db::{static_file::create_static_file_T1_T2_T3, tables, RawKey, RawTable}; use reth_db_api::{cursor::DbCursorRO, database::Database, transaction::DbTx}; @@ -8,7 +9,8 @@ use reth_provider::{ }; use reth_static_file_types::{SegmentConfig, StaticFileSegment}; use reth_storage_errors::provider::ProviderResult; -use std::{ops::RangeInclusive, path::Path}; + +use crate::segments::{dataset_for_compression, prepare_jar, Segment, SegmentHeader}; /// Static File segment responsible for [`StaticFileSegment::Headers`] part of data. #[derive(Debug, Default)] diff --git a/crates/static-file/static-file/src/segments/mod.rs b/crates/static-file/static-file/src/segments/mod.rs index 77798dd085426..f1a2d284c3931 100644 --- a/crates/static-file/static-file/src/segments/mod.rs +++ b/crates/static-file/static-file/src/segments/mod.rs @@ -7,9 +7,10 @@ mod headers; pub use headers::Headers; mod receipts; -pub use receipts::Receipts; +use std::{ops::RangeInclusive, path::Path}; use alloy_primitives::BlockNumber; +pub use receipts::Receipts; use reth_db::{RawKey, RawTable}; use reth_db_api::{cursor::DbCursorRO, database::Database, table::Table, transaction::DbTx}; use reth_nippy_jar::NippyJar; @@ -21,7 +22,6 @@ use reth_static_file_types::{ SegmentHeader, StaticFileSegment, }; use reth_storage_errors::provider::ProviderResult; -use std::{ops::RangeInclusive, path::Path}; pub(crate) type Rows = [Vec>; COLUMNS]; diff --git a/crates/static-file/static-file/src/segments/receipts.rs b/crates/static-file/static-file/src/segments/receipts.rs index e09b5e690df9c..e20b3642e38b8 100644 --- a/crates/static-file/static-file/src/segments/receipts.rs +++ b/crates/static-file/static-file/src/segments/receipts.rs @@ -1,4 +1,5 @@ -use crate::segments::{dataset_for_compression, prepare_jar, Segment}; +use std::{ops::RangeInclusive, path::Path}; + use alloy_primitives::{BlockNumber, TxNumber}; use reth_db::{static_file::create_static_file_T1, tables}; use reth_db_api::{cursor::DbCursorRO, database::Database, transaction::DbTx}; @@ -8,7 +9,8 @@ use reth_provider::{ }; use reth_static_file_types::{SegmentConfig, SegmentHeader, StaticFileSegment}; use reth_storage_errors::provider::{ProviderError, ProviderResult}; -use std::{ops::RangeInclusive, path::Path}; + +use crate::segments::{dataset_for_compression, prepare_jar, Segment}; /// Static File segment responsible for [`StaticFileSegment::Receipts`] part of data. #[derive(Debug, Default)] diff --git a/crates/static-file/static-file/src/segments/transactions.rs b/crates/static-file/static-file/src/segments/transactions.rs index c7daeba0675f8..df03ef43f1342 100644 --- a/crates/static-file/static-file/src/segments/transactions.rs +++ b/crates/static-file/static-file/src/segments/transactions.rs @@ -1,4 +1,5 @@ -use crate::segments::{dataset_for_compression, prepare_jar, Segment}; +use std::{ops::RangeInclusive, path::Path}; + use alloy_primitives::{BlockNumber, TxNumber}; use reth_db::{static_file::create_static_file_T1, tables}; use reth_db_api::{cursor::DbCursorRO, database::Database, transaction::DbTx}; @@ -8,7 +9,8 @@ use reth_provider::{ }; use reth_static_file_types::{SegmentConfig, SegmentHeader, StaticFileSegment}; use reth_storage_errors::provider::{ProviderError, ProviderResult}; -use std::{ops::RangeInclusive, path::Path}; + +use crate::segments::{dataset_for_compression, prepare_jar, Segment}; /// Static File segment responsible for [`StaticFileSegment::Transactions`] part of data. #[derive(Debug, Default)] diff --git a/crates/static-file/static-file/src/static_file_producer.rs b/crates/static-file/static-file/src/static_file_producer.rs index eb94228044958..2bc0a7dc30ca5 100644 --- a/crates/static-file/static-file/src/static_file_producer.rs +++ b/crates/static-file/static-file/src/static_file_producer.rs @@ -1,6 +1,11 @@ //! Support for producing static files. -use crate::{segments, segments::Segment, StaticFileProducerEvent}; +use std::{ + ops::{Deref, RangeInclusive}, + sync::Arc, + time::Instant, +}; + use alloy_primitives::BlockNumber; use parking_lot::Mutex; use rayon::prelude::*; @@ -14,13 +19,10 @@ use reth_stages_types::StageId; use reth_static_file_types::HighestStaticFiles; use reth_storage_errors::provider::ProviderResult; use reth_tokio_util::{EventSender, EventStream}; -use std::{ - ops::{Deref, RangeInclusive}, - sync::Arc, - time::Instant, -}; use tracing::{debug, trace}; +use crate::{segments, segments::Segment, StaticFileProducerEvent}; + /// Result of [`StaticFileProducerInner::run`] execution. pub type StaticFileProducerResult = ProviderResult; @@ -252,9 +254,11 @@ impl StaticFileProducerInner { #[cfg(test)] mod tests { - use crate::static_file_producer::{ - StaticFileProducer, StaticFileProducerInner, StaticFileTargets, + use std::{ + sync::{mpsc::channel, Arc}, + time::Duration, }; + use alloy_primitives::{B256, U256}; use assert_matches::assert_matches; use reth_db::{test_utils::TempDatabase, DatabaseEnv}; @@ -269,12 +273,12 @@ mod tests { generators, generators::{random_block_range, random_receipt}, }; - use std::{ - sync::{mpsc::channel, Arc}, - time::Duration, - }; use tempfile::TempDir; + use crate::static_file_producer::{ + StaticFileProducer, StaticFileProducerInner, StaticFileTargets, + }; + fn setup() -> (ProviderFactory>>, TempDir) { let mut rng = generators::rng(); let db = TestStageDB::default(); diff --git a/crates/static-file/types/src/segment.rs b/crates/static-file/types/src/segment.rs index d609f4a98b27d..0ae18f85537da 100644 --- a/crates/static-file/types/src/segment.rs +++ b/crates/static-file/types/src/segment.rs @@ -1,10 +1,12 @@ -use crate::{BlockNumber, Compression, Filters, InclusionFilter}; +use std::{ops::RangeInclusive, str::FromStr}; + use alloy_primitives::TxNumber; use derive_more::Display; use serde::{Deserialize, Serialize}; -use std::{ops::RangeInclusive, str::FromStr}; use strum::{AsRefStr, EnumIter, EnumString}; +use crate::{BlockNumber, Compression, Filters, InclusionFilter}; + #[derive( Debug, Copy, diff --git a/crates/storage/codecs/derive/src/compact/generator.rs b/crates/storage/codecs/derive/src/compact/generator.rs index c28bf8d1a4fbc..2f0ee3edc3644 100644 --- a/crates/storage/codecs/derive/src/compact/generator.rs +++ b/crates/storage/codecs/derive/src/compact/generator.rs @@ -1,8 +1,9 @@ //! Code generator for the `Compact` trait. -use super::*; use convert_case::{Case, Casing}; +use super::*; + /// Generates code to implement the `Compact` trait for a data type. pub fn generate_from_to(ident: &Ident, fields: &FieldList, is_zstd: bool) -> TokenStream2 { let flags = format_ident!("{ident}Flags"); diff --git a/crates/storage/codecs/derive/src/compact/mod.rs b/crates/storage/codecs/derive/src/compact/mod.rs index c2f0b1e567931..031e5eba6cc5b 100644 --- a/crates/storage/codecs/derive/src/compact/mod.rs +++ b/crates/storage/codecs/derive/src/compact/mod.rs @@ -186,10 +186,11 @@ pub fn is_flag_type(ftype: &str) -> bool { #[cfg(test)] mod tests { - use super::*; use similar_asserts::assert_eq; use syn::parse2; + use super::*; + #[test] fn gen() { let f_struct = quote! { diff --git a/crates/storage/codecs/src/alloy/access_list.rs b/crates/storage/codecs/src/alloy/access_list.rs index f5564e81601aa..59af015fcb601 100644 --- a/crates/storage/codecs/src/alloy/access_list.rs +++ b/crates/storage/codecs/src/alloy/access_list.rs @@ -1,7 +1,8 @@ -use crate::Compact; use alloy_eips::eip2930::{AccessList, AccessListItem}; use alloy_primitives::Address; +use crate::Compact; + /// Implement `Compact` for `AccessListItem` and `AccessList`. impl Compact for AccessListItem { fn to_compact(self, buf: &mut B) -> usize @@ -46,11 +47,12 @@ impl Compact for AccessList { #[cfg(test)] mod tests { - use super::*; use alloy_primitives::Bytes; use proptest::proptest; use serde::Deserialize; + use super::*; + proptest! { #[test] fn test_roundtrip_compact_access_list_item(access_list_item: AccessListItem) { diff --git a/crates/storage/codecs/src/alloy/genesis_account.rs b/crates/storage/codecs/src/alloy/genesis_account.rs index bc3843ab7a6d1..7970c193f0736 100644 --- a/crates/storage/codecs/src/alloy/genesis_account.rs +++ b/crates/storage/codecs/src/alloy/genesis_account.rs @@ -1,8 +1,9 @@ -use crate::Compact; use alloy_genesis::GenesisAccount as AlloyGenesisAccount; use alloy_primitives::{Bytes, B256, U256}; use reth_codecs_derive::main_codec; +use crate::Compact; + /// GenesisAccount acts as bridge which simplifies Compact implementation for AlloyGenesisAccount. /// /// Notice: Make sure this struct is 1:1 with `alloy_genesis::GenesisAccount` diff --git a/crates/storage/codecs/src/alloy/log.rs b/crates/storage/codecs/src/alloy/log.rs index eadcb894f3f14..d9bb0a9f3b89e 100644 --- a/crates/storage/codecs/src/alloy/log.rs +++ b/crates/storage/codecs/src/alloy/log.rs @@ -1,9 +1,10 @@ //! Native Compact codec impl for primitive alloy log types. -use crate::Compact; use alloy_primitives::{Address, Bytes, Log, LogData}; use bytes::BufMut; +use crate::Compact; + /// Implement `Compact` for `LogData` and `Log`. impl Compact for LogData { fn to_compact(self, buf: &mut B) -> usize @@ -51,11 +52,12 @@ impl Compact for Log { #[cfg(test)] mod tests { - use super::{Compact, Log}; use alloy_primitives::{Address, Bytes, LogData, B256}; use proptest::proptest; use serde::Deserialize; + use super::{Compact, Log}; + proptest! { #[test] fn roundtrip(log: Log) { diff --git a/crates/storage/codecs/src/alloy/request.rs b/crates/storage/codecs/src/alloy/request.rs index 388f2a2b5291f..09b836d89179b 100644 --- a/crates/storage/codecs/src/alloy/request.rs +++ b/crates/storage/codecs/src/alloy/request.rs @@ -1,11 +1,12 @@ //! Native Compact codec impl for EIP-7685 requests. -use crate::Compact; use alloy_consensus::Request; use alloy_eips::eip7685::{Decodable7685, Encodable7685}; use alloy_primitives::Bytes; use bytes::BufMut; +use crate::Compact; + impl Compact for Request { fn to_compact(self, buf: &mut B) -> usize where @@ -24,10 +25,11 @@ impl Compact for Request { #[cfg(test)] mod tests { - use super::*; use proptest::proptest; use proptest_arbitrary_interop::arb; + use super::*; + proptest! { #[test] fn roundtrip(request in arb::()) { diff --git a/crates/storage/codecs/src/alloy/txkind.rs b/crates/storage/codecs/src/alloy/txkind.rs index b2d55400f3e7d..adc2a1fc2191f 100644 --- a/crates/storage/codecs/src/alloy/txkind.rs +++ b/crates/storage/codecs/src/alloy/txkind.rs @@ -1,8 +1,9 @@ //! Native Compact codec impl for primitive alloy [`TxKind`]. -use crate::Compact; use alloy_primitives::{Address, TxKind}; +use crate::Compact; + impl Compact for TxKind { fn to_compact(self, buf: &mut B) -> usize where diff --git a/crates/storage/codecs/src/alloy/withdrawal.rs b/crates/storage/codecs/src/alloy/withdrawal.rs index 3238048ad098e..b8a216b4fe3fb 100644 --- a/crates/storage/codecs/src/alloy/withdrawal.rs +++ b/crates/storage/codecs/src/alloy/withdrawal.rs @@ -1,8 +1,9 @@ -use crate::Compact; use alloy_eips::eip4895::Withdrawal as AlloyWithdrawal; use alloy_primitives::Address; use reth_codecs_derive::main_codec; +use crate::Compact; + /// Withdrawal acts as bridge which simplifies Compact implementation for AlloyWithdrawal. /// /// Notice: Make sure this struct is 1:1 with `alloy_eips::eip4895::Withdrawal` @@ -47,9 +48,10 @@ impl Compact for AlloyWithdrawal { #[cfg(test)] mod tests { - use super::*; use proptest::proptest; + use super::*; + proptest! { #[test] fn roundtrip(withdrawal: AlloyWithdrawal) { diff --git a/crates/storage/codecs/src/lib.rs b/crates/storage/codecs/src/lib.rs index bea26090deb13..f8fcc3d6c61c0 100644 --- a/crates/storage/codecs/src/lib.rs +++ b/crates/storage/codecs/src/lib.rs @@ -17,10 +17,9 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(feature = "std"), no_std)] -pub use reth_codecs_derive::*; - use alloy_primitives::{Address, Bloom, Bytes, FixedBytes, U256}; use bytes::Buf; +pub use reth_codecs_derive::*; #[cfg(any(test, feature = "alloy"))] mod alloy; @@ -412,9 +411,10 @@ const fn decode_varuint_panic() -> ! { #[cfg(test)] mod tests { - use super::*; use alloy_primitives::B256; + use super::*; + #[test] fn compact_bytes() { let arr = [1, 2, 3, 4, 5]; diff --git a/crates/storage/db-api/src/database.rs b/crates/storage/db-api/src/database.rs index 22c61284b4a70..2284196a4d5af 100644 --- a/crates/storage/db-api/src/database.rs +++ b/crates/storage/db-api/src/database.rs @@ -1,9 +1,10 @@ +use std::{fmt::Debug, sync::Arc}; + use crate::{ table::TableImporter, transaction::{DbTx, DbTxMut}, DatabaseError, }; -use std::{fmt::Debug, sync::Arc}; /// Main Database trait that can open read-only and read-write transactions. /// diff --git a/crates/storage/db-api/src/database_metrics.rs b/crates/storage/db-api/src/database_metrics.rs index 8ca6b35bc4e95..17f1ed1630373 100644 --- a/crates/storage/db-api/src/database_metrics.rs +++ b/crates/storage/db-api/src/database_metrics.rs @@ -1,6 +1,7 @@ -use metrics::{counter, gauge, histogram, Label}; use std::sync::Arc; +use metrics::{counter, gauge, histogram, Label}; + /// Represents a type that can report metrics, used mainly with the database. The `report_metrics` /// method can be used as a prometheus hook. pub trait DatabaseMetrics { diff --git a/crates/storage/db-api/src/mock.rs b/crates/storage/db-api/src/mock.rs index e972821d8fefa..d49a5de29ecf3 100644 --- a/crates/storage/db-api/src/mock.rs +++ b/crates/storage/db-api/src/mock.rs @@ -1,5 +1,8 @@ //! Mock database +use core::ops::Bound; +use std::{collections::BTreeMap, ops::RangeBounds}; + use crate::{ common::{IterPairResult, PairResult, ValueOnlyResult}, cursor::{ @@ -11,8 +14,6 @@ use crate::{ transaction::{DbTx, DbTxMut}, DatabaseError, }; -use core::ops::Bound; -use std::{collections::BTreeMap, ops::RangeBounds}; /// Mock database used for testing with inner `BTreeMap` structure // TODO diff --git a/crates/storage/db-api/src/models/accounts.rs b/crates/storage/db-api/src/models/accounts.rs index f53f29a121e1c..08d7af964a784 100644 --- a/crates/storage/db-api/src/models/accounts.rs +++ b/crates/storage/db-api/src/models/accounts.rs @@ -2,14 +2,15 @@ use std::ops::{Range, RangeInclusive}; +use reth_codecs::{derive_arbitrary, Compact}; +use reth_primitives::{Account, Address, BlockNumber, Buf, StorageKey}; +use serde::{Deserialize, Serialize}; + use crate::{ impl_fixed_arbitrary, table::{Decode, Encode}, DatabaseError, }; -use reth_codecs::{derive_arbitrary, Compact}; -use reth_primitives::{Account, Address, BlockNumber, Buf, StorageKey}; -use serde::{Deserialize, Serialize}; /// Account as it is saved in the database. /// @@ -157,10 +158,12 @@ impl_fixed_arbitrary!((BlockNumberAddress, 28), (AddressStorageKey, 52)); #[cfg(test)] mod tests { - use super::*; - use rand::{thread_rng, Rng}; use std::str::FromStr; + use rand::{thread_rng, Rng}; + + use super::*; + #[test] fn test_block_number_address() { let num = 1u64; diff --git a/crates/storage/db-api/src/models/blocks.rs b/crates/storage/db-api/src/models/blocks.rs index 97beccf877513..bb4dc77ed19d6 100644 --- a/crates/storage/db-api/src/models/blocks.rs +++ b/crates/storage/db-api/src/models/blocks.rs @@ -1,8 +1,9 @@ //! Block related models and types. +use std::ops::Range; + use reth_codecs::{main_codec, Compact}; use reth_primitives::{Header, TxNumber, Withdrawals, B256}; -use std::ops::Range; /// Total number of transactions. pub type NumTransactions = u64; diff --git a/crates/storage/db-api/src/models/integer_list.rs b/crates/storage/db-api/src/models/integer_list.rs index f47605bf88b52..158a9d30ac676 100644 --- a/crates/storage/db-api/src/models/integer_list.rs +++ b/crates/storage/db-api/src/models/integer_list.rs @@ -1,10 +1,11 @@ //! Implements [`Compress`] and [`Decompress`] for [`IntegerList`] +use reth_primitives_traits::IntegerList; + use crate::{ table::{Compress, Decompress}, DatabaseError, }; -use reth_primitives_traits::IntegerList; impl Compress for IntegerList { type Compressed = Vec; diff --git a/crates/storage/db-api/src/models/mod.rs b/crates/storage/db-api/src/models/mod.rs index f5ef4ea5fcce9..847823135f146 100644 --- a/crates/storage/db-api/src/models/mod.rs +++ b/crates/storage/db-api/src/models/mod.rs @@ -1,15 +1,16 @@ //! Implements data structures specific to the database -use crate::{ - table::{Compress, Decode, Decompress, Encode}, - DatabaseError, -}; use reth_codecs::{main_codec, Compact}; use reth_primitives::{Address, B256, *}; use reth_prune_types::{PruneCheckpoint, PruneSegment}; use reth_stages_types::StageCheckpoint; use reth_trie_common::{StoredNibbles, StoredNibblesSubKey, *}; +use crate::{ + table::{Compress, Decode, Decompress, Encode}, + DatabaseError, +}; + pub mod accounts; pub mod blocks; pub mod client_version; @@ -297,7 +298,6 @@ add_wrapper_struct!((ClientVersion, CompactClientVersion)); #[cfg(test)] mod tests { - use super::*; use reth_primitives::{ Account, Header, Receipt, ReceiptWithBloom, SealedHeader, TxEip1559, TxEip2930, TxEip4844, TxLegacy, Withdrawals, @@ -309,6 +309,8 @@ mod tests { StorageHashingCheckpoint, }; + use super::*; + // each value in the database has an extra field named flags that encodes metadata about other // fields in the value, e.g. offset and length. // diff --git a/crates/storage/db-api/src/models/sharded_key.rs b/crates/storage/db-api/src/models/sharded_key.rs index feba230a60e5a..3cfc44a960f22 100644 --- a/crates/storage/db-api/src/models/sharded_key.rs +++ b/crates/storage/db-api/src/models/sharded_key.rs @@ -1,11 +1,13 @@ //! Sharded key +use std::hash::Hash; + +use reth_primitives::BlockNumber; +use serde::{Deserialize, Serialize}; + use crate::{ table::{Decode, Encode}, DatabaseError, }; -use reth_primitives::BlockNumber; -use serde::{Deserialize, Serialize}; -use std::hash::Hash; /// Number of indices in one shard. pub const NUM_OF_INDICES_IN_SHARD: usize = 2_000; diff --git a/crates/storage/db-api/src/models/storage_sharded_key.rs b/crates/storage/db-api/src/models/storage_sharded_key.rs index f76f0468a98f9..061e54b2a1f6a 100644 --- a/crates/storage/db-api/src/models/storage_sharded_key.rs +++ b/crates/storage/db-api/src/models/storage_sharded_key.rs @@ -1,13 +1,13 @@ //! Storage sharded key -use crate::{ - table::{Decode, Encode}, - DatabaseError, -}; use derive_more::AsRef; use reth_primitives::{Address, BlockNumber, B256}; use serde::{Deserialize, Serialize}; use super::ShardedKey; +use crate::{ + table::{Decode, Encode}, + DatabaseError, +}; /// Number of indices in one shard. pub const NUM_OF_INDICES_IN_SHARD: usize = 2_000; diff --git a/crates/storage/db-api/src/scale.rs b/crates/storage/db-api/src/scale.rs index a837dadef95db..53d3c76dddf57 100644 --- a/crates/storage/db-api/src/scale.rs +++ b/crates/storage/db-api/src/scale.rs @@ -1,8 +1,9 @@ +use reth_primitives::*; + use crate::{ table::{Compress, Decompress}, DatabaseError, }; -use reth_primitives::*; mod sealed { pub trait Sealed {} diff --git a/crates/storage/db-api/src/table.rs b/crates/storage/db-api/src/table.rs index 6d3f52198d28a..5ae46c0e4d293 100644 --- a/crates/storage/db-api/src/table.rs +++ b/crates/storage/db-api/src/table.rs @@ -1,12 +1,13 @@ +use std::fmt::Debug; + +use serde::{Deserialize, Serialize}; + use crate::{ cursor::{DbCursorRO, DbCursorRW, DbDupCursorRO, DbDupCursorRW}, transaction::{DbTx, DbTxMut}, DatabaseError, }; -use serde::{Deserialize, Serialize}; -use std::fmt::Debug; - /// Trait that will transform the data to be saved in the DB in a (ideally) compressed format pub trait Compress: Send + Sync + Sized + Debug { /// Compressed type. diff --git a/crates/storage/db-common/src/db_tool/mod.rs b/crates/storage/db-common/src/db_tool/mod.rs index 3884089b43708..347333d1dff05 100644 --- a/crates/storage/db-common/src/db_tool/mod.rs +++ b/crates/storage/db-common/src/db_tool/mod.rs @@ -1,5 +1,7 @@ //! Common db operations +use std::{path::Path, rc::Rc, sync::Arc}; + use boyer_moore_magiclen::BMByte; use eyre::Result; use reth_chainspec::ChainSpec; @@ -13,7 +15,6 @@ use reth_db_api::{ }; use reth_fs_util as fs; use reth_provider::{ChainSpecProvider, ProviderFactory}; -use std::{path::Path, rc::Rc, sync::Arc}; use tracing::info; /// Wrapper over DB that implements many useful DB queries. diff --git a/crates/storage/db-common/src/init.rs b/crates/storage/db-common/src/init.rs index c6b4802b78290..9700e388e0d78 100644 --- a/crates/storage/db-common/src/init.rs +++ b/crates/storage/db-common/src/init.rs @@ -1,5 +1,12 @@ //! Reth genesis initialization utility functions. +use std::{ + collections::{BTreeMap, HashMap}, + io::BufRead, + ops::DerefMut, + sync::Arc, +}; + use alloy_genesis::GenesisAccount; use reth_chainspec::ChainSpec; use reth_codecs::Compact; @@ -21,12 +28,6 @@ use reth_provider::{ use reth_stages_types::{StageCheckpoint, StageId}; use reth_trie::{IntermediateStateRootState, StateRoot as StateRootComputer, StateRootProgress}; use serde::{Deserialize, Serialize}; -use std::{ - collections::{BTreeMap, HashMap}, - io::BufRead, - ops::DerefMut, - sync::Arc, -}; use tracing::{debug, error, info, trace}; /// Default soft limit for number of bytes to read from state dump file, before inserting into @@ -524,7 +525,6 @@ struct GenesisAccountWithAddress { #[cfg(test)] mod tests { - use super::*; use alloy_genesis::Genesis; use reth_chainspec::{Chain, GOERLI, MAINNET, SEPOLIA}; use reth_db::DatabaseEnv; @@ -538,6 +538,8 @@ mod tests { use reth_primitives_traits::IntegerList; use reth_provider::test_utils::create_test_provider_factory_with_chain_spec; + use super::*; + fn collect_table_entries( tx: &::TX, ) -> Result>, InitDatabaseError> diff --git a/crates/storage/db/benches/hash_keys.rs b/crates/storage/db/benches/hash_keys.rs index d37146fd1e287..6cc541b428851 100644 --- a/crates/storage/db/benches/hash_keys.rs +++ b/crates/storage/db/benches/hash_keys.rs @@ -1,4 +1,6 @@ #![allow(missing_docs)] +use std::collections::HashSet; + use criterion::{ black_box, criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion, }; @@ -11,7 +13,6 @@ use proptest::{ }; use reth_db::TransactionHashNumbers; use reth_db_api::cursor::DbCursorRW; -use std::collections::HashSet; criterion_group! { name = benches; diff --git a/crates/storage/db/benches/utils.rs b/crates/storage/db/benches/utils.rs index 7856627e16f6a..0ddeacb23223b 100644 --- a/crates/storage/db/benches/utils.rs +++ b/crates/storage/db/benches/utils.rs @@ -1,3 +1,5 @@ +use std::{path::Path, sync::Arc}; + use reth_db::{test_utils::create_test_rw_db_with_path, DatabaseEnv}; use reth_db_api::{ database::Database, @@ -6,7 +8,6 @@ use reth_db_api::{ }; use reth_fs_util as fs; use reth_primitives::Bytes; -use std::{path::Path, sync::Arc}; /// Path where the DB is initialized for benchmarks. #[allow(dead_code)] diff --git a/crates/storage/db/src/implementation/mdbx/cursor.rs b/crates/storage/db/src/implementation/mdbx/cursor.rs index e2afbe0c16c76..2089d4c4bd606 100644 --- a/crates/storage/db/src/implementation/mdbx/cursor.rs +++ b/crates/storage/db/src/implementation/mdbx/cursor.rs @@ -1,10 +1,7 @@ //! Cursor wrapper for libmdbx-sys. -use crate::{ - metrics::{DatabaseEnvMetrics, Operation}, - tables::utils::*, - DatabaseError, -}; +use std::{borrow::Cow, collections::Bound, marker::PhantomData, ops::RangeBounds, sync::Arc}; + use reth_db_api::{ common::{PairResult, ValueOnlyResult}, cursor::{ @@ -15,7 +12,12 @@ use reth_db_api::{ }; use reth_libmdbx::{Error as MDBXError, TransactionKind, WriteFlags, RO, RW}; use reth_storage_errors::db::{DatabaseErrorInfo, DatabaseWriteError, DatabaseWriteOperation}; -use std::{borrow::Cow, collections::Bound, marker::PhantomData, ops::RangeBounds, sync::Arc}; + +use crate::{ + metrics::{DatabaseEnvMetrics, Operation}, + tables::utils::*, + DatabaseError, +}; /// Read only Cursor. pub type CursorRO = Cursor; diff --git a/crates/storage/db/src/implementation/mdbx/mod.rs b/crates/storage/db/src/implementation/mdbx/mod.rs index cc9f055e95333..a6c20d1f7220a 100644 --- a/crates/storage/db/src/implementation/mdbx/mod.rs +++ b/crates/storage/db/src/implementation/mdbx/mod.rs @@ -1,12 +1,12 @@ //! Module that interacts with MDBX. -use crate::{ - lockfile::StorageLock, - metrics::DatabaseEnvMetrics, - tables::{self, TableType, Tables}, - utils::default_page_size, - DatabaseError, +use std::{ + ops::Deref, + path::Path, + sync::Arc, + time::{SystemTime, UNIX_EPOCH}, }; + use eyre::Context; use metrics::{gauge, Label}; use reth_db_api::{ @@ -22,14 +22,16 @@ use reth_libmdbx::{ }; use reth_storage_errors::db::LogLevel; use reth_tracing::tracing::error; -use std::{ - ops::Deref, - path::Path, - sync::Arc, - time::{SystemTime, UNIX_EPOCH}, -}; use tx::Tx; +use crate::{ + lockfile::StorageLock, + metrics::DatabaseEnvMetrics, + tables::{self, TableType, Tables}, + utils::default_page_size, + DatabaseError, +}; + pub mod cursor; pub mod tx; @@ -468,14 +470,8 @@ impl Deref for DatabaseEnv { #[cfg(test)] mod tests { - use super::*; - use crate::{ - tables::{ - AccountsHistory, CanonicalHeaders, Headers, PlainAccountState, PlainStorageState, - }, - test_utils::*, - AccountChangeSets, - }; + use std::str::FromStr; + use reth_db_api::{ cursor::{DbDupCursorRO, DbDupCursorRW, ReverseWalker, Walker}, models::{AccountBeforeTx, ShardedKey}, @@ -485,9 +481,17 @@ mod tests { use reth_primitives::{Account, Address, Header, StorageEntry, B256, U256}; use reth_primitives_traits::IntegerList; use reth_storage_errors::db::{DatabaseWriteError, DatabaseWriteOperation}; - use std::str::FromStr; use tempfile::TempDir; + use super::*; + use crate::{ + tables::{ + AccountsHistory, CanonicalHeaders, Headers, PlainAccountState, PlainStorageState, + }, + test_utils::*, + AccountChangeSets, + }; + /// Create database for testing fn create_test_db(kind: DatabaseEnvKind) -> Arc { Arc::new(create_test_db_with_path( diff --git a/crates/storage/db/src/implementation/mdbx/tx.rs b/crates/storage/db/src/implementation/mdbx/tx.rs index 8feb6c90ab27e..1815b977bb35b 100644 --- a/crates/storage/db/src/implementation/mdbx/tx.rs +++ b/crates/storage/db/src/implementation/mdbx/tx.rs @@ -1,18 +1,5 @@ //! Transaction wrapper for libmdbx-sys. -use super::cursor::Cursor; -use crate::{ - metrics::{DatabaseEnvMetrics, Operation, TransactionMode, TransactionOutcome}, - tables::utils::decode_one, - DatabaseError, -}; -use reth_db_api::{ - table::{Compress, DupSort, Encode, Table, TableImporter}, - transaction::{DbTx, DbTxMut}, -}; -use reth_libmdbx::{ffi::MDBX_dbi, CommitLatency, Transaction, TransactionKind, WriteFlags, RW}; -use reth_storage_errors::db::{DatabaseWriteError, DatabaseWriteOperation}; -use reth_tracing::tracing::{debug, trace, warn}; use std::{ backtrace::Backtrace, marker::PhantomData, @@ -23,6 +10,21 @@ use std::{ time::{Duration, Instant}, }; +use reth_db_api::{ + table::{Compress, DupSort, Encode, Table, TableImporter}, + transaction::{DbTx, DbTxMut}, +}; +use reth_libmdbx::{ffi::MDBX_dbi, CommitLatency, Transaction, TransactionKind, WriteFlags, RW}; +use reth_storage_errors::db::{DatabaseWriteError, DatabaseWriteOperation}; +use reth_tracing::tracing::{debug, trace, warn}; + +use super::cursor::Cursor; +use crate::{ + metrics::{DatabaseEnvMetrics, Operation, TransactionMode, TransactionOutcome}, + tables::utils::decode_one, + DatabaseError, +}; + /// Duration after which we emit the log about long-lived database transactions. const LONG_TRANSACTION_DURATION: Duration = Duration::from_secs(60); @@ -377,13 +379,15 @@ impl DbTxMut for Tx { #[cfg(test)] mod tests { - use crate::{mdbx::DatabaseArguments, tables, DatabaseEnv, DatabaseEnvKind}; + use std::{sync::atomic::Ordering, thread::sleep, time::Duration}; + use reth_db_api::{database::Database, models::ClientVersion, transaction::DbTx}; use reth_libmdbx::MaxReadTransactionDuration; use reth_storage_errors::db::DatabaseError; - use std::{sync::atomic::Ordering, thread::sleep, time::Duration}; use tempfile::tempdir; + use crate::{mdbx::DatabaseArguments, tables, DatabaseEnv, DatabaseEnvKind}; + #[test] fn long_read_transaction_safety_disabled() { const MAX_DURATION: Duration = Duration::from_secs(1); diff --git a/crates/storage/db/src/lib.rs b/crates/storage/db/src/lib.rs index e5414b574328a..c4bc6321c58a6 100644 --- a/crates/storage/db/src/lib.rs +++ b/crates/storage/db/src/lib.rs @@ -26,20 +26,21 @@ pub mod version; #[cfg(feature = "mdbx")] pub mod mdbx; -pub use reth_storage_errors::db::{DatabaseError, DatabaseWriteOperation}; -pub use tables::*; -pub use utils::is_database_empty; - #[cfg(feature = "mdbx")] pub use mdbx::{create_db, init_db, open_db, open_db_read_only, DatabaseEnv, DatabaseEnvKind}; - pub use reth_db_api::*; +pub use reth_storage_errors::db::{DatabaseError, DatabaseWriteOperation}; +pub use tables::*; +pub use utils::is_database_empty; /// Collection of database test utilities #[cfg(any(test, feature = "test-utils"))] pub mod test_utils { - use super::*; - use crate::mdbx::DatabaseArguments; + use std::{ + path::{Path, PathBuf}, + sync::Arc, + }; + use reth_db_api::{ database::Database, database_metrics::{DatabaseMetadata, DatabaseMetadataValue, DatabaseMetrics}, @@ -47,12 +48,11 @@ pub mod test_utils { }; use reth_fs_util; use reth_libmdbx::MaxReadTransactionDuration; - use std::{ - path::{Path, PathBuf}, - sync::Arc, - }; use tempfile::TempDir; + use super::*; + use crate::mdbx::DatabaseArguments; + /// Error during database open pub const ERROR_DB_OPEN: &str = "Not able to open the database file."; /// Error during database creation @@ -177,20 +177,22 @@ pub mod test_utils { #[cfg(test)] mod tests { - use crate::{ - init_db, - mdbx::DatabaseArguments, - open_db, tables, - version::{db_version_file_path, DatabaseVersionError}, - }; + use std::time::Duration; + use assert_matches::assert_matches; use reth_db_api::{ cursor::DbCursorRO, database::Database, models::ClientVersion, transaction::DbTx, }; use reth_libmdbx::MaxReadTransactionDuration; - use std::time::Duration; use tempfile::tempdir; + use crate::{ + init_db, + mdbx::DatabaseArguments, + open_db, tables, + version::{db_version_file_path, DatabaseVersionError}, + }; + #[test] fn db_version() { let path = tempdir().unwrap(); diff --git a/crates/storage/db/src/lockfile.rs b/crates/storage/db/src/lockfile.rs index e0da20348a53d..767ca847a6936 100644 --- a/crates/storage/db/src/lockfile.rs +++ b/crates/storage/db/src/lockfile.rs @@ -2,13 +2,14 @@ #![cfg_attr(feature = "disable-lock", allow(dead_code))] -use reth_storage_errors::lockfile::StorageLockError; -use reth_tracing::tracing::error; use std::{ path::{Path, PathBuf}, process, sync::Arc, }; + +use reth_storage_errors::lockfile::StorageLockError; +use reth_tracing::tracing::error; use sysinfo::{ProcessRefreshKind, RefreshKind, System}; /// File lock name. diff --git a/crates/storage/db/src/mdbx.rs b/crates/storage/db/src/mdbx.rs index 328b9caabfdfe..cee9e954d684f 100644 --- a/crates/storage/db/src/mdbx.rs +++ b/crates/storage/db/src/mdbx.rs @@ -1,11 +1,12 @@ //! Bindings for [MDBX](https://libmdbx.dqdkfa.ru/). -pub use crate::implementation::mdbx::*; +use std::path::Path; + +use eyre::Context; pub use reth_libmdbx::*; +pub use crate::implementation::mdbx::*; use crate::is_database_empty; -use eyre::Context; -use std::path::Path; /// Creates a new database at the specified path if it doesn't exist. Does NOT create tables. Check /// [`init_db`]. diff --git a/crates/storage/db/src/metrics.rs b/crates/storage/db/src/metrics.rs index fecd691ee5d7a..4f5f266606946 100644 --- a/crates/storage/db/src/metrics.rs +++ b/crates/storage/db/src/metrics.rs @@ -1,10 +1,12 @@ -use crate::Tables; +use std::time::{Duration, Instant}; + use metrics::{Gauge, Histogram}; use reth_metrics::{metrics::Counter, Metrics}; use rustc_hash::FxHashMap; -use std::time::{Duration, Instant}; use strum::{EnumCount, EnumIter, IntoEnumIterator}; +use crate::Tables; + const LARGE_VALUE_THRESHOLD_BYTES: usize = 4096; /// Caches metric handles for database environment to make sure handles are not re-created diff --git a/crates/storage/db/src/static_file/cursor.rs b/crates/storage/db/src/static_file/cursor.rs index 9a93ca2244297..1a35f78c6685f 100644 --- a/crates/storage/db/src/static_file/cursor.rs +++ b/crates/storage/db/src/static_file/cursor.rs @@ -1,10 +1,12 @@ -use super::mask::{ColumnSelectorOne, ColumnSelectorThree, ColumnSelectorTwo}; +use std::sync::Arc; + use derive_more::{Deref, DerefMut}; use reth_db_api::table::Decompress; use reth_nippy_jar::{DataReader, NippyJar, NippyJarCursor}; use reth_primitives::{static_file::SegmentHeader, B256}; use reth_storage_errors::provider::{ProviderError, ProviderResult}; -use std::sync::Arc; + +use super::mask::{ColumnSelectorOne, ColumnSelectorThree, ColumnSelectorTwo}; /// Cursor of a static file segment. #[derive(Debug, Deref, DerefMut)] diff --git a/crates/storage/db/src/static_file/generation.rs b/crates/storage/db/src/static_file/generation.rs index 9c2a64a23b184..a05f383cb05aa 100644 --- a/crates/storage/db/src/static_file/generation.rs +++ b/crates/storage/db/src/static_file/generation.rs @@ -1,14 +1,15 @@ -use crate::{RawKey, RawTable}; +use std::{error::Error as StdError, ops::RangeInclusive}; + use reth_db_api::{ cursor::DbCursorRO, table::{Key, Table}, transaction::DbTx, }; - use reth_nippy_jar::{ColumnResult, NippyJar, NippyJarHeader, PHFKey}; use reth_storage_errors::provider::{ProviderError, ProviderResult}; use reth_tracing::tracing::*; -use std::{error::Error as StdError, ops::RangeInclusive}; + +use crate::{RawKey, RawTable}; /// Macro that generates static file creation functions that take an arbitrary number of [`Table`] /// and creates a [`NippyJar`] file out of their [`Table::Value`]. Each list of [`Table::Value`] diff --git a/crates/storage/db/src/static_file/masks.rs b/crates/storage/db/src/static_file/masks.rs index f3ce90f0dfa22..802b84dd4ec33 100644 --- a/crates/storage/db/src/static_file/masks.rs +++ b/crates/storage/db/src/static_file/masks.rs @@ -1,11 +1,12 @@ +use reth_db_api::table::Table; +use reth_primitives::{BlockHash, Header}; + use super::{ReceiptMask, TransactionMask}; use crate::{ add_static_file_mask, static_file::mask::{ColumnSelectorOne, ColumnSelectorTwo, HeaderMask}, HeaderTerminalDifficulties, RawValue, Receipts, Transactions, }; -use reth_db_api::table::Table; -use reth_primitives::{BlockHash, Header}; // HEADER MASKS add_static_file_mask!(HeaderMask, Header, 0b001); diff --git a/crates/storage/db/src/tables/mod.rs b/crates/storage/db/src/tables/mod.rs index af350b74ae829..5f7144a1d467f 100644 --- a/crates/storage/db/src/tables/mod.rs +++ b/crates/storage/db/src/tables/mod.rs @@ -18,6 +18,8 @@ pub use raw::{RawDupSort, RawKey, RawTable, RawValue, TableRawRow}; pub(crate) mod utils; +use std::fmt; + use reth_db_api::{ models::{ accounts::{AccountBeforeTx, BlockNumberAddress}, @@ -37,7 +39,6 @@ use reth_prune_types::{PruneCheckpoint, PruneSegment}; use reth_stages_types::StageCheckpoint; use reth_trie_common::{StorageTrieEntry, StoredBranchNode, StoredNibbles, StoredNibblesSubKey}; use serde::{Deserialize, Serialize}; -use std::fmt; /// Enum for the types of tables present in libmdbx. #[derive(Debug, PartialEq, Eq, Copy, Clone)] @@ -447,9 +448,10 @@ pub type StageId = String; #[cfg(test)] mod tests { - use super::*; use std::str::FromStr; + use super::*; + #[test] fn parse_table_from_str() { for table in Tables::ALL { diff --git a/crates/storage/db/src/tables/raw.rs b/crates/storage/db/src/tables/raw.rs index 1e8fa56b3603c..a7e9c45fa9bdf 100644 --- a/crates/storage/db/src/tables/raw.rs +++ b/crates/storage/db/src/tables/raw.rs @@ -1,7 +1,8 @@ -use crate::DatabaseError; use reth_db_api::table::{Compress, Decode, Decompress, DupSort, Encode, Key, Table, Value}; use serde::{Deserialize, Serialize}; +use crate::DatabaseError; + /// Tuple with `RawKey` and `RawValue`. pub type TableRawRow = (RawKey<::Key>, RawValue<::Value>); diff --git a/crates/storage/db/src/tables/utils.rs b/crates/storage/db/src/tables/utils.rs index 616d1038264e7..617b9563fc360 100644 --- a/crates/storage/db/src/tables/utils.rs +++ b/crates/storage/db/src/tables/utils.rs @@ -1,9 +1,11 @@ //! Small database table utilities and helper functions. -use crate::DatabaseError; -use reth_db_api::table::{Decode, Decompress, Table, TableRow}; use std::borrow::Cow; +use reth_db_api::table::{Decode, Decompress, Table, TableRow}; + +use crate::DatabaseError; + /// Helper function to decode a `(key, value)` pair. pub(crate) fn decoder<'a, T>( kv: (Cow<'a, [u8]>, Cow<'a, [u8]>), diff --git a/crates/storage/db/src/version.rs b/crates/storage/db/src/version.rs index 09c1f946780a9..d01be13071e7a 100644 --- a/crates/storage/db/src/version.rs +++ b/crates/storage/db/src/version.rs @@ -85,11 +85,13 @@ pub fn db_version_file_path>(db_path: P) -> PathBuf { #[cfg(test)] mod tests { - use super::{check_db_version_file, db_version_file_path, DatabaseVersionError}; - use assert_matches::assert_matches; use std::fs; + + use assert_matches::assert_matches; use tempfile::tempdir; + use super::{check_db_version_file, db_version_file_path, DatabaseVersionError}; + #[test] fn missing_file() { let dir = tempdir().unwrap(); diff --git a/crates/storage/errors/src/db.rs b/crates/storage/errors/src/db.rs index 8b4896d23236a..1b9fb5285f6cb 100644 --- a/crates/storage/errors/src/db.rs +++ b/crates/storage/errors/src/db.rs @@ -1,6 +1,3 @@ -#[cfg(feature = "std")] -use std::{fmt::Display, str::FromStr, string::String}; - #[cfg(not(feature = "std"))] use alloc::{ boxed::Box, @@ -8,9 +5,10 @@ use alloc::{ string::{String, ToString}, vec::Vec, }; - #[cfg(not(feature = "std"))] use core::{fmt::Display, str::FromStr}; +#[cfg(feature = "std")] +use std::{fmt::Display, str::FromStr, string::String}; /// Database error type. #[derive(Clone, Debug, PartialEq, Eq, thiserror_no_std::Error)] diff --git a/crates/storage/errors/src/lockfile.rs b/crates/storage/errors/src/lockfile.rs index db27cb6e2e457..f114bdef4f84a 100644 --- a/crates/storage/errors/src/lockfile.rs +++ b/crates/storage/errors/src/lockfile.rs @@ -1,8 +1,8 @@ -use reth_fs_util::FsPathError; - #[cfg(not(feature = "std"))] use alloc::string::{String, ToString}; +use reth_fs_util::FsPathError; + /// Storage lock error. #[derive(Debug, Clone, PartialEq, Eq, thiserror_no_std::Error)] pub enum StorageLockError { diff --git a/crates/storage/errors/src/provider.rs b/crates/storage/errors/src/provider.rs index 52a010474f963..8c34c8f1d78b3 100644 --- a/crates/storage/errors/src/provider.rs +++ b/crates/storage/errors/src/provider.rs @@ -1,16 +1,15 @@ -use reth_primitives::{ - Address, BlockHash, BlockHashOrNumber, BlockNumber, GotExpected, StaticFileSegment, - TxHashOrNumber, TxNumber, B256, U256, -}; - -#[cfg(feature = "std")] -use std::path::PathBuf; - #[cfg(not(feature = "std"))] use alloc::{ boxed::Box, string::{String, ToString}, }; +#[cfg(feature = "std")] +use std::path::PathBuf; + +use reth_primitives::{ + Address, BlockHash, BlockHashOrNumber, BlockNumber, GotExpected, StaticFileSegment, + TxHashOrNumber, TxNumber, B256, U256, +}; /// Provider result type. pub type ProviderResult = Result; diff --git a/crates/storage/libmdbx-rs/benches/cursor.rs b/crates/storage/libmdbx-rs/benches/cursor.rs index acd7d9a72c72a..c17f51005f9ab 100644 --- a/crates/storage/libmdbx-rs/benches/cursor.rs +++ b/crates/storage/libmdbx-rs/benches/cursor.rs @@ -1,10 +1,11 @@ #![allow(missing_docs)] mod utils; +use std::ptr; + use criterion::{black_box, criterion_group, criterion_main, Criterion}; use pprof::criterion::{Output, PProfProfiler}; use reth_libmdbx::{ffi::*, *}; -use std::ptr; use utils::*; /// Benchmark of iterator sequential read performance. diff --git a/crates/storage/libmdbx-rs/benches/transaction.rs b/crates/storage/libmdbx-rs/benches/transaction.rs index 33d25cdaa68a5..25fce2214caab 100644 --- a/crates/storage/libmdbx-rs/benches/transaction.rs +++ b/crates/storage/libmdbx-rs/benches/transaction.rs @@ -1,11 +1,12 @@ #![allow(missing_docs, unreachable_pub)] mod utils; +use std::ptr; + use criterion::{black_box, criterion_group, criterion_main, Criterion}; use rand::{prelude::SliceRandom, SeedableRng}; use rand_xorshift::XorShiftRng; use reth_libmdbx::{ffi::*, ObjectLength, WriteFlags}; -use std::ptr; use utils::*; fn bench_get_rand(c: &mut Criterion) { diff --git a/crates/storage/libmdbx-rs/src/codec.rs b/crates/storage/libmdbx-rs/src/codec.rs index 15f20204e20a2..bf63c644b0188 100644 --- a/crates/storage/libmdbx-rs/src/codec.rs +++ b/crates/storage/libmdbx-rs/src/codec.rs @@ -1,7 +1,9 @@ -use crate::{Error, TransactionKind}; -use derive_more::*; use std::{borrow::Cow, slice}; +use derive_more::*; + +use crate::{Error, TransactionKind}; + /// Implement this to be able to decode data values pub trait TableObject: Sized { /// Decodes the object from the given bytes. diff --git a/crates/storage/libmdbx-rs/src/cursor.rs b/crates/storage/libmdbx-rs/src/cursor.rs index 36da31caa6330..5311aa24640ab 100644 --- a/crates/storage/libmdbx-rs/src/cursor.rs +++ b/crates/storage/libmdbx-rs/src/cursor.rs @@ -1,3 +1,12 @@ +use std::{borrow::Cow, ffi::c_void, fmt, marker::PhantomData, mem, ptr}; + +use ffi::{ + MDBX_cursor_op, MDBX_FIRST, MDBX_FIRST_DUP, MDBX_GET_BOTH, MDBX_GET_BOTH_RANGE, + MDBX_GET_CURRENT, MDBX_GET_MULTIPLE, MDBX_LAST, MDBX_LAST_DUP, MDBX_NEXT, MDBX_NEXT_DUP, + MDBX_NEXT_MULTIPLE, MDBX_NEXT_NODUP, MDBX_PREV, MDBX_PREV_DUP, MDBX_PREV_MULTIPLE, + MDBX_PREV_NODUP, MDBX_SET, MDBX_SET_KEY, MDBX_SET_LOWERBOUND, MDBX_SET_RANGE, +}; + use crate::{ error::{mdbx_result, Error, Result}, flags::*, @@ -5,13 +14,6 @@ use crate::{ transaction::{TransactionKind, RW}, TableObject, Transaction, }; -use ffi::{ - MDBX_cursor_op, MDBX_FIRST, MDBX_FIRST_DUP, MDBX_GET_BOTH, MDBX_GET_BOTH_RANGE, - MDBX_GET_CURRENT, MDBX_GET_MULTIPLE, MDBX_LAST, MDBX_LAST_DUP, MDBX_NEXT, MDBX_NEXT_DUP, - MDBX_NEXT_MULTIPLE, MDBX_NEXT_NODUP, MDBX_PREV, MDBX_PREV_DUP, MDBX_PREV_MULTIPLE, - MDBX_PREV_NODUP, MDBX_SET, MDBX_SET_KEY, MDBX_SET_LOWERBOUND, MDBX_SET_RANGE, -}; -use std::{borrow::Cow, ffi::c_void, fmt, marker::PhantomData, mem, ptr}; /// A cursor for navigating the items within a database. pub struct Cursor diff --git a/crates/storage/libmdbx-rs/src/database.rs b/crates/storage/libmdbx-rs/src/database.rs index 1c4739b2bee71..3a49dd13b3143 100644 --- a/crates/storage/libmdbx-rs/src/database.rs +++ b/crates/storage/libmdbx-rs/src/database.rs @@ -1,10 +1,12 @@ +use std::{ffi::CString, ptr}; + +use ffi::MDBX_db_flags_t; + use crate::{ error::{mdbx_result, Result}, transaction::TransactionKind, Environment, Transaction, }; -use ffi::MDBX_db_flags_t; -use std::{ffi::CString, ptr}; /// A handle to an individual database in an environment. /// diff --git a/crates/storage/libmdbx-rs/src/environment.rs b/crates/storage/libmdbx-rs/src/environment.rs index 1549d42e18662..947438a9bbe08 100644 --- a/crates/storage/libmdbx-rs/src/environment.rs +++ b/crates/storage/libmdbx-rs/src/environment.rs @@ -1,13 +1,3 @@ -use crate::{ - database::Database, - error::{mdbx_result, Error, Result}, - flags::EnvironmentFlags, - transaction::{RO, RW}, - txn_manager::{TxnManager, TxnManagerMessage, TxnPtr}, - Transaction, TransactionKind, -}; -use byteorder::{ByteOrder, NativeEndian}; -use mem::size_of; use std::{ ffi::CString, fmt::{self, Debug}, @@ -19,8 +9,20 @@ use std::{ thread::sleep, time::Duration, }; + +use byteorder::{ByteOrder, NativeEndian}; +use mem::size_of; use tracing::warn; +use crate::{ + database::Database, + error::{mdbx_result, Error, Result}, + flags::EnvironmentFlags, + transaction::{RO, RW}, + txn_manager::{TxnManager, TxnManagerMessage, TxnPtr}, + Transaction, TransactionKind, +}; + /// The default maximum duration of a read transaction. #[cfg(feature = "read-tx-timeouts")] const DEFAULT_MAX_READ_TRANSACTION_DURATION: Duration = Duration::from_secs(5 * 60); @@ -830,9 +832,10 @@ impl EnvironmentBuilder { #[cfg(feature = "read-tx-timeouts")] pub(crate) mod read_transactions { - use crate::EnvironmentBuilder; use std::time::Duration; + use crate::EnvironmentBuilder; + /// The maximum duration of a read transaction. #[derive(Debug, Clone, Copy)] #[cfg(feature = "read-tx-timeouts")] @@ -873,12 +876,13 @@ fn convert_hsr_fn(callback: Option) -> ffi::MDBX_hsr_ #[cfg(test)] mod tests { - use crate::{Environment, Error, Geometry, HandleSlowReadersReturnCode, PageSize, WriteFlags}; use std::{ ops::RangeInclusive, sync::atomic::{AtomicBool, Ordering}, }; + use crate::{Environment, Error, Geometry, HandleSlowReadersReturnCode, PageSize, WriteFlags}; + #[test] fn test_handle_slow_readers_callback() { static CALLED: AtomicBool = AtomicBool::new(false); diff --git a/crates/storage/libmdbx-rs/src/lib.rs b/crates/storage/libmdbx-rs/src/lib.rs index 6a0fe97f72765..97a450d6201cd 100644 --- a/crates/storage/libmdbx-rs/src/lib.rs +++ b/crates/storage/libmdbx-rs/src/lib.rs @@ -10,6 +10,8 @@ pub extern crate reth_mdbx_sys as ffi; +#[cfg(feature = "read-tx-timeouts")] +pub use crate::environment::read_transactions::MaxReadTransactionDuration; pub use crate::{ codec::*, cursor::{Cursor, Iter, IterDup}, @@ -23,9 +25,6 @@ pub use crate::{ transaction::{CommitLatency, Transaction, TransactionKind, RO, RW}, }; -#[cfg(feature = "read-tx-timeouts")] -pub use crate::environment::read_transactions::MaxReadTransactionDuration; - mod codec; mod cursor; mod database; @@ -37,10 +36,11 @@ mod txn_manager; #[cfg(test)] mod test_utils { - use super::*; use byteorder::{ByteOrder, LittleEndian}; use tempfile::tempdir; + use super::*; + /// Regression test for . /// This test reliably segfaults when run against lmbdb compiled with opt level -O3 and newer /// GCC compilers. diff --git a/crates/storage/libmdbx-rs/src/transaction.rs b/crates/storage/libmdbx-rs/src/transaction.rs index 37af501c18383..0d93bce55d666 100644 --- a/crates/storage/libmdbx-rs/src/transaction.rs +++ b/crates/storage/libmdbx-rs/src/transaction.rs @@ -1,14 +1,3 @@ -use crate::{ - database::Database, - environment::Environment, - error::{mdbx_result, Result}, - flags::{DatabaseFlags, WriteFlags}, - txn_manager::{TxnManagerMessage, TxnPtr}, - Cursor, Error, Stat, TableObject, -}; -use ffi::{mdbx_txn_renew, MDBX_txn_flags_t, MDBX_TXN_RDONLY, MDBX_TXN_READWRITE}; -use indexmap::IndexSet; -use parking_lot::{Mutex, MutexGuard}; use std::{ ffi::{c_uint, c_void}, fmt::{self, Debug}, @@ -18,6 +7,19 @@ use std::{ time::Duration, }; +use ffi::{mdbx_txn_renew, MDBX_txn_flags_t, MDBX_TXN_RDONLY, MDBX_TXN_READWRITE}; +use indexmap::IndexSet; +use parking_lot::{Mutex, MutexGuard}; + +use crate::{ + database::Database, + environment::Environment, + error::{mdbx_result, Result}, + flags::{DatabaseFlags, WriteFlags}, + txn_manager::{TxnManagerMessage, TxnPtr}, + Cursor, Error, Stat, TableObject, +}; + mod private { use super::*; diff --git a/crates/storage/libmdbx-rs/src/txn_manager.rs b/crates/storage/libmdbx-rs/src/txn_manager.rs index 716e8ee62bde7..8e4cb433ba851 100644 --- a/crates/storage/libmdbx-rs/src/txn_manager.rs +++ b/crates/storage/libmdbx-rs/src/txn_manager.rs @@ -1,12 +1,13 @@ +use std::{ + ptr, + sync::mpsc::{sync_channel, Receiver, SyncSender}, +}; + use crate::{ environment::EnvPtr, error::{mdbx_result, Result}, CommitLatency, }; -use std::{ - ptr, - sync::mpsc::{sync_channel, Receiver, SyncSender}, -}; #[derive(Copy, Clone, Debug)] pub(crate) struct TxnPtr(pub(crate) *mut ffi::MDBX_txn); @@ -101,17 +102,19 @@ impl TxnManager { #[cfg(feature = "read-tx-timeouts")] mod read_transactions { - use crate::{ - environment::EnvPtr, error::mdbx_result, transaction::TransactionPtr, - txn_manager::TxnManager, - }; - use dashmap::{DashMap, DashSet}; use std::{ sync::{mpsc::sync_channel, Arc}, time::{Duration, Instant}, }; + + use dashmap::{DashMap, DashSet}; use tracing::{error, trace, warn}; + use crate::{ + environment::EnvPtr, error::mdbx_result, transaction::TransactionPtr, + txn_manager::TxnManager, + }; + const READ_TRANSACTIONS_CHECK_INTERVAL: Duration = Duration::from_secs(5); impl TxnManager { @@ -305,12 +308,14 @@ mod read_transactions { #[cfg(test)] mod tests { + use std::{thread::sleep, time::Duration}; + + use tempfile::tempdir; + use crate::{ txn_manager::read_transactions::READ_TRANSACTIONS_CHECK_INTERVAL, Environment, Error, MaxReadTransactionDuration, }; - use std::{thread::sleep, time::Duration}; - use tempfile::tempdir; #[test] fn txn_manager_read_transactions_duration_set() { diff --git a/crates/storage/libmdbx-rs/tests/cursor.rs b/crates/storage/libmdbx-rs/tests/cursor.rs index 306b87c0de6a9..279b06e07367d 100644 --- a/crates/storage/libmdbx-rs/tests/cursor.rs +++ b/crates/storage/libmdbx-rs/tests/cursor.rs @@ -1,5 +1,6 @@ -use reth_libmdbx::*; use std::borrow::Cow; + +use reth_libmdbx::*; use tempfile::tempdir; #[test] diff --git a/crates/storage/libmdbx-rs/tests/transaction.rs b/crates/storage/libmdbx-rs/tests/transaction.rs index 8cdd2531c585c..8d8b975f7793f 100644 --- a/crates/storage/libmdbx-rs/tests/transaction.rs +++ b/crates/storage/libmdbx-rs/tests/transaction.rs @@ -1,10 +1,11 @@ -use reth_libmdbx::*; use std::{ borrow::Cow, io::Write, sync::{Arc, Barrier}, thread::{self, JoinHandle}, }; + +use reth_libmdbx::*; use tempfile::tempdir; #[test] diff --git a/crates/storage/nippy-jar/src/compression/lz4.rs b/crates/storage/nippy-jar/src/compression/lz4.rs index 670bed82b669c..6235693eb1ebb 100644 --- a/crates/storage/nippy-jar/src/compression/lz4.rs +++ b/crates/storage/nippy-jar/src/compression/lz4.rs @@ -1,6 +1,7 @@ -use crate::{compression::Compression, NippyJarError}; use serde::{Deserialize, Serialize}; +use crate::{compression::Compression, NippyJarError}; + /// Wrapper type for `lz4_flex` that implements [`Compression`]. #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Default)] #[non_exhaustive] diff --git a/crates/storage/nippy-jar/src/compression/mod.rs b/crates/storage/nippy-jar/src/compression/mod.rs index 76e8c6d16b693..924a212f8b261 100644 --- a/crates/storage/nippy-jar/src/compression/mod.rs +++ b/crates/storage/nippy-jar/src/compression/mod.rs @@ -1,6 +1,7 @@ -use crate::NippyJarError; use serde::{Deserialize, Serialize}; +use crate::NippyJarError; + mod zstd; pub use self::zstd::{DecoderDictionary, Decompressor, Zstd, ZstdState}; mod lz4; diff --git a/crates/storage/nippy-jar/src/compression/zstd.rs b/crates/storage/nippy-jar/src/compression/zstd.rs index c55ca103aff5c..e49e71a8c0fc3 100644 --- a/crates/storage/nippy-jar/src/compression/zstd.rs +++ b/crates/storage/nippy-jar/src/compression/zstd.rs @@ -1,15 +1,17 @@ -use crate::{compression::Compression, NippyJarError}; -use derive_more::Deref; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::{ fs::File, io::{Read, Write}, sync::Arc, }; + +use derive_more::Deref; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; use tracing::*; use zstd::bulk::Compressor; pub use zstd::{bulk::Decompressor, dict::DecoderDictionary}; +use crate::{compression::Compression, NippyJarError}; + type RawDictionary = Vec; #[derive(Debug, Default, PartialEq, Eq, Serialize, Deserialize)] diff --git a/crates/storage/nippy-jar/src/cursor.rs b/crates/storage/nippy-jar/src/cursor.rs index 434c40a9a69b1..70feb6b8b9992 100644 --- a/crates/storage/nippy-jar/src/cursor.rs +++ b/crates/storage/nippy-jar/src/cursor.rs @@ -1,11 +1,13 @@ +use std::{ops::Range, sync::Arc}; + +use sucds::int_vectors::Access; +use zstd::bulk::Decompressor; + use crate::{ compression::{Compression, Compressors, Zstd}, DataReader, InclusionFilter, NippyJar, NippyJarError, NippyJarHeader, PerfectHashingFunction, RefRow, }; -use std::{ops::Range, sync::Arc}; -use sucds::int_vectors::Access; -use zstd::bulk::Decompressor; /// Simple cursor implementation to retrieve data from [`NippyJar`]. #[derive(Clone)] diff --git a/crates/storage/nippy-jar/src/filter/cuckoo.rs b/crates/storage/nippy-jar/src/filter/cuckoo.rs index b4e05fbb74935..a62204bb9bd6f 100644 --- a/crates/storage/nippy-jar/src/filter/cuckoo.rs +++ b/crates/storage/nippy-jar/src/filter/cuckoo.rs @@ -1,8 +1,10 @@ -use super::InclusionFilter; -use crate::NippyJarError; +use std::collections::hash_map::DefaultHasher; + use cuckoofilter::{CuckooFilter, ExportedCuckooFilter}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use std::collections::hash_map::DefaultHasher; + +use super::InclusionFilter; +use crate::NippyJarError; /// [CuckooFilter](https://www.cs.cmu.edu/~dga/papers/cuckoo-conext2014.pdf). It builds and provides an approximated set-membership filter to answer queries such as "Does this element belong to this set?". Has a theoretical 3% false positive rate. pub struct Cuckoo { diff --git a/crates/storage/nippy-jar/src/filter/mod.rs b/crates/storage/nippy-jar/src/filter/mod.rs index 3ddae0148cd71..28f2d522ebcda 100644 --- a/crates/storage/nippy-jar/src/filter/mod.rs +++ b/crates/storage/nippy-jar/src/filter/mod.rs @@ -1,6 +1,7 @@ -use crate::NippyJarError; use serde::{Deserialize, Serialize}; +use crate::NippyJarError; + mod cuckoo; pub use cuckoo::Cuckoo; diff --git a/crates/storage/nippy-jar/src/lib.rs b/crates/storage/nippy-jar/src/lib.rs index 8247599d7aeb4..5a4e95fb457bc 100644 --- a/crates/storage/nippy-jar/src/lib.rs +++ b/crates/storage/nippy-jar/src/lib.rs @@ -13,14 +13,15 @@ #![allow(missing_docs)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -use memmap2::Mmap; -use serde::{Deserialize, Serialize}; use std::{ error::Error as StdError, fs::{File, OpenOptions}, ops::Range, path::{Path, PathBuf}, }; + +use memmap2::Mmap; +use serde::{Deserialize, Serialize}; use sucds::{int_vectors::PrefixSummedEliasFano, Serializable}; use tracing::*; @@ -580,10 +581,12 @@ impl DataReader { #[cfg(test)] mod tests { - use super::*; - use rand::{rngs::SmallRng, seq::SliceRandom, RngCore, SeedableRng}; use std::{collections::HashSet, fs::OpenOptions}; + use rand::{rngs::SmallRng, seq::SliceRandom, RngCore, SeedableRng}; + + use super::*; + type ColumnResults = Vec>; type ColumnValues = Vec>; diff --git a/crates/storage/nippy-jar/src/phf/fmph.rs b/crates/storage/nippy-jar/src/phf/fmph.rs index a332c40cf7204..b72b0de7fe966 100644 --- a/crates/storage/nippy-jar/src/phf/fmph.rs +++ b/crates/storage/nippy-jar/src/phf/fmph.rs @@ -1,10 +1,11 @@ -use crate::{NippyJarError, PHFKey, PerfectHashingFunction}; use ph::fmph::{BuildConf, Function}; use serde::{ de::Error as DeSerdeError, ser::Error as SerdeError, Deserialize, Deserializer, Serialize, Serializer, }; +use crate::{NippyJarError, PHFKey, PerfectHashingFunction}; + /// Wrapper struct for [`Function`]. Implementation of the following [paper](https://dl.acm.org/doi/10.1145/3596453). #[derive(Default)] pub struct Fmph { diff --git a/crates/storage/nippy-jar/src/phf/go_fmph.rs b/crates/storage/nippy-jar/src/phf/go_fmph.rs index 328ddcb4ddcb6..ca97e49c7fef0 100644 --- a/crates/storage/nippy-jar/src/phf/go_fmph.rs +++ b/crates/storage/nippy-jar/src/phf/go_fmph.rs @@ -1,10 +1,11 @@ -use crate::{NippyJarError, PHFKey, PerfectHashingFunction}; use ph::fmph::{GOBuildConf, GOFunction}; use serde::{ de::Error as DeSerdeError, ser::Error as SerdeError, Deserialize, Deserializer, Serialize, Serializer, }; +use crate::{NippyJarError, PHFKey, PerfectHashingFunction}; + /// Wrapper struct for [`GOFunction`]. Implementation of the following [paper](https://dl.acm.org/doi/10.1145/3596453). #[derive(Default)] pub struct GoFmph { diff --git a/crates/storage/nippy-jar/src/phf/mod.rs b/crates/storage/nippy-jar/src/phf/mod.rs index ade48b60a33df..9dfa9c6059604 100644 --- a/crates/storage/nippy-jar/src/phf/mod.rs +++ b/crates/storage/nippy-jar/src/phf/mod.rs @@ -1,7 +1,9 @@ -use crate::NippyJarError; -use serde::{Deserialize, Serialize}; use std::hash::Hash; +use serde::{Deserialize, Serialize}; + +use crate::NippyJarError; + mod fmph; pub use fmph::Fmph; diff --git a/crates/storage/nippy-jar/src/writer.rs b/crates/storage/nippy-jar/src/writer.rs index 695fd6642e542..c870cd0f8fc53 100644 --- a/crates/storage/nippy-jar/src/writer.rs +++ b/crates/storage/nippy-jar/src/writer.rs @@ -1,4 +1,3 @@ -use crate::{compression::Compression, ColumnResult, NippyJar, NippyJarError, NippyJarHeader}; use std::{ cmp::Ordering, fs::{File, OpenOptions}, @@ -6,6 +5,8 @@ use std::{ path::Path, }; +use crate::{compression::Compression, ColumnResult, NippyJar, NippyJarError, NippyJarHeader}; + /// Size of one offset in bytes. const OFFSET_SIZE_BYTES: u8 = 8; diff --git a/crates/storage/provider/src/bundle_state/bundle_state_with_receipts.rs b/crates/storage/provider/src/bundle_state/bundle_state_with_receipts.rs index 4d3b92b05734a..2bfee4f750bbf 100644 --- a/crates/storage/provider/src/bundle_state/bundle_state_with_receipts.rs +++ b/crates/storage/provider/src/bundle_state/bundle_state_with_receipts.rs @@ -1,4 +1,3 @@ -use crate::{providers::StaticFileProviderRWRefMut, StateChanges, StateReverts, StateWriter}; use reth_db::tables; use reth_db_api::{ cursor::{DbCursorRO, DbCursorRW}, @@ -9,6 +8,8 @@ use reth_primitives::StaticFileSegment; use reth_storage_errors::provider::{ProviderError, ProviderResult}; pub use revm::db::states::OriginalValuesKnown; +use crate::{providers::StaticFileProviderRWRefMut, StateChanges, StateReverts, StateWriter}; + impl StateWriter for ExecutionOutcome { fn write_to_storage( self, @@ -67,8 +68,8 @@ impl StateWriter for ExecutionOutcome { #[cfg(test)] mod tests { - use super::*; - use crate::{test_utils::create_test_provider_factory, AccountReader}; + use std::collections::{BTreeMap, HashMap}; + use reth_db::test_utils::create_test_rw_db; use reth_db_api::{ cursor::DbDupCursorRO, @@ -91,7 +92,9 @@ mod tests { }, DatabaseCommit, State, }; - use std::collections::{BTreeMap, HashMap}; + + use super::*; + use crate::{test_utils::create_test_provider_factory, AccountReader}; #[test] fn write_to_db_account_info() { diff --git a/crates/storage/provider/src/bundle_state/hashed_state_changes.rs b/crates/storage/provider/src/bundle_state/hashed_state_changes.rs index b768ec3c2edb1..ad7cc7dc65d15 100644 --- a/crates/storage/provider/src/bundle_state/hashed_state_changes.rs +++ b/crates/storage/provider/src/bundle_state/hashed_state_changes.rs @@ -57,11 +57,12 @@ impl HashedStateChanges { #[cfg(test)] mod tests { - use super::*; - use crate::test_utils::create_test_provider_factory; use reth_primitives::{keccak256, Account, Address, B256}; use reth_trie::HashedStorage; + use super::*; + use crate::test_utils::create_test_provider_factory; + #[test] fn wiped_entries_are_removed() { let provider_factory = create_test_provider_factory(); diff --git a/crates/storage/provider/src/bundle_state/state_reverts.rs b/crates/storage/provider/src/bundle_state/state_reverts.rs index d65fcaa829f11..9162f5de60ec9 100644 --- a/crates/storage/provider/src/bundle_state/state_reverts.rs +++ b/crates/storage/provider/src/bundle_state/state_reverts.rs @@ -1,3 +1,5 @@ +use std::iter::Peekable; + use rayon::slice::ParallelSliceMut; use reth_db::tables; use reth_db_api::{ @@ -8,7 +10,6 @@ use reth_db_api::{ use reth_primitives::{BlockNumber, StorageEntry, B256, U256}; use reth_storage_errors::db::DatabaseError; use revm::db::states::{PlainStateReverts, PlainStorageRevert, RevertToSlot}; -use std::iter::Peekable; /// Revert of the state. #[derive(Debug, Default)] diff --git a/crates/storage/provider/src/lib.rs b/crates/storage/provider/src/lib.rs index 17c6af8758188..3903652ffbcc4 100644 --- a/crates/storage/provider/src/lib.rs +++ b/crates/storage/provider/src/lib.rs @@ -28,11 +28,10 @@ pub use providers::{ /// Common test helpers for mocking the Provider. pub mod test_utils; +pub use reth_execution_types::*; /// Re-export provider error. pub use reth_storage_errors::provider::{ProviderError, ProviderResult}; -pub use reth_execution_types::*; - pub mod bundle_state; pub use bundle_state::{OriginalValuesKnown, StateChanges, StateReverts}; diff --git a/crates/storage/provider/src/providers/bundle_state_provider.rs b/crates/storage/provider/src/providers/bundle_state_provider.rs index 49fb196ffb18b..7815556ffc813 100644 --- a/crates/storage/provider/src/providers/bundle_state_provider.rs +++ b/crates/storage/provider/src/providers/bundle_state_provider.rs @@ -1,11 +1,12 @@ -use crate::{ - AccountReader, BlockHashReader, ExecutionDataProvider, StateProvider, StateRootProvider, -}; use reth_primitives::{Account, Address, BlockNumber, Bytecode, B256}; use reth_storage_errors::provider::{ProviderError, ProviderResult}; use reth_trie::{updates::TrieUpdates, AccountProof}; use revm::db::BundleState; +use crate::{ + AccountReader, BlockHashReader, ExecutionDataProvider, StateProvider, StateRootProvider, +}; + /// A state provider that resolves to data from either a wrapped [`crate::ExecutionOutcome`] /// or an underlying state provider. /// diff --git a/crates/storage/provider/src/providers/chain_info.rs b/crates/storage/provider/src/providers/chain_info.rs index c696fefea9e34..baa1b4d16159d 100644 --- a/crates/storage/provider/src/providers/chain_info.rs +++ b/crates/storage/provider/src/providers/chain_info.rs @@ -1,6 +1,3 @@ -use parking_lot::RwLock; -use reth_chainspec::ChainInfo; -use reth_primitives::{BlockNumHash, BlockNumber, SealedHeader}; use std::{ sync::{ atomic::{AtomicU64, Ordering}, @@ -8,6 +5,10 @@ use std::{ }, time::Instant, }; + +use parking_lot::RwLock; +use reth_chainspec::ChainInfo; +use reth_primitives::{BlockNumHash, BlockNumber, SealedHeader}; use tokio::sync::watch; /// Tracks the chain info: canonical head, safe block, finalized block. diff --git a/crates/storage/provider/src/providers/consistent_view.rs b/crates/storage/provider/src/providers/consistent_view.rs index fe9b65941107c..4733db0d611c9 100644 --- a/crates/storage/provider/src/providers/consistent_view.rs +++ b/crates/storage/provider/src/providers/consistent_view.rs @@ -1,10 +1,11 @@ -use crate::{BlockNumReader, DatabaseProviderFactory, DatabaseProviderRO, HeaderProvider}; +use std::marker::PhantomData; + use reth_db_api::database::Database; use reth_primitives::{GotExpected, B256}; +pub use reth_storage_errors::provider::ConsistentViewError; use reth_storage_errors::provider::ProviderResult; -use std::marker::PhantomData; -pub use reth_storage_errors::provider::ConsistentViewError; +use crate::{BlockNumReader, DatabaseProviderFactory, DatabaseProviderRO, HeaderProvider}; /// A consistent view over state in the database. /// diff --git a/crates/storage/provider/src/providers/database/metrics.rs b/crates/storage/provider/src/providers/database/metrics.rs index ba43298c36b56..538f5091febfc 100644 --- a/crates/storage/provider/src/providers/database/metrics.rs +++ b/crates/storage/provider/src/providers/database/metrics.rs @@ -1,6 +1,7 @@ +use std::time::{Duration, Instant}; + use metrics::Histogram; use reth_metrics::Metrics; -use std::time::{Duration, Instant}; #[derive(Debug)] pub(crate) struct DurationsRecorder { diff --git a/crates/storage/provider/src/providers/database/mod.rs b/crates/storage/provider/src/providers/database/mod.rs index 57e7e9615217e..85ea3e2343ad8 100644 --- a/crates/storage/provider/src/providers/database/mod.rs +++ b/crates/storage/provider/src/providers/database/mod.rs @@ -1,12 +1,9 @@ -use crate::{ - providers::{state::latest::LatestStateProvider, StaticFileProvider}, - to_range, - traits::{BlockSource, ReceiptProvider}, - BlockHashReader, BlockNumReader, BlockReader, ChainSpecProvider, DatabaseProviderFactory, - EvmEnvProvider, HeaderProvider, HeaderSyncGap, HeaderSyncGapProvider, ProviderError, - PruneCheckpointReader, RequestsProvider, StageCheckpointReader, StateProviderBox, - StaticFileProviderFactory, TransactionVariant, TransactionsProvider, WithdrawalsProvider, +use std::{ + ops::{RangeBounds, RangeInclusive}, + path::Path, + sync::Arc, }; + use reth_chainspec::{ChainInfo, ChainSpec}; use reth_db::{init_db, mdbx::DatabaseArguments, DatabaseEnv}; use reth_db_api::{database::Database, models::StoredBlockBodyIndices}; @@ -22,14 +19,19 @@ use reth_prune_types::{PruneCheckpoint, PruneSegment}; use reth_stages_types::{StageCheckpoint, StageId}; use reth_storage_errors::provider::ProviderResult; use revm::primitives::{BlockEnv, CfgEnvWithHandlerCfg}; -use std::{ - ops::{RangeBounds, RangeInclusive}, - path::Path, - sync::Arc, -}; use tokio::sync::watch; use tracing::trace; +use crate::{ + providers::{state::latest::LatestStateProvider, StaticFileProvider}, + to_range, + traits::{BlockSource, ReceiptProvider}, + BlockHashReader, BlockNumReader, BlockReader, ChainSpecProvider, DatabaseProviderFactory, + EvmEnvProvider, HeaderProvider, HeaderSyncGap, HeaderSyncGapProvider, ProviderError, + PruneCheckpointReader, RequestsProvider, StageCheckpointReader, StateProviderBox, + StaticFileProviderFactory, TransactionVariant, TransactionsProvider, WithdrawalsProvider, +}; + mod metrics; mod provider; @@ -589,12 +591,8 @@ impl Clone for ProviderFactory { } #[cfg(test)] mod tests { - use super::*; - use crate::{ - providers::{StaticFileProvider, StaticFileWriter}, - test_utils::create_test_provider_factory, - BlockHashReader, BlockNumReader, BlockWriter, HeaderSyncGapProvider, TransactionsProvider, - }; + use std::{ops::RangeInclusive, sync::Arc}; + use alloy_rlp::Decodable; use assert_matches::assert_matches; use rand::Rng; @@ -611,9 +609,15 @@ mod tests { generators, generators::{random_block, random_header}, }; - use std::{ops::RangeInclusive, sync::Arc}; use tokio::sync::watch; + use super::*; + use crate::{ + providers::{StaticFileProvider, StaticFileWriter}, + test_utils::create_test_provider_factory, + BlockHashReader, BlockNumReader, BlockWriter, HeaderSyncGapProvider, TransactionsProvider, + }; + #[test] fn common_history_provider() { let factory = create_test_provider_factory(); diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index 02287b96cad0c..49819ed4a5d9c 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -1,18 +1,12 @@ -use crate::{ - bundle_state::{BundleStateInit, HashedStateChanges, RevertsInit}, - providers::{database::metrics, static_file::StaticFileWriter, StaticFileProvider}, - to_range, - traits::{ - AccountExtReader, BlockSource, ChangeSetReader, ReceiptProvider, StageCheckpointWriter, - }, - AccountReader, BlockExecutionWriter, BlockHashReader, BlockNumReader, BlockReader, BlockWriter, - EvmEnvProvider, FinalizedBlockReader, FinalizedBlockWriter, HashingWriter, HeaderProvider, - HeaderSyncGap, HeaderSyncGapProvider, HistoricalStateProvider, HistoryWriter, - LatestStateProvider, OriginalValuesKnown, ProviderError, PruneCheckpointReader, - PruneCheckpointWriter, RequestsProvider, StageCheckpointReader, StateProviderBox, StateWriter, - StatsReader, StorageReader, TransactionVariant, TransactionsProvider, TransactionsProviderExt, - WithdrawalsProvider, +use std::{ + cmp::Ordering, + collections::{hash_map, BTreeMap, BTreeSet, HashMap, HashSet}, + fmt::Debug, + ops::{Bound, Deref, DerefMut, Range, RangeBounds, RangeInclusive}, + sync::{mpsc, Arc}, + time::{Duration, Instant}, }; + use itertools::{izip, Itertools}; use reth_chainspec::{ChainInfo, ChainSpec}; use reth_db::{tables, BlockNumberList}; @@ -49,17 +43,25 @@ use reth_trie::{ HashedPostState, Nibbles, StateRoot, }; use revm::primitives::{BlockEnv, CfgEnvWithHandlerCfg, SpecId}; -use std::{ - cmp::Ordering, - collections::{hash_map, BTreeMap, BTreeSet, HashMap, HashSet}, - fmt::Debug, - ops::{Bound, Deref, DerefMut, Range, RangeBounds, RangeInclusive}, - sync::{mpsc, Arc}, - time::{Duration, Instant}, -}; use tokio::sync::watch; use tracing::{debug, error, warn}; +use crate::{ + bundle_state::{BundleStateInit, HashedStateChanges, RevertsInit}, + providers::{database::metrics, static_file::StaticFileWriter, StaticFileProvider}, + to_range, + traits::{ + AccountExtReader, BlockSource, ChangeSetReader, ReceiptProvider, StageCheckpointWriter, + }, + AccountReader, BlockExecutionWriter, BlockHashReader, BlockNumReader, BlockReader, BlockWriter, + EvmEnvProvider, FinalizedBlockReader, FinalizedBlockWriter, HashingWriter, HeaderProvider, + HeaderSyncGap, HeaderSyncGapProvider, HistoricalStateProvider, HistoryWriter, + LatestStateProvider, OriginalValuesKnown, ProviderError, PruneCheckpointReader, + PruneCheckpointWriter, RequestsProvider, StageCheckpointReader, StateProviderBox, StateWriter, + StatsReader, StorageReader, TransactionVariant, TransactionsProvider, TransactionsProviderExt, + WithdrawalsProvider, +}; + /// A [`DatabaseProvider`] that holds a read-only database transaction. pub type DatabaseProviderRO = DatabaseProvider<::TX>; diff --git a/crates/storage/provider/src/providers/mod.rs b/crates/storage/provider/src/providers/mod.rs index 9da41269c1377..45bdf407498ba 100644 --- a/crates/storage/provider/src/providers/mod.rs +++ b/crates/storage/provider/src/providers/mod.rs @@ -1,12 +1,10 @@ -use crate::{ - AccountReader, BlockHashReader, BlockIdReader, BlockNumReader, BlockReader, BlockReaderIdExt, - BlockSource, BlockchainTreePendingStateProvider, CanonChainTracker, CanonStateNotifications, - CanonStateSubscriptions, ChainSpecProvider, ChangeSetReader, DatabaseProviderFactory, - EvmEnvProvider, FullExecutionDataProvider, HeaderProvider, ProviderError, - PruneCheckpointReader, ReceiptProvider, ReceiptProviderIdExt, RequestsProvider, - StageCheckpointReader, StateProviderBox, StateProviderFactory, StaticFileProviderFactory, - TransactionVariant, TransactionsProvider, TreeViewer, WithdrawalsProvider, +use std::{ + collections::BTreeMap, + ops::{RangeBounds, RangeInclusive}, + sync::Arc, + time::Instant, }; + use reth_blockchain_tree_api::{ error::{CanonicalError, InsertBlockError}, BlockValidationKind, BlockchainTreeEngine, BlockchainTreeViewer, CanonicalOutcome, @@ -28,14 +26,18 @@ use reth_prune_types::{PruneCheckpoint, PruneSegment}; use reth_stages_types::{StageCheckpoint, StageId}; use reth_storage_errors::provider::ProviderResult; use revm::primitives::{BlockEnv, CfgEnvWithHandlerCfg}; -use std::{ - collections::BTreeMap, - ops::{RangeBounds, RangeInclusive}, - sync::Arc, - time::Instant, -}; use tracing::trace; +use crate::{ + AccountReader, BlockHashReader, BlockIdReader, BlockNumReader, BlockReader, BlockReaderIdExt, + BlockSource, BlockchainTreePendingStateProvider, CanonChainTracker, CanonStateNotifications, + CanonStateSubscriptions, ChainSpecProvider, ChangeSetReader, DatabaseProviderFactory, + EvmEnvProvider, FullExecutionDataProvider, HeaderProvider, ProviderError, + PruneCheckpointReader, ReceiptProvider, ReceiptProviderIdExt, RequestsProvider, + StageCheckpointReader, StateProviderBox, StateProviderFactory, StaticFileProviderFactory, + TransactionVariant, TransactionsProvider, TreeViewer, WithdrawalsProvider, +}; + mod database; pub use database::*; diff --git a/crates/storage/provider/src/providers/state/historical.rs b/crates/storage/provider/src/providers/state/historical.rs index 12545fe7838e1..13b82059db39a 100644 --- a/crates/storage/provider/src/providers/state/historical.rs +++ b/crates/storage/provider/src/providers/state/historical.rs @@ -1,7 +1,5 @@ -use crate::{ - providers::{state::macros::delegate_provider_impls, StaticFileProvider}, - AccountReader, BlockHashReader, ProviderError, StateProvider, StateRootProvider, -}; +use std::fmt::Debug; + use reth_db::{tables, BlockNumberList}; use reth_db_api::{ cursor::{DbCursorRO, DbDupCursorRO}, @@ -16,7 +14,11 @@ use reth_primitives::{ use reth_storage_errors::provider::ProviderResult; use reth_trie::{updates::TrieUpdates, AccountProof, HashedPostState}; use revm::db::BundleState; -use std::fmt::Debug; + +use crate::{ + providers::{state::macros::delegate_provider_impls, StaticFileProvider}, + AccountReader, BlockHashReader, ProviderError, StateProvider, StateRootProvider, +}; /// State provider for a given block number which takes a tx reference. /// @@ -400,12 +402,6 @@ impl LowestAvailableBlocks { #[cfg(test)] mod tests { - use crate::{ - providers::state::historical::{HistoryInfo, LowestAvailableBlocks}, - test_utils::create_test_provider_factory, - AccountReader, HistoricalStateProvider, HistoricalStateProviderRef, StateProvider, - StaticFileProviderFactory, - }; use reth_db::{tables, BlockNumberList}; use reth_db_api::{ models::{storage_sharded_key::StorageShardedKey, AccountBeforeTx, ShardedKey}, @@ -414,6 +410,13 @@ mod tests { use reth_primitives::{address, b256, Account, Address, StorageEntry, B256, U256}; use reth_storage_errors::provider::ProviderError; + use crate::{ + providers::state::historical::{HistoryInfo, LowestAvailableBlocks}, + test_utils::create_test_provider_factory, + AccountReader, HistoricalStateProvider, HistoricalStateProviderRef, StateProvider, + StaticFileProviderFactory, + }; + const ADDRESS: Address = address!("0000000000000000000000000000000000000001"); const HIGHER_ADDRESS: Address = address!("0000000000000000000000000000000000000005"); const STORAGE: B256 = b256!("0000000000000000000000000000000000000000000000000000000000000001"); diff --git a/crates/storage/provider/src/providers/state/latest.rs b/crates/storage/provider/src/providers/state/latest.rs index 56b4ecc38b11c..6a2a187c0f462 100644 --- a/crates/storage/provider/src/providers/state/latest.rs +++ b/crates/storage/provider/src/providers/state/latest.rs @@ -1,7 +1,3 @@ -use crate::{ - providers::{state::macros::delegate_provider_impls, StaticFileProvider}, - AccountReader, BlockHashReader, StateProvider, StateRootProvider, -}; use reth_db::tables; use reth_db_api::{ cursor::{DbCursorRO, DbDupCursorRO}, @@ -14,6 +10,11 @@ use reth_storage_errors::provider::{ProviderError, ProviderResult}; use reth_trie::{proof::Proof, updates::TrieUpdates, AccountProof, HashedPostState}; use revm::db::BundleState; +use crate::{ + providers::{state::macros::delegate_provider_impls, StaticFileProvider}, + AccountReader, BlockHashReader, StateProvider, StateRootProvider, +}; + /// State provider over latest state that takes tx reference. #[derive(Debug)] pub struct LatestStateProviderRef<'b, TX: DbTx> { diff --git a/crates/storage/provider/src/providers/static_file/jar.rs b/crates/storage/provider/src/providers/static_file/jar.rs index 5e20572e3d617..922735522174f 100644 --- a/crates/storage/provider/src/providers/static_file/jar.rs +++ b/crates/storage/provider/src/providers/static_file/jar.rs @@ -1,11 +1,8 @@ -use super::{ - metrics::{StaticFileProviderMetrics, StaticFileProviderOperation}, - LoadedJarRef, -}; -use crate::{ - to_range, BlockHashReader, BlockNumReader, HeaderProvider, ReceiptProvider, - TransactionsProvider, +use std::{ + ops::{Deref, RangeBounds}, + sync::Arc, }; + use reth_chainspec::ChainInfo; use reth_db::static_file::{HeaderMask, ReceiptMask, StaticFileCursor, TransactionMask}; use reth_db_api::models::CompactU256; @@ -14,9 +11,14 @@ use reth_primitives::{ TransactionMeta, TransactionSigned, TransactionSignedNoHash, TxHash, TxNumber, B256, U256, }; use reth_storage_errors::provider::{ProviderError, ProviderResult}; -use std::{ - ops::{Deref, RangeBounds}, - sync::Arc, + +use super::{ + metrics::{StaticFileProviderMetrics, StaticFileProviderOperation}, + LoadedJarRef, +}; +use crate::{ + to_range, BlockHashReader, BlockNumReader, HeaderProvider, ReceiptProvider, + TransactionsProvider, }; /// Provider over a specific `NippyJar` and range. diff --git a/crates/storage/provider/src/providers/static_file/manager.rs b/crates/storage/provider/src/providers/static_file/manager.rs index 39e588c7f5f49..918bbe9834c83 100644 --- a/crates/storage/provider/src/providers/static_file/manager.rs +++ b/crates/storage/provider/src/providers/static_file/manager.rs @@ -1,12 +1,10 @@ -use super::{ - metrics::StaticFileProviderMetrics, LoadedJar, StaticFileJarProvider, StaticFileProviderRW, - StaticFileProviderRWRefMut, BLOCKS_PER_STATIC_FILE, -}; -use crate::{ - to_range, BlockHashReader, BlockNumReader, BlockReader, BlockSource, DatabaseProvider, - HeaderProvider, ReceiptProvider, RequestsProvider, StageCheckpointReader, StatsReader, - TransactionVariant, TransactionsProvider, TransactionsProviderExt, WithdrawalsProvider, +use std::{ + collections::{hash_map::Entry, BTreeMap, HashMap}, + ops::{Deref, Range, RangeBounds, RangeInclusive}, + path::{Path, PathBuf}, + sync::{mpsc, Arc}, }; + use dashmap::{mapref::entry::Entry as DashMapEntry, DashMap}; use parking_lot::RwLock; use reth_chainspec::ChainInfo; @@ -32,15 +30,19 @@ use reth_primitives::{ }; use reth_stages_types::{PipelineTarget, StageId}; use reth_storage_errors::provider::{ProviderError, ProviderResult}; -use std::{ - collections::{hash_map::Entry, BTreeMap, HashMap}, - ops::{Deref, Range, RangeBounds, RangeInclusive}, - path::{Path, PathBuf}, - sync::{mpsc, Arc}, -}; use strum::IntoEnumIterator; use tracing::{info, warn}; +use super::{ + metrics::StaticFileProviderMetrics, LoadedJar, StaticFileJarProvider, StaticFileProviderRW, + StaticFileProviderRWRefMut, BLOCKS_PER_STATIC_FILE, +}; +use crate::{ + to_range, BlockHashReader, BlockNumReader, BlockReader, BlockSource, DatabaseProvider, + HeaderProvider, ReceiptProvider, RequestsProvider, StageCheckpointReader, StatsReader, + TransactionVariant, TransactionsProvider, TransactionsProviderExt, WithdrawalsProvider, +}; + /// Alias type for a map that can be queried for block ranges from a transaction /// segment respectively. It uses `TxNumber` to represent the transaction end of a static file /// range. diff --git a/crates/storage/provider/src/providers/static_file/mod.rs b/crates/storage/provider/src/providers/static_file/mod.rs index 5c2057b3b57dd..5b6e7d9b446ca 100644 --- a/crates/storage/provider/src/providers/static_file/mod.rs +++ b/crates/storage/provider/src/providers/static_file/mod.rs @@ -9,10 +9,11 @@ pub use writer::{StaticFileProviderRW, StaticFileProviderRWRefMut}; mod metrics; +use std::{ops::Deref, sync::Arc}; + use reth_nippy_jar::NippyJar; use reth_primitives::{static_file::SegmentHeader, StaticFileSegment}; use reth_storage_errors::provider::{ProviderError, ProviderResult}; -use std::{ops::Deref, sync::Arc}; const BLOCKS_PER_STATIC_FILE: u64 = 500_000; @@ -56,8 +57,6 @@ impl Deref for LoadedJar { #[cfg(test)] mod tests { - use super::*; - use crate::{test_utils::create_test_provider_factory, HeaderProvider}; use rand::seq::SliceRandom; use reth_db::{ static_file::create_static_file_T1_T2_T3, CanonicalHeaders, HeaderNumbers, @@ -70,6 +69,9 @@ mod tests { use reth_primitives::{static_file::find_fixed_range, BlockNumber, B256, U256}; use reth_testing_utils::generators::{self, random_header_range}; + use super::*; + use crate::{test_utils::create_test_provider_factory, HeaderProvider}; + #[test] fn test_snap() { // Ranges diff --git a/crates/storage/provider/src/providers/static_file/writer.rs b/crates/storage/provider/src/providers/static_file/writer.rs index 304429a0150b7..88c104c492678 100644 --- a/crates/storage/provider/src/providers/static_file/writer.rs +++ b/crates/storage/provider/src/providers/static_file/writer.rs @@ -1,8 +1,9 @@ -use crate::providers::static_file::metrics::StaticFileProviderOperation; - -use super::{ - manager::StaticFileProviderInner, metrics::StaticFileProviderMetrics, StaticFileProvider, +use std::{ + path::{Path, PathBuf}, + sync::{Arc, Weak}, + time::Instant, }; + use dashmap::mapref::one::RefMut; use reth_codecs::Compact; use reth_db_api::models::CompactU256; @@ -13,13 +14,13 @@ use reth_primitives::{ U256, }; use reth_storage_errors::provider::{ProviderError, ProviderResult}; -use std::{ - path::{Path, PathBuf}, - sync::{Arc, Weak}, - time::Instant, -}; use tracing::debug; +use super::{ + manager::StaticFileProviderInner, metrics::StaticFileProviderMetrics, StaticFileProvider, +}; +use crate::providers::static_file::metrics::StaticFileProviderOperation; + /// Mutable reference to a dashmap element of [`StaticFileProviderRW`]. pub type StaticFileProviderRWRefMut<'a> = RefMut<'a, StaticFileSegment, StaticFileProviderRW>; diff --git a/crates/storage/provider/src/test_utils/blocks.rs b/crates/storage/provider/src/test_utils/blocks.rs index 2a0f900a5e160..50fccb7f6e730 100644 --- a/crates/storage/provider/src/test_utils/blocks.rs +++ b/crates/storage/provider/src/test_utils/blocks.rs @@ -1,5 +1,4 @@ //! Dummy blocks and data for tests -use crate::{DatabaseProviderRW, ExecutionOutcome}; use alloy_primitives::Log; use alloy_rlp::Decodable; use reth_db::tables; @@ -15,6 +14,8 @@ use revm::{ primitives::{AccountInfo, HashMap}, }; +use crate::{DatabaseProviderRW, ExecutionOutcome}; + /// Assert genesis block pub fn assert_genesis_block(provider: &DatabaseProviderRW, g: SealedBlock) { let n = g.number; diff --git a/crates/storage/provider/src/test_utils/events.rs b/crates/storage/provider/src/test_utils/events.rs index 39e53772ca5dd..ce06fd2d99f30 100644 --- a/crates/storage/provider/src/test_utils/events.rs +++ b/crates/storage/provider/src/test_utils/events.rs @@ -1,4 +1,5 @@ use std::sync::{Arc, Mutex}; + use tokio::sync::broadcast::{self, Sender}; use crate::{CanonStateNotification, CanonStateNotifications, CanonStateSubscriptions, Chain}; diff --git a/crates/storage/provider/src/test_utils/mock.rs b/crates/storage/provider/src/test_utils/mock.rs index 974982121a7e4..f4c2d59d925f0 100644 --- a/crates/storage/provider/src/test_utils/mock.rs +++ b/crates/storage/provider/src/test_utils/mock.rs @@ -1,10 +1,9 @@ -use crate::{ - traits::{BlockSource, ReceiptProvider}, - AccountReader, BlockHashReader, BlockIdReader, BlockNumReader, BlockReader, BlockReaderIdExt, - ChainSpecProvider, ChangeSetReader, EvmEnvProvider, FullExecutionDataProvider, HeaderProvider, - ReceiptProviderIdExt, RequestsProvider, StateProvider, StateProviderBox, StateProviderFactory, - StateRootProvider, TransactionVariant, TransactionsProvider, WithdrawalsProvider, +use std::{ + collections::{BTreeMap, HashMap}, + ops::{RangeBounds, RangeInclusive}, + sync::Arc, }; + use parking_lot::Mutex; use reth_chainspec::{ChainInfo, ChainSpec}; use reth_db_api::models::{AccountBeforeTx, StoredBlockBodyIndices}; @@ -21,10 +20,13 @@ use revm::{ db::BundleState, primitives::{BlockEnv, CfgEnvWithHandlerCfg}, }; -use std::{ - collections::{BTreeMap, HashMap}, - ops::{RangeBounds, RangeInclusive}, - sync::Arc, + +use crate::{ + traits::{BlockSource, ReceiptProvider}, + AccountReader, BlockHashReader, BlockIdReader, BlockNumReader, BlockReader, BlockReaderIdExt, + ChainSpecProvider, ChangeSetReader, EvmEnvProvider, FullExecutionDataProvider, HeaderProvider, + ReceiptProviderIdExt, RequestsProvider, StateProvider, StateProviderBox, StateProviderFactory, + StateRootProvider, TransactionVariant, TransactionsProvider, WithdrawalsProvider, }; /// A mock implementation for Provider interfaces. diff --git a/crates/storage/provider/src/test_utils/mod.rs b/crates/storage/provider/src/test_utils/mod.rs index 4d40ad54e9908..b14df698c52e4 100644 --- a/crates/storage/provider/src/test_utils/mod.rs +++ b/crates/storage/provider/src/test_utils/mod.rs @@ -1,10 +1,12 @@ -use crate::{providers::StaticFileProvider, ProviderFactory}; +use std::sync::Arc; + use reth_chainspec::{ChainSpec, MAINNET}; use reth_db::{ test_utils::{create_test_rw_db, create_test_static_files_dir, TempDatabase}, DatabaseEnv, }; -use std::sync::Arc; + +use crate::{providers::StaticFileProvider, ProviderFactory}; pub mod blocks; mod events; diff --git a/crates/storage/provider/src/test_utils/noop.rs b/crates/storage/provider/src/test_utils/noop.rs index 74577732d2a7a..27da5f30afbb6 100644 --- a/crates/storage/provider/src/test_utils/noop.rs +++ b/crates/storage/provider/src/test_utils/noop.rs @@ -1,11 +1,8 @@ -use crate::{ - traits::{BlockSource, ReceiptProvider}, - AccountReader, BlockHashReader, BlockIdReader, BlockNumReader, BlockReader, BlockReaderIdExt, - ChainSpecProvider, ChangeSetReader, EvmEnvProvider, HeaderProvider, PruneCheckpointReader, - ReceiptProviderIdExt, RequestsProvider, StageCheckpointReader, StateProvider, StateProviderBox, - StateProviderFactory, StateRootProvider, TransactionVariant, TransactionsProvider, - WithdrawalsProvider, +use std::{ + ops::{RangeBounds, RangeInclusive}, + sync::Arc, }; + use reth_chainspec::{ChainInfo, ChainSpec, MAINNET}; use reth_db_api::models::{AccountBeforeTx, StoredBlockBodyIndices}; use reth_evm::ConfigureEvmEnv; @@ -23,9 +20,14 @@ use revm::{ db::BundleState, primitives::{BlockEnv, CfgEnvWithHandlerCfg}, }; -use std::{ - ops::{RangeBounds, RangeInclusive}, - sync::Arc, + +use crate::{ + traits::{BlockSource, ReceiptProvider}, + AccountReader, BlockHashReader, BlockIdReader, BlockNumReader, BlockReader, BlockReaderIdExt, + ChainSpecProvider, ChangeSetReader, EvmEnvProvider, HeaderProvider, PruneCheckpointReader, + ReceiptProviderIdExt, RequestsProvider, StageCheckpointReader, StateProvider, StateProviderBox, + StateProviderFactory, StateRootProvider, TransactionVariant, TransactionsProvider, + WithdrawalsProvider, }; /// Supports various api interfaces for testing purposes. diff --git a/crates/storage/provider/src/traits/block.rs b/crates/storage/provider/src/traits/block.rs index 7211cb691fb64..be9190c48d83b 100644 --- a/crates/storage/provider/src/traits/block.rs +++ b/crates/storage/provider/src/traits/block.rs @@ -1,3 +1,5 @@ +use std::ops::RangeInclusive; + use reth_db_api::models::StoredBlockBodyIndices; use reth_execution_types::{Chain, ExecutionOutcome}; use reth_primitives::{BlockNumber, SealedBlockWithSenders}; @@ -5,7 +7,6 @@ use reth_prune_types::PruneModes; use reth_storage_api::BlockReader; use reth_storage_errors::provider::ProviderResult; use reth_trie::{updates::TrieUpdates, HashedPostState}; -use std::ops::RangeInclusive; /// BlockExecution Writer #[auto_impl::auto_impl(&, Arc, Box)] diff --git a/crates/storage/provider/src/traits/chain.rs b/crates/storage/provider/src/traits/chain.rs index 98957fcfdcc83..6a15cbc97a808 100644 --- a/crates/storage/provider/src/traits/chain.rs +++ b/crates/storage/provider/src/traits/chain.rs @@ -1,17 +1,19 @@ //! Canonical chain state notification trait and types. -use crate::{BlockReceipts, Chain}; -use auto_impl::auto_impl; -use reth_primitives::SealedBlockWithSenders; use std::{ pin::Pin, sync::Arc, task::{ready, Context, Poll}, }; + +use auto_impl::auto_impl; +use reth_primitives::SealedBlockWithSenders; use tokio::sync::broadcast; use tokio_stream::{wrappers::BroadcastStream, Stream}; use tracing::debug; +use crate::{BlockReceipts, Chain}; + /// Type alias for a receiver that receives [`CanonStateNotification`] pub type CanonStateNotifications = broadcast::Receiver; diff --git a/crates/storage/provider/src/traits/chain_info.rs b/crates/storage/provider/src/traits/chain_info.rs index 39f8639dd2744..9af7bee41d674 100644 --- a/crates/storage/provider/src/traits/chain_info.rs +++ b/crates/storage/provider/src/traits/chain_info.rs @@ -1,6 +1,7 @@ +use std::time::Instant; + use alloy_rpc_types_engine::ForkchoiceState; use reth_primitives::SealedHeader; -use std::time::Instant; /// A type that can track updates related to fork choice updates. pub trait CanonChainTracker: Send + Sync { diff --git a/crates/storage/provider/src/traits/database_provider.rs b/crates/storage/provider/src/traits/database_provider.rs index fab60fe2e704a..338d463c63821 100644 --- a/crates/storage/provider/src/traits/database_provider.rs +++ b/crates/storage/provider/src/traits/database_provider.rs @@ -1,7 +1,8 @@ -use crate::DatabaseProviderRO; use reth_db_api::database::Database; use reth_storage_errors::provider::ProviderResult; +use crate::DatabaseProviderRO; + /// Database provider factory. pub trait DatabaseProviderFactory { /// Create new read-only database provider. diff --git a/crates/storage/provider/src/traits/full.rs b/crates/storage/provider/src/traits/full.rs index 6b35d6b251352..21dbebaebdb06 100644 --- a/crates/storage/provider/src/traits/full.rs +++ b/crates/storage/provider/src/traits/full.rs @@ -1,11 +1,12 @@ //! Helper provider traits to encapsulate all provider traits for simplicity. +use reth_db_api::database::Database; + use crate::{ AccountReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider, ChangeSetReader, DatabaseProviderFactory, EvmEnvProvider, StageCheckpointReader, StateProviderFactory, StaticFileProviderFactory, }; -use reth_db_api::database::Database; /// Helper trait to unify all provider traits for simplicity. pub trait FullProvider: diff --git a/crates/storage/provider/src/traits/hashing.rs b/crates/storage/provider/src/traits/hashing.rs index 78efcc6273e06..f05a4960f8539 100644 --- a/crates/storage/provider/src/traits/hashing.rs +++ b/crates/storage/provider/src/traits/hashing.rs @@ -1,12 +1,13 @@ -use auto_impl::auto_impl; -use reth_db_api::models::BlockNumberAddress; -use reth_primitives::{Account, Address, BlockNumber, StorageEntry, B256}; -use reth_storage_errors::provider::ProviderResult; use std::{ collections::{BTreeMap, BTreeSet, HashMap}, ops::{Range, RangeInclusive}, }; +use auto_impl::auto_impl; +use reth_db_api::models::BlockNumberAddress; +use reth_primitives::{Account, Address, BlockNumber, StorageEntry, B256}; +use reth_storage_errors::provider::ProviderResult; + /// Hashing Writer #[auto_impl(&, Arc, Box)] pub trait HashingWriter: Send + Sync { diff --git a/crates/storage/provider/src/traits/history.rs b/crates/storage/provider/src/traits/history.rs index 726fe0cb7812c..890b7a9bbe49d 100644 --- a/crates/storage/provider/src/traits/history.rs +++ b/crates/storage/provider/src/traits/history.rs @@ -1,12 +1,13 @@ -use auto_impl::auto_impl; -use reth_db_api::models::BlockNumberAddress; -use reth_primitives::{Address, BlockNumber, B256}; -use reth_storage_errors::provider::ProviderResult; use std::{ collections::BTreeMap, ops::{Range, RangeInclusive}, }; +use auto_impl::auto_impl; +use reth_db_api::models::BlockNumberAddress; +use reth_primitives::{Address, BlockNumber, B256}; +use reth_storage_errors::provider::ProviderResult; + /// History Writer #[auto_impl(&, Arc, Box)] pub trait HistoryWriter: Send + Sync { diff --git a/crates/storage/provider/src/traits/mod.rs b/crates/storage/provider/src/traits/mod.rs index bf69eda03b0b2..6ff37f1e79d27 100644 --- a/crates/storage/provider/src/traits/mod.rs +++ b/crates/storage/provider/src/traits/mod.rs @@ -1,10 +1,9 @@ //! Collection of common provider traits. // Re-export all the traits -pub use reth_storage_api::*; - // Re-export for convenience pub use reth_evm::provider::EvmEnvProvider; +pub use reth_storage_api::*; mod block; pub use block::*; diff --git a/crates/storage/provider/src/traits/spec.rs b/crates/storage/provider/src/traits/spec.rs index 917051d97aca4..72a7a0ddd6d71 100644 --- a/crates/storage/provider/src/traits/spec.rs +++ b/crates/storage/provider/src/traits/spec.rs @@ -1,6 +1,7 @@ -use reth_chainspec::ChainSpec; use std::sync::Arc; +use reth_chainspec::ChainSpec; + /// A trait for reading the current chainspec. pub trait ChainSpecProvider: Send + Sync { /// Get an [`Arc`] to the chainspec. diff --git a/crates/storage/provider/src/traits/state.rs b/crates/storage/provider/src/traits/state.rs index a774d0f5cc924..36dfeb8bd1383 100644 --- a/crates/storage/provider/src/traits/state.rs +++ b/crates/storage/provider/src/traits/state.rs @@ -1,8 +1,9 @@ -use crate::providers::StaticFileProviderRWRefMut; use reth_db_api::transaction::{DbTx, DbTxMut}; use reth_storage_errors::provider::ProviderResult; use revm::db::OriginalValuesKnown; +use crate::providers::StaticFileProviderRWRefMut; + /// A helper trait for [`ExecutionOutcome`](reth_execution_types::ExecutionOutcome) to /// write state and receipts to storage. pub trait StateWriter { diff --git a/crates/storage/provider/src/traits/tree_viewer.rs b/crates/storage/provider/src/traits/tree_viewer.rs index a8eea44a69283..95951549b4d2c 100644 --- a/crates/storage/provider/src/traits/tree_viewer.rs +++ b/crates/storage/provider/src/traits/tree_viewer.rs @@ -1,6 +1,7 @@ -use crate::{BlockchainTreePendingStateProvider, CanonStateSubscriptions}; use reth_blockchain_tree_api::{BlockchainTreeEngine, BlockchainTreeViewer}; +use crate::{BlockchainTreePendingStateProvider, CanonStateSubscriptions}; + /// Helper trait to combine all the traits we need for the `BlockchainProvider` /// /// This is a temporary solution diff --git a/crates/storage/storage-api/src/account.rs b/crates/storage/storage-api/src/account.rs index 1257f07b4a846..39316cb6d41eb 100644 --- a/crates/storage/storage-api/src/account.rs +++ b/crates/storage/storage-api/src/account.rs @@ -1,12 +1,13 @@ -use auto_impl::auto_impl; -use reth_db_api::models::AccountBeforeTx; -use reth_primitives::{Account, Address, BlockNumber}; -use reth_storage_errors::provider::ProviderResult; use std::{ collections::{BTreeMap, BTreeSet}, ops::{RangeBounds, RangeInclusive}, }; +use auto_impl::auto_impl; +use reth_db_api::models::AccountBeforeTx; +use reth_primitives::{Account, Address, BlockNumber}; +use reth_storage_errors::provider::ProviderResult; + /// Account reader #[auto_impl(&, Arc, Box)] pub trait AccountReader: Send + Sync { diff --git a/crates/storage/storage-api/src/block.rs b/crates/storage/storage-api/src/block.rs index 42ab05f225032..3e91accced540 100644 --- a/crates/storage/storage-api/src/block.rs +++ b/crates/storage/storage-api/src/block.rs @@ -1,14 +1,16 @@ -use crate::{ - BlockIdReader, BlockNumReader, HeaderProvider, ReceiptProvider, ReceiptProviderIdExt, - RequestsProvider, TransactionVariant, TransactionsProvider, WithdrawalsProvider, -}; +use std::ops::RangeInclusive; + use reth_db_api::models::StoredBlockBodyIndices; use reth_primitives::{ Block, BlockHashOrNumber, BlockId, BlockNumber, BlockNumberOrTag, BlockWithSenders, Header, Receipt, SealedBlock, SealedBlockWithSenders, SealedHeader, B256, }; use reth_storage_errors::provider::ProviderResult; -use std::ops::RangeInclusive; + +use crate::{ + BlockIdReader, BlockNumReader, HeaderProvider, ReceiptProvider, ReceiptProviderIdExt, + RequestsProvider, TransactionVariant, TransactionsProvider, WithdrawalsProvider, +}; /// A helper enum that represents the origin of the requested block. /// diff --git a/crates/storage/storage-api/src/block_id.rs b/crates/storage/storage-api/src/block_id.rs index ca92b8a2f1843..5f0115b370043 100644 --- a/crates/storage/storage-api/src/block_id.rs +++ b/crates/storage/storage-api/src/block_id.rs @@ -1,8 +1,9 @@ -use crate::BlockHashReader; use reth_chainspec::ChainInfo; use reth_primitives::{BlockHashOrNumber, BlockId, BlockNumber, BlockNumberOrTag, B256}; use reth_storage_errors::provider::{ProviderError, ProviderResult}; +use crate::BlockHashReader; + /// Client trait for getting important block numbers (such as the latest block number), converting /// block hashes to numbers, and fetching a block hash from its block number. /// diff --git a/crates/storage/storage-api/src/header.rs b/crates/storage/storage-api/src/header.rs index 433c907710444..a1c28c42258f2 100644 --- a/crates/storage/storage-api/src/header.rs +++ b/crates/storage/storage-api/src/header.rs @@ -1,6 +1,7 @@ +use std::ops::RangeBounds; + use reth_primitives::{BlockHash, BlockHashOrNumber, BlockNumber, Header, SealedHeader, U256}; use reth_storage_errors::provider::ProviderResult; -use std::ops::RangeBounds; /// Client trait for fetching `Header` related data. #[auto_impl::auto_impl(&, Arc)] diff --git a/crates/storage/storage-api/src/receipts.rs b/crates/storage/storage-api/src/receipts.rs index b050ca3e248c2..138adcfa779cf 100644 --- a/crates/storage/storage-api/src/receipts.rs +++ b/crates/storage/storage-api/src/receipts.rs @@ -1,7 +1,9 @@ -use crate::BlockIdReader; +use std::ops::RangeBounds; + use reth_primitives::{BlockHashOrNumber, BlockId, BlockNumberOrTag, Receipt, TxHash, TxNumber}; use reth_storage_errors::provider::ProviderResult; -use std::ops::RangeBounds; + +use crate::BlockIdReader; /// Client trait for fetching [Receipt] data . #[auto_impl::auto_impl(&, Arc)] diff --git a/crates/storage/storage-api/src/state.rs b/crates/storage/storage-api/src/state.rs index 059909a463b0c..58450c57e492f 100644 --- a/crates/storage/storage-api/src/state.rs +++ b/crates/storage/storage-api/src/state.rs @@ -1,4 +1,3 @@ -use super::{AccountReader, BlockHashReader, BlockIdReader, StateRootProvider}; use auto_impl::auto_impl; use reth_execution_types::ExecutionOutcome; use reth_primitives::{ @@ -8,6 +7,8 @@ use reth_primitives::{ use reth_storage_errors::provider::{ProviderError, ProviderResult}; use reth_trie::AccountProof; +use super::{AccountReader, BlockHashReader, BlockIdReader, StateRootProvider}; + /// Type alias of boxed [`StateProvider`]. pub type StateProviderBox = Box; diff --git a/crates/storage/storage-api/src/storage.rs b/crates/storage/storage-api/src/storage.rs index a45df9d72f6c7..f51e523780e87 100644 --- a/crates/storage/storage-api/src/storage.rs +++ b/crates/storage/storage-api/src/storage.rs @@ -1,10 +1,11 @@ -use reth_primitives::{Address, BlockNumber, StorageEntry, B256}; -use reth_storage_errors::provider::ProviderResult; use std::{ collections::{BTreeMap, BTreeSet}, ops::RangeInclusive, }; +use reth_primitives::{Address, BlockNumber, StorageEntry, B256}; +use reth_storage_errors::provider::ProviderResult; + /// Storage reader #[auto_impl::auto_impl(&, Arc, Box)] pub trait StorageReader: Send + Sync { diff --git a/crates/storage/storage-api/src/transactions.rs b/crates/storage/storage-api/src/transactions.rs index 0553ef787f055..413235092688c 100644 --- a/crates/storage/storage-api/src/transactions.rs +++ b/crates/storage/storage-api/src/transactions.rs @@ -1,10 +1,12 @@ -use crate::{BlockNumReader, BlockReader}; +use std::ops::{Range, RangeBounds, RangeInclusive}; + use reth_primitives::{ Address, BlockHashOrNumber, BlockNumber, TransactionMeta, TransactionSigned, TransactionSignedNoHash, TxHash, TxNumber, }; use reth_storage_errors::provider::{ProviderError, ProviderResult}; -use std::ops::{Range, RangeBounds, RangeInclusive}; + +use crate::{BlockNumReader, BlockReader}; /// Enum to control transaction hash inclusion. /// diff --git a/crates/tasks/src/lib.rs b/crates/tasks/src/lib.rs index 2d3f5f41b2b65..125f84464ef57 100644 --- a/crates/tasks/src/lib.rs +++ b/crates/tasks/src/lib.rs @@ -12,15 +12,6 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -use crate::{ - metrics::{IncCounterOnDrop, TaskExecutorMetrics}, - shutdown::{signal, GracefulShutdown, GracefulShutdownGuard, Shutdown, Signal}, -}; -use dyn_clone::DynClone; -use futures_util::{ - future::{select, BoxFuture}, - Future, FutureExt, TryFutureExt, -}; use std::{ any::Any, fmt::{Display, Formatter}, @@ -31,6 +22,12 @@ use std::{ }, task::{ready, Context, Poll}, }; + +use dyn_clone::DynClone; +use futures_util::{ + future::{select, BoxFuture}, + Future, FutureExt, TryFutureExt, +}; use tokio::{ runtime::Handle, sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender}, @@ -39,6 +36,11 @@ use tokio::{ use tracing::{debug, error}; use tracing_futures::Instrument; +use crate::{ + metrics::{IncCounterOnDrop, TaskExecutorMetrics}, + shutdown::{signal, GracefulShutdown, GracefulShutdownGuard, Shutdown, Signal}, +}; + pub mod metrics; pub mod shutdown; @@ -637,9 +639,10 @@ enum TaskKind { #[cfg(test)] mod tests { - use super::*; use std::{sync::atomic::AtomicBool, time::Duration}; + use super::*; + #[test] fn test_cloneable() { #[derive(Clone)] diff --git a/crates/tasks/src/pool.rs b/crates/tasks/src/pool.rs index dbb4e19de98d0..33ff83c2bcdec 100644 --- a/crates/tasks/src/pool.rs +++ b/crates/tasks/src/pool.rs @@ -8,6 +8,7 @@ use std::{ task::{ready, Context, Poll}, thread, }; + use tokio::sync::{oneshot, AcquireError, OwnedSemaphorePermit, Semaphore}; /// RPC Tracing call guard semaphore. diff --git a/crates/tasks/src/shutdown.rs b/crates/tasks/src/shutdown.rs index bd9a50dc9aa37..321f49a307307 100644 --- a/crates/tasks/src/shutdown.rs +++ b/crates/tasks/src/shutdown.rs @@ -1,15 +1,16 @@ //! Helper for shutdown signals -use futures_util::{ - future::{FusedFuture, Shared}, - FutureExt, -}; use std::{ future::Future, pin::Pin, sync::{atomic::AtomicUsize, Arc}, task::{ready, Context, Poll}, }; + +use futures_util::{ + future::{FusedFuture, Shared}, + FutureExt, +}; use tokio::sync::oneshot; /// A Future that resolves when the shutdown event has been fired. @@ -105,10 +106,12 @@ pub fn signal() -> (Signal, Shutdown) { #[cfg(test)] mod tests { - use super::*; - use futures_util::future::join_all; use std::time::Duration; + use futures_util::future::join_all; + + use super::*; + #[tokio::test(flavor = "multi_thread")] async fn test_shutdown() { let (_signal, _shutdown) = signal(); diff --git a/crates/tokio-util/src/event_sender.rs b/crates/tokio-util/src/event_sender.rs index a4e9815388cdd..f598333a18b55 100644 --- a/crates/tokio-util/src/event_sender.rs +++ b/crates/tokio-util/src/event_sender.rs @@ -1,7 +1,8 @@ -use crate::EventStream; use tokio::sync::broadcast::{self, Sender}; use tracing::trace; +use crate::EventStream; + const DEFAULT_SIZE_BROADCAST_CHANNEL: usize = 2000; /// A bounded broadcast channel for a task. diff --git a/crates/tokio-util/src/event_stream.rs b/crates/tokio-util/src/event_stream.rs index 0e041f8d4c31c..9969157647a88 100644 --- a/crates/tokio-util/src/event_stream.rs +++ b/crates/tokio-util/src/event_stream.rs @@ -4,6 +4,7 @@ use std::{ pin::Pin, task::{Context, Poll}, }; + use tokio_stream::Stream; use tracing::warn; @@ -47,10 +48,11 @@ where #[cfg(test)] mod tests { - use super::*; use tokio::sync::broadcast; use tokio_stream::StreamExt; + use super::*; + #[tokio::test] async fn test_event_stream_yields_items() { let (tx, _) = broadcast::channel(16); diff --git a/crates/tokio-util/src/ratelimit.rs b/crates/tokio-util/src/ratelimit.rs index 16e403f10aa25..de0102c7123ed 100644 --- a/crates/tokio-util/src/ratelimit.rs +++ b/crates/tokio-util/src/ratelimit.rs @@ -6,6 +6,7 @@ use std::{ task::{Context, Poll}, time::Duration, }; + use tokio::time::Sleep; /// Given a [Rate] this type enforces a rate limit. diff --git a/crates/tracing/src/formatter.rs b/crates/tracing/src/formatter.rs index 1322377f1c9fa..ff90c00897925 100644 --- a/crates/tracing/src/formatter.rs +++ b/crates/tracing/src/formatter.rs @@ -1,9 +1,11 @@ -use crate::layers::BoxedLayer; -use clap::ValueEnum; use std::{fmt, fmt::Display}; + +use clap::ValueEnum; use tracing_appender::non_blocking::NonBlocking; use tracing_subscriber::{EnvFilter, Layer, Registry}; +use crate::layers::BoxedLayer; + /// Represents the logging format. /// /// This enum defines the supported formats for logging output. diff --git a/crates/tracing/src/lib.rs b/crates/tracing/src/lib.rs index 4f8f7de42aa3f..2ae5ed83902fb 100644 --- a/crates/tracing/src/lib.rs +++ b/crates/tracing/src/lib.rs @@ -44,24 +44,23 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] // Re-export tracing crates -pub use tracing; -pub use tracing_subscriber; - // Re-export LogFormat pub use formatter::LogFormat; pub use layers::{FileInfo, FileWorkerGuard}; - pub use test_tracer::TestTracer; +pub use tracing; +pub use tracing_subscriber; mod formatter; mod layers; mod test_tracer; -use crate::layers::Layers; use tracing::level_filters::LevelFilter; use tracing_appender::non_blocking::WorkerGuard; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; +use crate::layers::Layers; + /// Tracer for application logging. /// /// Manages the configuration and initialization of logging layers, diff --git a/crates/transaction-pool/benches/reorder.rs b/crates/transaction-pool/benches/reorder.rs index 1836ce40c0855..52768bcd76f18 100644 --- a/crates/transaction-pool/benches/reorder.rs +++ b/crates/transaction-pool/benches/reorder.rs @@ -115,10 +115,12 @@ fn generate_test_data( } mod implementations { - use super::*; - use reth_transaction_pool::PoolTransaction; use std::collections::BinaryHeap; + use reth_transaction_pool::PoolTransaction; + + use super::*; + /// This implementation appends the transactions and uses [`Vec::sort_by`] function for sorting. #[derive(Default)] pub(crate) struct VecTxPoolSortStable { diff --git a/crates/transaction-pool/src/blobstore/disk.rs b/crates/transaction-pool/src/blobstore/disk.rs index 5799297cc53af..a71397325f303 100644 --- a/crates/transaction-pool/src/blobstore/disk.rs +++ b/crates/transaction-pool/src/blobstore/disk.rs @@ -1,13 +1,15 @@ //! A simple diskstore for blobs -use crate::blobstore::{BlobStore, BlobStoreCleanupStat, BlobStoreError, BlobStoreSize}; +use std::{collections::HashSet, fmt, fs, io, path::PathBuf, sync::Arc}; + use alloy_rlp::{Decodable, Encodable}; use parking_lot::{Mutex, RwLock}; use reth_primitives::{BlobTransactionSidecar, TxHash, B256}; use schnellru::{ByLength, LruMap}; -use std::{collections::HashSet, fmt, fs, io, path::PathBuf, sync::Arc}; use tracing::{debug, trace}; +use crate::blobstore::{BlobStore, BlobStoreCleanupStat, BlobStoreError, BlobStoreSize}; + /// How many [`BlobTransactionSidecar`] to cache in memory. pub const DEFAULT_MAX_CACHED_BLOBS: u32 = 100; @@ -444,9 +446,10 @@ pub enum OpenDiskFileBlobStore { #[cfg(test)] mod tests { - use super::*; use std::sync::atomic::Ordering; + use super::*; + fn tmp_store() -> (DiskFileBlobStore, tempfile::TempDir) { let dir = tempfile::tempdir().unwrap(); let store = DiskFileBlobStore::open(dir.path(), Default::default()).unwrap(); diff --git a/crates/transaction-pool/src/blobstore/mem.rs b/crates/transaction-pool/src/blobstore/mem.rs index 326cd987a9d3e..ceba05bd265fd 100644 --- a/crates/transaction-pool/src/blobstore/mem.rs +++ b/crates/transaction-pool/src/blobstore/mem.rs @@ -1,9 +1,11 @@ +use std::{collections::HashMap, sync::Arc}; + +use parking_lot::RwLock; +use reth_primitives::B256; + use crate::blobstore::{ BlobStore, BlobStoreCleanupStat, BlobStoreError, BlobStoreSize, BlobTransactionSidecar, }; -use parking_lot::RwLock; -use reth_primitives::B256; -use std::{collections::HashMap, sync::Arc}; /// An in-memory blob store. #[derive(Clone, Debug, Default, PartialEq)] diff --git a/crates/transaction-pool/src/blobstore/mod.rs b/crates/transaction-pool/src/blobstore/mod.rs index bba4b85336d63..f74241a2eaa88 100644 --- a/crates/transaction-pool/src/blobstore/mod.rs +++ b/crates/transaction-pool/src/blobstore/mod.rs @@ -1,13 +1,14 @@ //! Storage for blob data of EIP4844 transactions. -pub use disk::{DiskFileBlobStore, DiskFileBlobStoreConfig, OpenDiskFileBlobStore}; -pub use mem::InMemoryBlobStore; -pub use noop::NoopBlobStore; -use reth_primitives::{BlobTransactionSidecar, B256}; use std::{ fmt, sync::atomic::{AtomicUsize, Ordering}, }; + +pub use disk::{DiskFileBlobStore, DiskFileBlobStoreConfig, OpenDiskFileBlobStore}; +pub use mem::InMemoryBlobStore; +pub use noop::NoopBlobStore; +use reth_primitives::{BlobTransactionSidecar, B256}; pub use tracker::{BlobStoreCanonTracker, BlobStoreUpdates}; pub mod disk; diff --git a/crates/transaction-pool/src/blobstore/noop.rs b/crates/transaction-pool/src/blobstore/noop.rs index ef9773dabafc6..8914eb82d399f 100644 --- a/crates/transaction-pool/src/blobstore/noop.rs +++ b/crates/transaction-pool/src/blobstore/noop.rs @@ -1,6 +1,7 @@ -use crate::blobstore::{BlobStore, BlobStoreCleanupStat, BlobStoreError, BlobTransactionSidecar}; use reth_primitives::B256; +use crate::blobstore::{BlobStore, BlobStoreCleanupStat, BlobStoreError, BlobTransactionSidecar}; + /// A blobstore implementation that does nothing #[derive(Clone, Copy, Debug, PartialOrd, PartialEq, Eq, Default)] #[non_exhaustive] diff --git a/crates/transaction-pool/src/blobstore/tracker.rs b/crates/transaction-pool/src/blobstore/tracker.rs index 96cb5552fc1e5..2641242e64b87 100644 --- a/crates/transaction-pool/src/blobstore/tracker.rs +++ b/crates/transaction-pool/src/blobstore/tracker.rs @@ -1,8 +1,9 @@ //! Support for maintaining the blob pool. +use std::collections::BTreeMap; + use reth_primitives::{BlockNumber, B256}; use reth_provider::ChainBlocks; -use std::collections::BTreeMap; /// The type that is used to track canonical blob transactions. #[derive(Debug, Default, Eq, PartialEq)] diff --git a/crates/transaction-pool/src/config.rs b/crates/transaction-pool/src/config.rs index a58c1a285dce5..0d2bfa08842b8 100644 --- a/crates/transaction-pool/src/config.rs +++ b/crates/transaction-pool/src/config.rs @@ -1,6 +1,8 @@ -use crate::{PoolSize, TransactionOrigin}; -use reth_primitives::{Address, EIP4844_TX_TYPE_ID}; use std::collections::HashSet; + +use reth_primitives::{Address, EIP4844_TX_TYPE_ID}; + +use crate::{PoolSize, TransactionOrigin}; /// Guarantees max transactions for one sender, compatible with geth/erigon pub const TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER: usize = 16; diff --git a/crates/transaction-pool/src/identifier.rs b/crates/transaction-pool/src/identifier.rs index 876fa00dca5b6..34fe735ef10ee 100644 --- a/crates/transaction-pool/src/identifier.rs +++ b/crates/transaction-pool/src/identifier.rs @@ -1,7 +1,8 @@ //! Identifier types for transactions and senders. +use std::collections::HashMap; + use reth_primitives::Address; use rustc_hash::FxHashMap; -use std::collections::HashMap; /// An internal mapping of addresses. /// @@ -120,9 +121,10 @@ impl TransactionId { #[cfg(test)] mod tests { - use super::*; use std::collections::BTreeSet; + use super::*; + #[test] fn test_transaction_id_ord_eq_sender() { let tx1 = TransactionId::new(100u64.into(), 0u64); diff --git a/crates/transaction-pool/src/lib.rs b/crates/transaction-pool/src/lib.rs index 527c3412e1aa6..f19908a97979b 100644 --- a/crates/transaction-pool/src/lib.rs +++ b/crates/transaction-pool/src/lib.rs @@ -150,12 +150,12 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![warn(clippy::missing_const_for_fn)] -use crate::{identifier::TransactionId, pool::PoolInner}; +use std::{collections::HashSet, sync::Arc}; + use aquamarine as _; use reth_eth_wire_types::HandleMempoolData; use reth_primitives::{Address, BlobTransactionSidecar, PooledTransactionsElement, TxHash, U256}; use reth_provider::StateProviderFactory; -use std::{collections::HashSet, sync::Arc}; use tokio::sync::mpsc::Receiver; use tracing::{instrument, trace}; @@ -178,6 +178,7 @@ pub use crate::{ TransactionValidator, ValidPoolTransaction, }, }; +use crate::{identifier::TransactionId, pool::PoolInner}; pub mod error; pub mod maintain; diff --git a/crates/transaction-pool/src/maintain.rs b/crates/transaction-pool/src/maintain.rs index 10f2ea2e59f93..a0216bf88383a 100644 --- a/crates/transaction-pool/src/maintain.rs +++ b/crates/transaction-pool/src/maintain.rs @@ -1,12 +1,12 @@ //! Support for maintaining the state of the transaction pool -use crate::{ - blobstore::{BlobStoreCanonTracker, BlobStoreUpdates}, - error::PoolError, - metrics::MaintainPoolMetrics, - traits::{CanonicalStateUpdate, ChangedAccount, TransactionPool, TransactionPoolExt}, - BlockInfo, +use std::{ + borrow::Borrow, + collections::HashSet, + hash::{Hash, Hasher}, + path::{Path, PathBuf}, }; + use futures_util::{ future::{BoxFuture, Fuse, FusedFuture}, FutureExt, Stream, StreamExt, @@ -23,15 +23,17 @@ use reth_provider::{ StateProviderFactory, }; use reth_tasks::TaskSpawner; -use std::{ - borrow::Borrow, - collections::HashSet, - hash::{Hash, Hasher}, - path::{Path, PathBuf}, -}; use tokio::sync::oneshot; use tracing::{debug, error, info, trace, warn}; +use crate::{ + blobstore::{BlobStoreCanonTracker, BlobStoreUpdates}, + error::PoolError, + metrics::MaintainPoolMetrics, + traits::{CanonicalStateUpdate, ChangedAccount, TransactionPool, TransactionPoolExt}, + BlockInfo, +}; + /// Additional settings for maintaining the transaction pool #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct MaintainPoolConfig { @@ -677,17 +679,18 @@ pub async fn backup_local_transactions_task

( #[cfg(test)] mod tests { - use super::*; - use crate::{ - blobstore::InMemoryBlobStore, validate::EthTransactionValidatorBuilder, - CoinbaseTipOrdering, EthPooledTransaction, Pool, PoolTransaction, TransactionOrigin, - }; use reth_chainspec::MAINNET; use reth_fs_util as fs; use reth_primitives::{hex, PooledTransactionsElement, U256}; use reth_provider::test_utils::{ExtendedAccount, MockEthProvider}; use reth_tasks::TaskManager; + use super::*; + use crate::{ + blobstore::InMemoryBlobStore, validate::EthTransactionValidatorBuilder, + CoinbaseTipOrdering, EthPooledTransaction, Pool, PoolTransaction, TransactionOrigin, + }; + #[test] fn changed_acc_entry() { let changed_acc = ChangedAccountEntry(ChangedAccount::empty(Address::random())); diff --git a/crates/transaction-pool/src/noop.rs b/crates/transaction-pool/src/noop.rs index 8c3a52f4c348c..0804f017ad885 100644 --- a/crates/transaction-pool/src/noop.rs +++ b/crates/transaction-pool/src/noop.rs @@ -3,6 +3,12 @@ //! This is useful for wiring components together that don't require an actual pool but still need //! to be generic over it. +use std::{collections::HashSet, marker::PhantomData, sync::Arc}; + +use reth_eth_wire_types::HandleMempoolData; +use reth_primitives::{Address, BlobTransactionSidecar, TxHash, U256}; +use tokio::sync::{mpsc, mpsc::Receiver}; + use crate::{ blobstore::BlobStoreError, error::PoolError, @@ -16,10 +22,6 @@ use crate::{ PooledTransactionsElement, PropagatedTransactions, TransactionEvents, TransactionOrigin, TransactionPool, TransactionValidationOutcome, TransactionValidator, ValidPoolTransaction, }; -use reth_eth_wire_types::HandleMempoolData; -use reth_primitives::{Address, BlobTransactionSidecar, TxHash, U256}; -use std::{collections::HashSet, marker::PhantomData, sync::Arc}; -use tokio::sync::{mpsc, mpsc::Receiver}; /// A [`TransactionPool`] implementation that does nothing. /// diff --git a/crates/transaction-pool/src/ordering.rs b/crates/transaction-pool/src/ordering.rs index e4928710b600d..da6f3bd4f96a6 100644 --- a/crates/transaction-pool/src/ordering.rs +++ b/crates/transaction-pool/src/ordering.rs @@ -1,7 +1,9 @@ -use crate::traits::PoolTransaction; -use reth_primitives::U256; use std::{fmt, marker::PhantomData}; +use reth_primitives::U256; + +use crate::traits::PoolTransaction; + /// Priority of the transaction that can be missing. /// /// Transactions with missing priorities are ranked lower. diff --git a/crates/transaction-pool/src/pool/best.rs b/crates/transaction-pool/src/pool/best.rs index a595b9f4d6ed4..6b904c88845a9 100644 --- a/crates/transaction-pool/src/pool/best.rs +++ b/crates/transaction-pool/src/pool/best.rs @@ -1,17 +1,18 @@ -use crate::{ - identifier::TransactionId, pool::pending::PendingTransaction, PoolTransaction, - TransactionOrdering, ValidPoolTransaction, -}; use core::fmt; -use reth_primitives::B256 as TxHash; use std::{ collections::{BTreeMap, BTreeSet, HashSet}, sync::Arc, }; +use reth_primitives::B256 as TxHash; use tokio::sync::broadcast::{error::TryRecvError, Receiver}; use tracing::debug; +use crate::{ + identifier::TransactionId, pool::pending::PendingTransaction, PoolTransaction, + TransactionOrdering, ValidPoolTransaction, +}; + /// An iterator that returns transactions that can be executed on the current state (*best* /// transactions). /// diff --git a/crates/transaction-pool/src/pool/blob.rs b/crates/transaction-pool/src/pool/blob.rs index cb09e82340953..24a4d5eae0040 100644 --- a/crates/transaction-pool/src/pool/blob.rs +++ b/crates/transaction-pool/src/pool/blob.rs @@ -1,14 +1,15 @@ -use super::txpool::PendingFees; -use crate::{ - identifier::TransactionId, pool::size::SizeTracker, traits::BestTransactionsAttributes, - PoolTransaction, SubPoolLimit, ValidPoolTransaction, -}; use std::{ cmp::Ordering, collections::{BTreeMap, BTreeSet}, sync::Arc, }; +use super::txpool::PendingFees; +use crate::{ + identifier::TransactionId, pool::size::SizeTracker, traits::BestTransactionsAttributes, + PoolTransaction, SubPoolLimit, ValidPoolTransaction, +}; + /// A set of validated blob transactions in the pool that are __not pending__. /// /// The purpose of this pool is keep track of blob transactions that are queued and to evict the diff --git a/crates/transaction-pool/src/pool/events.rs b/crates/transaction-pool/src/pool/events.rs index 7b17dcec50ccd..fdfcc63f0d422 100644 --- a/crates/transaction-pool/src/pool/events.rs +++ b/crates/transaction-pool/src/pool/events.rs @@ -1,10 +1,11 @@ -use crate::{traits::PropagateKind, PoolTransaction, ValidPoolTransaction}; -use reth_primitives::{TxHash, B256}; use std::sync::Arc; +use reth_primitives::{TxHash, B256}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; +use crate::{traits::PropagateKind, PoolTransaction, ValidPoolTransaction}; + /// An event that happened to a transaction and contains its full body where possible. #[derive(Debug)] pub enum FullTransactionEvent { diff --git a/crates/transaction-pool/src/pool/listener.rs b/crates/transaction-pool/src/pool/listener.rs index b9d6c46b5fd90..3dece35f95267 100644 --- a/crates/transaction-pool/src/pool/listener.rs +++ b/crates/transaction-pool/src/pool/listener.rs @@ -1,22 +1,24 @@ //! Listeners for the transaction-pool -use crate::{ - pool::events::{FullTransactionEvent, TransactionEvent}, - traits::PropagateKind, - PoolTransaction, ValidPoolTransaction, -}; -use futures_util::Stream; -use reth_primitives::{TxHash, B256}; use std::{ collections::{hash_map::Entry, HashMap}, pin::Pin, sync::Arc, task::{Context, Poll}, }; + +use futures_util::Stream; +use reth_primitives::{TxHash, B256}; use tokio::sync::mpsc::{ error::TrySendError, Receiver, Sender, UnboundedReceiver, UnboundedSender, }; +use crate::{ + pool::events::{FullTransactionEvent, TransactionEvent}, + traits::PropagateKind, + PoolTransaction, ValidPoolTransaction, +}; + /// The size of the event channel used to propagate transaction events. const TX_POOL_EVENT_CHANNEL_SIZE: usize = 1024; diff --git a/crates/transaction-pool/src/pool/mod.rs b/crates/transaction-pool/src/pool/mod.rs index a00d6522d1478..712297cd93ff9 100644 --- a/crates/transaction-pool/src/pool/mod.rs +++ b/crates/transaction-pool/src/pool/mod.rs @@ -65,6 +65,23 @@ //! transactions are _currently_ waiting for state changes that eventually move them into //! category (2.) and become pending. +use std::{ + collections::{HashMap, HashSet}, + fmt, + sync::Arc, + time::Instant, +}; + +use best::BestTransactions; +use parking_lot::{Mutex, RwLock, RwLockReadGuard}; +use reth_eth_wire_types::HandleMempoolData; +use reth_primitives::{ + Address, BlobTransaction, BlobTransactionSidecar, IntoRecoveredTransaction, + PooledTransactionsElement, TransactionSigned, TxHash, B256, +}; +use tokio::sync::mpsc; +use tracing::{debug, trace, warn}; + use crate::{ error::{PoolError, PoolErrorKind, PoolResult}, identifier::{SenderId, SenderIdentifiers, TransactionId}, @@ -80,22 +97,14 @@ use crate::{ validate::{TransactionValidationOutcome, ValidPoolTransaction}, CanonicalStateUpdate, ChangedAccount, PoolConfig, TransactionOrdering, TransactionValidator, }; -use best::BestTransactions; -use parking_lot::{Mutex, RwLock, RwLockReadGuard}; -use reth_eth_wire_types::HandleMempoolData; -use reth_primitives::{ - Address, BlobTransaction, BlobTransactionSidecar, IntoRecoveredTransaction, - PooledTransactionsElement, TransactionSigned, TxHash, B256, -}; -use std::{ - collections::{HashMap, HashSet}, - fmt, - sync::Arc, - time::Instant, -}; -use tokio::sync::mpsc; -use tracing::{debug, trace, warn}; mod events; +pub use best::BestTransactionFilter; +pub use blob::{blob_tx_priority, fee_delta}; +pub use events::{FullTransactionEvent, TransactionEvent}; +pub use listener::{AllTransactionsEvents, TransactionEvents}; +pub use parked::{BasefeeOrd, ParkedOrd, ParkedPool, QueuedOrd}; +pub use pending::PendingPool; + use crate::{ blobstore::BlobStore, metrics::BlobStoreMetrics, @@ -103,12 +112,6 @@ use crate::{ traits::{GetPooledTransactionLimit, NewBlobSidecar, TransactionListenerKind}, validate::ValidTransaction, }; -pub use best::BestTransactionFilter; -pub use blob::{blob_tx_priority, fee_delta}; -pub use events::{FullTransactionEvent, TransactionEvent}; -pub use listener::{AllTransactionsEvents, TransactionEvents}; -pub use parked::{BasefeeOrd, ParkedOrd, ParkedPool, QueuedOrd}; -pub use pending::PendingPool; mod best; mod blob; @@ -1131,14 +1134,16 @@ impl OnNewCanonicalStateOutcome { #[cfg(test)] mod tests { + use std::{fs, path::PathBuf}; + + use reth_primitives::{kzg::Blob, transaction::generate_blob_sidecar}; + use crate::{ blobstore::{BlobStore, InMemoryBlobStore}, test_utils::{MockTransaction, TestPoolBuilder}, validate::ValidTransaction, BlockInfo, PoolConfig, SubPoolLimit, TransactionOrigin, TransactionValidationOutcome, U256, }; - use reth_primitives::{kzg::Blob, transaction::generate_blob_sidecar}; - use std::{fs, path::PathBuf}; #[test] fn test_discard_blobs_on_blob_tx_eviction() { diff --git a/crates/transaction-pool/src/pool/parked.rs b/crates/transaction-pool/src/pool/parked.rs index c36f3bd6c52f1..5a5c78bc1a38e 100644 --- a/crates/transaction-pool/src/pool/parked.rs +++ b/crates/transaction-pool/src/pool/parked.rs @@ -1,10 +1,3 @@ -use crate::{ - identifier::{SenderId, TransactionId}, - pool::size::SizeTracker, - PoolTransaction, SubPoolLimit, ValidPoolTransaction, TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER, -}; -use rustc_hash::FxHashMap; -use smallvec::SmallVec; use std::{ cmp::Ordering, collections::{hash_map::Entry, BTreeMap, BTreeSet}, @@ -12,6 +5,15 @@ use std::{ sync::Arc, }; +use rustc_hash::FxHashMap; +use smallvec::SmallVec; + +use crate::{ + identifier::{SenderId, TransactionId}, + pool::size::SizeTracker, + PoolTransaction, SubPoolLimit, ValidPoolTransaction, TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER, +}; + /// A pool of transactions that are currently parked and are waiting for external changes (e.g. /// basefee, ancestor transactions, balance) that eventually move the transaction into the pending /// pool. @@ -518,10 +520,12 @@ impl Ord for QueuedOrd { #[cfg(test)] mod tests { + use std::collections::HashSet; + + use reth_primitives::{address, TxType}; + use super::*; use crate::test_utils::{MockTransaction, MockTransactionFactory, MockTransactionSet}; - use reth_primitives::{address, TxType}; - use std::collections::HashSet; #[test] fn test_enforce_parked_basefee() { diff --git a/crates/transaction-pool/src/pool/pending.rs b/crates/transaction-pool/src/pool/pending.rs index dde7292b17e62..4b3e2b83b95d1 100644 --- a/crates/transaction-pool/src/pool/pending.rs +++ b/crates/transaction-pool/src/pool/pending.rs @@ -1,3 +1,12 @@ +use std::{ + cmp::Ordering, + collections::{BTreeMap, BTreeSet}, + ops::Bound::Unbounded, + sync::Arc, +}; + +use tokio::sync::broadcast; + use crate::{ identifier::{SenderId, TransactionId}, pool::{ @@ -6,13 +15,6 @@ use crate::{ }, Priority, SubPoolLimit, TransactionOrdering, ValidPoolTransaction, }; -use std::{ - cmp::Ordering, - collections::{BTreeMap, BTreeSet}, - ops::Bound::Unbounded, - sync::Arc, -}; -use tokio::sync::broadcast; /// A pool of validated and gapless transactions that are ready to be executed on the current state /// and are waiting to be included in a block. @@ -592,13 +594,15 @@ impl Ord for PendingTransaction { #[cfg(test)] mod tests { + use std::collections::HashSet; + + use reth_primitives::{address, TxType}; + use super::*; use crate::{ test_utils::{MockOrdering, MockTransaction, MockTransactionFactory, MockTransactionSet}, PoolTransaction, }; - use reth_primitives::{address, TxType}; - use std::collections::HashSet; #[test] fn test_enforce_basefee() { diff --git a/crates/transaction-pool/src/pool/txpool.rs b/crates/transaction-pool/src/pool/txpool.rs index a51cdc44ee4c2..b3dea257feb58 100644 --- a/crates/transaction-pool/src/pool/txpool.rs +++ b/crates/transaction-pool/src/pool/txpool.rs @@ -1,5 +1,23 @@ //! The internal transaction pool implementation. +use std::{ + cmp::Ordering, + collections::{btree_map::Entry, hash_map, BTreeMap, HashMap, HashSet}, + fmt, + ops::Bound::{Excluded, Unbounded}, + sync::Arc, +}; + +use reth_primitives::{ + constants::{ + eip4844::BLOB_TX_MIN_BLOB_GASPRICE, ETHEREUM_BLOCK_GAS_LIMIT, MIN_PROTOCOL_BASE_FEE, + }, + Address, TxHash, B256, +}; +use rustc_hash::FxHashMap; +use smallvec::SmallVec; +use tracing::trace; + use crate::{ config::{LocalTransactionConfig, TXPOOL_MAX_ACCOUNT_SLOTS_PER_SENDER}, error::{Eip4844PoolTransactionError, InvalidPoolTransactionError, PoolError, PoolErrorKind}, @@ -18,22 +36,6 @@ use crate::{ PoolConfig, PoolResult, PoolTransaction, PriceBumpConfig, TransactionOrdering, ValidPoolTransaction, U256, }; -use reth_primitives::{ - constants::{ - eip4844::BLOB_TX_MIN_BLOB_GASPRICE, ETHEREUM_BLOCK_GAS_LIMIT, MIN_PROTOCOL_BASE_FEE, - }, - Address, TxHash, B256, -}; -use rustc_hash::FxHashMap; -use smallvec::SmallVec; -use std::{ - cmp::Ordering, - collections::{btree_map::Entry, hash_map, BTreeMap, HashMap, HashSet}, - fmt, - ops::Bound::{Excluded, Unbounded}, - sync::Arc, -}; -use tracing::trace; #[cfg_attr(doc, aquamarine::aquamarine)] /// A pool that manages transactions. diff --git a/crates/transaction-pool/src/pool/update.rs b/crates/transaction-pool/src/pool/update.rs index 12221b7283c25..443a23c3867c8 100644 --- a/crates/transaction-pool/src/pool/update.rs +++ b/crates/transaction-pool/src/pool/update.rs @@ -1,8 +1,9 @@ //! Support types for updating the pool. -use crate::{identifier::TransactionId, pool::state::SubPool}; use reth_primitives::TxHash; +use crate::{identifier::TransactionId, pool::state::SubPool}; + /// A change of the transaction's location /// /// NOTE: this guarantees that `current` and `destination` differ. diff --git a/crates/transaction-pool/src/test_utils/gen.rs b/crates/transaction-pool/src/test_utils/gen.rs index 2be4d8aa9a9a8..6aad656fe552e 100644 --- a/crates/transaction-pool/src/test_utils/gen.rs +++ b/crates/transaction-pool/src/test_utils/gen.rs @@ -1,4 +1,3 @@ -use crate::EthPooledTransaction; use rand::Rng; use reth_chainspec::MAINNET; use reth_primitives::{ @@ -7,6 +6,8 @@ use reth_primitives::{ U256, }; +use crate::EthPooledTransaction; + /// A generator for transactions for testing purposes. #[derive(Debug)] pub struct TransactionGenerator { @@ -359,9 +360,10 @@ impl Default for TransactionBuilder { #[cfg(test)] mod tests { - use super::*; use rand::thread_rng; + use super::*; + #[test] fn test_generate_transaction() { let rng = thread_rng(); diff --git a/crates/transaction-pool/src/test_utils/mock.rs b/crates/transaction-pool/src/test_utils/mock.rs index 72c7a4121730a..3c8004abeb8c3 100644 --- a/crates/transaction-pool/src/test_utils/mock.rs +++ b/crates/transaction-pool/src/test_utils/mock.rs @@ -1,12 +1,7 @@ //! Mock types. -use crate::{ - identifier::{SenderIdentifiers, TransactionId}, - pool::txpool::TxPool, - traits::TransactionOrigin, - CoinbaseTipOrdering, EthBlobTransactionSidecar, EthPoolTransaction, PoolTransaction, - ValidPoolTransaction, -}; +use std::{ops::Range, sync::Arc, time::Instant, vec::IntoIter}; + use paste::paste; use rand::{ distributions::{Uniform, WeightedIndex}, @@ -21,7 +16,14 @@ use reth_primitives::{ TryFromRecoveredTransaction, TxEip1559, TxEip2930, TxEip4844, TxHash, TxKind, TxLegacy, TxType, B256, EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, LEGACY_TX_TYPE_ID, U256, }; -use std::{ops::Range, sync::Arc, time::Instant, vec::IntoIter}; + +use crate::{ + identifier::{SenderIdentifiers, TransactionId}, + pool::txpool::TxPool, + traits::TransactionOrigin, + CoinbaseTipOrdering, EthBlobTransactionSidecar, EthPoolTransaction, PoolTransaction, + ValidPoolTransaction, +}; /// A transaction pool implementation using [`MockOrdering`] for transaction ordering. /// diff --git a/crates/transaction-pool/src/test_utils/mod.rs b/crates/transaction-pool/src/test_utils/mod.rs index 363d6e2a4f83d..0f04a90c8757e 100644 --- a/crates/transaction-pool/src/test_utils/mod.rs +++ b/crates/transaction-pool/src/test_utils/mod.rs @@ -1,8 +1,9 @@ //! Internal helpers for testing. -use crate::{blobstore::InMemoryBlobStore, noop::MockTransactionValidator, Pool, PoolConfig}; use std::ops::Deref; +use crate::{blobstore::InMemoryBlobStore, noop::MockTransactionValidator, Pool, PoolConfig}; + mod gen; pub use gen::*; diff --git a/crates/transaction-pool/src/test_utils/pool.rs b/crates/transaction-pool/src/test_utils/pool.rs index e8745a9460235..da040ef64f86f 100644 --- a/crates/transaction-pool/src/test_utils/pool.rs +++ b/crates/transaction-pool/src/test_utils/pool.rs @@ -2,17 +2,19 @@ #![allow(dead_code)] -use crate::{ - pool::{txpool::TxPool, AddedTransaction}, - test_utils::{MockOrdering, MockTransactionDistribution, MockTransactionFactory}, - TransactionOrdering, +use std::{ + collections::HashMap, + ops::{Deref, DerefMut}, }; + use rand::Rng; use reth_primitives::{Address, U256}; use serde::{Deserialize, Serialize}; -use std::{ - collections::HashMap, - ops::{Deref, DerefMut}, + +use crate::{ + pool::{txpool::TxPool, AddedTransaction}, + test_utils::{MockOrdering, MockTransactionDistribution, MockTransactionFactory}, + TransactionOrdering, }; /// A wrapped `TxPool` with additional helpers for testing diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index 41d57e94165ec..e28ff2e658bb9 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -1,12 +1,14 @@ #![allow(deprecated)] -use crate::{ - blobstore::BlobStoreError, - error::PoolResult, - pool::{state::SubPool, BestTransactionFilter, TransactionEvents}, - validate::ValidPoolTransaction, - AllTransactionsEvents, +use std::{ + collections::{HashMap, HashSet}, + fmt, + future::Future, + pin::Pin, + sync::Arc, + task::{Context, Poll}, }; + use futures_util::{ready, Stream}; use reth_eth_wire_types::HandleMempoolData; use reth_primitives::{ @@ -18,16 +20,16 @@ use reth_primitives::{ }; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -use std::{ - collections::{HashMap, HashSet}, - fmt, - future::Future, - pin::Pin, - sync::Arc, - task::{Context, Poll}, -}; use tokio::sync::mpsc::Receiver; +use crate::{ + blobstore::BlobStoreError, + error::PoolResult, + pool::{state::SubPool, BestTransactionFilter, TransactionEvents}, + validate::ValidPoolTransaction, + AllTransactionsEvents, +}; + /// The `PeerId` type. pub type PeerId = reth_primitives::B512; diff --git a/crates/transaction-pool/src/validate/eth.rs b/crates/transaction-pool/src/validate/eth.rs index 79a93cf2e2a74..00139b514b487 100644 --- a/crates/transaction-pool/src/validate/eth.rs +++ b/crates/transaction-pool/src/validate/eth.rs @@ -1,14 +1,10 @@ //! Ethereum transaction validator. -use super::constants::DEFAULT_MAX_TX_INPUT_BYTES; -use crate::{ - blobstore::BlobStore, - error::{Eip4844PoolTransactionError, InvalidPoolTransactionError}, - traits::TransactionOrigin, - validate::{ValidTransaction, ValidationTask, MAX_INIT_CODE_BYTE_SIZE}, - EthBlobTransactionSidecar, EthPoolTransaction, LocalTransactionConfig, PoolTransaction, - TransactionValidationOutcome, TransactionValidationTaskExecutor, TransactionValidator, +use std::{ + marker::PhantomData, + sync::{atomic::AtomicBool, Arc}, }; + use reth_chainspec::ChainSpec; use reth_primitives::{ constants::{eip4844::MAX_BLOBS_PER_BLOCK, ETHEREUM_BLOCK_GAS_LIMIT}, @@ -21,12 +17,18 @@ use revm::{ interpreter::gas::validate_initial_tx_gas, primitives::{EnvKzgSettings, SpecId}, }; -use std::{ - marker::PhantomData, - sync::{atomic::AtomicBool, Arc}, -}; use tokio::sync::Mutex; +use super::constants::DEFAULT_MAX_TX_INPUT_BYTES; +use crate::{ + blobstore::BlobStore, + error::{Eip4844PoolTransactionError, InvalidPoolTransactionError}, + traits::TransactionOrigin, + validate::{ValidTransaction, ValidationTask, MAX_INIT_CODE_BYTE_SIZE}, + EthBlobTransactionSidecar, EthPoolTransaction, LocalTransactionConfig, PoolTransaction, + TransactionValidationOutcome, TransactionValidationTaskExecutor, TransactionValidator, +}; + /// Validator for Ethereum transactions. #[derive(Debug, Clone)] pub struct EthTransactionValidator { @@ -743,14 +745,15 @@ pub fn calculate_intrinsic_gas_after_merge( #[cfg(test)] mod tests { + use reth_chainspec::MAINNET; + use reth_primitives::{hex, FromRecoveredPooledTransaction, PooledTransactionsElement, U256}; + use reth_provider::test_utils::{ExtendedAccount, MockEthProvider}; + use super::*; use crate::{ blobstore::InMemoryBlobStore, error::PoolErrorKind, CoinbaseTipOrdering, EthPooledTransaction, Pool, TransactionPool, }; - use reth_chainspec::MAINNET; - use reth_primitives::{hex, FromRecoveredPooledTransaction, PooledTransactionsElement, U256}; - use reth_provider::test_utils::{ExtendedAccount, MockEthProvider}; fn get_transaction() -> EthPooledTransaction { let raw = "0x02f914950181ad84b2d05e0085117553845b830f7df88080b9143a6040608081523462000414576200133a803803806200001e8162000419565b9283398101608082820312620004145781516001600160401b03908181116200041457826200004f9185016200043f565b92602092838201519083821162000414576200006d9183016200043f565b8186015190946001600160a01b03821692909183900362000414576060015190805193808511620003145760038054956001938488811c9816801562000409575b89891014620003f3578190601f988981116200039d575b50899089831160011462000336576000926200032a575b505060001982841b1c191690841b1781555b8751918211620003145760049788548481811c9116801562000309575b89821014620002f457878111620002a9575b5087908784116001146200023e5793839491849260009562000232575b50501b92600019911b1c19161785555b6005556007805460ff60a01b19169055600880546001600160a01b0319169190911790553015620001f3575060025469d3c21bcecceda100000092838201809211620001de57506000917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9160025530835282815284832084815401905584519384523093a351610e889081620004b28239f35b601190634e487b7160e01b6000525260246000fd5b90606493519262461bcd60e51b845283015260248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152fd5b0151935038806200013a565b9190601f198416928a600052848a6000209460005b8c8983831062000291575050501062000276575b50505050811b0185556200014a565b01519060f884600019921b161c191690553880808062000267565b86860151895590970196948501948893500162000253565b89600052886000208880860160051c8201928b8710620002ea575b0160051c019085905b828110620002dd5750506200011d565b60008155018590620002cd565b92508192620002c4565b60228a634e487b7160e01b6000525260246000fd5b90607f16906200010b565b634e487b7160e01b600052604160045260246000fd5b015190503880620000dc565b90869350601f19831691856000528b6000209260005b8d8282106200038657505084116200036d575b505050811b018155620000ee565b015160001983861b60f8161c191690553880806200035f565b8385015186558a979095019493840193016200034c565b90915083600052896000208980850160051c8201928c8610620003e9575b918891869594930160051c01915b828110620003d9575050620000c5565b60008155859450889101620003c9565b92508192620003bb565b634e487b7160e01b600052602260045260246000fd5b97607f1697620000ae565b600080fd5b6040519190601f01601f191682016001600160401b038111838210176200031457604052565b919080601f84011215620004145782516001600160401b038111620003145760209062000475601f8201601f1916830162000419565b92818452828287010111620004145760005b8181106200049d57508260009394955001015290565b85810183015184820184015282016200048756fe608060408181526004918236101561001657600080fd5b600092833560e01c91826306fdde0314610a1c57508163095ea7b3146109f257816318160ddd146109d35781631b4c84d2146109ac57816323b872dd14610833578163313ce5671461081757816339509351146107c357816370a082311461078c578163715018a6146107685781638124f7ac146107495781638da5cb5b1461072057816395d89b411461061d578163a457c2d714610575578163a9059cbb146104e4578163c9567bf914610120575063dd62ed3e146100d557600080fd5b3461011c578060031936011261011c57806020926100f1610b5a565b6100f9610b75565b6001600160a01b0391821683526001865283832091168252845220549051908152f35b5080fd5b905082600319360112610338576008546001600160a01b039190821633036104975760079283549160ff8360a01c1661045557737a250d5630b4cf539739df2c5dacb4c659f2488d92836bffffffffffffffffffffffff60a01b8092161786553087526020938785528388205430156104065730895260018652848920828a52865280858a205584519081527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925863092a38554835163c45a015560e01b815290861685828581845afa9182156103dd57849187918b946103e7575b5086516315ab88c960e31b815292839182905afa9081156103dd576044879289928c916103c0575b508b83895196879586946364e329cb60e11b8652308c870152166024850152165af19081156103b6579086918991610389575b50169060065416176006558385541660604730895288865260c4858a20548860085416928751958694859363f305d71960e01b8552308a86015260248501528d60448501528d606485015260848401524260a48401525af1801561037f579084929161034c575b50604485600654169587541691888551978894859363095ea7b360e01b855284015260001960248401525af1908115610343575061030c575b5050805460ff60a01b1916600160a01b17905580f35b81813d831161033c575b6103208183610b8b565b8101031261033857518015150361011c5738806102f6565b8280fd5b503d610316565b513d86823e3d90fd5b6060809293503d8111610378575b6103648183610b8b565b81010312610374578290386102bd565b8580fd5b503d61035a565b83513d89823e3d90fd5b6103a99150863d88116103af575b6103a18183610b8b565b810190610e33565b38610256565b503d610397565b84513d8a823e3d90fd5b6103d79150843d86116103af576103a18183610b8b565b38610223565b85513d8b823e3d90fd5b6103ff919450823d84116103af576103a18183610b8b565b92386101fb565b845162461bcd60e51b81528085018790526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608490fd5b6020606492519162461bcd60e51b8352820152601760248201527f74726164696e6720697320616c7265616479206f70656e0000000000000000006044820152fd5b608490602084519162461bcd60e51b8352820152602160248201527f4f6e6c79206f776e65722063616e2063616c6c20746869732066756e6374696f6044820152603760f91b6064820152fd5b9050346103385781600319360112610338576104fe610b5a565b9060243593303303610520575b602084610519878633610bc3565b5160018152f35b600594919454808302908382041483151715610562576127109004820391821161054f5750925080602061050b565b634e487b7160e01b815260118552602490fd5b634e487b7160e01b825260118652602482fd5b9050823461061a578260031936011261061a57610590610b5a565b918360243592338152600160205281812060018060a01b03861682526020522054908282106105c9576020856105198585038733610d31565b608490602086519162461bcd60e51b8352820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152fd5b80fd5b83833461011c578160031936011261011c57805191809380549160019083821c92828516948515610716575b6020958686108114610703578589529081156106df5750600114610687575b6106838787610679828c0383610b8b565b5191829182610b11565b0390f35b81529295507f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b5b8284106106cc57505050826106839461067992820101948680610668565b80548685018801529286019281016106ae565b60ff19168887015250505050151560051b8301019250610679826106838680610668565b634e487b7160e01b845260228352602484fd5b93607f1693610649565b50503461011c578160031936011261011c5760085490516001600160a01b039091168152602090f35b50503461011c578160031936011261011c576020906005549051908152f35b833461061a578060031936011261061a57600880546001600160a01b031916905580f35b50503461011c57602036600319011261011c5760209181906001600160a01b036107b4610b5a565b16815280845220549051908152f35b82843461061a578160031936011261061a576107dd610b5a565b338252600160209081528383206001600160a01b038316845290528282205460243581019290831061054f57602084610519858533610d31565b50503461011c578160031936011261011c576020905160128152f35b83833461011c57606036600319011261011c5761084e610b5a565b610856610b75565b6044359160018060a01b0381169485815260209560018752858220338352875285822054976000198903610893575b505050906105199291610bc3565b85891061096957811561091a5733156108cc5750948481979861051997845260018a528284203385528a52039120558594938780610885565b865162461bcd60e51b8152908101889052602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608490fd5b865162461bcd60e51b81529081018890526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608490fd5b865162461bcd60e51b8152908101889052601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606490fd5b50503461011c578160031936011261011c5760209060ff60075460a01c1690519015158152f35b50503461011c578160031936011261011c576020906002549051908152f35b50503461011c578060031936011261011c57602090610519610a12610b5a565b6024359033610d31565b92915034610b0d5783600319360112610b0d57600354600181811c9186908281168015610b03575b6020958686108214610af05750848852908115610ace5750600114610a75575b6106838686610679828b0383610b8b565b929550600383527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b5b828410610abb575050508261068394610679928201019438610a64565b8054868501880152928601928101610a9e565b60ff191687860152505050151560051b83010192506106798261068338610a64565b634e487b7160e01b845260229052602483fd5b93607f1693610a44565b8380fd5b6020808252825181830181905290939260005b828110610b4657505060409293506000838284010152601f8019910116010190565b818101860151848201604001528501610b24565b600435906001600160a01b0382168203610b7057565b600080fd5b602435906001600160a01b0382168203610b7057565b90601f8019910116810190811067ffffffffffffffff821117610bad57604052565b634e487b7160e01b600052604160045260246000fd5b6001600160a01b03908116918215610cde5716918215610c8d57600082815280602052604081205491808310610c3957604082827fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef958760209652828652038282205586815220818154019055604051908152a3565b60405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608490fd5b60405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608490fd5b60405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608490fd5b6001600160a01b03908116918215610de25716918215610d925760207f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925918360005260018252604060002085600052825280604060002055604051908152a3565b60405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608490fd5b60405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608490fd5b90816020910312610b7057516001600160a01b0381168103610b70579056fea2646970667358221220285c200b3978b10818ff576bb83f2dc4a2a7c98dfb6a36ea01170de792aa652764736f6c63430008140033000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000d3fd4f95820a9aa848ce716d6c200eaefb9a2e4900000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000003543131000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000035431310000000000000000000000000000000000000000000000000000000000c001a04e551c75810ffdfe6caff57da9f5a8732449f42f0f4c57f935b05250a76db3b6a046cd47e6d01914270c1ec0d9ac7fae7dfb240ec9a8b6ec7898c4d6aa174388f2"; diff --git a/crates/transaction-pool/src/validate/mod.rs b/crates/transaction-pool/src/validate/mod.rs index 9cadec2563aeb..d3fa528ae108b 100644 --- a/crates/transaction-pool/src/validate/mod.rs +++ b/crates/transaction-pool/src/validate/mod.rs @@ -1,30 +1,30 @@ //! Transaction validation abstractions. +use std::{fmt, future::Future, time::Instant}; + +use reth_primitives::{ + Address, BlobTransactionSidecar, IntoRecoveredTransaction, SealedBlock, + TransactionSignedEcRecovered, TxHash, B256, U256, +}; + use crate::{ error::InvalidPoolTransactionError, identifier::{SenderId, TransactionId}, traits::{PoolTransaction, TransactionOrigin}, }; -use reth_primitives::{ - Address, BlobTransactionSidecar, IntoRecoveredTransaction, SealedBlock, - TransactionSignedEcRecovered, TxHash, B256, U256, -}; -use std::{fmt, future::Future, time::Instant}; mod constants; mod eth; mod task; -/// A `TransactionValidator` implementation that validates ethereum transaction. -pub use eth::*; - -/// A spawnable task that performs transaction validation. -pub use task::{TransactionValidationTaskExecutor, ValidationTask}; - /// Validation constants. pub use constants::{ DEFAULT_MAX_TX_INPUT_BYTES, MAX_CODE_BYTE_SIZE, MAX_INIT_CODE_BYTE_SIZE, TX_SLOT_BYTE_SIZE, }; +/// A `TransactionValidator` implementation that validates ethereum transaction. +pub use eth::*; +/// A spawnable task that performs transaction validation. +pub use task::{TransactionValidationTaskExecutor, ValidationTask}; /// A Result type returned after checking a transaction's validity. #[derive(Debug)] diff --git a/crates/transaction-pool/src/validate/task.rs b/crates/transaction-pool/src/validate/task.rs index 72ab1d81a13a0..8516b4a478668 100644 --- a/crates/transaction-pool/src/validate/task.rs +++ b/crates/transaction-pool/src/validate/task.rs @@ -1,23 +1,25 @@ //! A validation service for transactions. -use crate::{ - blobstore::BlobStore, - validate::{EthTransactionValidatorBuilder, TransactionValidatorError}, - EthTransactionValidator, PoolTransaction, TransactionOrigin, TransactionValidationOutcome, - TransactionValidator, -}; +use std::{future::Future, pin::Pin, sync::Arc}; + use futures_util::{lock::Mutex, StreamExt}; use reth_chainspec::ChainSpec; use reth_primitives::SealedBlock; use reth_provider::BlockReaderIdExt; use reth_tasks::TaskSpawner; -use std::{future::Future, pin::Pin, sync::Arc}; use tokio::{ sync, sync::{mpsc, oneshot}, }; use tokio_stream::wrappers::ReceiverStream; +use crate::{ + blobstore::BlobStore, + validate::{EthTransactionValidatorBuilder, TransactionValidatorError}, + EthTransactionValidator, PoolTransaction, TransactionOrigin, TransactionValidationOutcome, + TransactionValidator, +}; + /// Represents a future outputting unit type and is sendable. type ValidationFuture = Pin + Send>>; diff --git a/crates/transaction-pool/tests/it/listeners.rs b/crates/transaction-pool/tests/it/listeners.rs index ad13af22a6a21..ade8d16d0ee5b 100644 --- a/crates/transaction-pool/tests/it/listeners.rs +++ b/crates/transaction-pool/tests/it/listeners.rs @@ -1,3 +1,5 @@ +use std::{future::poll_fn, task::Poll}; + use assert_matches::assert_matches; use reth_transaction_pool::{ noop::MockTransactionValidator, @@ -5,7 +7,6 @@ use reth_transaction_pool::{ FullTransactionEvent, TransactionEvent, TransactionListenerKind, TransactionOrigin, TransactionPool, }; -use std::{future::poll_fn, task::Poll}; use tokio_stream::StreamExt; #[tokio::test(flavor = "multi_thread")] diff --git a/crates/trie/common/src/account.rs b/crates/trie/common/src/account.rs index 64860ab78b31d..9e8f66c2de5f5 100644 --- a/crates/trie/common/src/account.rs +++ b/crates/trie/common/src/account.rs @@ -1,4 +1,3 @@ -use crate::root::storage_root_unhashed; use alloy_consensus::constants::KECCAK_EMPTY; use alloy_genesis::GenesisAccount; use alloy_primitives::{keccak256, B256, U256}; @@ -7,6 +6,8 @@ use alloy_trie::EMPTY_ROOT_HASH; use reth_primitives_traits::Account; use revm_primitives::AccountInfo; +use crate::root::storage_root_unhashed; + /// An Ethereum account as represented in the trie. #[derive(Clone, Copy, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)] pub struct TrieAccount { diff --git a/crates/trie/common/src/hash_builder/mod.rs b/crates/trie/common/src/hash_builder/mod.rs index a9bad00a53a25..138f825b055d7 100644 --- a/crates/trie/common/src/hash_builder/mod.rs +++ b/crates/trie/common/src/hash_builder/mod.rs @@ -4,6 +4,5 @@ mod state; pub use state::HashBuilderState; mod value; -pub(crate) use value::StoredHashBuilderValue; - pub use alloy_trie::hash_builder::*; +pub(crate) use value::StoredHashBuilderValue; diff --git a/crates/trie/common/src/hash_builder/state.rs b/crates/trie/common/src/hash_builder/state.rs index c70d7817e4c85..336c2c58f8ef5 100644 --- a/crates/trie/common/src/hash_builder/state.rs +++ b/crates/trie/common/src/hash_builder/state.rs @@ -1,11 +1,12 @@ -use super::StoredHashBuilderValue; -use crate::{StoredTrieMask, TrieMask}; use alloy_trie::{hash_builder::HashBuilderValue, HashBuilder}; use bytes::Buf; use nybbles::Nibbles; use reth_codecs::{derive_arbitrary, Compact}; use serde::{Deserialize, Serialize}; +use super::StoredHashBuilderValue; +use crate::{StoredTrieMask, TrieMask}; + /// The hash builder state for storing in the database. /// Check the `reth-trie` crate for more info on hash builder. #[derive_arbitrary(compact)] @@ -146,10 +147,11 @@ impl Compact for HashBuilderState { #[cfg(test)] mod tests { - use super::*; use proptest::prelude::*; use proptest_arbitrary_interop::arb; + use super::*; + #[test] fn hash_builder_state_regression() { let mut state = HashBuilderState::default(); diff --git a/crates/trie/common/src/mask.rs b/crates/trie/common/src/mask.rs index 02c74d2cc071b..899d8be9a792e 100644 --- a/crates/trie/common/src/mask.rs +++ b/crates/trie/common/src/mask.rs @@ -1,7 +1,8 @@ -use super::TrieMask; use bytes::Buf; use reth_codecs::Compact; +use super::TrieMask; + pub(crate) struct StoredTrieMask(pub(crate) TrieMask); impl Compact for StoredTrieMask { diff --git a/crates/trie/common/src/nibbles.rs b/crates/trie/common/src/nibbles.rs index 5a46887f823bf..6e694322cd970 100644 --- a/crates/trie/common/src/nibbles.rs +++ b/crates/trie/common/src/nibbles.rs @@ -1,10 +1,9 @@ use bytes::Buf; use derive_more::Deref; +pub use nybbles::Nibbles; use reth_codecs::Compact; use serde::{Deserialize, Serialize}; -pub use nybbles::Nibbles; - /// The representation of nibbles of the merkle trie stored in the database. #[derive( Clone, diff --git a/crates/trie/common/src/nodes/branch.rs b/crates/trie/common/src/nodes/branch.rs index a4f10d740307c..f107de7e8c90d 100644 --- a/crates/trie/common/src/nodes/branch.rs +++ b/crates/trie/common/src/nodes/branch.rs @@ -1,10 +1,11 @@ -use crate::StoredTrieMask; use alloy_primitives::B256; use alloy_trie::BranchNodeCompact; use bytes::Buf; use reth_codecs::Compact; use serde::{Deserialize, Serialize}; +use crate::StoredTrieMask; + /// Wrapper around `BranchNodeCompact` that implements `Compact`. #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct StoredBranchNode(pub BranchNodeCompact); @@ -70,9 +71,10 @@ impl Compact for StoredBranchNode { #[cfg(test)] mod tests { - use super::*; use alloy_primitives::hex; + use super::*; + #[test] fn node_encoding() { let n = BranchNodeCompact::new( diff --git a/crates/trie/common/src/nodes/mod.rs b/crates/trie/common/src/nodes/mod.rs index f3db93f3e7e88..59939d37cafe1 100644 --- a/crates/trie/common/src/nodes/mod.rs +++ b/crates/trie/common/src/nodes/mod.rs @@ -1,6 +1,5 @@ //! Various branch nodes produced by the hash builder. mod branch; -pub use branch::StoredBranchNode; - pub use alloy_trie::nodes::*; +pub use branch::StoredBranchNode; diff --git a/crates/trie/common/src/proofs.rs b/crates/trie/common/src/proofs.rs index 11953a48decf8..87fb5b149a8e4 100644 --- a/crates/trie/common/src/proofs.rs +++ b/crates/trie/common/src/proofs.rs @@ -1,6 +1,5 @@ //! Merkle trie proofs. -use crate::{Nibbles, TrieAccount}; use alloy_primitives::{keccak256, Address, Bytes, B256, U256}; use alloy_rlp::encode_fixed_size; use alloy_trie::{ @@ -9,6 +8,8 @@ use alloy_trie::{ }; use reth_primitives_traits::Account; +use crate::{Nibbles, TrieAccount}; + /// The merkle proof with the relevant account info. #[derive(PartialEq, Eq, Debug)] pub struct AccountProof { diff --git a/crates/trie/common/src/root.rs b/crates/trie/common/src/root.rs index 434eea20b59cb..48ff99f909d5f 100644 --- a/crates/trie/common/src/root.rs +++ b/crates/trie/common/src/root.rs @@ -1,12 +1,13 @@ //! Common root computation functions. -use crate::TrieAccount; use alloy_primitives::{keccak256, Address, B256, U256}; use alloy_rlp::Encodable; use alloy_trie::HashBuilder; use itertools::Itertools; use nybbles::Nibbles; +use crate::TrieAccount; + /// Adjust the index of an item for rlp encoding. pub const fn adjust_index_for_rlp(i: usize, len: usize) -> usize { if i > 0x7f { diff --git a/crates/trie/common/src/storage.rs b/crates/trie/common/src/storage.rs index 04ff57e1f31cb..5c75d30669d90 100644 --- a/crates/trie/common/src/storage.rs +++ b/crates/trie/common/src/storage.rs @@ -1,7 +1,8 @@ -use super::{BranchNodeCompact, StoredBranchNode, StoredNibblesSubKey}; use reth_codecs::Compact; use serde::{Deserialize, Serialize}; +use super::{BranchNodeCompact, StoredBranchNode, StoredNibblesSubKey}; + /// Account storage trie node. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Ord)] pub struct StorageTrieEntry { diff --git a/crates/trie/common/src/subnode.rs b/crates/trie/common/src/subnode.rs index 0a51b561b3751..2d9b0e918301f 100644 --- a/crates/trie/common/src/subnode.rs +++ b/crates/trie/common/src/subnode.rs @@ -1,7 +1,8 @@ -use super::{BranchNodeCompact, StoredBranchNode}; use bytes::Buf; use reth_codecs::Compact; +use super::{BranchNodeCompact, StoredBranchNode}; + /// Walker sub node for storing intermediate state root calculation state in the database. #[derive(Debug, Clone, PartialEq, Eq, Default)] pub struct StoredSubNode { @@ -68,9 +69,10 @@ impl Compact for StoredSubNode { #[cfg(test)] mod tests { + use alloy_primitives::B256; + use super::*; use crate::TrieMask; - use alloy_primitives::B256; #[test] fn subnode_roundtrip() { diff --git a/crates/trie/parallel/benches/root.rs b/crates/trie/parallel/benches/root.rs index d52702fbcc4a2..3ad42e50b2a3b 100644 --- a/crates/trie/parallel/benches/root.rs +++ b/crates/trie/parallel/benches/root.rs @@ -1,4 +1,6 @@ #![allow(missing_docs, unreachable_pub)] +use std::collections::HashMap; + use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; use proptest::{prelude::*, strategy::ValueTree, test_runner::TestRunner}; use proptest_arbitrary_interop::arb; @@ -13,7 +15,6 @@ use reth_trie::{ hashed_cursor::HashedPostStateCursorFactory, HashedPostState, HashedStorage, StateRoot, }; use reth_trie_parallel::{async_root::AsyncStateRoot, parallel_root::ParallelStateRoot}; -use std::collections::HashMap; pub fn calculate_state_root(c: &mut Criterion) { let mut group = c.benchmark_group("Calculate State Root"); diff --git a/crates/trie/parallel/src/async_root.rs b/crates/trie/parallel/src/async_root.rs index a36a01be5ecb7..46ecade10a040 100644 --- a/crates/trie/parallel/src/async_root.rs +++ b/crates/trie/parallel/src/async_root.rs @@ -1,4 +1,5 @@ -use crate::{stats::ParallelTrieTracker, storage_root_targets::StorageRootTargets}; +use std::{collections::HashMap, sync::Arc}; + use alloy_rlp::{BufMut, Encodable}; use itertools::Itertools; use reth_db_api::database::Database; @@ -14,12 +15,12 @@ use reth_trie::{ walker::TrieWalker, HashBuilder, HashedPostState, Nibbles, StorageRoot, TrieAccount, }; -use std::{collections::HashMap, sync::Arc}; use thiserror::Error; use tracing::*; #[cfg(feature = "metrics")] use crate::metrics::ParallelStateRootMetrics; +use crate::{stats::ParallelTrieTracker, storage_root_targets::StorageRootTargets}; /// Async state root calculator. /// @@ -224,13 +225,14 @@ pub enum AsyncStateRootError { #[cfg(test)] mod tests { - use super::*; use rand::Rng; use rayon::ThreadPoolBuilder; use reth_primitives::{keccak256, Account, Address, StorageEntry, U256}; use reth_provider::{test_utils::create_test_provider_factory, HashingWriter}; use reth_trie::{test_utils, HashedStorage}; + use super::*; + #[tokio::test] async fn random_async_root() { let blocking_pool = BlockingTaskPool::new(ThreadPoolBuilder::default().build().unwrap()); diff --git a/crates/trie/parallel/src/metrics.rs b/crates/trie/parallel/src/metrics.rs index 5a4a3ba740600..13c4fd0446946 100644 --- a/crates/trie/parallel/src/metrics.rs +++ b/crates/trie/parallel/src/metrics.rs @@ -1,8 +1,9 @@ -use crate::stats::ParallelTrieStats; use metrics::Histogram; use reth_metrics::Metrics; use reth_trie::metrics::{TrieRootMetrics, TrieType}; +use crate::stats::ParallelTrieStats; + /// Parallel state root metrics. #[derive(Debug)] pub struct ParallelStateRootMetrics { diff --git a/crates/trie/parallel/src/parallel_root.rs b/crates/trie/parallel/src/parallel_root.rs index edf552096fca7..f5aebc5b23a6f 100644 --- a/crates/trie/parallel/src/parallel_root.rs +++ b/crates/trie/parallel/src/parallel_root.rs @@ -1,4 +1,5 @@ -use crate::{stats::ParallelTrieTracker, storage_root_targets::StorageRootTargets}; +use std::collections::HashMap; + use alloy_rlp::{BufMut, Encodable}; use rayon::prelude::*; use reth_db_api::database::Database; @@ -13,12 +14,12 @@ use reth_trie::{ walker::TrieWalker, HashBuilder, HashedPostState, Nibbles, StorageRoot, TrieAccount, }; -use std::collections::HashMap; use thiserror::Error; use tracing::*; #[cfg(feature = "metrics")] use crate::metrics::ParallelStateRootMetrics; +use crate::{stats::ParallelTrieTracker, storage_root_targets::StorageRootTargets}; /// Parallel incremental state root calculator. /// @@ -211,12 +212,13 @@ impl From for ProviderError { #[cfg(test)] mod tests { - use super::*; use rand::Rng; use reth_primitives::{keccak256, Account, Address, StorageEntry, U256}; use reth_provider::{test_utils::create_test_provider_factory, HashingWriter}; use reth_trie::{test_utils, HashedStorage}; + use super::*; + #[tokio::test] async fn random_parallel_root() { let factory = create_test_provider_factory(); diff --git a/crates/trie/parallel/src/storage_root_targets.rs b/crates/trie/parallel/src/storage_root_targets.rs index d34441d3bef1f..f2df6212093e3 100644 --- a/crates/trie/parallel/src/storage_root_targets.rs +++ b/crates/trie/parallel/src/storage_root_targets.rs @@ -1,7 +1,8 @@ +use std::collections::HashMap; + use derive_more::{Deref, DerefMut}; use reth_primitives::B256; use reth_trie::prefix_set::PrefixSet; -use std::collections::HashMap; /// Target accounts with corresponding prefix sets for storage root calculation. #[derive(Deref, DerefMut, Debug)] diff --git a/crates/trie/trie/benches/hash_post_state.rs b/crates/trie/trie/benches/hash_post_state.rs index 636ce44621732..b5bc71789eaaf 100644 --- a/crates/trie/trie/benches/hash_post_state.rs +++ b/crates/trie/trie/benches/hash_post_state.rs @@ -1,10 +1,11 @@ #![allow(missing_docs, unreachable_pub)] +use std::collections::HashMap; + use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; use proptest::{prelude::*, strategy::ValueTree, test_runner::TestRunner}; use reth_primitives::{keccak256, Address, B256, U256}; use reth_trie::{HashedPostState, HashedStorage}; use revm::db::{states::BundleBuilder, BundleAccount}; -use std::collections::HashMap; pub fn hash_post_state(c: &mut Criterion) { let mut group = c.benchmark_group("Hash Post State"); diff --git a/crates/trie/trie/benches/prefix_set.rs b/crates/trie/trie/benches/prefix_set.rs index db02b5dd17cca..d42cea558844b 100644 --- a/crates/trie/trie/benches/prefix_set.rs +++ b/crates/trie/trie/benches/prefix_set.rs @@ -1,4 +1,6 @@ #![allow(missing_docs, unreachable_pub)] +use std::collections::BTreeSet; + use criterion::{ black_box, criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion, }; @@ -8,7 +10,6 @@ use proptest::{ test_runner::{basic_result_cache, TestRunner}, }; use reth_trie::{prefix_set::PrefixSetMut, Nibbles}; -use std::collections::BTreeSet; /// Abstractions used for benching pub trait PrefixSetAbstraction: Default { @@ -111,9 +112,10 @@ criterion_group!(prefix_set, prefix_set_lookups); criterion_main!(prefix_set); mod implementations { - use super::*; use std::ops::Bound; + use super::*; + #[derive(Default)] pub struct BTreeAnyPrefixSet { keys: BTreeSet, diff --git a/crates/trie/trie/benches/trie_root.rs b/crates/trie/trie/benches/trie_root.rs index 3f7efecc3a1fb..6dd15f511fbc5 100644 --- a/crates/trie/trie/benches/trie_root.rs +++ b/crates/trie/trie/benches/trie_root.rs @@ -41,10 +41,11 @@ criterion_group! { criterion_main!(benches); mod implementations { - use super::*; use alloy_rlp::Encodable; use reth_trie_common::{root::adjust_index_for_rlp, HashBuilder, Nibbles}; + use super::*; + pub fn trie_hash_ordered_trie_root(receipts: &[ReceiptWithBloom]) -> B256 { triehash::ordered_trie_root::(receipts.iter().map(|receipt| { let mut receipt_rlp = Vec::new(); diff --git a/crates/trie/trie/src/hashed_cursor/default.rs b/crates/trie/trie/src/hashed_cursor/default.rs index 197fd7ecde769..26a46475da236 100644 --- a/crates/trie/trie/src/hashed_cursor/default.rs +++ b/crates/trie/trie/src/hashed_cursor/default.rs @@ -1,4 +1,3 @@ -use super::{HashedCursor, HashedCursorFactory, HashedStorageCursor}; use reth_db::tables; use reth_db_api::{ cursor::{DbCursorRO, DbDupCursorRO}, @@ -6,6 +5,8 @@ use reth_db_api::{ }; use reth_primitives::{Account, B256, U256}; +use super::{HashedCursor, HashedCursorFactory, HashedStorageCursor}; + impl<'a, TX: DbTx> HashedCursorFactory for &'a TX { type AccountCursor = ::Cursor; type StorageCursor = diff --git a/crates/trie/trie/src/hashed_cursor/post_state.rs b/crates/trie/trie/src/hashed_cursor/post_state.rs index ac262f3d44fcc..e18df37f3694a 100644 --- a/crates/trie/trie/src/hashed_cursor/post_state.rs +++ b/crates/trie/trie/src/hashed_cursor/post_state.rs @@ -1,11 +1,13 @@ +use std::collections::HashSet; + +use reth_db::DatabaseError; +use reth_primitives::{Account, B256, U256}; + use super::{HashedCursor, HashedCursorFactory, HashedStorageCursor}; use crate::{ forward_cursor::ForwardInMemoryCursor, HashedAccountsSorted, HashedPostStateSorted, HashedStorageSorted, }; -use reth_db::DatabaseError; -use reth_primitives::{Account, B256, U256}; -use std::collections::HashSet; /// The hashed cursor factory for the post state. #[derive(Debug, Clone)] @@ -327,14 +329,16 @@ where #[cfg(test)] mod tests { - use super::*; - use crate::{HashedPostState, HashedStorage}; + use std::collections::BTreeMap; + use proptest::prelude::*; use proptest_arbitrary_interop::arb; use reth_db::{tables, test_utils::create_test_rw_db}; use reth_db_api::{database::Database, transaction::DbTxMut}; use reth_primitives::StorageEntry; - use std::collections::BTreeMap; + + use super::*; + use crate::{HashedPostState, HashedStorage}; fn assert_account_cursor_order( factory: &impl HashedCursorFactory, diff --git a/crates/trie/trie/src/metrics.rs b/crates/trie/trie/src/metrics.rs index 7582f37418d95..1949a3f173e15 100644 --- a/crates/trie/trie/src/metrics.rs +++ b/crates/trie/trie/src/metrics.rs @@ -1,7 +1,8 @@ -use crate::stats::TrieStats; use metrics::Histogram; use reth_metrics::Metrics; +use crate::stats::TrieStats; + /// Wrapper for state root metrics. #[derive(Debug)] pub struct StateRootMetrics { diff --git a/crates/trie/trie/src/node_iter.rs b/crates/trie/trie/src/node_iter.rs index 29c6fd4f2344a..97284fe86018f 100644 --- a/crates/trie/trie/src/node_iter.rs +++ b/crates/trie/trie/src/node_iter.rs @@ -1,7 +1,8 @@ -use crate::{hashed_cursor::HashedCursor, trie_cursor::TrieCursor, walker::TrieWalker, Nibbles}; use reth_db::DatabaseError; use reth_primitives::B256; +use crate::{hashed_cursor::HashedCursor, trie_cursor::TrieCursor, walker::TrieWalker, Nibbles}; + /// Represents a branch node in the trie. #[derive(Debug)] pub struct TrieBranchNode { diff --git a/crates/trie/trie/src/prefix_set/loader.rs b/crates/trie/trie/src/prefix_set/loader.rs index 2f0b7048af516..32acfe6f98347 100644 --- a/crates/trie/trie/src/prefix_set/loader.rs +++ b/crates/trie/trie/src/prefix_set/loader.rs @@ -1,5 +1,8 @@ -use super::{PrefixSetMut, TriePrefixSets}; -use crate::Nibbles; +use std::{ + collections::{HashMap, HashSet}, + ops::RangeInclusive, +}; + use derive_more::Deref; use reth_db::tables; use reth_db_api::{ @@ -9,10 +12,9 @@ use reth_db_api::{ DatabaseError, }; use reth_primitives::{keccak256, BlockNumber, StorageEntry, B256}; -use std::{ - collections::{HashMap, HashSet}, - ops::RangeInclusive, -}; + +use super::{PrefixSetMut, TriePrefixSets}; +use crate::Nibbles; /// A wrapper around a database transaction that loads prefix sets within a given block range. #[derive(Deref, Debug)] pub struct PrefixSetLoader<'a, TX>(&'a TX); diff --git a/crates/trie/trie/src/prefix_set/mod.rs b/crates/trie/trie/src/prefix_set/mod.rs index f6a8789e0105f..2303d2e2d1687 100644 --- a/crates/trie/trie/src/prefix_set/mod.rs +++ b/crates/trie/trie/src/prefix_set/mod.rs @@ -1,10 +1,12 @@ -use crate::Nibbles; -use reth_primitives::B256; use std::{ collections::{HashMap, HashSet}, sync::Arc, }; +use reth_primitives::B256; + +use crate::Nibbles; + mod loader; pub use loader::PrefixSetLoader; diff --git a/crates/trie/trie/src/progress.rs b/crates/trie/trie/src/progress.rs index 1594d7f6e084d..528d78655c56e 100644 --- a/crates/trie/trie/src/progress.rs +++ b/crates/trie/trie/src/progress.rs @@ -1,7 +1,8 @@ -use crate::{hash_builder::HashBuilder, trie_cursor::CursorSubNode, updates::TrieUpdates}; use reth_primitives::B256; use reth_stages_types::MerkleCheckpoint; +use crate::{hash_builder::HashBuilder, trie_cursor::CursorSubNode, updates::TrieUpdates}; + /// The progress of the state root computation. #[derive(Debug)] pub enum StateRootProgress { diff --git a/crates/trie/trie/src/proof.rs b/crates/trie/trie/src/proof.rs index 04e7952f5db78..779048c6f5aea 100644 --- a/crates/trie/trie/src/proof.rs +++ b/crates/trie/trie/src/proof.rs @@ -1,3 +1,10 @@ +use alloy_rlp::{BufMut, Encodable}; +use reth_db::tables; +use reth_db_api::transaction::DbTx; +use reth_execution_errors::{StateRootError, StorageRootError}; +use reth_primitives::{constants::EMPTY_ROOT_HASH, keccak256, Address, B256}; +use reth_trie_common::{proof::ProofRetainer, AccountProof, StorageProof, TrieAccount}; + use crate::{ hashed_cursor::{HashedCursorFactory, HashedStorageCursor}, node_iter::{TrieElement, TrieNodeIter}, @@ -6,12 +13,6 @@ use crate::{ walker::TrieWalker, HashBuilder, Nibbles, }; -use alloy_rlp::{BufMut, Encodable}; -use reth_db::tables; -use reth_db_api::transaction::DbTx; -use reth_execution_errors::{StateRootError, StorageRootError}; -use reth_primitives::{constants::EMPTY_ROOT_HASH, keccak256, Address, B256}; -use reth_trie_common::{proof::ProofRetainer, AccountProof, StorageProof, TrieAccount}; /// A struct for generating merkle proofs. /// /// Proof generator adds the target address and slots to the prefix set, enables the proof retainer @@ -161,15 +162,17 @@ where #[cfg(test)] mod tests { - use super::*; - use crate::StateRoot; + use std::{str::FromStr, sync::Arc}; + use once_cell::sync::Lazy; use reth_chainspec::{Chain, ChainSpec, HOLESKY, MAINNET}; use reth_db_api::database::Database; use reth_primitives::{Account, Bytes, StorageEntry, U256}; use reth_provider::{test_utils::create_test_provider_factory, HashingWriter, ProviderFactory}; use reth_storage_errors::provider::ProviderResult; - use std::{str::FromStr, sync::Arc}; + + use super::*; + use crate::StateRoot; /* World State (sampled from ) diff --git a/crates/trie/trie/src/state.rs b/crates/trie/trie/src/state.rs index de7ecc236dbe9..ad8ec822b2a4b 100644 --- a/crates/trie/trie/src/state.rs +++ b/crates/trie/trie/src/state.rs @@ -1,9 +1,8 @@ -use crate::{ - hashed_cursor::HashedPostStateCursorFactory, - prefix_set::{PrefixSetMut, TriePrefixSets}, - updates::TrieUpdates, - Nibbles, StateRoot, +use std::{ + collections::{hash_map, HashMap, HashSet}, + ops::RangeInclusive, }; + use rayon::prelude::{IntoParallelIterator, ParallelIterator}; use reth_db::{tables, DatabaseError}; use reth_db_api::{ @@ -14,9 +13,12 @@ use reth_db_api::{ use reth_execution_errors::StateRootError; use reth_primitives::{keccak256, Account, Address, BlockNumber, B256, U256}; use revm::db::BundleAccount; -use std::{ - collections::{hash_map, HashMap, HashSet}, - ops::RangeInclusive, + +use crate::{ + hashed_cursor::HashedPostStateCursorFactory, + prefix_set::{PrefixSetMut, TriePrefixSets}, + updates::TrieUpdates, + Nibbles, StateRoot, }; /// Representation of in-memory hashed state. @@ -338,7 +340,6 @@ pub struct HashedStorageSorted { #[cfg(test)] mod tests { - use super::*; use reth_db::test_utils::create_test_rw_db; use reth_db_api::database::Database; use reth_primitives::hex; @@ -347,6 +348,8 @@ mod tests { primitives::{AccountInfo, HashMap}, }; + use super::*; + #[test] fn hashed_state_wiped_extension() { let hashed_address = B256::default(); diff --git a/crates/trie/trie/src/test_utils.rs b/crates/trie/trie/src/test_utils.rs index e2fc1f192c322..48f78f63b5736 100644 --- a/crates/trie/trie/src/test_utils.rs +++ b/crates/trie/trie/src/test_utils.rs @@ -1,7 +1,6 @@ use alloy_rlp::encode_fixed_size; use reth_primitives::{Account, Address, B256, U256}; use reth_trie_common::{triehash::KeccakHasher, TrieAccount}; - /// Re-export of [triehash]. pub use triehash; diff --git a/crates/trie/trie/src/trie.rs b/crates/trie/trie/src/trie.rs index 25ae616584d7a..22a8fc7a9d639 100644 --- a/crates/trie/trie/src/trie.rs +++ b/crates/trie/trie/src/trie.rs @@ -1,3 +1,13 @@ +use std::ops::RangeInclusive; + +use alloy_rlp::{BufMut, Encodable}; +use reth_db_api::transaction::DbTx; +use reth_execution_errors::{StateRootError, StorageRootError}; +use reth_primitives::{constants::EMPTY_ROOT_HASH, keccak256, Address, BlockNumber, B256}; +use tracing::{debug, trace}; + +#[cfg(feature = "metrics")] +use crate::metrics::{StateRootMetrics, TrieRootMetrics, TrieType}; use crate::{ hashed_cursor::{HashedCursorFactory, HashedStorageCursor}, node_iter::{TrieElement, TrieNodeIter}, @@ -9,15 +19,6 @@ use crate::{ walker::TrieWalker, HashBuilder, Nibbles, TrieAccount, }; -use alloy_rlp::{BufMut, Encodable}; -use reth_db_api::transaction::DbTx; -use reth_execution_errors::{StateRootError, StorageRootError}; -use reth_primitives::{constants::EMPTY_ROOT_HASH, keccak256, Address, BlockNumber, B256}; -use std::ops::RangeInclusive; -use tracing::{debug, trace}; - -#[cfg(feature = "metrics")] -use crate::metrics::{StateRootMetrics, TrieRootMetrics, TrieType}; /// `StateRoot` is used to compute the root node of a state trie. #[derive(Debug)] @@ -544,12 +545,13 @@ where #[cfg(test)] mod tests { - use super::*; - use crate::{ - prefix_set::PrefixSetMut, - test_utils::{state_root, state_root_prehashed, storage_root, storage_root_prehashed}, - BranchNodeCompact, TrieMask, + use std::{ + collections::{BTreeMap, HashMap}, + ops::Mul, + str::FromStr, + sync::Arc, }; + use proptest::{prelude::ProptestConfig, proptest}; use proptest_arbitrary_interop::arb; use reth_db::{tables, test_utils::TempDatabase, DatabaseEnv}; @@ -560,11 +562,12 @@ mod tests { use reth_primitives::{hex_literal::hex, Account, StorageEntry, U256}; use reth_provider::{test_utils::create_test_provider_factory, DatabaseProviderRW}; use reth_trie_common::triehash::KeccakHasher; - use std::{ - collections::{BTreeMap, HashMap}, - ops::Mul, - str::FromStr, - sync::Arc, + + use super::*; + use crate::{ + prefix_set::PrefixSetMut, + test_utils::{state_root, state_root_prehashed, storage_root, storage_root_prehashed}, + BranchNodeCompact, TrieMask, }; fn insert_account( diff --git a/crates/trie/trie/src/trie_cursor/database_cursors.rs b/crates/trie/trie/src/trie_cursor/database_cursors.rs index 910ae61b4648b..cf1cce7b81bef 100644 --- a/crates/trie/trie/src/trie_cursor/database_cursors.rs +++ b/crates/trie/trie/src/trie_cursor/database_cursors.rs @@ -1,5 +1,3 @@ -use super::{TrieCursor, TrieCursorFactory}; -use crate::{updates::TrieKey, BranchNodeCompact, Nibbles, StoredNibbles, StoredNibblesSubKey}; use reth_db::{tables, DatabaseError}; use reth_db_api::{ cursor::{DbCursorRO, DbDupCursorRO}, @@ -7,6 +5,9 @@ use reth_db_api::{ }; use reth_primitives::B256; +use super::{TrieCursor, TrieCursorFactory}; +use crate::{updates::TrieKey, BranchNodeCompact, Nibbles, StoredNibbles, StoredNibblesSubKey}; + /// Implementation of the trie cursor factory for a database transaction. impl<'a, TX: DbTx> TrieCursorFactory for &'a TX { fn account_trie_cursor(&self) -> Result, DatabaseError> { @@ -112,12 +113,13 @@ where #[cfg(test)] mod tests { - use super::*; - use crate::{StorageTrieEntry, StoredBranchNode}; use reth_db_api::{cursor::DbCursorRW, transaction::DbTxMut}; use reth_primitives::hex_literal::hex; use reth_provider::test_utils::create_test_provider_factory; + use super::*; + use crate::{StorageTrieEntry, StoredBranchNode}; + #[test] fn test_account_trie_order() { let factory = create_test_provider_factory(); diff --git a/crates/trie/trie/src/trie_cursor/mod.rs b/crates/trie/trie/src/trie_cursor/mod.rs index aae7e773c690c..542588fa3cbfa 100644 --- a/crates/trie/trie/src/trie_cursor/mod.rs +++ b/crates/trie/trie/src/trie_cursor/mod.rs @@ -1,6 +1,7 @@ -use crate::{updates::TrieKey, BranchNodeCompact, Nibbles}; use reth_db::DatabaseError; use reth_primitives::B256; + +use crate::{updates::TrieKey, BranchNodeCompact, Nibbles}; mod database_cursors; mod subnode; diff --git a/crates/trie/trie/src/trie_cursor/noop.rs b/crates/trie/trie/src/trie_cursor/noop.rs index 46163180b8b98..5f3f3a1a82203 100644 --- a/crates/trie/trie/src/trie_cursor/noop.rs +++ b/crates/trie/trie/src/trie_cursor/noop.rs @@ -1,6 +1,7 @@ +use reth_db::DatabaseError; + use super::{TrieCursor, TrieCursorFactory}; use crate::{updates::TrieKey, BranchNodeCompact, Nibbles}; -use reth_db::DatabaseError; /// Noop trie cursor factory. #[derive(Default, Debug)] diff --git a/crates/trie/trie/src/trie_cursor/subnode.rs b/crates/trie/trie/src/trie_cursor/subnode.rs index 15e2ac31d7977..891b8e7853e58 100644 --- a/crates/trie/trie/src/trie_cursor/subnode.rs +++ b/crates/trie/trie/src/trie_cursor/subnode.rs @@ -1,6 +1,7 @@ -use crate::{nodes::CHILD_INDEX_RANGE, BranchNodeCompact, Nibbles, StoredSubNode}; use reth_primitives::B256; +use crate::{nodes::CHILD_INDEX_RANGE, BranchNodeCompact, Nibbles, StoredSubNode}; + /// Cursor for iterating over a subtrie. #[derive(Clone)] pub struct CursorSubNode { diff --git a/crates/trie/trie/src/updates.rs b/crates/trie/trie/src/updates.rs index 53830fd8a3c21..1a905f09dfa89 100644 --- a/crates/trie/trie/src/updates.rs +++ b/crates/trie/trie/src/updates.rs @@ -1,7 +1,5 @@ -use crate::{ - walker::TrieWalker, BranchNodeCompact, HashBuilder, Nibbles, StorageTrieEntry, - StoredBranchNode, StoredNibbles, StoredNibblesSubKey, -}; +use std::collections::{hash_map::IntoIter, HashMap, HashSet}; + use derive_more::Deref; use reth_db::tables; use reth_db_api::{ @@ -9,7 +7,11 @@ use reth_db_api::{ transaction::{DbTx, DbTxMut}, }; use reth_primitives::B256; -use std::collections::{hash_map::IntoIter, HashMap, HashSet}; + +use crate::{ + walker::TrieWalker, BranchNodeCompact, HashBuilder, Nibbles, StorageTrieEntry, + StoredBranchNode, StoredNibbles, StoredNibblesSubKey, +}; /// The key of a trie node. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/crates/trie/trie/src/walker.rs b/crates/trie/trie/src/walker.rs index 6486a9b08006a..a267d8f613742 100644 --- a/crates/trie/trie/src/walker.rs +++ b/crates/trie/trie/src/walker.rs @@ -1,11 +1,12 @@ +use reth_db::DatabaseError; +use reth_primitives::B256; + use crate::{ prefix_set::PrefixSet, trie_cursor::{CursorSubNode, TrieCursor}, updates::TrieUpdates, BranchNodeCompact, Nibbles, }; -use reth_db::DatabaseError; -use reth_primitives::B256; /// `TrieWalker` is a structure that enables traversal of a Merkle trie. /// It allows moving through the trie in a depth-first manner, skipping certain branches @@ -243,15 +244,16 @@ impl TrieWalker { #[cfg(test)] mod tests { + use reth_db::tables; + use reth_db_api::{cursor::DbCursorRW, transaction::DbTxMut}; + use reth_provider::test_utils::create_test_provider_factory; + use super::*; use crate::{ prefix_set::PrefixSetMut, trie_cursor::{DatabaseAccountTrieCursor, DatabaseStorageTrieCursor}, StorageTrieEntry, StoredBranchNode, }; - use reth_db::tables; - use reth_db_api::{cursor::DbCursorRW, transaction::DbTxMut}; - use reth_provider::test_utils::create_test_provider_factory; #[test] fn walk_nodes_with_common_prefix() { diff --git a/examples/beacon-api-sidecar-fetcher/src/mined_sidecar.rs b/examples/beacon-api-sidecar-fetcher/src/mined_sidecar.rs index 70c6c98a9fd09..c1dbdd956abfc 100644 --- a/examples/beacon-api-sidecar-fetcher/src/mined_sidecar.rs +++ b/examples/beacon-api-sidecar-fetcher/src/mined_sidecar.rs @@ -1,4 +1,9 @@ -use crate::BeaconSidecarConfig; +use std::{ + collections::VecDeque, + pin::Pin, + task::{Context, Poll}, +}; + use alloy_rpc_types_beacon::sidecar::{BeaconBlobBundle, SidecarIterator}; use eyre::Result; use futures_util::{stream::FuturesUnordered, Future, Stream, StreamExt}; @@ -9,13 +14,10 @@ use reth::{ transaction_pool::{BlobStoreError, TransactionPoolExt}, }; use serde::{Deserialize, Serialize}; -use std::{ - collections::VecDeque, - pin::Pin, - task::{Context, Poll}, -}; use thiserror::Error; +use crate::BeaconSidecarConfig; + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct BlockMetadata { pub block_hash: B256, diff --git a/examples/beacon-api-sse/src/main.rs b/examples/beacon-api-sse/src/main.rs index a2d74a77c21c4..9853a26b29863 100644 --- a/examples/beacon-api-sse/src/main.rs +++ b/examples/beacon-api-sse/src/main.rs @@ -17,13 +17,14 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] +use std::net::{IpAddr, Ipv4Addr}; + use alloy_rpc_types_beacon::events::PayloadAttributesEvent; use clap::Parser; use futures_util::stream::StreamExt; use mev_share_sse::{client::EventStream, EventClient}; use reth::cli::Cli; use reth_node_ethereum::EthereumNode; -use std::net::{IpAddr, Ipv4Addr}; use tracing::{info, warn}; fn main() { diff --git a/examples/bsc-p2p/src/chainspec.rs b/examples/bsc-p2p/src/chainspec.rs index d9c3a868297a1..46545f8c508b9 100644 --- a/examples/bsc-p2p/src/chainspec.rs +++ b/examples/bsc-p2p/src/chainspec.rs @@ -1,8 +1,8 @@ +use std::{collections::BTreeMap, sync::Arc}; + use reth_chainspec::{net::NodeRecord, BaseFeeParams, Chain, ChainSpec, ForkCondition, Hardfork}; use reth_primitives::{b256, B256}; -use std::{collections::BTreeMap, sync::Arc}; - pub const SHANGHAI_TIME: u64 = 1705996800; pub(crate) fn bsc_chain_spec() -> Arc { diff --git a/examples/bsc-p2p/src/main.rs b/examples/bsc-p2p/src/main.rs index 558eed171c203..129d14cf37abc 100644 --- a/examples/bsc-p2p/src/main.rs +++ b/examples/bsc-p2p/src/main.rs @@ -12,6 +12,11 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] +use std::{ + net::{Ipv4Addr, SocketAddr}, + time::Duration, +}; + use chainspec::{boot_nodes, bsc_chain_spec}; use reth_discv4::Discv4ConfigBuilder; use reth_network::{NetworkConfig, NetworkEvent, NetworkEvents, NetworkManager}; @@ -22,10 +27,6 @@ use reth_tracing::{ Tracer, }; use secp256k1::{rand, SecretKey}; -use std::{ - net::{Ipv4Addr, SocketAddr}, - time::Duration, -}; use tokio_stream::StreamExt; pub mod chainspec; diff --git a/examples/custom-dev-node/src/main.rs b/examples/custom-dev-node/src/main.rs index 498971dbd1b60..d9b1ffa374739 100644 --- a/examples/custom-dev-node/src/main.rs +++ b/examples/custom-dev-node/src/main.rs @@ -3,6 +3,8 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] +use std::sync::Arc; + use futures_util::StreamExt; use reth::{ builder::{NodeBuilder, NodeHandle}, @@ -14,7 +16,6 @@ use reth_chainspec::ChainSpec; use reth_node_core::{args::RpcServerArgs, node_config::NodeConfig}; use reth_node_ethereum::EthereumNode; use reth_primitives::{b256, hex, Genesis}; -use std::sync::Arc; #[tokio::main] async fn main() -> eyre::Result<()> { diff --git a/examples/custom-engine-types/src/main.rs b/examples/custom-engine-types/src/main.rs index c006e396e2c7a..7251c787da102 100644 --- a/examples/custom-engine-types/src/main.rs +++ b/examples/custom-engine-types/src/main.rs @@ -19,9 +19,6 @@ use std::convert::Infallible; -use serde::{Deserialize, Serialize}; -use thiserror::Error; - use alloy_genesis::Genesis; use reth::{ api::PayloadTypes, @@ -61,6 +58,8 @@ use reth_rpc_types::{ ExecutionPayloadV1, Withdrawal, }; use reth_tracing::{RethTracer, Tracer}; +use serde::{Deserialize, Serialize}; +use thiserror::Error; /// A custom payload attributes type. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] diff --git a/examples/custom-evm/src/main.rs b/examples/custom-evm/src/main.rs index 9d394126fde25..c97ce9af50b2f 100644 --- a/examples/custom-evm/src/main.rs +++ b/examples/custom-evm/src/main.rs @@ -2,6 +2,8 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] +use std::sync::Arc; + use alloy_genesis::Genesis; use reth::{ builder::{components::ExecutorBuilder, BuilderContext, NodeBuilder}, @@ -24,7 +26,6 @@ use reth_node_core::{args::RpcServerArgs, node_config::NodeConfig}; use reth_node_ethereum::{EthEvmConfig, EthExecutorProvider, EthereumNode}; use reth_primitives::{Header, TransactionSigned}; use reth_tracing::{RethTracer, Tracer}; -use std::sync::Arc; /// Custom EVM configuration #[derive(Debug, Clone, Copy, Default)] diff --git a/examples/custom-payload-builder/src/generator.rs b/examples/custom-payload-builder/src/generator.rs index a220315cb4276..3a6dd79055dbe 100644 --- a/examples/custom-payload-builder/src/generator.rs +++ b/examples/custom-payload-builder/src/generator.rs @@ -1,4 +1,5 @@ -use crate::job::EmptyBlockPayloadJob; +use std::sync::Arc; + use reth::{ providers::{BlockReaderIdExt, BlockSource, StateProviderFactory}, tasks::TaskSpawner, @@ -9,7 +10,8 @@ use reth_chainspec::ChainSpec; use reth_node_api::PayloadBuilderAttributes; use reth_payload_builder::{error::PayloadBuilderError, PayloadJobGenerator}; use reth_primitives::{BlockNumberOrTag, Bytes}; -use std::sync::Arc; + +use crate::job::EmptyBlockPayloadJob; /// The generator type that creates new jobs that builds empty blocks. #[derive(Debug)] diff --git a/examples/custom-payload-builder/src/job.rs b/examples/custom-payload-builder/src/job.rs index 154e5165e8274..075d92fac9a03 100644 --- a/examples/custom-payload-builder/src/job.rs +++ b/examples/custom-payload-builder/src/job.rs @@ -1,3 +1,8 @@ +use std::{ + pin::Pin, + task::{Context, Poll}, +}; + use futures_util::Future; use reth::{ providers::StateProviderFactory, tasks::TaskSpawner, transaction_pool::TransactionPool, @@ -5,11 +10,6 @@ use reth::{ use reth_basic_payload_builder::{PayloadBuilder, PayloadConfig}; use reth_payload_builder::{error::PayloadBuilderError, KeepPayloadJobAlive, PayloadJob}; -use std::{ - pin::Pin, - task::{Context, Poll}, -}; - /// A [PayloadJob] that builds empty blocks. pub struct EmptyBlockPayloadJob where diff --git a/examples/custom-rlpx-subprotocol/src/main.rs b/examples/custom-rlpx-subprotocol/src/main.rs index 3a198c38d2858..36dcdc0991e29 100644 --- a/examples/custom-rlpx-subprotocol/src/main.rs +++ b/examples/custom-rlpx-subprotocol/src/main.rs @@ -7,6 +7,8 @@ //! ``` //! //! This launch a regular reth node with a custom rlpx subprotocol. +use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; + use reth::builder::NodeHandle; use reth_network::{ config::SecretKey, protocol::IntoRlpxSubProtocol, NetworkConfig, NetworkManager, @@ -15,7 +17,6 @@ use reth_network::{ use reth_network_api::NetworkInfo; use reth_node_ethereum::EthereumNode; use reth_provider::test_utils::NoopProvider; -use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; use subprotocol::{ connection::CustomCommand, protocol::{ diff --git a/examples/custom-rlpx-subprotocol/src/subprotocol/connection/handler.rs b/examples/custom-rlpx-subprotocol/src/subprotocol/connection/handler.rs index dae2d5c8679e6..b85141ad9724b 100644 --- a/examples/custom-rlpx-subprotocol/src/subprotocol/connection/handler.rs +++ b/examples/custom-rlpx-subprotocol/src/subprotocol/connection/handler.rs @@ -1,7 +1,3 @@ -use super::CustomRlpxConnection; -use crate::subprotocol::protocol::{ - event::ProtocolEvent, handler::ProtocolState, proto::CustomRlpxProtoMessage, -}; use reth_eth_wire::{ capability::SharedCapabilities, multiplex::ProtocolConnection, protocol::Protocol, }; @@ -11,6 +7,11 @@ use reth_rpc_types::PeerId; use tokio::sync::mpsc; use tokio_stream::wrappers::UnboundedReceiverStream; +use super::CustomRlpxConnection; +use crate::subprotocol::protocol::{ + event::ProtocolEvent, handler::ProtocolState, proto::CustomRlpxProtoMessage, +}; + /// The connection handler for the custom RLPx protocol. pub(crate) struct CustomRlpxConnectionHandler { pub(crate) state: ProtocolState, diff --git a/examples/custom-rlpx-subprotocol/src/subprotocol/connection/mod.rs b/examples/custom-rlpx-subprotocol/src/subprotocol/connection/mod.rs index a6d835b70c263..db020de9099ed 100644 --- a/examples/custom-rlpx-subprotocol/src/subprotocol/connection/mod.rs +++ b/examples/custom-rlpx-subprotocol/src/subprotocol/connection/mod.rs @@ -1,14 +1,16 @@ -use super::protocol::proto::{CustomRlpxProtoMessage, CustomRlpxProtoMessageKind}; -use futures::{Stream, StreamExt}; -use reth_eth_wire::multiplex::ProtocolConnection; -use reth_primitives::BytesMut; use std::{ pin::Pin, task::{ready, Context, Poll}, }; + +use futures::{Stream, StreamExt}; +use reth_eth_wire::multiplex::ProtocolConnection; +use reth_primitives::BytesMut; use tokio::sync::oneshot; use tokio_stream::wrappers::UnboundedReceiverStream; +use super::protocol::proto::{CustomRlpxProtoMessage, CustomRlpxProtoMessageKind}; + pub(crate) mod handler; /// We define some custom commands that the subprotocol supports. diff --git a/examples/custom-rlpx-subprotocol/src/subprotocol/protocol/event.rs b/examples/custom-rlpx-subprotocol/src/subprotocol/protocol/event.rs index ea9e588e592b4..a5c3c79d74e9d 100644 --- a/examples/custom-rlpx-subprotocol/src/subprotocol/protocol/event.rs +++ b/examples/custom-rlpx-subprotocol/src/subprotocol/protocol/event.rs @@ -1,8 +1,9 @@ -use crate::subprotocol::connection::CustomCommand; use reth_network::Direction; use reth_network_api::PeerId; use tokio::sync::mpsc; +use crate::subprotocol::connection::CustomCommand; + /// The events that can be emitted by our custom protocol. #[derive(Debug)] pub(crate) enum ProtocolEvent { diff --git a/examples/custom-rlpx-subprotocol/src/subprotocol/protocol/handler.rs b/examples/custom-rlpx-subprotocol/src/subprotocol/protocol/handler.rs index d5a35398dae10..855d6ee289cbb 100644 --- a/examples/custom-rlpx-subprotocol/src/subprotocol/protocol/handler.rs +++ b/examples/custom-rlpx-subprotocol/src/subprotocol/protocol/handler.rs @@ -1,10 +1,12 @@ -use super::event::ProtocolEvent; -use crate::subprotocol::connection::handler::CustomRlpxConnectionHandler; +use std::net::SocketAddr; + use reth_network::protocol::ProtocolHandler; use reth_network_api::PeerId; -use std::net::SocketAddr; use tokio::sync::mpsc; +use super::event::ProtocolEvent; +use crate::subprotocol::connection::handler::CustomRlpxConnectionHandler; + /// Protocol state is an helper struct to store the protocol events. #[derive(Clone, Debug)] pub(crate) struct ProtocolState { diff --git a/examples/db-access/src/main.rs b/examples/db-access/src/main.rs index 27047fd3f8ec6..b8cf66000ca92 100644 --- a/examples/db-access/src/main.rs +++ b/examples/db-access/src/main.rs @@ -1,3 +1,5 @@ +use std::path::Path; + use reth_chainspec::ChainSpecBuilder; use reth_db::open_db_read_only; use reth_primitives::{Address, B256}; @@ -6,7 +8,6 @@ use reth_provider::{ ProviderFactory, ReceiptProvider, StateProvider, TransactionsProvider, }; use reth_rpc_types::{Filter, FilteredParams}; -use std::path::Path; // Providers are zero cost abstractions on top of an opened MDBX Transaction // exposing a familiar API to query the chain's information without requiring knowledge diff --git a/examples/exex/discv5/src/exex/mod.rs b/examples/exex/discv5/src/exex/mod.rs index 4631f392979cf..5a3b3cb24ee23 100644 --- a/examples/exex/discv5/src/exex/mod.rs +++ b/examples/exex/discv5/src/exex/mod.rs @@ -1,12 +1,13 @@ +use std::{ + pin::Pin, + task::{ready, Context, Poll}, +}; + use eyre::Result; use futures::{Future, FutureExt}; use reth_exex::{ExExContext, ExExEvent, ExExNotification}; use reth_node_api::FullNodeComponents; use reth_tracing::tracing::info; -use std::{ - pin::Pin, - task::{ready, Context, Poll}, -}; use tracing::error; use crate::network::DiscV5ExEx; diff --git a/examples/exex/discv5/src/main.rs b/examples/exex/discv5/src/main.rs index 2374326050b7a..c3c41986c09a4 100644 --- a/examples/exex/discv5/src/main.rs +++ b/examples/exex/discv5/src/main.rs @@ -1,5 +1,4 @@ use clap::Parser; - use exex::ExEx; use network::{cli_ext::Discv5ArgsExt, DiscV5ExEx}; use reth_node_ethereum::EthereumNode; diff --git a/examples/exex/discv5/src/network/mod.rs b/examples/exex/discv5/src/network/mod.rs index 41f57bffc478a..e66e631da474c 100644 --- a/examples/exex/discv5/src/network/mod.rs +++ b/examples/exex/discv5/src/network/mod.rs @@ -1,16 +1,17 @@ #![allow(dead_code)] -use discv5::{enr::secp256k1::rand, Enr, Event, ListenConfig}; -use reth::network::config::SecretKey; -use reth_chainspec::net::NodeRecord; -use reth_discv5::{enr::EnrCombinedKeyWrapper, Config, Discv5}; -use reth_tracing::tracing::info; use std::{ future::Future, net::SocketAddr, pin::Pin, task::{ready, Context, Poll}, }; + +use discv5::{enr::secp256k1::rand, Enr, Event, ListenConfig}; +use reth::network::config::SecretKey; +use reth_chainspec::net::NodeRecord; +use reth_discv5::{enr::EnrCombinedKeyWrapper, Config, Discv5}; +use reth_tracing::tracing::info; use tokio::sync::mpsc; pub(crate) mod cli_ext; @@ -75,9 +76,10 @@ impl Future for DiscV5ExEx { #[cfg(test)] mod tests { - use crate::network::DiscV5ExEx; use tracing::info; + use crate::network::DiscV5ExEx; + #[tokio::test] async fn can_establish_discv5_session_with_peer() { reth_tracing::init_test_tracing(); diff --git a/examples/exex/in-memory-state/src/main.rs b/examples/exex/in-memory-state/src/main.rs index c56cdcf5044b4..ad7c4c873312d 100644 --- a/examples/exex/in-memory-state/src/main.rs +++ b/examples/exex/in-memory-state/src/main.rs @@ -1,16 +1,17 @@ #![warn(unused_crate_dependencies)] -use reth_execution_types::ExecutionOutcome; -use reth_exex::{ExExContext, ExExEvent, ExExNotification}; -use reth_node_api::FullNodeComponents; -use reth_node_ethereum::EthereumNode; -use reth_tracing::tracing::info; use std::{ future::Future, pin::Pin, task::{ready, Context, Poll}, }; +use reth_execution_types::ExecutionOutcome; +use reth_exex::{ExExContext, ExExEvent, ExExNotification}; +use reth_node_api::FullNodeComponents; +use reth_node_ethereum::EthereumNode; +use reth_tracing::tracing::info; + /// An ExEx that keeps track of the entire state in memory struct InMemoryStateExEx { /// The context of the ExEx @@ -73,11 +74,12 @@ fn main() -> eyre::Result<()> { #[cfg(test)] mod tests { + use std::pin::pin; + use reth::revm::db::BundleState; use reth_execution_types::{Chain, ExecutionOutcome}; use reth_exex_test_utils::{test_exex_context, PollOnce}; use reth_testing_utils::generators::{self, random_block, random_receipt}; - use std::pin::pin; #[tokio::test] async fn test_exex() -> eyre::Result<()> { diff --git a/examples/exex/minimal/src/main.rs b/examples/exex/minimal/src/main.rs index cb7af242e65d4..03005a09bfac3 100644 --- a/examples/exex/minimal/src/main.rs +++ b/examples/exex/minimal/src/main.rs @@ -54,9 +54,10 @@ fn main() -> eyre::Result<()> { #[cfg(test)] mod tests { + use std::pin::pin; + use reth_execution_types::{Chain, ExecutionOutcome}; use reth_exex_test_utils::{test_exex_context, PollOnce}; - use std::pin::pin; #[tokio::test] async fn test_exex() -> eyre::Result<()> { diff --git a/examples/exex/rollup/src/execution.rs b/examples/exex/rollup/src/execution.rs index cc5b716bdc092..d85a6db18566d 100644 --- a/examples/exex/rollup/src/execution.rs +++ b/examples/exex/rollup/src/execution.rs @@ -1,4 +1,3 @@ -use crate::{db::Database, RollupContract, CHAIN_ID, CHAIN_SPEC}; use alloy_consensus::{Blob, SidecarCoder, SimpleCoder}; use alloy_rlp::Decodable as _; use eyre::OptionExt; @@ -21,6 +20,8 @@ use reth_revm::{ }; use reth_tracing::tracing::debug; +use crate::{db::Database, RollupContract, CHAIN_ID, CHAIN_SPEC}; + /// Execute a rollup block and return (block with recovered senders)[BlockWithSenders], (bundle /// state)[BundleState] and list of (receipts)[Receipt]. pub async fn execute_block( diff --git a/examples/exex/rollup/src/main.rs b/examples/exex/rollup/src/main.rs index 0bac98cd77451..7efc055c19799 100644 --- a/examples/exex/rollup/src/main.rs +++ b/examples/exex/rollup/src/main.rs @@ -4,6 +4,8 @@ //! The rollup contract accepts blocks of transactions and deposits of ETH and is deployed on //! Holesky at [ROLLUP_CONTRACT_ADDRESS], see . +use std::sync::Arc; + use alloy_genesis::Genesis; use alloy_sol_types::{sol, SolEventInterface, SolInterface}; use db::Database; @@ -17,7 +19,6 @@ use reth_node_ethereum::EthereumNode; use reth_primitives::{address, Address, SealedBlockWithSenders, TransactionSigned, U256}; use reth_tracing::tracing::{error, info}; use rusqlite::Connection; -use std::sync::Arc; mod db; mod execution; diff --git a/examples/node-custom-rpc/src/main.rs b/examples/node-custom-rpc/src/main.rs index 08b27d3ac4a67..36a22a2e14e59 100644 --- a/examples/node-custom-rpc/src/main.rs +++ b/examples/node-custom-rpc/src/main.rs @@ -83,10 +83,11 @@ where #[cfg(test)] mod tests { - use super::*; use jsonrpsee::{http_client::HttpClientBuilder, server::ServerBuilder}; use reth_transaction_pool::noop::NoopTransactionPool; + use super::*; + #[tokio::test(flavor = "multi_thread")] async fn test_call_transaction_count_http() { let server_addr = start_server().await; diff --git a/examples/polygon-p2p/src/chain_cfg.rs b/examples/polygon-p2p/src/chain_cfg.rs index b178d13499d74..6c18e75bed2c8 100644 --- a/examples/polygon-p2p/src/chain_cfg.rs +++ b/examples/polygon-p2p/src/chain_cfg.rs @@ -1,9 +1,9 @@ +use std::{collections::BTreeMap, sync::Arc}; + use reth_chainspec::{BaseFeeParams, Chain, ChainSpec, ForkCondition, Hardfork}; use reth_discv4::NodeRecord; use reth_primitives::{b256, Head, B256}; -use std::{collections::BTreeMap, sync::Arc}; - const SHANGAI_BLOCK: u64 = 50523000; pub(crate) fn polygon_chain_spec() -> Arc { diff --git a/examples/polygon-p2p/src/main.rs b/examples/polygon-p2p/src/main.rs index acfa3d82b1d49..50d4deca911c8 100644 --- a/examples/polygon-p2p/src/main.rs +++ b/examples/polygon-p2p/src/main.rs @@ -9,6 +9,11 @@ //! This launch the regular reth node overriding the engine api payload builder with our custom. //! //! Credits to: +use std::{ + net::{Ipv4Addr, SocketAddr}, + time::Duration, +}; + use chain_cfg::{boot_nodes, head, polygon_chain_spec}; use reth_discv4::Discv4ConfigBuilder; use reth_network::{ @@ -20,10 +25,6 @@ use reth_tracing::{ Tracer, }; use secp256k1::{rand, SecretKey}; -use std::{ - net::{Ipv4Addr, SocketAddr}, - time::Duration, -}; use tokio_stream::StreamExt; pub mod chain_cfg; diff --git a/examples/rpc-db/src/main.rs b/examples/rpc-db/src/main.rs index 90447790561fd..3695ebe354cc7 100644 --- a/examples/rpc-db/src/main.rs +++ b/examples/rpc-db/src/main.rs @@ -12,29 +12,28 @@ //! cast rpc myrpcExt_customMethod //! ``` +use std::{path::Path, sync::Arc}; + +// Configuring the network parts, ideally also wouldn't need to think about this. +use myrpc_ext::{MyRpcExt, MyRpcExtApiServer}; +// Bringing up the RPC +use reth::rpc::builder::{ + RethRpcModule, RpcModuleBuilder, RpcServerConfig, TransportRpcModuleConfig, +}; use reth::{ + blockchain_tree::noop::NoopBlockchainTree, providers::{ providers::{BlockchainProvider, StaticFileProvider}, + test_utils::TestCanonStateSubscriptions, ProviderFactory, }, + tasks::TokioTaskExecutor, utils::open_db_read_only, }; use reth_chainspec::ChainSpecBuilder; use reth_db::mdbx::DatabaseArguments; use reth_db_api::models::ClientVersion; - -// Bringing up the RPC -use reth::rpc::builder::{ - RethRpcModule, RpcModuleBuilder, RpcServerConfig, TransportRpcModuleConfig, -}; -// Configuring the network parts, ideally also wouldn't need to think about this. -use myrpc_ext::{MyRpcExt, MyRpcExtApiServer}; -use reth::{ - blockchain_tree::noop::NoopBlockchainTree, providers::test_utils::TestCanonStateSubscriptions, - tasks::TokioTaskExecutor, -}; use reth_node_ethereum::EthEvmConfig; -use std::{path::Path, sync::Arc}; // Custom rpc extension pub mod myrpc_ext; diff --git a/examples/rpc-db/src/myrpc_ext.rs b/examples/rpc-db/src/myrpc_ext.rs index d1898b81cb15f..ca7ce0f04d597 100644 --- a/examples/rpc-db/src/myrpc_ext.rs +++ b/examples/rpc-db/src/myrpc_ext.rs @@ -1,9 +1,7 @@ // Reth block related imports -use reth::{primitives::Block, providers::BlockReaderIdExt}; - // Rpc related imports use jsonrpsee::proc_macros::rpc; -use reth::rpc::eth::error::EthResult; +use reth::{primitives::Block, providers::BlockReaderIdExt, rpc::eth::error::EthResult}; /// trait interface for a custom rpc namespace: `MyRpc` /// diff --git a/examples/stateful-precompile/src/main.rs b/examples/stateful-precompile/src/main.rs index 8eaecb29ac73b..b6979ef585589 100644 --- a/examples/stateful-precompile/src/main.rs +++ b/examples/stateful-precompile/src/main.rs @@ -2,6 +2,8 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] +use std::{collections::HashMap, sync::Arc}; + use alloy_genesis::Genesis; use parking_lot::RwLock; use reth::{ @@ -28,7 +30,6 @@ use reth_primitives::{ }; use reth_tracing::{RethTracer, Tracer}; use schnellru::{ByLength, LruMap}; -use std::{collections::HashMap, sync::Arc}; /// A cache for precompile inputs / outputs. /// diff --git a/rustfmt.toml b/rustfmt.toml index 68c3c93033d4f..7c315bdfadc4e 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -9,3 +9,4 @@ trailing_semicolon = false use_field_init_shorthand = true format_code_in_doc_comments = true doc_comment_code_block_width = 100 +group_imports = "StdExternalCrate" diff --git a/testing/ef-tests/src/assert.rs b/testing/ef-tests/src/assert.rs index 9f1f83e001ae9..ee5c14fc8027c 100644 --- a/testing/ef-tests/src/assert.rs +++ b/testing/ef-tests/src/assert.rs @@ -1,8 +1,9 @@ //! Various assertion helpers. -use crate::Error; use std::fmt::Debug; +use crate::Error; + /// A helper like `assert_eq!` that instead returns `Err(Error::Assertion)` on failure. pub fn assert_equal(left: T, right: T, msg: &str) -> Result<(), Error> where diff --git a/testing/ef-tests/src/case.rs b/testing/ef-tests/src/case.rs index 7258dafb22aac..0c319fed91ad4 100644 --- a/testing/ef-tests/src/case.rs +++ b/testing/ef-tests/src/case.rs @@ -1,11 +1,12 @@ //! Test case definitions -use crate::result::{CaseResult, Error}; use std::{ fmt::Debug, path::{Path, PathBuf}, }; +use crate::result::{CaseResult, Error}; + /// A single test case, capable of loading a JSON description of itself and running it. /// /// See for test specs. diff --git a/testing/ef-tests/src/cases/blockchain_test.rs b/testing/ef-tests/src/cases/blockchain_test.rs index 87c3b8df1d8fb..ce3cd832b7cc4 100644 --- a/testing/ef-tests/src/cases/blockchain_test.rs +++ b/testing/ef-tests/src/cases/blockchain_test.rs @@ -1,9 +1,7 @@ //! Test runners for `BlockchainTests` in -use crate::{ - models::{BlockchainTest, ForkSpec}, - Case, Error, Suite, -}; +use std::{collections::BTreeMap, fs, path::Path, sync::Arc}; + use alloy_rlp::Decodable; use rayon::iter::{ParallelBridge, ParallelIterator}; use reth_db::test_utils::{create_test_rw_db, create_test_static_files_dir}; @@ -13,7 +11,11 @@ use reth_provider::{ HashingWriter, ProviderFactory, }; use reth_stages::{stages::ExecutionStage, ExecInput, Stage}; -use std::{collections::BTreeMap, fs, path::Path, sync::Arc}; + +use crate::{ + models::{BlockchainTest, ForkSpec}, + Case, Error, Suite, +}; /// A handler for the blockchain test suite. #[derive(Debug)] diff --git a/testing/ef-tests/src/models.rs b/testing/ef-tests/src/models.rs index 2c580dc54ea85..2fd1b01efcae1 100644 --- a/testing/ef-tests/src/models.rs +++ b/testing/ef-tests/src/models.rs @@ -1,6 +1,7 @@ //! Shared models for -use crate::{assert::assert_equal, Error}; +use std::{collections::BTreeMap, ops::Deref}; + use reth_chainspec::{ChainSpec, ChainSpecBuilder}; use reth_db::tables; use reth_db_api::{ @@ -12,7 +13,8 @@ use reth_primitives::{ SealedHeader, StorageEntry, Withdrawals, B256, B64, U256, }; use serde::Deserialize; -use std::{collections::BTreeMap, ops::Deref}; + +use crate::{assert::assert_equal, Error}; /// The definition of a blockchain test. #[derive(Debug, PartialEq, Eq, Deserialize)] diff --git a/testing/ef-tests/src/result.rs b/testing/ef-tests/src/result.rs index da967325a2ad1..ba73be632a95b 100644 --- a/testing/ef-tests/src/result.rs +++ b/testing/ef-tests/src/result.rs @@ -1,11 +1,13 @@ //! Test results and errors -use crate::Case; +use std::path::{Path, PathBuf}; + use reth_db::DatabaseError; use reth_provider::ProviderError; -use std::path::{Path, PathBuf}; use thiserror::Error; +use crate::Case; + /// Test errors /// /// # Note diff --git a/testing/ef-tests/src/suite.rs b/testing/ef-tests/src/suite.rs index b26e129945bc2..61f2865156c23 100644 --- a/testing/ef-tests/src/suite.rs +++ b/testing/ef-tests/src/suite.rs @@ -1,11 +1,13 @@ //! Abstractions for groups of tests. +use std::path::{Path, PathBuf}; + +use walkdir::{DirEntry, WalkDir}; + use crate::{ case::{Case, Cases}, result::assert_tests_pass, }; -use std::path::{Path, PathBuf}; -use walkdir::{DirEntry, WalkDir}; /// A collection of tests. pub trait Suite { diff --git a/testing/testing-utils/src/generators.rs b/testing/testing-utils/src/generators.rs index 4ef65043f6022..c3af927414a8e 100644 --- a/testing/testing-utils/src/generators.rs +++ b/testing/testing-utils/src/generators.rs @@ -1,5 +1,12 @@ //! Generators for different data structures like block headers, block bodies and ranges of those. +use std::{ + cmp::{max, min}, + collections::{hash_map::DefaultHasher, BTreeMap}, + hash::Hasher, + ops::{Range, RangeInclusive}, +}; + pub use rand::Rng; use rand::{ distributions::uniform::SampleRange, rngs::StdRng, seq::SliceRandom, thread_rng, SeedableRng, @@ -9,12 +16,6 @@ use reth_primitives::{ SealedHeader, StorageEntry, Transaction, TransactionSigned, TxKind, TxLegacy, B256, U256, }; use secp256k1::{Keypair, Secp256k1}; -use std::{ - cmp::{max, min}, - collections::{hash_map::DefaultHasher, BTreeMap}, - hash::Hasher, - ops::{Range, RangeInclusive}, -}; /// Returns a random number generator that can be seeded using the `SEED` environment variable. /// @@ -385,10 +386,12 @@ pub fn random_log(rng: &mut R, address: Option

, topics_count: O #[cfg(test)] mod tests { - use super::*; - use reth_primitives::{hex, public_key_to_address, AccessList, Signature, TxEip1559}; use std::str::FromStr; + use reth_primitives::{hex, public_key_to_address, AccessList, Signature, TxEip1559}; + + use super::*; + #[test] fn test_sign_message() { let secp = Secp256k1::new(); diff --git a/testing/testing-utils/src/genesis_allocator.rs b/testing/testing-utils/src/genesis_allocator.rs index a146401f04a12..0de230cef2eff 100644 --- a/testing/testing-utils/src/genesis_allocator.rs +++ b/testing/testing-utils/src/genesis_allocator.rs @@ -1,16 +1,17 @@ //! Helps create a custom genesis alloc by making it easy to add funded accounts with known //! signers to the genesis block. +use std::{ + collections::{hash_map::Entry, BTreeMap, HashMap}, + fmt, +}; + use alloy_genesis::GenesisAccount; use reth_primitives::{public_key_to_address, Address, Bytes, B256, U256}; use secp256k1::{ rand::{thread_rng, RngCore}, Keypair, Secp256k1, }; -use std::{ - collections::{hash_map::Entry, BTreeMap, HashMap}, - fmt, -}; /// This helps create a custom genesis alloc by making it easy to add funded accounts with known /// signers to the genesis block.