diff --git a/crates/net/network-api/Cargo.toml b/crates/net/network-api/Cargo.toml index 31c93a076..0769c5dae 100644 --- a/crates/net/network-api/Cargo.toml +++ b/crates/net/network-api/Cargo.toml @@ -25,4 +25,3 @@ tokio = { workspace = true, features = ["sync"] } [features] default = ["serde"] serde = ["dep:serde"] -test-utils = [] diff --git a/crates/net/network-api/src/lib.rs b/crates/net/network-api/src/lib.rs index fb1a92761..f880fe745 100644 --- a/crates/net/network-api/src/lib.rs +++ b/crates/net/network-api/src/lib.rs @@ -32,9 +32,8 @@ pub mod error; /// Reputation score pub mod reputation; -#[cfg(feature = "test-utils")] -/// Implementation of network traits for testing purposes. -pub mod test_utils; +/// Implementation of network traits for that does nothing. +pub mod noop; /// Provides general purpose information about the network. #[async_trait] diff --git a/crates/net/network-api/src/test_utils.rs b/crates/net/network-api/src/noop.rs similarity index 91% rename from crates/net/network-api/src/test_utils.rs rename to crates/net/network-api/src/noop.rs index f914138b9..9a5309993 100644 --- a/crates/net/network-api/src/test_utils.rs +++ b/crates/net/network-api/src/noop.rs @@ -1,3 +1,8 @@ +//! A network implementation that does nothing. +//! +//! This is useful for wiring components together that don't require network but still need to be +//! generic over it. + use crate::{ NetworkError, NetworkInfo, PeerKind, Peers, PeersInfo, Reputation, ReputationChangeKind, }; @@ -11,6 +16,7 @@ use std::net::{IpAddr, SocketAddr}; /// /// Intended for testing purposes where network is not used. #[derive(Debug, Clone, Default)] +#[non_exhaustive] pub struct NoopNetwork; #[async_trait] diff --git a/crates/rpc/rpc-builder/Cargo.toml b/crates/rpc/rpc-builder/Cargo.toml index d0dfab2ca..b4159bfb6 100644 --- a/crates/rpc/rpc-builder/Cargo.toml +++ b/crates/rpc/rpc-builder/Cargo.toml @@ -39,7 +39,7 @@ reth-tracing = { path = "../../tracing" } reth-rpc-api = { path = "../rpc-api", features = ["client"] } reth-transaction-pool = { workspace = true, features = ["test-utils"] } reth-provider = { workspace = true, features = ["test-utils"] } -reth-network-api = { workspace = true, features = ["test-utils"] } +reth-network-api = { workspace = true } reth-interfaces = { workspace = true, features = ["test-utils"] } reth-beacon-consensus = { path = "../../consensus/beacon" } reth-payload-builder = { workspace = true, features = ["test-utils"] } diff --git a/crates/rpc/rpc-builder/tests/it/utils.rs b/crates/rpc/rpc-builder/tests/it/utils.rs index 1281a8ae0..e7c4a4eb8 100644 --- a/crates/rpc/rpc-builder/tests/it/utils.rs +++ b/crates/rpc/rpc-builder/tests/it/utils.rs @@ -1,5 +1,5 @@ use reth_beacon_consensus::BeaconConsensusEngineHandle; -use reth_network_api::test_utils::NoopNetwork; +use reth_network_api::noop::NoopNetwork; use reth_payload_builder::test_utils::spawn_test_payload_service; use reth_primitives::MAINNET; use reth_provider::test_utils::{NoopProvider, TestCanonStateSubscriptions}; @@ -101,7 +101,7 @@ pub fn test_rpc_builder() -> RpcModuleBuilder< RpcModuleBuilder::default() .with_provider(NoopProvider::default()) .with_pool(testing_pool()) - .with_network(NoopNetwork) + .with_network(NoopNetwork::default()) .with_executor(TokioTaskExecutor::default()) .with_events(TestCanonStateSubscriptions::default()) } diff --git a/crates/rpc/rpc/Cargo.toml b/crates/rpc/rpc/Cargo.toml index c3003e496..11111cafb 100644 --- a/crates/rpc/rpc/Cargo.toml +++ b/crates/rpc/rpc/Cargo.toml @@ -18,7 +18,7 @@ reth-rlp = { workspace = true } reth-rpc-types = { workspace = true } reth-provider = { workspace = true, features = ["test-utils"] } reth-transaction-pool = { workspace = true, features = ["test-utils"] } -reth-network-api = { workspace = true, features = ["test-utils"] } +reth-network-api = { workspace = true } reth-rpc-engine-api = { path = "../rpc-engine-api" } reth-revm = { path = "../../revm" } reth-tasks = { workspace = true } diff --git a/crates/rpc/rpc/src/eth/api/server.rs b/crates/rpc/rpc/src/eth/api/server.rs index acca88323..b1643e896 100644 --- a/crates/rpc/rpc/src/eth/api/server.rs +++ b/crates/rpc/rpc/src/eth/api/server.rs @@ -396,7 +396,7 @@ mod tests { }; use jsonrpsee::types::error::INVALID_PARAMS_CODE; use reth_interfaces::test_utils::{generators, generators::Rng}; - use reth_network_api::test_utils::NoopNetwork; + use reth_network_api::noop::NoopNetwork; use reth_primitives::{ basefee::calculate_next_block_base_fee, Block, BlockNumberOrTag, Header, TransactionSigned, H256, U256, @@ -424,7 +424,7 @@ mod tests { EthApi::new( provider.clone(), testing_pool(), - NoopNetwork, + NoopNetwork::default(), cache.clone(), GasPriceOracle::new(provider, Default::default(), cache), ) diff --git a/crates/rpc/rpc/src/eth/api/transactions.rs b/crates/rpc/rpc/src/eth/api/transactions.rs index fe4eca4be..1cbd5df2b 100644 --- a/crates/rpc/rpc/src/eth/api/transactions.rs +++ b/crates/rpc/rpc/src/eth/api/transactions.rs @@ -892,7 +892,7 @@ mod tests { eth::{cache::EthStateCache, gas_oracle::GasPriceOracle}, EthApi, }; - use reth_network_api::test_utils::NoopNetwork; + use reth_network_api::noop::NoopNetwork; use reth_primitives::{hex_literal::hex, Bytes}; use reth_provider::test_utils::NoopProvider; use reth_transaction_pool::{test_utils::testing_pool, TransactionPool}; @@ -900,7 +900,7 @@ mod tests { #[tokio::test] async fn send_raw_transaction() { let noop_provider = NoopProvider::default(); - let noop_network_provider = NoopNetwork; + let noop_network_provider = NoopNetwork::default(); let pool = testing_pool(); diff --git a/examples/Cargo.toml b/examples/Cargo.toml index ed1a18eb6..c77a2d687 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -17,8 +17,8 @@ reth-rpc-types = { workspace = true } reth-revm = { workspace = true } reth-blockchain-tree = { workspace = true } reth-beacon-consensus = { workspace = true } -reth-network-api = { workspace = true, features = ["test-utils"] } -reth-transaction-pool = { workspace = true, features = ["test-utils"] } +reth-network-api = { workspace = true } +reth-transaction-pool = { workspace = true } reth-tasks = { workspace = true } diff --git a/examples/db-access.rs b/examples/db-access.rs index fee4239a1..5b8aec77f 100644 --- a/examples/db-access.rs +++ b/examples/db-access.rs @@ -18,7 +18,7 @@ fn main() -> eyre::Result<()> { // Opens a RO handle to the database file. // TODO: Should be able to do `ProviderFactory::new_with_db_path_ro(...)` instead of // doing in 2 steps. - let db = open_db_read_only(&Path::new(&std::env::var("RETH_DB_PATH")?), None)?; + let db = open_db_read_only(Path::new(&std::env::var("RETH_DB_PATH")?), None)?; // Instantiate a provider factory for Ethereum mainnet using the provided DB. // TODO: Should the DB version include the spec so that you do not need to specify it here? @@ -197,7 +197,7 @@ fn receipts_provider_example eyre::Result<()> { // 1. Setup the DB - let db = Arc::new(open_db_read_only(&Path::new(&std::env::var("RETH_DB_PATH")?), None)?); + let db = Arc::new(open_db_read_only(Path::new(&std::env::var("RETH_DB_PATH")?), None)?); let spec = Arc::new(ChainSpecBuilder::mainnet().build()); let factory = ProviderFactory::new(db.clone(), spec.clone()); @@ -47,20 +46,18 @@ async fn main() -> eyre::Result<()> { let tree = ShareableBlockchainTree::new(BlockchainTree::new( externals, - canon_state_notification_sender.clone(), + canon_state_notification_sender, tree_config, )?); BlockchainProvider::new(factory, tree)? }; - let noop_pool = testing_pool(); let rpc_builder = RpcModuleBuilder::default() .with_provider(provider) - // Rest is just defaults - // TODO: How do we make this easier to configure? - .with_pool(noop_pool) - .with_network(NoopNetwork) + // Rest is just noops that do nothing + .with_pool(NoopTransactionPool::default()) + .with_network(NoopNetwork::default()) .with_executor(TokioTaskExecutor::default()) .with_events(TestCanonStateSubscriptions::default());