mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add non feature gated noop block reader (#9261)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -7485,6 +7485,7 @@ dependencies = [
|
||||
"reth-network-types",
|
||||
"reth-primitives",
|
||||
"reth-provider",
|
||||
"reth-storage-api",
|
||||
"reth-tasks",
|
||||
"reth-tokio-util",
|
||||
"reth-tracing",
|
||||
|
||||
@ -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
|
||||
@ -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"
|
||||
|
||||
@ -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};
|
||||
@ -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`]
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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;
|
||||
@ -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.
|
||||
///
|
||||
@ -955,7 +955,7 @@ where
|
||||
|
||||
impl<C> Future for NetworkManager<C>
|
||||
where
|
||||
C: BlockReader + Unpin,
|
||||
C: BlockNumReader + Unpin,
|
||||
{
|
||||
type Output = ();
|
||||
|
||||
|
||||
@ -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},
|
||||
|
||||
@ -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,
|
||||
@ -287,7 +287,7 @@ where
|
||||
|
||||
impl<C> Stream for Swarm<C>
|
||||
where
|
||||
C: BlockReader + Unpin,
|
||||
C: BlockNumReader + Unpin,
|
||||
{
|
||||
type Item = SwarmEvent;
|
||||
|
||||
|
||||
@ -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::{
|
||||
|
||||
@ -51,3 +51,5 @@ pub use trie::*;
|
||||
|
||||
mod withdrawals;
|
||||
pub use withdrawals::*;
|
||||
|
||||
pub mod noop;
|
||||
|
||||
44
crates/storage/storage-api/src/noop.rs
Normal file
44
crates/storage/storage-api/src/noop.rs
Normal file
@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user