mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-29 09:08:05 -05:00
chore: move FullNodeTypes to node-api (#7425)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -6124,6 +6124,7 @@ dependencies = [
|
||||
name = "reth-node-api"
|
||||
version = "0.2.0-beta.4"
|
||||
dependencies = [
|
||||
"reth-db",
|
||||
"reth-evm",
|
||||
"reth-primitives",
|
||||
"reth-provider",
|
||||
|
||||
@@ -16,6 +16,7 @@ reth-primitives.workspace = true
|
||||
reth-rpc-types.workspace = true
|
||||
reth-evm.workspace = true
|
||||
reth-provider.workspace = true
|
||||
reth-db.workspace = true
|
||||
|
||||
# misc
|
||||
serde.workspace = true
|
||||
|
||||
@@ -25,7 +25,7 @@ pub use reth_evm::{ConfigureEvm, ConfigureEvmEnv};
|
||||
pub mod primitives;
|
||||
|
||||
pub mod node;
|
||||
pub use node::NodeTypes;
|
||||
pub use node::*;
|
||||
|
||||
// re-export for convenience
|
||||
pub use reth_provider::FullProvider;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
//! Traits for configuring a node
|
||||
|
||||
use crate::{primitives::NodePrimitives, ConfigureEvm, EngineTypes};
|
||||
use reth_db::database::Database;
|
||||
use reth_provider::FullProvider;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
/// The type that configures the essential types of an ethereum like node.
|
||||
///
|
||||
@@ -17,3 +20,55 @@ pub trait NodeTypes: Send + Sync + 'static {
|
||||
/// Returns the node's evm config.
|
||||
fn evm_config(&self) -> Self::Evm;
|
||||
}
|
||||
|
||||
/// A helper type that is downstream of the [NodeTypes] trait and adds stateful components to the
|
||||
/// node.
|
||||
pub trait FullNodeTypes: NodeTypes + 'static {
|
||||
/// Underlying database type.
|
||||
type DB: Database + Clone + 'static;
|
||||
/// The provider type used to interact with the node.
|
||||
type Provider: FullProvider<Self::DB>;
|
||||
}
|
||||
|
||||
/// An adapter type that adds the builtin provider type to the user configured node types.
|
||||
#[derive(Debug)]
|
||||
pub struct FullNodeTypesAdapter<Types, DB, Provider> {
|
||||
/// An instance of the user configured node types.
|
||||
pub types: Types,
|
||||
/// The database type used by the node.
|
||||
pub db: PhantomData<DB>,
|
||||
/// The provider type used by the node.
|
||||
pub provider: PhantomData<Provider>,
|
||||
}
|
||||
|
||||
impl<Types, DB, Provider> FullNodeTypesAdapter<Types, DB, Provider> {
|
||||
/// Create a new adapter from the given node types.
|
||||
pub fn new(types: Types) -> Self {
|
||||
Self { types, db: Default::default(), provider: Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<Types, DB, Provider> NodeTypes for FullNodeTypesAdapter<Types, DB, Provider>
|
||||
where
|
||||
Types: NodeTypes,
|
||||
DB: Send + Sync + 'static,
|
||||
Provider: Send + Sync + 'static,
|
||||
{
|
||||
type Primitives = Types::Primitives;
|
||||
type Engine = Types::Engine;
|
||||
type Evm = Types::Evm;
|
||||
|
||||
fn evm_config(&self) -> Self::Evm {
|
||||
self.types.evm_config()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Types, DB, Provider> FullNodeTypes for FullNodeTypesAdapter<Types, DB, Provider>
|
||||
where
|
||||
Types: NodeTypes,
|
||||
Provider: FullProvider<DB>,
|
||||
DB: Database + Clone + 'static,
|
||||
{
|
||||
type DB = DB;
|
||||
type Provider = Provider;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::{
|
||||
},
|
||||
exex::{BoxedLaunchExEx, ExExContext},
|
||||
hooks::NodeHooks,
|
||||
node::{FullNode, FullNodeTypes, FullNodeTypesAdapter},
|
||||
node::FullNode,
|
||||
rpc::{RethRpcServerHandles, RpcContext, RpcHooks},
|
||||
Node, NodeHandle,
|
||||
};
|
||||
@@ -30,7 +30,7 @@ use reth_db::{
|
||||
};
|
||||
use reth_interfaces::p2p::either::EitherDownloader;
|
||||
use reth_network::{NetworkBuilder, NetworkConfig, NetworkEvents, NetworkHandle};
|
||||
use reth_node_api::NodeTypes;
|
||||
use reth_node_api::{FullNodeTypes, FullNodeTypesAdapter, NodeTypes};
|
||||
use reth_node_core::{
|
||||
cli::config::{PayloadBuilderConfig, RethRpcConfig, RethTransactionPoolConfig},
|
||||
dirs::{ChainPath, DataDirPath, MaybePlatformPath},
|
||||
|
||||
@@ -4,8 +4,7 @@ use crate::{
|
||||
components::{
|
||||
NetworkBuilder, NodeComponents, NodeComponentsBuilder, PayloadServiceBuilder, PoolBuilder,
|
||||
},
|
||||
node::FullNodeTypes,
|
||||
BuilderContext,
|
||||
BuilderContext, FullNodeTypes,
|
||||
};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//!
|
||||
//! Components depend on a fully type configured node: [FullNodeTypes](crate::node::FullNodeTypes).
|
||||
|
||||
use crate::node::FullNodeTypes;
|
||||
use crate::FullNodeTypes;
|
||||
pub use builder::*;
|
||||
pub use network::*;
|
||||
pub use payload::*;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Network component for the node builder.
|
||||
|
||||
use crate::{node::FullNodeTypes, BuilderContext};
|
||||
use crate::{BuilderContext, FullNodeTypes};
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
use std::future::Future;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Payload service component for the node builder.
|
||||
|
||||
use crate::{node::FullNodeTypes, BuilderContext};
|
||||
use crate::{BuilderContext, FullNodeTypes};
|
||||
use reth_payload_builder::PayloadBuilderHandle;
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
use std::future::Future;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Pool component for the node builder.
|
||||
use crate::{node::FullNodeTypes, BuilderContext};
|
||||
use crate::{BuilderContext, FullNodeTypes};
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
use std::future::Future;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! Traits for the builder
|
||||
|
||||
use crate::{components::NodeComponents, node::FullNodeTypes, BuilderContext};
|
||||
use crate::{components::NodeComponents, BuilderContext};
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_node_api::NodeTypes;
|
||||
use reth_node_api::{FullNodeTypes, NodeTypes};
|
||||
use reth_payload_builder::PayloadBuilderHandle;
|
||||
use reth_tasks::TaskExecutor;
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
use crate::{
|
||||
components::{ComponentsBuilder, FullNodeComponents},
|
||||
rpc::{RethRpcServerHandles, RpcRegistry},
|
||||
FullProvider,
|
||||
};
|
||||
use reth_db::database::Database;
|
||||
use reth_network::NetworkHandle;
|
||||
pub use reth_node_api::NodeTypes;
|
||||
use reth_node_core::{
|
||||
dirs::{ChainPath, DataDirPath},
|
||||
node_config::NodeConfig,
|
||||
@@ -18,7 +15,10 @@ use reth_payload_builder::PayloadBuilderHandle;
|
||||
use reth_primitives::ChainSpec;
|
||||
use reth_provider::ChainSpecProvider;
|
||||
use reth_tasks::TaskExecutor;
|
||||
use std::{marker::PhantomData, sync::Arc};
|
||||
use std::sync::Arc;
|
||||
|
||||
// re-export the node api types
|
||||
pub use reth_node_api::{FullNodeTypes, NodeTypes};
|
||||
|
||||
/// A [Node] is a [NodeTypes] that comes with preconfigured components.
|
||||
///
|
||||
@@ -37,54 +37,6 @@ pub trait Node<N>: NodeTypes + Clone {
|
||||
) -> ComponentsBuilder<N, Self::PoolBuilder, Self::PayloadBuilder, Self::NetworkBuilder>;
|
||||
}
|
||||
|
||||
/// A helper type that is downstream of the node types and adds stateful components to the node.
|
||||
pub trait FullNodeTypes: NodeTypes + 'static {
|
||||
/// Underlying database type.
|
||||
type DB: Database + Clone + 'static;
|
||||
/// The provider type used to interact with the node.
|
||||
type Provider: FullProvider<Self::DB>;
|
||||
}
|
||||
|
||||
/// An adapter type that adds the builtin provider type to the user configured node types.
|
||||
#[derive(Debug)]
|
||||
pub struct FullNodeTypesAdapter<Types, DB, Provider> {
|
||||
pub(crate) types: Types,
|
||||
_db: PhantomData<DB>,
|
||||
_provider: PhantomData<Provider>,
|
||||
}
|
||||
|
||||
impl<Types, DB, Provider> FullNodeTypesAdapter<Types, DB, Provider> {
|
||||
/// Create a new adapter from the given node types.
|
||||
pub fn new(types: Types) -> Self {
|
||||
Self { types, _db: Default::default(), _provider: Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<Types, DB, Provider> NodeTypes for FullNodeTypesAdapter<Types, DB, Provider>
|
||||
where
|
||||
Types: NodeTypes,
|
||||
DB: Send + Sync + 'static,
|
||||
Provider: Send + Sync + 'static,
|
||||
{
|
||||
type Primitives = Types::Primitives;
|
||||
type Engine = Types::Engine;
|
||||
type Evm = Types::Evm;
|
||||
|
||||
fn evm_config(&self) -> Self::Evm {
|
||||
self.types.evm_config()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Types, DB, Provider> FullNodeTypes for FullNodeTypesAdapter<Types, DB, Provider>
|
||||
where
|
||||
Types: NodeTypes,
|
||||
Provider: FullProvider<DB>,
|
||||
DB: Database + Clone + 'static,
|
||||
{
|
||||
type DB = DB;
|
||||
type Provider = Provider;
|
||||
}
|
||||
|
||||
/// The launched node with all components including RPC handlers.
|
||||
///
|
||||
/// This can be used to interact with the launched node.
|
||||
|
||||
Reference in New Issue
Block a user