Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add non feature gated noop block reader #9261

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions crates/net/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ reth-eth-wire.workspace = true
reth-ecies.workspace = true
reth-tasks.workspace = true
reth-transaction-pool.workspace = true
reth-provider.workspace = true
reth-storage-api.workspace = true
reth-provider = { workspace = true, optional = true }
reth-tokio-util.workspace = true
reth-consensus.workspace = true
reth-network-peers.workspace = true
Expand Down Expand Up @@ -98,7 +99,7 @@ criterion = { workspace = true, features = ["async_tokio", "html_reports"] }
default = ["serde"]
geth-tests = []
serde = ["dep:serde", "dep:humantime-serde", "secp256k1/serde", "enr/serde", "dep:serde_json", "reth-network-types/serde"]
test-utils = ["reth-provider/test-utils", "dep:tempfile", "reth-transaction-pool/test-utils", "reth-network-types/test-utils"]
test-utils = ["dep:reth-provider", "reth-provider?/test-utils", "dep:tempfile", "reth-transaction-pool/test-utils", "reth-network-types/test-utils"]

[[bench]]
name = "bench"
Expand Down
7 changes: 3 additions & 4 deletions crates/net/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use reth_eth_wire::{HelloMessage, HelloMessageWithProtocols, Status};
use reth_network_peers::{mainnet_nodes, pk2id, sepolia_nodes, PeerId, TrustedPeer};
use reth_network_types::{PeersConfig, SessionsConfig};
use reth_primitives::{ForkFilter, Head};
use reth_provider::{BlockReader, HeaderProvider};
use reth_storage_api::{BlockReader, HeaderProvider};
use reth_tasks::{TaskSpawner, TokioTaskExecutor};
use secp256k1::SECP256K1;
use std::{collections::HashSet, net::SocketAddr, sync::Arc};
Expand Down Expand Up @@ -443,11 +443,10 @@ impl NetworkConfigBuilder {

/// Convenience function for creating a [`NetworkConfig`] with a noop provider that does
/// nothing.
#[cfg(any(test, feature = "test-utils"))]
pub fn build_with_noop_provider(
self,
) -> NetworkConfig<reth_provider::test_utils::NoopProvider> {
self.build(reth_provider::test_utils::NoopProvider::default())
) -> NetworkConfig<reth_storage_api::noop::NoopBlockReader> {
self.build(Default::default())
}

/// Consumes the type and creates the actual [`NetworkConfig`]
Expand Down
2 changes: 1 addition & 1 deletion crates/net/network/src/eth_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use reth_eth_wire::{
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 reth_storage_api::{BlockReader, HeaderProvider, ReceiptProvider};
use std::{
future::Future,
pin::Pin,
Expand Down
6 changes: 3 additions & 3 deletions crates/net/network/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use reth_metrics::common::mpsc::UnboundedMeteredSender;
use reth_network_api::{EthProtocolInfo, NetworkStatus, PeerInfo, ReputationChangeKind};
use reth_network_peers::{NodeRecord, PeerId};
use reth_primitives::ForkId;
use reth_provider::{BlockNumReader, BlockReader};
use reth_storage_api::BlockNumReader;
use reth_tasks::shutdown::GracefulShutdown;
use reth_tokio_util::EventSender;
use secp256k1::SecretKey;
Expand Down Expand Up @@ -926,7 +926,7 @@ where

impl<C> NetworkManager<C>
where
C: BlockReader + Unpin,
C: BlockNumReader + Unpin,
{
/// Drives the [`NetworkManager`] future until a [`GracefulShutdown`] signal is received.
///
Expand Down Expand Up @@ -955,7 +955,7 @@ where

impl<C> Future for NetworkManager<C>
where
C: BlockReader + Unpin,
C: BlockNumReader + Unpin,
{
type Output = ();

Expand Down
2 changes: 1 addition & 1 deletion crates/net/network/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use reth_eth_wire::{
use reth_network_api::PeerKind;
use reth_network_peers::PeerId;
use reth_primitives::{ForkId, B256};
use reth_provider::BlockNumReader;
use reth_storage_api::BlockNumReader;
use std::{
collections::{HashMap, VecDeque},
net::{IpAddr, SocketAddr},
Expand Down
4 changes: 2 additions & 2 deletions crates/net/network/src/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use reth_eth_wire::{
EthVersion, Status,
};
use reth_network_peers::PeerId;
use reth_provider::{BlockNumReader, BlockReader};
use reth_storage_api::BlockNumReader;
use std::{
io,
net::SocketAddr,
Expand Down Expand Up @@ -287,7 +287,7 @@ where

impl<C> Stream for Swarm<C>
where
C: BlockReader + Unpin,
C: BlockNumReader + Unpin,
{
type Item = SwarmEvent;

Expand Down
5 changes: 2 additions & 3 deletions crates/net/network/src/test_utils/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ use reth_chainspec::MAINNET;
use reth_eth_wire::{protocol::Protocol, DisconnectReason, HelloMessageWithProtocols};
use reth_network_api::{NetworkInfo, Peers};
use reth_network_peers::PeerId;
use reth_provider::{
test_utils::NoopProvider, BlockReader, BlockReaderIdExt, HeaderProvider, StateProviderFactory,
};
use reth_provider::test_utils::NoopProvider;
use reth_storage_api::{BlockReader, BlockReaderIdExt, HeaderProvider, StateProviderFactory};
use reth_tasks::TokioTaskExecutor;
use reth_tokio_util::EventStream;
use reth_transaction_pool::{
Expand Down
2 changes: 2 additions & 0 deletions crates/storage/storage-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ pub use trie::*;

mod withdrawals;
pub use withdrawals::*;

pub mod noop;
44 changes: 44 additions & 0 deletions crates/storage/storage-api/src/noop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//! Various noop implementations for traits.

use crate::{BlockHashReader, BlockNumReader};
use reth_chainspec::ChainInfo;
use reth_primitives::{BlockNumber, B256};
use reth_storage_errors::provider::ProviderResult;

/// Supports various api interfaces for testing purposes.
#[derive(Debug, Clone, Default, Copy)]
#[non_exhaustive]
pub struct NoopBlockReader;

/// Noop implementation for testing purposes
impl BlockHashReader for NoopBlockReader {
fn block_hash(&self, _number: u64) -> ProviderResult<Option<B256>> {
Ok(None)
}

fn canonical_hashes_range(
&self,
_start: BlockNumber,
_end: BlockNumber,
) -> ProviderResult<Vec<B256>> {
Ok(vec![])
}
}

impl BlockNumReader for NoopBlockReader {
fn chain_info(&self) -> ProviderResult<ChainInfo> {
Ok(ChainInfo::default())
}

fn best_block_number(&self) -> ProviderResult<BlockNumber> {
Ok(0)
}

fn last_block_number(&self) -> ProviderResult<BlockNumber> {
Ok(0)
}

fn block_number(&self, _hash: B256) -> ProviderResult<Option<BlockNumber>> {
Ok(None)
}
}
Loading