mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore(sdk): enable referencing network type via FullNodeComponents::Network (#9921)
This commit is contained in:
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -7338,7 +7338,6 @@ dependencies = [
|
||||
"reth-evm-ethereum",
|
||||
"reth-exex-types",
|
||||
"reth-metrics",
|
||||
"reth-network",
|
||||
"reth-node-api",
|
||||
"reth-node-core",
|
||||
"reth-payload-builder",
|
||||
@ -7995,7 +7994,6 @@ dependencies = [
|
||||
"parking_lot 0.12.3",
|
||||
"reth-evm",
|
||||
"reth-evm-optimism",
|
||||
"reth-network",
|
||||
"reth-network-api",
|
||||
"reth-node-api",
|
||||
"reth-primitives",
|
||||
@ -8265,6 +8263,7 @@ dependencies = [
|
||||
"reth-evm-ethereum",
|
||||
"reth-network-api",
|
||||
"reth-network-peers",
|
||||
"reth-network-types",
|
||||
"reth-node-api",
|
||||
"reth-primitives",
|
||||
"reth-provider",
|
||||
|
||||
@ -127,7 +127,7 @@ pub mod tasks {
|
||||
/// Re-exported from `reth_network`.
|
||||
pub mod network {
|
||||
pub use reth_network::*;
|
||||
pub use reth_network_api::{noop, NetworkInfo, PeerKind, Peers, PeersInfo};
|
||||
pub use reth_network_api::{noop, NetworkInfo, Peers, PeersHandleProvider, PeersInfo};
|
||||
}
|
||||
|
||||
/// Re-exported from `reth_transaction_pool`.
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
//! P2P Debugging tool
|
||||
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
use backon::{ConstantBuilder, Retryable};
|
||||
use clap::{Parser, Subcommand};
|
||||
use reth_chainspec::ChainSpec;
|
||||
@ -15,7 +17,6 @@ use reth_node_core::{
|
||||
utils::get_single_header,
|
||||
};
|
||||
use reth_primitives::BlockHashOrNumber;
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
/// `reth p2p` command
|
||||
#[derive(Debug, Parser)]
|
||||
|
||||
@ -6,6 +6,7 @@ use node::NodeTestContext;
|
||||
use reth::{
|
||||
args::{DiscoveryArgs, NetworkArgs, RpcServerArgs},
|
||||
builder::{NodeBuilder, NodeConfig, NodeHandle},
|
||||
network::PeersHandleProvider,
|
||||
rpc::api::eth::{helpers::AddDevSigners, FullEthApiServer},
|
||||
tasks::TaskManager,
|
||||
};
|
||||
@ -13,7 +14,7 @@ use reth_chainspec::ChainSpec;
|
||||
use reth_db::{test_utils::TempDatabase, DatabaseEnv};
|
||||
use reth_node_builder::{
|
||||
components::NodeComponentsBuilder, rpc::EthApiBuilderProvider, FullNodeTypesAdapter, Node,
|
||||
NodeAdapter, NodeAddOns, RethFullAdapter,
|
||||
NodeAdapter, NodeAddOns, NodeComponents, RethFullAdapter,
|
||||
};
|
||||
use reth_provider::providers::BlockchainProvider;
|
||||
use tracing::{span, Level};
|
||||
@ -50,6 +51,7 @@ pub async fn setup<N>(
|
||||
) -> eyre::Result<(Vec<NodeHelperType<N, N::AddOns>>, TaskManager, Wallet)>
|
||||
where
|
||||
N: Default + Node<TmpNodeAdapter<N>>,
|
||||
<<N::ComponentsBuilder as NodeComponentsBuilder<TmpNodeAdapter<N>>>::Components as NodeComponents<TmpNodeAdapter<N>>>::Network: PeersHandleProvider,
|
||||
<N::AddOns as NodeAddOns<Adapter<N>>>::EthApi:
|
||||
FullEthApiServer + AddDevSigners + EthApiBuilderProvider<Adapter<N>>,
|
||||
{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use futures_util::StreamExt;
|
||||
use reth::{
|
||||
network::{NetworkEvent, NetworkEvents, NetworkHandle, PeersHandleProvider, PeersInfo},
|
||||
network::{NetworkEvent, NetworkEvents, PeersHandleProvider, PeersInfo},
|
||||
rpc::types::PeerId,
|
||||
};
|
||||
use reth_network_peers::NodeRecord;
|
||||
@ -9,14 +9,17 @@ use reth_tracing::tracing::info;
|
||||
|
||||
/// Helper for network operations
|
||||
#[derive(Debug)]
|
||||
pub struct NetworkTestContext {
|
||||
pub struct NetworkTestContext<Network> {
|
||||
network_events: EventStream<NetworkEvent>,
|
||||
network: NetworkHandle,
|
||||
network: Network,
|
||||
}
|
||||
|
||||
impl NetworkTestContext {
|
||||
impl<Network> NetworkTestContext<Network>
|
||||
where
|
||||
Network: NetworkEvents + PeersInfo + PeersHandleProvider,
|
||||
{
|
||||
/// Creates a new network helper
|
||||
pub fn new(network: NetworkHandle) -> Self {
|
||||
pub fn new(network: Network) -> Self {
|
||||
let network_events = network.event_listener();
|
||||
Self { network_events, network }
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ use futures_util::Future;
|
||||
use reth::{
|
||||
api::{BuiltPayload, EngineTypes, FullNodeComponents, PayloadBuilderAttributes},
|
||||
builder::FullNode,
|
||||
network::PeersHandleProvider,
|
||||
payload::PayloadTypes,
|
||||
providers::{BlockReader, BlockReaderIdExt, CanonStateSubscriptions, StageCheckpointReader},
|
||||
rpc::{
|
||||
@ -35,7 +36,7 @@ where
|
||||
/// Context for testing payload-related features.
|
||||
pub payload: PayloadTestContext<Node::Engine>,
|
||||
/// Context for testing network functionalities.
|
||||
pub network: NetworkTestContext,
|
||||
pub network: NetworkTestContext<Node::Network>,
|
||||
/// Context for testing the Engine API.
|
||||
pub engine_api: EngineApiTestContext<Node::Engine>,
|
||||
/// Context for testing RPC features.
|
||||
@ -45,6 +46,7 @@ where
|
||||
impl<Node, AddOns> NodeTestContext<Node, AddOns>
|
||||
where
|
||||
Node: FullNodeComponents,
|
||||
Node::Network: PeersHandleProvider,
|
||||
AddOns: NodeAddOns<Node>,
|
||||
{
|
||||
/// Creates a new test node
|
||||
|
||||
@ -17,7 +17,6 @@ reth-config.workspace = true
|
||||
reth-evm.workspace = true
|
||||
reth-exex-types.workspace = true
|
||||
reth-metrics.workspace = true
|
||||
reth-network.workspace = true
|
||||
reth-node-api.workspace = true
|
||||
reth-node-core.workspace = true
|
||||
reth-payload-builder.workspace = true
|
||||
|
||||
@ -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<Node: FullNodeComponents> {
|
||||
/// The current head of the blockchain at launch.
|
||||
@ -69,7 +71,7 @@ impl<Node: FullNodeComponents> ExExContext<Node> {
|
||||
}
|
||||
|
||||
/// Returns the handle to the network
|
||||
pub fn network(&self) -> &reth_network::NetworkHandle {
|
||||
pub fn network(&self) -> &Node::Network {
|
||||
self.components.network()
|
||||
}
|
||||
|
||||
|
||||
@ -26,9 +26,7 @@ pub use peers::{
|
||||
addr::PeerAddr,
|
||||
handle::PeersHandle,
|
||||
kind::PeerKind,
|
||||
reputation::{
|
||||
is_banned_reputation, ReputationChange, ReputationChangeOutcome, DEFAULT_REPUTATION,
|
||||
},
|
||||
reputation::{is_banned_reputation, ReputationChangeOutcome, DEFAULT_REPUTATION},
|
||||
state::PeerConnectionState,
|
||||
ConnectionsConfig, Peer, PeerCommand, PeersConfig,
|
||||
};
|
||||
|
||||
@ -7,7 +7,7 @@ use reth_db_api::{
|
||||
database_metrics::{DatabaseMetadata, DatabaseMetrics},
|
||||
};
|
||||
use reth_evm::execute::BlockExecutorProvider;
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_network::FullNetwork;
|
||||
use reth_payload_builder::PayloadBuilderHandle;
|
||||
use reth_provider::FullProvider;
|
||||
use reth_tasks::TaskExecutor;
|
||||
@ -126,6 +126,9 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
|
||||
/// The type that knows how to execute blocks.
|
||||
type Executor: BlockExecutorProvider;
|
||||
|
||||
/// Network API.
|
||||
type Network: FullNetwork;
|
||||
|
||||
/// Returns the transaction pool of the node.
|
||||
fn pool(&self) -> &Self::Pool;
|
||||
|
||||
@ -139,12 +142,12 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
|
||||
fn provider(&self) -> &Self::Provider;
|
||||
|
||||
/// Returns the handle to the network
|
||||
fn network(&self) -> &NetworkHandle;
|
||||
fn network(&self) -> &Self::Network;
|
||||
|
||||
/// Returns the handle to the payload builder service.
|
||||
fn payload_builder(&self) -> &PayloadBuilderHandle<Self::Engine>;
|
||||
|
||||
/// Returns the task executor.
|
||||
/// Returns handle to runtime.
|
||||
fn task_executor(&self) -> &TaskExecutor;
|
||||
}
|
||||
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
use std::{fmt, future::Future, marker::PhantomData};
|
||||
|
||||
use reth_exex::ExExContext;
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_node_api::{FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypes};
|
||||
use reth_node_core::{
|
||||
node_config::NodeConfig,
|
||||
@ -103,6 +102,7 @@ impl<T: FullNodeTypes, C: NodeComponents<T>> FullNodeComponents for NodeAdapter<
|
||||
type Pool = C::Pool;
|
||||
type Evm = C::Evm;
|
||||
type Executor = C::Executor;
|
||||
type Network = C::Network;
|
||||
|
||||
fn pool(&self) -> &Self::Pool {
|
||||
self.components.pool()
|
||||
@ -120,7 +120,7 @@ impl<T: FullNodeTypes, C: NodeComponents<T>> FullNodeComponents for NodeAdapter<
|
||||
&self.provider
|
||||
}
|
||||
|
||||
fn network(&self) -> &NetworkHandle {
|
||||
fn network(&self) -> &Self::Network {
|
||||
self.components.network()
|
||||
}
|
||||
|
||||
|
||||
@ -7,19 +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::*;
|
||||
pub use network::*;
|
||||
pub use payload::*;
|
||||
pub use pool::*;
|
||||
use reth_consensus::Consensus;
|
||||
use reth_evm::execute::BlockExecutorProvider;
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_payload_builder::PayloadBuilderHandle;
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
|
||||
mod builder;
|
||||
mod consensus;
|
||||
mod execute;
|
||||
@ -27,6 +14,21 @@ mod network;
|
||||
mod payload;
|
||||
mod pool;
|
||||
|
||||
pub use builder::*;
|
||||
pub use consensus::*;
|
||||
pub use execute::*;
|
||||
pub use network::*;
|
||||
pub use payload::*;
|
||||
pub use pool::*;
|
||||
|
||||
use reth_consensus::Consensus;
|
||||
use reth_evm::execute::BlockExecutorProvider;
|
||||
use reth_network::{FullNetwork, NetworkHandle};
|
||||
use reth_payload_builder::PayloadBuilderHandle;
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
|
||||
use crate::{ConfigureEvm, FullNodeTypes};
|
||||
|
||||
/// An abstraction over the components of a node, consisting of:
|
||||
/// - evm and executor
|
||||
/// - transaction pool
|
||||
@ -45,6 +47,9 @@ pub trait NodeComponents<NodeTypes: FullNodeTypes>: Clone + Unpin + Send + Sync
|
||||
/// The consensus type of the node.
|
||||
type Consensus: Consensus + Clone + Unpin + 'static;
|
||||
|
||||
/// Network API.
|
||||
type Network: FullNetwork;
|
||||
|
||||
/// Returns the transaction pool of the node.
|
||||
fn pool(&self) -> &Self::Pool;
|
||||
|
||||
@ -58,7 +63,7 @@ pub trait NodeComponents<NodeTypes: FullNodeTypes>: Clone + Unpin + Send + Sync
|
||||
fn consensus(&self) -> &Self::Consensus;
|
||||
|
||||
/// Returns the handle to the network
|
||||
fn network(&self) -> &NetworkHandle;
|
||||
fn network(&self) -> &Self::Network;
|
||||
|
||||
/// Returns the handle to the payload builder service.
|
||||
fn payload_builder(&self) -> &PayloadBuilderHandle<NodeTypes::Engine>;
|
||||
@ -96,6 +101,7 @@ where
|
||||
type Evm = EVM;
|
||||
type Executor = Executor;
|
||||
type Consensus = Cons;
|
||||
type Network = NetworkHandle;
|
||||
|
||||
fn pool(&self) -> &Self::Pool {
|
||||
&self.transaction_pool
|
||||
@ -113,7 +119,7 @@ where
|
||||
&self.consensus
|
||||
}
|
||||
|
||||
fn network(&self) -> &NetworkHandle {
|
||||
fn network(&self) -> &Self::Network {
|
||||
&self.network
|
||||
}
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ use reth_blockchain_tree::{noop::NoopBlockchainTree, BlockchainTreeConfig};
|
||||
use reth_consensus_debug_client::{DebugConsensusClient, EtherscanBlockProvider, RpcBlockProvider};
|
||||
use reth_engine_util::EngineMessageStreamExt;
|
||||
use reth_exex::ExExManagerHandle;
|
||||
use reth_network::{BlockDownloaderProvider, NetworkEvents, NetworkHandle};
|
||||
use reth_network::{BlockDownloaderProvider, NetworkEvents};
|
||||
use reth_node_api::{FullNodeComponents, FullNodeTypes, NodeAddOns};
|
||||
use reth_node_core::{
|
||||
dirs::{ChainPath, DataDirPath},
|
||||
@ -49,7 +49,7 @@ pub type EthApiBuilderCtx<N> = reth_rpc_eth_types::EthApiBuilderCtx<
|
||||
<N as FullNodeTypes>::Provider,
|
||||
<N as FullNodeComponents>::Pool,
|
||||
<N as FullNodeComponents>::Evm,
|
||||
NetworkHandle,
|
||||
<N as FullNodeComponents>::Network,
|
||||
TaskExecutor,
|
||||
<N as FullNodeTypes>::Provider,
|
||||
>;
|
||||
|
||||
@ -4,7 +4,6 @@ pub use reth_node_api::{FullNodeTypes, NodeTypes};
|
||||
use std::{marker::PhantomData, sync::Arc};
|
||||
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_node_api::FullNodeComponents;
|
||||
use reth_node_core::{
|
||||
dirs::{ChainPath, DataDirPath},
|
||||
@ -91,7 +90,7 @@ pub struct FullNode<Node: FullNodeComponents, AddOns: NodeAddOns<Node>> {
|
||||
/// The node's transaction pool.
|
||||
pub pool: Node::Pool,
|
||||
/// Handle to the node's network.
|
||||
pub network: NetworkHandle,
|
||||
pub network: Node::Network,
|
||||
/// Provider to interact with the node's database
|
||||
pub provider: Node::Provider,
|
||||
/// Handle to the node's payload builder service.
|
||||
|
||||
@ -6,7 +6,6 @@ use std::{
|
||||
};
|
||||
|
||||
use futures::TryFutureExt;
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_node_api::{BuilderProvider, FullNodeComponents};
|
||||
use reth_node_core::{
|
||||
node_config::NodeConfig,
|
||||
@ -161,7 +160,7 @@ pub struct RpcRegistry<Node: FullNodeComponents, EthApi> {
|
||||
pub(crate) registry: RpcRegistryInner<
|
||||
Node::Provider,
|
||||
Node::Pool,
|
||||
NetworkHandle,
|
||||
Node::Network,
|
||||
TaskExecutor,
|
||||
Node::Provider,
|
||||
EthApi,
|
||||
@ -172,7 +171,7 @@ impl<Node: FullNodeComponents, EthApi> Deref for RpcRegistry<Node, EthApi> {
|
||||
type Target = RpcRegistryInner<
|
||||
Node::Provider,
|
||||
Node::Pool,
|
||||
NetworkHandle,
|
||||
Node::Network,
|
||||
TaskExecutor,
|
||||
Node::Provider,
|
||||
EthApi,
|
||||
@ -241,7 +240,7 @@ impl<'a, Node: FullNodeComponents, EthApi> RpcContext<'a, Node, EthApi> {
|
||||
}
|
||||
|
||||
/// Returns the handle to the network
|
||||
pub fn network(&self) -> &NetworkHandle {
|
||||
pub fn network(&self) -> &Node::Network {
|
||||
self.node.network()
|
||||
}
|
||||
|
||||
|
||||
@ -26,7 +26,6 @@ reth-transaction-pool.workspace = true
|
||||
reth-rpc.workspace = true
|
||||
reth-node-api.workspace = true
|
||||
reth-network-api.workspace = true
|
||||
reth-network.workspace = true
|
||||
|
||||
# ethereum
|
||||
alloy-primitives.workspace = true
|
||||
|
||||
@ -12,7 +12,6 @@ use std::{fmt, sync::Arc};
|
||||
use alloy_primitives::U256;
|
||||
use derive_more::Deref;
|
||||
use reth_evm::ConfigureEvm;
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_network_api::NetworkInfo;
|
||||
use reth_node_api::{BuilderProvider, FullNodeComponents, FullNodeTypes};
|
||||
use reth_provider::{
|
||||
@ -40,7 +39,7 @@ use crate::OpEthApiError;
|
||||
pub type EthApiNodeBackend<N> = EthApiInner<
|
||||
<N as FullNodeTypes>::Provider,
|
||||
<N as FullNodeComponents>::Pool,
|
||||
NetworkHandle,
|
||||
<N as FullNodeComponents>::Network,
|
||||
<N as FullNodeComponents>::Evm,
|
||||
>;
|
||||
|
||||
@ -49,7 +48,7 @@ pub type EthApiBuilderCtx<N> = reth_rpc_eth_types::EthApiBuilderCtx<
|
||||
<N as FullNodeTypes>::Provider,
|
||||
<N as FullNodeComponents>::Pool,
|
||||
<N as FullNodeComponents>::Evm,
|
||||
NetworkHandle,
|
||||
<N as FullNodeComponents>::Network,
|
||||
TaskExecutor,
|
||||
<N as FullNodeTypes>::Provider,
|
||||
>;
|
||||
|
||||
@ -33,6 +33,7 @@ reth-evm.workspace = true
|
||||
reth-rpc-eth-types.workspace = true
|
||||
reth-rpc-server-types.workspace = true
|
||||
reth-node-api.workspace = true
|
||||
reth-network-types.workspace = true
|
||||
|
||||
# eth
|
||||
alloy-dyn-abi.workspace = true
|
||||
|
||||
@ -4,8 +4,9 @@ use alloy_genesis::ChainConfig;
|
||||
use async_trait::async_trait;
|
||||
use jsonrpsee::core::RpcResult;
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_network_api::{NetworkInfo, PeerKind, Peers};
|
||||
use reth_network_api::{NetworkInfo, Peers};
|
||||
use reth_network_peers::{id2pk, AnyNode, NodeRecord};
|
||||
use reth_network_types::PeerKind;
|
||||
use reth_primitives::EthereumHardfork;
|
||||
use reth_rpc_api::AdminApiServer;
|
||||
use reth_rpc_server_types::ToRpcResult;
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
//!
|
||||
//! This launch a regular reth node with a custom rlpx subprotocol.
|
||||
|
||||
mod subprotocol;
|
||||
|
||||
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
|
||||
|
||||
use reth::builder::NodeHandle;
|
||||
@ -28,8 +30,6 @@ use subprotocol::{
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
use tracing::info;
|
||||
|
||||
mod subprotocol;
|
||||
|
||||
fn main() -> eyre::Result<()> {
|
||||
reth::cli::Cli::parse_args().run(|builder, _args| async move {
|
||||
// launch the node
|
||||
|
||||
Reference in New Issue
Block a user