mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-24 06:37:57 -05:00
chore(node-api): move FullNodeComponents from builder (#7597)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
5
Cargo.lock
generated
5
Cargo.lock
generated
@@ -6816,7 +6816,11 @@ dependencies = [
|
||||
"reth-db",
|
||||
"reth-engine-primitives",
|
||||
"reth-evm",
|
||||
"reth-network",
|
||||
"reth-payload-builder",
|
||||
"reth-provider",
|
||||
"reth-tasks",
|
||||
"reth-transaction-pool",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6930,6 +6934,7 @@ dependencies = [
|
||||
"reth-evm-ethereum",
|
||||
"reth-exex",
|
||||
"reth-network",
|
||||
"reth-node-api",
|
||||
"reth-node-builder",
|
||||
"reth-payload-builder",
|
||||
"reth-provider",
|
||||
|
||||
@@ -39,6 +39,11 @@ pub mod payload {
|
||||
pub use reth_payload_validator::ExecutionPayloadValidator;
|
||||
}
|
||||
|
||||
/// Re-exported from `reth_node_api`.
|
||||
pub mod api {
|
||||
pub use reth_node_api::*;
|
||||
}
|
||||
|
||||
/// Re-exported from `reth_node_core`.
|
||||
pub mod core {
|
||||
pub use reth_node_core::*;
|
||||
|
||||
@@ -16,3 +16,7 @@ reth-evm.workspace = true
|
||||
reth-provider.workspace = true
|
||||
reth-db.workspace = true
|
||||
reth-engine-primitives.workspace = true
|
||||
reth-transaction-pool.workspace = true
|
||||
reth-network.workspace = true
|
||||
reth-payload-builder.workspace = true
|
||||
reth-tasks.workspace = true
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
|
||||
use crate::{primitives::NodePrimitives, ConfigureEvm, EngineTypes};
|
||||
use reth_db::database::Database;
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_payload_builder::PayloadBuilderHandle;
|
||||
use reth_provider::FullProvider;
|
||||
use reth_tasks::TaskExecutor;
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
/// The type that configures the essential types of an ethereum like node.
|
||||
@@ -72,3 +76,108 @@ where
|
||||
type DB = DB;
|
||||
type Provider = Provider;
|
||||
}
|
||||
|
||||
/// Encapsulates all types and components of the node.
|
||||
pub trait FullNodeComponents: FullNodeTypes + 'static {
|
||||
/// The transaction pool of the node.
|
||||
type Pool: TransactionPool;
|
||||
|
||||
/// Returns the transaction pool of the node.
|
||||
fn pool(&self) -> &Self::Pool;
|
||||
|
||||
/// Returns the provider of the node.
|
||||
fn provider(&self) -> &Self::Provider;
|
||||
|
||||
/// Returns the handle to the network
|
||||
fn network(&self) -> &NetworkHandle;
|
||||
|
||||
/// Returns the handle to the payload builder service.
|
||||
fn payload_builder(&self) -> &PayloadBuilderHandle<Self::Engine>;
|
||||
|
||||
/// Returns the task executor.
|
||||
fn task_executor(&self) -> &TaskExecutor;
|
||||
}
|
||||
|
||||
/// A type that encapsulates all the components of the node.
|
||||
#[derive(Debug)]
|
||||
pub struct FullNodeComponentsAdapter<Node: FullNodeTypes, Pool> {
|
||||
/// The EVM configuration of the node.
|
||||
pub evm_config: Node::Evm,
|
||||
/// The transaction pool of the node.
|
||||
pub pool: Pool,
|
||||
/// The network handle of the node.
|
||||
pub network: NetworkHandle,
|
||||
/// The provider of the node.
|
||||
pub provider: Node::Provider,
|
||||
/// The payload builder service handle of the node.
|
||||
pub payload_builder: PayloadBuilderHandle<Node::Engine>,
|
||||
/// The task executor of the node.
|
||||
pub executor: TaskExecutor,
|
||||
}
|
||||
|
||||
impl<Node, Pool> FullNodeTypes for FullNodeComponentsAdapter<Node, Pool>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
Pool: TransactionPool + 'static,
|
||||
{
|
||||
type DB = Node::DB;
|
||||
type Provider = Node::Provider;
|
||||
}
|
||||
|
||||
impl<Node, Pool> NodeTypes for FullNodeComponentsAdapter<Node, Pool>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
Pool: TransactionPool + 'static,
|
||||
{
|
||||
type Primitives = Node::Primitives;
|
||||
type Engine = Node::Engine;
|
||||
type Evm = Node::Evm;
|
||||
|
||||
fn evm_config(&self) -> Self::Evm {
|
||||
self.evm_config.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node, Pool> FullNodeComponents for FullNodeComponentsAdapter<Node, Pool>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
Pool: TransactionPool + 'static,
|
||||
{
|
||||
type Pool = Pool;
|
||||
|
||||
fn pool(&self) -> &Self::Pool {
|
||||
&self.pool
|
||||
}
|
||||
|
||||
fn provider(&self) -> &Self::Provider {
|
||||
&self.provider
|
||||
}
|
||||
|
||||
fn network(&self) -> &NetworkHandle {
|
||||
&self.network
|
||||
}
|
||||
|
||||
fn payload_builder(&self) -> &PayloadBuilderHandle<Self::Engine> {
|
||||
&self.payload_builder
|
||||
}
|
||||
|
||||
fn task_executor(&self) -> &TaskExecutor {
|
||||
&self.executor
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node: FullNodeTypes, Pool> Clone for FullNodeComponentsAdapter<Node, Pool>
|
||||
where
|
||||
Pool: Clone,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
evm_config: self.evm_config.clone(),
|
||||
pool: self.pool.clone(),
|
||||
network: self.network.clone(),
|
||||
provider: self.provider.clone(),
|
||||
payload_builder: self.payload_builder.clone(),
|
||||
executor: self.executor.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
#![allow(clippy::type_complexity, missing_debug_implementations)]
|
||||
|
||||
use crate::{
|
||||
components::{
|
||||
ComponentsBuilder, FullNodeComponents, FullNodeComponentsAdapter, NodeComponents,
|
||||
NodeComponentsBuilder, PoolBuilder,
|
||||
},
|
||||
components::{ComponentsBuilder, NodeComponents, NodeComponentsBuilder, PoolBuilder},
|
||||
exex::BoxedLaunchExEx,
|
||||
hooks::NodeHooks,
|
||||
node::FullNode,
|
||||
@@ -33,7 +30,9 @@ use reth_db::{
|
||||
use reth_exex::{ExExContext, ExExHandle, ExExManager};
|
||||
use reth_interfaces::p2p::either::EitherDownloader;
|
||||
use reth_network::{NetworkBuilder, NetworkConfig, NetworkEvents, NetworkHandle};
|
||||
use reth_node_api::{FullNodeTypes, FullNodeTypesAdapter, NodeTypes};
|
||||
use reth_node_api::{
|
||||
FullNodeComponents, FullNodeComponentsAdapter, FullNodeTypes, FullNodeTypesAdapter, NodeTypes,
|
||||
};
|
||||
use reth_node_core::{
|
||||
cli::config::{PayloadBuilderConfig, RethRpcConfig, RethTransactionPoolConfig},
|
||||
dirs::{ChainPath, DataDirPath, MaybePlatformPath},
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
//! A generic [NodeComponentsBuilder]
|
||||
|
||||
use crate::{
|
||||
components::{
|
||||
NetworkBuilder, NodeComponents, NodeComponentsBuilder, PayloadServiceBuilder, PoolBuilder,
|
||||
},
|
||||
components::{NetworkBuilder, NodeComponents, PayloadServiceBuilder, PoolBuilder},
|
||||
BuilderContext, FullNodeTypes,
|
||||
};
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
/// A generic, customizable [`NodeComponentsBuilder`].
|
||||
@@ -162,3 +161,40 @@ impl Default for ComponentsBuilder<(), (), (), ()> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A type that configures all the customizable components of the node and knows how to build them.
|
||||
///
|
||||
/// Implementors of this trait are responsible for building all the components of the node: See
|
||||
/// [NodeComponents].
|
||||
///
|
||||
/// The [ComponentsBuilder] is a generic implementation of this trait that can be used to customize
|
||||
/// certain components of the node using the builder pattern and defaults, e.g. Ethereum and
|
||||
/// Optimism.
|
||||
pub trait NodeComponentsBuilder<Node: FullNodeTypes> {
|
||||
/// The transaction pool to use.
|
||||
type Pool: TransactionPool + Unpin + 'static;
|
||||
|
||||
/// Builds the components of the node.
|
||||
fn build_components(
|
||||
self,
|
||||
context: &BuilderContext<Node>,
|
||||
) -> impl std::future::Future<Output = eyre::Result<NodeComponents<Node, Self::Pool>>> + Send;
|
||||
}
|
||||
|
||||
impl<Node, F, Fut, Pool> NodeComponentsBuilder<Node> for F
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
F: FnOnce(&BuilderContext<Node>) -> Fut + Send,
|
||||
Fut: std::future::Future<Output = eyre::Result<NodeComponents<Node, Pool>>> + Send,
|
||||
Pool: TransactionPool + Unpin + 'static,
|
||||
{
|
||||
type Pool = Pool;
|
||||
|
||||
fn build_components(
|
||||
self,
|
||||
ctx: &BuilderContext<Node>,
|
||||
) -> impl std::future::Future<Output = eyre::Result<NodeComponents<Node, Self::Pool>>> + Send
|
||||
{
|
||||
self(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,13 +14,11 @@ pub use payload::*;
|
||||
pub use pool::*;
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_payload_builder::PayloadBuilderHandle;
|
||||
pub use traits::*;
|
||||
|
||||
mod builder;
|
||||
mod network;
|
||||
mod payload;
|
||||
mod pool;
|
||||
mod traits;
|
||||
|
||||
/// All the components of the node.
|
||||
///
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
//! Traits for the builder
|
||||
|
||||
use crate::{components::NodeComponents, BuilderContext};
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_node_api::{FullNodeTypes, NodeTypes};
|
||||
use reth_payload_builder::PayloadBuilderHandle;
|
||||
use reth_tasks::TaskExecutor;
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
|
||||
/// Encapsulates all types and components of the node.
|
||||
pub trait FullNodeComponents: FullNodeTypes + 'static {
|
||||
/// The transaction pool of the node.
|
||||
type Pool: TransactionPool;
|
||||
|
||||
/// Returns the transaction pool of the node.
|
||||
fn pool(&self) -> &Self::Pool;
|
||||
|
||||
/// Returns the provider of the node.
|
||||
fn provider(&self) -> &Self::Provider;
|
||||
|
||||
/// Returns the handle to the network
|
||||
fn network(&self) -> &NetworkHandle;
|
||||
|
||||
/// Returns the handle to the payload builder service.
|
||||
fn payload_builder(&self) -> &PayloadBuilderHandle<Self::Engine>;
|
||||
|
||||
/// Returns the task executor.
|
||||
fn task_executor(&self) -> &TaskExecutor;
|
||||
}
|
||||
|
||||
/// A type that encapsulates all the components of the node.
|
||||
#[derive(Debug)]
|
||||
pub struct FullNodeComponentsAdapter<Node: FullNodeTypes, Pool> {
|
||||
pub(crate) evm_config: Node::Evm,
|
||||
pub(crate) pool: Pool,
|
||||
pub(crate) network: NetworkHandle,
|
||||
pub(crate) provider: Node::Provider,
|
||||
pub(crate) payload_builder: PayloadBuilderHandle<Node::Engine>,
|
||||
pub(crate) executor: TaskExecutor,
|
||||
}
|
||||
|
||||
impl<Node, Pool> FullNodeTypes for FullNodeComponentsAdapter<Node, Pool>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
Pool: TransactionPool + 'static,
|
||||
{
|
||||
type DB = Node::DB;
|
||||
type Provider = Node::Provider;
|
||||
}
|
||||
|
||||
impl<Node, Pool> NodeTypes for FullNodeComponentsAdapter<Node, Pool>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
Pool: TransactionPool + 'static,
|
||||
{
|
||||
type Primitives = Node::Primitives;
|
||||
type Engine = Node::Engine;
|
||||
type Evm = Node::Evm;
|
||||
|
||||
fn evm_config(&self) -> Self::Evm {
|
||||
self.evm_config.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node, Pool> FullNodeComponents for FullNodeComponentsAdapter<Node, Pool>
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
Pool: TransactionPool + 'static,
|
||||
{
|
||||
type Pool = Pool;
|
||||
|
||||
fn pool(&self) -> &Self::Pool {
|
||||
&self.pool
|
||||
}
|
||||
|
||||
fn provider(&self) -> &Self::Provider {
|
||||
&self.provider
|
||||
}
|
||||
|
||||
fn network(&self) -> &NetworkHandle {
|
||||
&self.network
|
||||
}
|
||||
|
||||
fn payload_builder(&self) -> &PayloadBuilderHandle<Self::Engine> {
|
||||
&self.payload_builder
|
||||
}
|
||||
|
||||
fn task_executor(&self) -> &TaskExecutor {
|
||||
&self.executor
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node: FullNodeTypes, Pool> Clone for FullNodeComponentsAdapter<Node, Pool>
|
||||
where
|
||||
Pool: Clone,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
evm_config: self.evm_config.clone(),
|
||||
pool: self.pool.clone(),
|
||||
network: self.network.clone(),
|
||||
provider: self.provider.clone(),
|
||||
payload_builder: self.payload_builder.clone(),
|
||||
executor: self.executor.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A type that configures all the customizable components of the node and knows how to build them.
|
||||
///
|
||||
/// Implementors of this trait are responsible for building all the components of the node: See
|
||||
/// [NodeComponents].
|
||||
///
|
||||
/// The [ComponentsBuilder](crate::components::builder::ComponentsBuilder) is a generic
|
||||
/// implementation of this trait that can be used to customize certain components of the node using
|
||||
/// the builder pattern and defaults, e.g. Ethereum and Optimism.
|
||||
pub trait NodeComponentsBuilder<Node: FullNodeTypes> {
|
||||
/// The transaction pool to use.
|
||||
type Pool: TransactionPool + Unpin + 'static;
|
||||
|
||||
/// Builds the components of the node.
|
||||
fn build_components(
|
||||
self,
|
||||
context: &BuilderContext<Node>,
|
||||
) -> impl std::future::Future<Output = eyre::Result<NodeComponents<Node, Self::Pool>>> + Send;
|
||||
}
|
||||
|
||||
impl<Node, F, Fut, Pool> NodeComponentsBuilder<Node> for F
|
||||
where
|
||||
Node: FullNodeTypes,
|
||||
F: FnOnce(&BuilderContext<Node>) -> Fut + Send,
|
||||
Fut: std::future::Future<Output = eyre::Result<NodeComponents<Node, Pool>>> + Send,
|
||||
Pool: TransactionPool + Unpin + 'static,
|
||||
{
|
||||
type Pool = Pool;
|
||||
|
||||
fn build_components(
|
||||
self,
|
||||
ctx: &BuilderContext<Node>,
|
||||
) -> impl std::future::Future<Output = eyre::Result<NodeComponents<Node, Self::Pool>>> + Send
|
||||
{
|
||||
self(ctx)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::{components::FullNodeComponents, node::FullNode};
|
||||
use crate::node::FullNode;
|
||||
use reth_node_api::FullNodeComponents;
|
||||
use reth_node_core::exit::NodeExitFuture;
|
||||
use std::fmt;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::{components::FullNodeComponents, node::FullNode};
|
||||
use crate::node::FullNode;
|
||||
use reth_node_api::FullNodeComponents;
|
||||
use std::fmt;
|
||||
|
||||
/// Container for all the configurable hook functions.
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
use crate::{
|
||||
components::{ComponentsBuilder, FullNodeComponents},
|
||||
components::ComponentsBuilder,
|
||||
rpc::{RethRpcServerHandles, RpcRegistry},
|
||||
};
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_node_api::FullNodeComponents;
|
||||
use reth_node_core::{
|
||||
dirs::{ChainPath, DataDirPath},
|
||||
node_config::NodeConfig,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! Builder support for rpc components.
|
||||
|
||||
use crate::components::FullNodeComponents;
|
||||
use futures::TryFutureExt;
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_node_api::FullNodeComponents;
|
||||
use reth_node_core::{
|
||||
cli::config::RethRpcConfig,
|
||||
node_config::NodeConfig,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use futures_util::StreamExt;
|
||||
use reth::{
|
||||
builder::{components::FullNodeComponents, FullNode, NodeBuilder, NodeHandle},
|
||||
api::FullNodeComponents,
|
||||
builder::{FullNode, NodeBuilder, NodeHandle},
|
||||
providers::CanonStateSubscriptions,
|
||||
rpc::eth::EthTransactions,
|
||||
tasks::TaskManager,
|
||||
@@ -55,7 +56,7 @@ async fn assert_chain_advances<Node: FullNodeComponents>(mut node: FullNode<Node
|
||||
fn custom_chain() -> Arc<ChainSpec> {
|
||||
let custom_genesis = r#"
|
||||
{
|
||||
|
||||
|
||||
"nonce": "0x42",
|
||||
"timestamp": "0x0",
|
||||
"extraData": "0x5343",
|
||||
|
||||
@@ -29,4 +29,6 @@ eyre.workspace = true
|
||||
[dev-dependencies]
|
||||
reth-db.workspace = true
|
||||
reth-exex.workspace = true
|
||||
reth-node-api.workspace = true
|
||||
|
||||
futures.workspace = true
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//! Node builder setup tests.
|
||||
|
||||
use reth_db::test_utils::create_test_rw_db;
|
||||
use reth_node_builder::{components::FullNodeComponents, NodeBuilder, NodeConfig};
|
||||
use reth_node_api::FullNodeComponents;
|
||||
use reth_node_builder::{NodeBuilder, NodeConfig};
|
||||
use reth_node_ethereum::node::EthereumNode;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//! Node builder setup tests.
|
||||
|
||||
use reth_db::test_utils::create_test_rw_db;
|
||||
use reth_node_builder::{components::FullNodeComponents, NodeBuilder, NodeConfig};
|
||||
use reth_node_api::FullNodeComponents;
|
||||
use reth_node_builder::{NodeBuilder, NodeConfig};
|
||||
use reth_node_optimism::node::OptimismNode;
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user