mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: move RPC launch to add-ons (#11532)
This commit is contained in:
21
Cargo.lock
generated
21
Cargo.lock
generated
@ -4464,7 +4464,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-targets 0.48.5",
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -7787,9 +7787,14 @@ dependencies = [
|
||||
name = "reth-node-api"
|
||||
version = "1.1.0"
|
||||
dependencies = [
|
||||
"alloy-rpc-types-engine",
|
||||
"eyre",
|
||||
"reth-beacon-consensus",
|
||||
"reth-consensus",
|
||||
"reth-engine-primitives",
|
||||
"reth-evm",
|
||||
"reth-network-api",
|
||||
"reth-node-core",
|
||||
"reth-node-types",
|
||||
"reth-payload-builder",
|
||||
"reth-payload-primitives",
|
||||
@ -9577,9 +9582,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustls-pki-types"
|
||||
version = "1.9.0"
|
||||
version = "1.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55"
|
||||
checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b"
|
||||
|
||||
[[package]]
|
||||
name = "rustls-platform-verifier"
|
||||
@ -9621,9 +9626,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.17"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6"
|
||||
checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248"
|
||||
|
||||
[[package]]
|
||||
name = "rusty-fork"
|
||||
@ -9660,9 +9665,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "scc"
|
||||
version = "2.2.1"
|
||||
version = "2.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "553f8299af7450cda9a52d3a370199904e7a46b5ffd1bef187c4a6af3bb6db69"
|
||||
checksum = "f2c1f7fc6deb21665a9060dfc7d271be784669295a31babdcd4dd2c79ae8cbfb"
|
||||
dependencies = [
|
||||
"sdd",
|
||||
]
|
||||
@ -11367,7 +11372,7 @@ version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
||||
dependencies = [
|
||||
"windows-sys 0.48.0",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@ -7,15 +7,13 @@ use reth::{
|
||||
args::{DiscoveryArgs, NetworkArgs, RpcServerArgs},
|
||||
builder::{NodeBuilder, NodeConfig, NodeHandle},
|
||||
network::PeersHandleProvider,
|
||||
rpc::api::eth::{helpers::AddDevSigners, FullEthApiServer},
|
||||
tasks::TaskManager,
|
||||
};
|
||||
use reth_chainspec::{EthChainSpec, EthereumHardforks};
|
||||
use reth_db::{test_utils::TempDatabase, DatabaseEnv};
|
||||
use reth_node_builder::{
|
||||
components::NodeComponentsBuilder, rpc::EthApiBuilderProvider, FullNodeTypesAdapter, Node,
|
||||
NodeAdapter, NodeAddOns, NodeComponents, NodeTypesWithDBAdapter, NodeTypesWithEngine,
|
||||
RethFullAdapter,
|
||||
components::NodeComponentsBuilder, rpc::RethRpcAddOns, FullNodeTypesAdapter, Node, NodeAdapter,
|
||||
NodeComponents, NodeTypesWithDBAdapter, NodeTypesWithEngine, RethFullAdapter,
|
||||
};
|
||||
use reth_provider::providers::BlockchainProvider;
|
||||
use tracing::{span, Level};
|
||||
@ -56,10 +54,7 @@ where
|
||||
TmpNodeAdapter<N>,
|
||||
Components: NodeComponents<TmpNodeAdapter<N>, Network: PeersHandleProvider>,
|
||||
>,
|
||||
N::AddOns: NodeAddOns<
|
||||
Adapter<N>,
|
||||
EthApi: FullEthApiServer + AddDevSigners + EthApiBuilderProvider<Adapter<N>>,
|
||||
>,
|
||||
N::AddOns: RethRpcAddOns<Adapter<N>>,
|
||||
{
|
||||
let tasks = TaskManager::current();
|
||||
let exec = tasks.executor();
|
||||
@ -115,7 +110,8 @@ type TmpNodeAdapter<N> = FullNodeTypesAdapter<
|
||||
BlockchainProvider<NodeTypesWithDBAdapter<N, TmpDB>>,
|
||||
>;
|
||||
|
||||
type Adapter<N> = NodeAdapter<
|
||||
/// Type alias for a `NodeAdapter`
|
||||
pub type Adapter<N> = NodeAdapter<
|
||||
RethFullAdapter<TmpDB, N>,
|
||||
<<N as Node<TmpNodeAdapter<N>>>::ComponentsBuilder as NodeComponentsBuilder<
|
||||
RethFullAdapter<TmpDB, N>,
|
||||
|
||||
@ -18,7 +18,7 @@ use reth::{
|
||||
},
|
||||
};
|
||||
use reth_chainspec::EthereumHardforks;
|
||||
use reth_node_builder::{NodeAddOns, NodeTypesWithEngine};
|
||||
use reth_node_builder::{rpc::RethRpcAddOns, NodeTypesWithEngine};
|
||||
use reth_stages_types::StageId;
|
||||
use tokio_stream::StreamExt;
|
||||
|
||||
@ -32,7 +32,7 @@ use crate::{
|
||||
pub struct NodeTestContext<Node, AddOns>
|
||||
where
|
||||
Node: FullNodeComponents,
|
||||
AddOns: NodeAddOns<Node>,
|
||||
AddOns: RethRpcAddOns<Node>,
|
||||
{
|
||||
/// The core structure representing the full node.
|
||||
pub inner: FullNode<Node, AddOns>,
|
||||
@ -52,7 +52,7 @@ where
|
||||
Node: FullNodeComponents,
|
||||
Node::Types: NodeTypesWithEngine<ChainSpec: EthereumHardforks, Engine = Engine>,
|
||||
Node::Network: PeersHandleProvider,
|
||||
AddOns: NodeAddOns<Node>,
|
||||
AddOns: RethRpcAddOns<Node>,
|
||||
{
|
||||
/// Creates a new test node
|
||||
pub async fn new(node: FullNode<Node, AddOns>) -> eyre::Result<Self> {
|
||||
@ -67,7 +67,7 @@ where
|
||||
canonical_stream: node.provider.canonical_state_stream(),
|
||||
_marker: PhantomData::<Engine>,
|
||||
},
|
||||
rpc: RpcTestContext { inner: node.rpc_registry },
|
||||
rpc: RpcTestContext { inner: node.add_ons_handle.rpc_registry },
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -11,14 +11,15 @@ use reth_ethereum_engine_primitives::{
|
||||
};
|
||||
use reth_evm_ethereum::execute::EthExecutorProvider;
|
||||
use reth_network::NetworkHandle;
|
||||
use reth_node_api::{ConfigureEvm, EngineValidator, FullNodeComponents, NodeAddOns};
|
||||
use reth_node_api::{ConfigureEvm, EngineValidator, FullNodeComponents, NodeTypesWithDB};
|
||||
use reth_node_builder::{
|
||||
components::{
|
||||
ComponentsBuilder, ConsensusBuilder, EngineValidatorBuilder, ExecutorBuilder,
|
||||
NetworkBuilder, PayloadServiceBuilder, PoolBuilder,
|
||||
},
|
||||
node::{FullNodeTypes, NodeTypes, NodeTypesWithEngine},
|
||||
BuilderContext, Node, PayloadBuilderConfig, PayloadTypes,
|
||||
rpc::RpcAddOns,
|
||||
BuilderContext, Node, NodeAdapter, NodeComponentsBuilder, PayloadBuilderConfig, PayloadTypes,
|
||||
};
|
||||
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
|
||||
use reth_primitives::Header;
|
||||
@ -77,17 +78,19 @@ impl NodeTypesWithEngine for EthereumNode {
|
||||
}
|
||||
|
||||
/// Add-ons w.r.t. l1 ethereum.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
#[non_exhaustive]
|
||||
pub struct EthereumAddOns;
|
||||
|
||||
impl<N: FullNodeComponents> NodeAddOns<N> for EthereumAddOns {
|
||||
type EthApi = EthApi<N::Provider, N::Pool, NetworkHandle, N::Evm>;
|
||||
}
|
||||
pub type EthereumAddOns<N> = RpcAddOns<
|
||||
N,
|
||||
EthApi<
|
||||
<N as FullNodeTypes>::Provider,
|
||||
<N as FullNodeComponents>::Pool,
|
||||
NetworkHandle,
|
||||
<N as FullNodeComponents>::Evm,
|
||||
>,
|
||||
>;
|
||||
|
||||
impl<Types, N> Node<N> for EthereumNode
|
||||
where
|
||||
Types: NodeTypesWithEngine<Engine = EthEngineTypes, ChainSpec = ChainSpec>,
|
||||
Types: NodeTypesWithDB + NodeTypesWithEngine<Engine = EthEngineTypes, ChainSpec = ChainSpec>,
|
||||
N: FullNodeTypes<Types = Types>,
|
||||
{
|
||||
type ComponentsBuilder = ComponentsBuilder<
|
||||
@ -100,7 +103,9 @@ where
|
||||
EthereumEngineValidatorBuilder,
|
||||
>;
|
||||
|
||||
type AddOns = EthereumAddOns;
|
||||
type AddOns = EthereumAddOns<
|
||||
NodeAdapter<N, <Self::ComponentsBuilder as NodeComponentsBuilder<N>>::Components>,
|
||||
>;
|
||||
|
||||
fn components_builder(&self) -> Self::ComponentsBuilder {
|
||||
Self::components()
|
||||
|
||||
@ -6,8 +6,10 @@ use futures::StreamExt;
|
||||
use reth::{args::DevArgs, core::rpc::eth::helpers::EthTransactions};
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_e2e_test_utils::setup;
|
||||
use reth_node_api::{FullNodeComponents, NodeAddOns};
|
||||
use reth_node_builder::{EngineNodeLauncher, FullNode, NodeBuilder, NodeConfig, NodeHandle};
|
||||
use reth_node_api::FullNodeComponents;
|
||||
use reth_node_builder::{
|
||||
rpc::RethRpcAddOns, EngineNodeLauncher, FullNode, NodeBuilder, NodeConfig, NodeHandle,
|
||||
};
|
||||
use reth_node_ethereum::{node::EthereumAddOns, EthereumNode};
|
||||
use reth_provider::{providers::BlockchainProvider2, CanonStateSubscriptions};
|
||||
use reth_tasks::TaskManager;
|
||||
@ -53,7 +55,7 @@ async fn can_run_dev_node_new_engine() -> eyre::Result<()> {
|
||||
async fn assert_chain_advances<N, AddOns>(node: FullNode<N, AddOns>)
|
||||
where
|
||||
N: FullNodeComponents<Provider: CanonStateSubscriptions>,
|
||||
AddOns: NodeAddOns<N, EthApi: EthTransactions>,
|
||||
AddOns: RethRpcAddOns<N, EthApi: EthTransactions>,
|
||||
{
|
||||
let mut notifications = node.provider.canonical_state_stream();
|
||||
|
||||
|
||||
@ -142,7 +142,9 @@ where
|
||||
TestConsensusBuilder,
|
||||
EthereumEngineValidatorBuilder,
|
||||
>;
|
||||
type AddOns = EthereumAddOns;
|
||||
type AddOns = EthereumAddOns<
|
||||
NodeAdapter<N, <Self::ComponentsBuilder as NodeComponentsBuilder<N>>::Components>,
|
||||
>;
|
||||
|
||||
fn components_builder(&self) -> Self::ComponentsBuilder {
|
||||
ComponentsBuilder::default()
|
||||
|
||||
@ -12,6 +12,8 @@ workspace = true
|
||||
|
||||
[dependencies]
|
||||
# reth
|
||||
reth-beacon-consensus.workspace = true
|
||||
reth-consensus.workspace = true
|
||||
reth-evm.workspace = true
|
||||
reth-provider.workspace = true
|
||||
reth-engine-primitives.workspace = true
|
||||
@ -23,3 +25,8 @@ reth-rpc-eth-api.workspace = true
|
||||
reth-network-api.workspace = true
|
||||
reth-node-types.workspace = true
|
||||
reth-primitives.workspace = true
|
||||
reth-node-core.workspace = true
|
||||
|
||||
alloy-rpc-types-engine.workspace = true
|
||||
|
||||
eyre.workspace = true
|
||||
@ -1,14 +1,18 @@
|
||||
//! Traits for configuring a node.
|
||||
|
||||
use std::marker::PhantomData;
|
||||
use std::{future::Future, marker::PhantomData};
|
||||
|
||||
use alloy_rpc_types_engine::JwtSecret;
|
||||
use reth_beacon_consensus::BeaconConsensusEngineHandle;
|
||||
use reth_consensus::Consensus;
|
||||
use reth_engine_primitives::EngineValidator;
|
||||
use reth_evm::execute::BlockExecutorProvider;
|
||||
use reth_network_api::FullNetwork;
|
||||
use reth_node_types::{NodeTypesWithDB, NodeTypesWithEngine};
|
||||
use reth_node_core::node_config::NodeConfig;
|
||||
use reth_node_types::{NodeTypes, NodeTypesWithDB, NodeTypesWithEngine};
|
||||
use reth_payload_builder::PayloadBuilderHandle;
|
||||
use reth_primitives::Header;
|
||||
use reth_provider::FullProvider;
|
||||
use reth_rpc_eth_api::EthApiTypes;
|
||||
use reth_tasks::TaskExecutor;
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
|
||||
@ -54,9 +58,15 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
|
||||
/// The type that knows how to execute blocks.
|
||||
type Executor: BlockExecutorProvider;
|
||||
|
||||
/// The consensus type of the node.
|
||||
type Consensus: Consensus + Clone + Unpin + 'static;
|
||||
|
||||
/// Network API.
|
||||
type Network: FullNetwork;
|
||||
|
||||
/// Validator for the engine API.
|
||||
type EngineValidator: EngineValidator<<Self::Types as NodeTypesWithEngine>::Engine>;
|
||||
|
||||
/// Returns the transaction pool of the node.
|
||||
fn pool(&self) -> &Self::Pool;
|
||||
|
||||
@ -66,8 +76,8 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
|
||||
/// Returns the node's executor type.
|
||||
fn block_executor(&self) -> &Self::Executor;
|
||||
|
||||
/// Returns the provider of the node.
|
||||
fn provider(&self) -> &Self::Provider;
|
||||
/// Returns the node's consensus type.
|
||||
fn consensus(&self) -> &Self::Consensus;
|
||||
|
||||
/// Returns the handle to the network
|
||||
fn network(&self) -> &Self::Network;
|
||||
@ -77,37 +87,46 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
|
||||
&self,
|
||||
) -> &PayloadBuilderHandle<<Self::Types as NodeTypesWithEngine>::Engine>;
|
||||
|
||||
/// Returns the engine validator.
|
||||
fn engine_validator(&self) -> &Self::EngineValidator;
|
||||
|
||||
/// Returns the provider of the node.
|
||||
fn provider(&self) -> &Self::Provider;
|
||||
|
||||
/// Returns handle to runtime.
|
||||
fn task_executor(&self) -> &TaskExecutor;
|
||||
}
|
||||
|
||||
/// Context passed to [`NodeAddOns::launch_add_ons`],
|
||||
#[derive(Debug)]
|
||||
pub struct AddOnsContext<'a, N: FullNodeComponents> {
|
||||
/// Node with all configured components.
|
||||
pub node: &'a N,
|
||||
/// Node configuration.
|
||||
pub config: &'a NodeConfig<<N::Types as NodeTypes>::ChainSpec>,
|
||||
/// Handle to the beacon consensus engine.
|
||||
pub beacon_engine_handle:
|
||||
&'a BeaconConsensusEngineHandle<<N::Types as NodeTypesWithEngine>::Engine>,
|
||||
/// JWT secret for the node.
|
||||
pub jwt_secret: &'a JwtSecret,
|
||||
}
|
||||
|
||||
/// Customizable node add-on types.
|
||||
pub trait NodeAddOns<N: FullNodeComponents>: Send + Sync + Unpin + Clone + 'static {
|
||||
/// The core `eth` namespace API type to install on the RPC server (see
|
||||
/// `reth_rpc_eth_api::EthApiServer`).
|
||||
type EthApi: EthApiTypes + Send + Clone;
|
||||
pub trait NodeAddOns<N: FullNodeComponents>: Send {
|
||||
/// Handle to add-ons.
|
||||
type Handle: Send + Sync + Clone;
|
||||
|
||||
/// Configures and launches the add-ons.
|
||||
fn launch_add_ons(
|
||||
self,
|
||||
ctx: AddOnsContext<'_, N>,
|
||||
) -> impl Future<Output = eyre::Result<Self::Handle>> + Send;
|
||||
}
|
||||
|
||||
impl<N: FullNodeComponents> NodeAddOns<N> for () {
|
||||
type EthApi = ();
|
||||
}
|
||||
type Handle = ();
|
||||
|
||||
/// Returns the builder for type.
|
||||
pub trait BuilderProvider<N: FullNodeComponents>: Send {
|
||||
/// Context required to build type.
|
||||
type Ctx<'a>;
|
||||
|
||||
/// Returns builder for type.
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn builder() -> Box<dyn for<'a> Fn(Self::Ctx<'a>) -> Self + Send>;
|
||||
}
|
||||
|
||||
impl<N: FullNodeComponents> BuilderProvider<N> for () {
|
||||
type Ctx<'a> = ();
|
||||
|
||||
fn builder() -> Box<dyn for<'a> Fn(Self::Ctx<'a>) -> Self + Send> {
|
||||
Box::new(noop_builder)
|
||||
async fn launch_add_ons(self, _components: AddOnsContext<'_, N>) -> eyre::Result<Self::Handle> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
const fn noop_builder(_: ()) {}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
//! Node add-ons. Depend on core [`NodeComponents`](crate::NodeComponents).
|
||||
|
||||
use reth_node_api::{EthApiTypes, FullNodeComponents, NodeAddOns};
|
||||
use reth_node_api::{FullNodeComponents, NodeAddOns};
|
||||
|
||||
use crate::{exex::BoxedLaunchExEx, hooks::NodeHooks, rpc::RpcHooks};
|
||||
use crate::{exex::BoxedLaunchExEx, hooks::NodeHooks};
|
||||
|
||||
/// Additional node extensions.
|
||||
///
|
||||
@ -12,16 +12,6 @@ pub struct AddOns<Node: FullNodeComponents, AddOns: NodeAddOns<Node>> {
|
||||
pub hooks: NodeHooks<Node, AddOns>,
|
||||
/// The `ExExs` (execution extensions) of the node.
|
||||
pub exexs: Vec<(String, Box<dyn BoxedLaunchExEx<Node>>)>,
|
||||
/// Additional RPC add-ons.
|
||||
pub rpc: RpcAddOns<Node, AddOns::EthApi>,
|
||||
/// Additional captured addons.
|
||||
pub addons: AddOns,
|
||||
}
|
||||
|
||||
/// Captures node specific addons that can be installed on top of the type configured node and are
|
||||
/// required for launching the node, such as RPC.
|
||||
#[derive(Default)]
|
||||
pub struct RpcAddOns<Node: FullNodeComponents, EthApi: EthApiTypes> {
|
||||
/// Additional RPC hooks.
|
||||
pub hooks: RpcHooks<Node, EthApi>,
|
||||
pub add_ons: AddOns,
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ use crate::{
|
||||
common::WithConfigs,
|
||||
components::NodeComponentsBuilder,
|
||||
node::FullNode,
|
||||
rpc::{EthApiBuilderProvider, RethRpcServerHandles, RpcContext},
|
||||
rpc::{RethRpcAddOns, RethRpcServerHandles, RpcContext},
|
||||
DefaultNodeLauncher, LaunchNode, Node, NodeHandle,
|
||||
};
|
||||
use futures::Future;
|
||||
@ -37,7 +37,6 @@ use reth_node_core::{
|
||||
dirs::{ChainPath, DataDirPath},
|
||||
node_config::NodeConfig,
|
||||
primitives::Head,
|
||||
rpc::eth::{helpers::AddDevSigners, FullEthApiServer},
|
||||
};
|
||||
use reth_primitives::revm_primitives::EnvKzgSettings;
|
||||
use reth_provider::{providers::BlockchainProvider, ChainSpecProvider, FullProvider};
|
||||
@ -358,19 +357,11 @@ where
|
||||
>
|
||||
where
|
||||
N: Node<RethFullAdapter<DB, N>, ChainSpec = ChainSpec>,
|
||||
N::AddOns: NodeAddOns<
|
||||
N::AddOns: RethRpcAddOns<
|
||||
NodeAdapter<
|
||||
RethFullAdapter<DB, N>,
|
||||
<N::ComponentsBuilder as NodeComponentsBuilder<RethFullAdapter<DB, N>>>::Components,
|
||||
>,
|
||||
EthApi: EthApiBuilderProvider<
|
||||
NodeAdapter<
|
||||
RethFullAdapter<DB, N>,
|
||||
<N::ComponentsBuilder as NodeComponentsBuilder<RethFullAdapter<DB, N>>>::Components,
|
||||
>
|
||||
>
|
||||
+ FullEthApiServer
|
||||
+ AddDevSigners
|
||||
>,
|
||||
{
|
||||
self.node(node).launch().await
|
||||
@ -418,7 +409,7 @@ impl<T, CB, AO> WithLaunchContext<NodeBuilderWithComponents<T, CB, AO>>
|
||||
where
|
||||
T: FullNodeTypes,
|
||||
CB: NodeComponentsBuilder<T>,
|
||||
AO: NodeAddOns<NodeAdapter<T, CB::Components>, EthApi: FullEthApiServer + AddDevSigners>,
|
||||
AO: RethRpcAddOns<NodeAdapter<T, CB::Components>>,
|
||||
{
|
||||
/// Returns a reference to the node builder's config.
|
||||
pub const fn config(&self) -> &NodeConfig<<T::Types as NodeTypes>::ChainSpec> {
|
||||
@ -466,6 +457,14 @@ where
|
||||
Self { builder: self.builder.on_node_started(hook), task_executor: self.task_executor }
|
||||
}
|
||||
|
||||
/// Modifies the addons with the given closure.
|
||||
pub fn map_add_ons<F>(self, f: F) -> Self
|
||||
where
|
||||
F: FnOnce(AO) -> AO,
|
||||
{
|
||||
Self { builder: self.builder.map_add_ons(f), task_executor: self.task_executor }
|
||||
}
|
||||
|
||||
/// Sets the hook that is run once the rpc server is started.
|
||||
pub fn on_rpc_started<F>(self, hook: F) -> Self
|
||||
where
|
||||
@ -553,12 +552,7 @@ where
|
||||
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
|
||||
T: NodeTypesWithEngine<ChainSpec: EthereumHardforks + EthChainSpec>,
|
||||
CB: NodeComponentsBuilder<RethFullAdapter<DB, T>>,
|
||||
AO: NodeAddOns<
|
||||
NodeAdapter<RethFullAdapter<DB, T>, CB::Components>,
|
||||
EthApi: EthApiBuilderProvider<NodeAdapter<RethFullAdapter<DB, T>, CB::Components>>
|
||||
+ FullEthApiServer
|
||||
+ AddDevSigners,
|
||||
>,
|
||||
AO: RethRpcAddOns<NodeAdapter<RethFullAdapter<DB, T>, CB::Components>>,
|
||||
{
|
||||
/// Launches the node with the [`DefaultNodeLauncher`] that sets up engine API consensus and rpc
|
||||
pub async fn launch(
|
||||
|
||||
@ -11,10 +11,7 @@ use reth_exex::ExExContext;
|
||||
use reth_node_api::{
|
||||
FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypes, NodeTypesWithDB, NodeTypesWithEngine,
|
||||
};
|
||||
use reth_node_core::{
|
||||
node_config::NodeConfig,
|
||||
rpc::eth::{helpers::AddDevSigners, FullEthApiServer},
|
||||
};
|
||||
use reth_node_core::node_config::NodeConfig;
|
||||
use reth_payload_builder::PayloadBuilderHandle;
|
||||
use reth_tasks::TaskExecutor;
|
||||
|
||||
@ -22,8 +19,8 @@ use crate::{
|
||||
components::{NodeComponents, NodeComponentsBuilder},
|
||||
hooks::NodeHooks,
|
||||
launch::LaunchNode,
|
||||
rpc::{EthApiBuilderProvider, RethRpcServerHandles, RpcContext, RpcHooks},
|
||||
AddOns, FullNode, RpcAddOns,
|
||||
rpc::{RethRpcAddOns, RethRpcServerHandles, RpcContext},
|
||||
AddOns, FullNode,
|
||||
};
|
||||
|
||||
/// A node builder that also has the configured types.
|
||||
@ -54,12 +51,7 @@ impl<T: FullNodeTypes> NodeBuilderWithTypes<T> {
|
||||
config,
|
||||
adapter,
|
||||
components_builder,
|
||||
add_ons: AddOns {
|
||||
hooks: NodeHooks::default(),
|
||||
rpc: RpcAddOns { hooks: RpcHooks::default() },
|
||||
exexs: Vec::new(),
|
||||
addons: (),
|
||||
},
|
||||
add_ons: AddOns { hooks: NodeHooks::default(), exexs: Vec::new(), add_ons: () },
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -83,8 +75,8 @@ impl<T: FullNodeTypes> fmt::Debug for NodeTypesAdapter<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Container for the node's types and the components and other internals that can be used by addons
|
||||
/// of the node.
|
||||
/// Container for the node's types and the components and other internals that can be used by
|
||||
/// addons of the node.
|
||||
pub struct NodeAdapter<T: FullNodeTypes, C: NodeComponents<T>> {
|
||||
/// The components of the node.
|
||||
pub components: C,
|
||||
@ -104,6 +96,8 @@ impl<T: FullNodeTypes, C: NodeComponents<T>> FullNodeComponents for NodeAdapter<
|
||||
type Evm = C::Evm;
|
||||
type Executor = C::Executor;
|
||||
type Network = C::Network;
|
||||
type Consensus = C::Consensus;
|
||||
type EngineValidator = C::EngineValidator;
|
||||
|
||||
fn pool(&self) -> &Self::Pool {
|
||||
self.components.pool()
|
||||
@ -132,6 +126,14 @@ impl<T: FullNodeTypes, C: NodeComponents<T>> FullNodeComponents for NodeAdapter<
|
||||
fn task_executor(&self) -> &TaskExecutor {
|
||||
&self.task_executor
|
||||
}
|
||||
|
||||
fn consensus(&self) -> &Self::Consensus {
|
||||
self.components.consensus()
|
||||
}
|
||||
|
||||
fn engine_validator(&self) -> &Self::EngineValidator {
|
||||
self.components.engine_validator()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FullNodeTypes, C: NodeComponents<T>> Clone for NodeAdapter<T, C> {
|
||||
@ -169,7 +171,7 @@ where
|
||||
{
|
||||
/// Advances the state of the node builder to the next state where all customizable
|
||||
/// [`NodeAddOns`] types are configured.
|
||||
pub fn with_add_ons<AO>(self, addons: AO) -> NodeBuilderWithComponents<T, CB, AO>
|
||||
pub fn with_add_ons<AO>(self, add_ons: AO) -> NodeBuilderWithComponents<T, CB, AO>
|
||||
where
|
||||
AO: NodeAddOns<NodeAdapter<T, CB::Components>>,
|
||||
{
|
||||
@ -179,12 +181,7 @@ where
|
||||
config,
|
||||
adapter,
|
||||
components_builder,
|
||||
add_ons: AddOns {
|
||||
hooks: NodeHooks::default(),
|
||||
rpc: RpcAddOns { hooks: RpcHooks::default() },
|
||||
exexs: Vec::new(),
|
||||
addons,
|
||||
},
|
||||
add_ons: AddOns { hooks: NodeHooks::default(), exexs: Vec::new(), add_ons },
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -215,31 +212,6 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the hook that is run once the rpc server is started.
|
||||
pub fn on_rpc_started<F>(mut self, hook: F) -> Self
|
||||
where
|
||||
F: FnOnce(
|
||||
RpcContext<'_, NodeAdapter<T, CB::Components>, AO::EthApi>,
|
||||
RethRpcServerHandles,
|
||||
) -> eyre::Result<()>
|
||||
+ Send
|
||||
+ 'static,
|
||||
{
|
||||
self.add_ons.rpc.hooks.set_on_rpc_started(hook);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the hook that is run to configure the rpc modules.
|
||||
pub fn extend_rpc_modules<F>(mut self, hook: F) -> Self
|
||||
where
|
||||
F: FnOnce(RpcContext<'_, NodeAdapter<T, CB::Components>, AO::EthApi>) -> eyre::Result<()>
|
||||
+ Send
|
||||
+ 'static,
|
||||
{
|
||||
self.add_ons.rpc.hooks.set_extend_rpc_modules(hook);
|
||||
self
|
||||
}
|
||||
|
||||
/// Installs an `ExEx` (Execution Extension) in the node.
|
||||
///
|
||||
/// # Note
|
||||
@ -269,18 +241,22 @@ where
|
||||
pub const fn check_launch(self) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
/// Modifies the addons with the given closure.
|
||||
pub fn map_add_ons<F>(mut self, f: F) -> Self
|
||||
where
|
||||
F: FnOnce(AO) -> AO,
|
||||
{
|
||||
self.add_ons.add_ons = f(self.add_ons.add_ons);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, CB, AO> NodeBuilderWithComponents<T, CB, AO>
|
||||
where
|
||||
T: FullNodeTypes,
|
||||
CB: NodeComponentsBuilder<T>,
|
||||
AO: NodeAddOns<
|
||||
NodeAdapter<T, CB::Components>,
|
||||
EthApi: EthApiBuilderProvider<NodeAdapter<T, CB::Components>>
|
||||
+ FullEthApiServer
|
||||
+ AddDevSigners,
|
||||
>,
|
||||
AO: RethRpcAddOns<NodeAdapter<T, CB::Components>>,
|
||||
{
|
||||
/// Launches the node with the given launcher.
|
||||
pub async fn launch_with<L>(self, launcher: L) -> eyre::Result<L::Node>
|
||||
@ -289,4 +265,33 @@ where
|
||||
{
|
||||
launcher.launch_node(self).await
|
||||
}
|
||||
|
||||
/// Sets the hook that is run once the rpc server is started.
|
||||
pub fn on_rpc_started<F>(self, hook: F) -> Self
|
||||
where
|
||||
F: FnOnce(
|
||||
RpcContext<'_, NodeAdapter<T, CB::Components>, AO::EthApi>,
|
||||
RethRpcServerHandles,
|
||||
) -> eyre::Result<()>
|
||||
+ Send
|
||||
+ 'static,
|
||||
{
|
||||
self.map_add_ons(|mut add_ons| {
|
||||
add_ons.hooks_mut().set_on_rpc_started(hook);
|
||||
add_ons
|
||||
})
|
||||
}
|
||||
|
||||
/// Sets the hook that is run to configure the rpc modules.
|
||||
pub fn extend_rpc_modules<F>(self, hook: F) -> Self
|
||||
where
|
||||
F: FnOnce(RpcContext<'_, NodeAdapter<T, CB::Components>, AO::EthApi>) -> eyre::Result<()>
|
||||
+ Send
|
||||
+ 'static,
|
||||
{
|
||||
self.map_add_ons(|mut add_ons| {
|
||||
add_ons.hooks_mut().set_extend_rpc_modules(hook);
|
||||
add_ons
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
use std::fmt;
|
||||
|
||||
use reth_node_api::{FullNodeComponents, NodeAddOns};
|
||||
use reth_node_api::FullNodeComponents;
|
||||
use reth_node_core::exit::NodeExitFuture;
|
||||
|
||||
use crate::node::FullNode;
|
||||
use crate::{node::FullNode, rpc::RethRpcAddOns};
|
||||
|
||||
/// A Handle to the launched node.
|
||||
#[must_use = "Needs to await the node exit future"]
|
||||
pub struct NodeHandle<Node: FullNodeComponents, AddOns: NodeAddOns<Node>> {
|
||||
pub struct NodeHandle<Node: FullNodeComponents, AddOns: RethRpcAddOns<Node>> {
|
||||
/// All node components.
|
||||
pub node: FullNode<Node, AddOns>,
|
||||
/// The exit future of the node.
|
||||
@ -17,7 +17,7 @@ pub struct NodeHandle<Node: FullNodeComponents, AddOns: NodeAddOns<Node>> {
|
||||
impl<Node, AddOns> NodeHandle<Node, AddOns>
|
||||
where
|
||||
Node: FullNodeComponents,
|
||||
AddOns: NodeAddOns<Node>,
|
||||
AddOns: RethRpcAddOns<Node>,
|
||||
{
|
||||
/// Waits for the node to exit, if it was configured to exit.
|
||||
pub async fn wait_for_node_exit(self) -> eyre::Result<()> {
|
||||
@ -28,7 +28,7 @@ where
|
||||
impl<Node, AddOns> fmt::Debug for NodeHandle<Node, AddOns>
|
||||
where
|
||||
Node: FullNodeComponents,
|
||||
AddOns: NodeAddOns<Node>,
|
||||
AddOns: RethRpcAddOns<Node>,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("NodeHandle")
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
//! Engine node related functionality.
|
||||
|
||||
use alloy_rpc_types::engine::ClientVersionV1;
|
||||
use futures::{future::Either, stream, stream_select, StreamExt};
|
||||
use reth_beacon_consensus::{
|
||||
hooks::{EngineHooks, StaticFileHook},
|
||||
@ -20,21 +19,17 @@ use reth_exex::ExExManagerHandle;
|
||||
use reth_network::{NetworkSyncUpdater, SyncState};
|
||||
use reth_network_api::{BlockDownloaderProvider, NetworkEventListenerProvider};
|
||||
use reth_node_api::{
|
||||
BuiltPayload, FullNodeTypes, NodeAddOns, NodeTypesWithEngine, PayloadAttributesBuilder,
|
||||
PayloadTypes,
|
||||
BuiltPayload, FullNodeTypes, NodeTypesWithEngine, PayloadAttributesBuilder, PayloadTypes,
|
||||
};
|
||||
use reth_node_core::{
|
||||
dirs::{ChainPath, DataDirPath},
|
||||
exit::NodeExitFuture,
|
||||
primitives::Head,
|
||||
rpc::eth::{helpers::AddDevSigners, FullEthApiServer},
|
||||
version::{CARGO_PKG_VERSION, CLIENT_CODE, NAME_CLIENT, VERGEN_GIT_SHA},
|
||||
};
|
||||
use reth_node_events::{cl::ConsensusLayerHealthEvents, node};
|
||||
use reth_payload_primitives::PayloadBuilder;
|
||||
use reth_primitives::EthereumHardforks;
|
||||
use reth_provider::providers::{BlockchainProvider2, ProviderNodeTypes};
|
||||
use reth_rpc_engine_api::{capabilities::EngineCapabilities, EngineApi};
|
||||
use reth_tasks::TaskExecutor;
|
||||
use reth_tokio_util::EventSender;
|
||||
use reth_tracing::tracing::{debug, error, info};
|
||||
@ -45,9 +40,9 @@ use tokio_stream::wrappers::UnboundedReceiverStream;
|
||||
use crate::{
|
||||
common::{Attached, LaunchContextWith, WithConfigs},
|
||||
hooks::NodeHooks,
|
||||
rpc::{launch_rpc_servers, EthApiBuilderProvider},
|
||||
rpc::{RethRpcAddOns, RpcHandle},
|
||||
setup::build_networked_pipeline,
|
||||
AddOns, ExExLauncher, FullNode, LaunchContext, LaunchNode, NodeAdapter,
|
||||
AddOns, AddOnsContext, ExExLauncher, FullNode, LaunchContext, LaunchNode, NodeAdapter,
|
||||
NodeBuilderWithComponents, NodeComponents, NodeComponentsBuilder, NodeHandle, NodeTypesAdapter,
|
||||
};
|
||||
|
||||
@ -78,12 +73,7 @@ where
|
||||
Types: ProviderNodeTypes + NodeTypesWithEngine,
|
||||
T: FullNodeTypes<Types = Types, Provider = BlockchainProvider2<Types>>,
|
||||
CB: NodeComponentsBuilder<T>,
|
||||
AO: NodeAddOns<
|
||||
NodeAdapter<T, CB::Components>,
|
||||
EthApi: EthApiBuilderProvider<NodeAdapter<T, CB::Components>>
|
||||
+ FullEthApiServer
|
||||
+ AddDevSigners,
|
||||
>,
|
||||
AO: RethRpcAddOns<NodeAdapter<T, CB::Components>>,
|
||||
LocalPayloadAttributesBuilder<Types::ChainSpec>: PayloadAttributesBuilder<
|
||||
<<Types as NodeTypesWithEngine>::Engine as PayloadTypes>::PayloadAttributes,
|
||||
>,
|
||||
@ -98,7 +88,7 @@ where
|
||||
let NodeBuilderWithComponents {
|
||||
adapter: NodeTypesAdapter { database },
|
||||
components_builder,
|
||||
add_ons: AddOns { hooks, rpc, exexs: installed_exex, .. },
|
||||
add_ons: AddOns { hooks, exexs: installed_exex, add_ons },
|
||||
config,
|
||||
} = target;
|
||||
let NodeHooks { on_component_initialized, on_node_started, .. } = hooks;
|
||||
@ -292,37 +282,18 @@ where
|
||||
),
|
||||
);
|
||||
|
||||
let client = ClientVersionV1 {
|
||||
code: CLIENT_CODE,
|
||||
name: NAME_CLIENT.to_string(),
|
||||
version: CARGO_PKG_VERSION.to_string(),
|
||||
commit: VERGEN_GIT_SHA.to_string(),
|
||||
};
|
||||
let engine_api = EngineApi::new(
|
||||
ctx.blockchain_db().clone(),
|
||||
ctx.chain_spec(),
|
||||
beacon_engine_handle,
|
||||
ctx.components().payload_builder().clone().into(),
|
||||
ctx.components().pool().clone(),
|
||||
Box::new(ctx.task_executor().clone()),
|
||||
client,
|
||||
EngineCapabilities::default(),
|
||||
ctx.components().engine_validator().clone(),
|
||||
);
|
||||
info!(target: "reth::cli", "Engine API handler initialized");
|
||||
|
||||
// extract the jwt secret from the args if possible
|
||||
let jwt_secret = ctx.auth_jwt_secret()?;
|
||||
|
||||
// Start RPC servers
|
||||
let (rpc_server_handles, rpc_registry) = launch_rpc_servers(
|
||||
ctx.node_adapter().clone(),
|
||||
engine_api,
|
||||
ctx.node_config(),
|
||||
jwt_secret,
|
||||
rpc,
|
||||
)
|
||||
.await?;
|
||||
let add_ons_ctx = AddOnsContext {
|
||||
node: ctx.node_adapter(),
|
||||
config: ctx.node_config(),
|
||||
beacon_engine_handle: &beacon_engine_handle,
|
||||
jwt_secret: &jwt_secret,
|
||||
};
|
||||
|
||||
let RpcHandle { rpc_server_handles, rpc_registry } =
|
||||
add_ons.launch_add_ons(add_ons_ctx).await?;
|
||||
|
||||
// TODO: migrate to devmode with https://github.com/paradigmxyz/reth/issues/10104
|
||||
if let Some(maybe_custom_etherscan_url) = ctx.node_config().debug.etherscan.clone() {
|
||||
@ -442,13 +413,12 @@ where
|
||||
provider: ctx.node_adapter().provider.clone(),
|
||||
payload_builder: ctx.components().payload_builder().clone(),
|
||||
task_executor: ctx.task_executor().clone(),
|
||||
rpc_server_handles,
|
||||
rpc_registry,
|
||||
config: ctx.node_config().clone(),
|
||||
data_dir: ctx.data_dir().clone(),
|
||||
add_ons_handle: RpcHandle { rpc_server_handles, rpc_registry },
|
||||
};
|
||||
// Notify on node started
|
||||
on_node_started.on_event(full_node.clone())?;
|
||||
on_node_started.on_event(FullNode::clone(&full_node))?;
|
||||
|
||||
let handle = NodeHandle {
|
||||
node_exit_future: NodeExitFuture::new(
|
||||
|
||||
@ -12,7 +12,6 @@ pub use exex::ExExLauncher;
|
||||
use std::{future::Future, sync::Arc};
|
||||
|
||||
use alloy_primitives::utils::format_ether;
|
||||
use alloy_rpc_types::engine::ClientVersionV1;
|
||||
use futures::{future::Either, stream, stream_select, StreamExt};
|
||||
use reth_beacon_consensus::{
|
||||
hooks::{EngineHooks, PruneHook, StaticFileHook},
|
||||
@ -25,17 +24,14 @@ use reth_engine_util::EngineMessageStreamExt;
|
||||
use reth_exex::ExExManagerHandle;
|
||||
use reth_network::{BlockDownloaderProvider, NetworkEventListenerProvider};
|
||||
use reth_node_api::{
|
||||
FullNodeComponents, FullNodeTypes, NodeAddOns, NodeTypesWithDB, NodeTypesWithEngine,
|
||||
AddOnsContext, FullNodeComponents, FullNodeTypes, NodeTypesWithDB, NodeTypesWithEngine,
|
||||
};
|
||||
use reth_node_core::{
|
||||
dirs::{ChainPath, DataDirPath},
|
||||
exit::NodeExitFuture,
|
||||
rpc::eth::{helpers::AddDevSigners, FullEthApiServer},
|
||||
version::{CARGO_PKG_VERSION, CLIENT_CODE, NAME_CLIENT, VERGEN_GIT_SHA},
|
||||
};
|
||||
use reth_node_events::{cl::ConsensusLayerHealthEvents, node};
|
||||
use reth_provider::providers::BlockchainProvider;
|
||||
use reth_rpc_engine_api::{capabilities::EngineCapabilities, EngineApi};
|
||||
use reth_tasks::TaskExecutor;
|
||||
use reth_tracing::tracing::{debug, info};
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
@ -47,19 +43,18 @@ use crate::{
|
||||
components::{NodeComponents, NodeComponentsBuilder},
|
||||
hooks::NodeHooks,
|
||||
node::FullNode,
|
||||
rpc::EthApiBuilderProvider,
|
||||
rpc::{RethRpcAddOns, RpcHandle},
|
||||
AddOns, NodeBuilderWithComponents, NodeHandle,
|
||||
};
|
||||
|
||||
/// Alias for [`reth_rpc_eth_types::EthApiBuilderCtx`], adapter for [`FullNodeComponents`].
|
||||
pub type EthApiBuilderCtx<N, Eth> = reth_rpc_eth_types::EthApiBuilderCtx<
|
||||
pub type EthApiBuilderCtx<N> = reth_rpc_eth_types::EthApiBuilderCtx<
|
||||
<N as FullNodeTypes>::Provider,
|
||||
<N as FullNodeComponents>::Pool,
|
||||
<N as FullNodeComponents>::Evm,
|
||||
<N as FullNodeComponents>::Network,
|
||||
TaskExecutor,
|
||||
<N as FullNodeTypes>::Provider,
|
||||
Eth,
|
||||
>;
|
||||
|
||||
/// A general purpose trait that launches a new node of any kind.
|
||||
@ -109,12 +104,7 @@ where
|
||||
Types: NodeTypesWithDB<ChainSpec: EthereumHardforks + EthChainSpec> + NodeTypesWithEngine,
|
||||
T: FullNodeTypes<Provider = BlockchainProvider<Types>, Types = Types>,
|
||||
CB: NodeComponentsBuilder<T>,
|
||||
AO: NodeAddOns<
|
||||
NodeAdapter<T, CB::Components>,
|
||||
EthApi: EthApiBuilderProvider<NodeAdapter<T, CB::Components>>
|
||||
+ FullEthApiServer
|
||||
+ AddDevSigners,
|
||||
>,
|
||||
AO: RethRpcAddOns<NodeAdapter<T, CB::Components>>,
|
||||
{
|
||||
type Node = NodeHandle<NodeAdapter<T, CB::Components>, AO>;
|
||||
|
||||
@ -126,7 +116,7 @@ where
|
||||
let NodeBuilderWithComponents {
|
||||
adapter: NodeTypesAdapter { database },
|
||||
components_builder,
|
||||
add_ons: AddOns { hooks, rpc, exexs: installed_exex, .. },
|
||||
add_ons: AddOns { hooks, exexs: installed_exex, add_ons },
|
||||
config,
|
||||
} = target;
|
||||
let NodeHooks { on_component_initialized, on_node_started, .. } = hooks;
|
||||
@ -336,42 +326,18 @@ where
|
||||
),
|
||||
);
|
||||
|
||||
let client = ClientVersionV1 {
|
||||
code: CLIENT_CODE,
|
||||
name: NAME_CLIENT.to_string(),
|
||||
version: CARGO_PKG_VERSION.to_string(),
|
||||
commit: VERGEN_GIT_SHA.to_string(),
|
||||
};
|
||||
let engine_api = EngineApi::new(
|
||||
ctx.blockchain_db().clone(),
|
||||
ctx.chain_spec(),
|
||||
beacon_engine_handle,
|
||||
ctx.components().payload_builder().clone().into(),
|
||||
ctx.components().pool().clone(),
|
||||
Box::new(ctx.task_executor().clone()),
|
||||
client,
|
||||
EngineCapabilities::default(),
|
||||
ctx.components().engine_validator().clone(),
|
||||
);
|
||||
info!(target: "reth::cli", "Engine API handler initialized");
|
||||
|
||||
// extract the jwt secret from the args if possible
|
||||
let jwt_secret = ctx.auth_jwt_secret()?;
|
||||
|
||||
// Start RPC servers
|
||||
let (rpc_server_handles, rpc_registry) = crate::rpc::launch_rpc_servers(
|
||||
ctx.node_adapter().clone(),
|
||||
engine_api,
|
||||
ctx.node_config(),
|
||||
jwt_secret,
|
||||
rpc,
|
||||
)
|
||||
.await?;
|
||||
let add_ons_ctx = AddOnsContext {
|
||||
node: ctx.node_adapter(),
|
||||
config: ctx.node_config(),
|
||||
beacon_engine_handle: &beacon_engine_handle,
|
||||
jwt_secret: &jwt_secret,
|
||||
};
|
||||
|
||||
// in dev mode we generate 20 random dev-signer accounts
|
||||
if ctx.is_dev() {
|
||||
rpc_registry.eth_api().with_dev_accounts();
|
||||
}
|
||||
let RpcHandle { rpc_server_handles, rpc_registry } =
|
||||
add_ons.launch_add_ons(add_ons_ctx).await?;
|
||||
|
||||
// Run consensus engine to completion
|
||||
let (tx, rx) = oneshot::channel();
|
||||
@ -431,13 +397,12 @@ where
|
||||
provider: ctx.node_adapter().provider.clone(),
|
||||
payload_builder: ctx.components().payload_builder().clone(),
|
||||
task_executor: ctx.task_executor().clone(),
|
||||
rpc_server_handles,
|
||||
rpc_registry,
|
||||
config: ctx.node_config().clone(),
|
||||
data_dir: ctx.data_dir().clone(),
|
||||
add_ons_handle: RpcHandle { rpc_server_handles, rpc_registry },
|
||||
};
|
||||
// Notify on node started
|
||||
on_node_started.on_event(full_node.clone())?;
|
||||
on_node_started.on_event(FullNode::clone(&full_node))?;
|
||||
|
||||
let handle = NodeHandle {
|
||||
node_exit_future: NodeExitFuture::new(
|
||||
|
||||
@ -20,10 +20,7 @@ pub mod components;
|
||||
pub use components::{NodeComponents, NodeComponentsBuilder};
|
||||
|
||||
mod builder;
|
||||
pub use builder::{
|
||||
add_ons::{AddOns, RpcAddOns},
|
||||
*,
|
||||
};
|
||||
pub use builder::{add_ons::AddOns, *};
|
||||
|
||||
mod launch;
|
||||
pub use launch::{engine::EngineNodeLauncher, *};
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
// re-export the node api types
|
||||
pub use reth_node_api::{FullNodeTypes, NodeTypes, NodeTypesWithEngine};
|
||||
|
||||
use std::{marker::PhantomData, sync::Arc};
|
||||
use std::{
|
||||
marker::PhantomData,
|
||||
ops::{Deref, DerefMut},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use reth_node_api::{EngineTypes, FullNodeComponents};
|
||||
use reth_node_core::{
|
||||
@ -14,11 +18,7 @@ use reth_provider::ChainSpecProvider;
|
||||
use reth_rpc_builder::{auth::AuthServerHandle, RpcServerHandle};
|
||||
use reth_tasks::TaskExecutor;
|
||||
|
||||
use crate::{
|
||||
components::NodeComponentsBuilder,
|
||||
rpc::{RethRpcServerHandles, RpcRegistry},
|
||||
NodeAdapter, NodeAddOns,
|
||||
};
|
||||
use crate::{components::NodeComponentsBuilder, rpc::RethRpcAddOns, NodeAdapter, NodeAddOns};
|
||||
|
||||
/// A [`crate::Node`] is a [`NodeTypesWithEngine`] that comes with preconfigured components.
|
||||
///
|
||||
@ -84,7 +84,7 @@ impl<N, C, AO> Node<N> for AnyNode<N, C, AO>
|
||||
where
|
||||
N: FullNodeTypes + Clone,
|
||||
C: NodeComponentsBuilder<N> + Clone + Sync + Unpin + 'static,
|
||||
AO: NodeAddOns<NodeAdapter<N, C::Components>>,
|
||||
AO: NodeAddOns<NodeAdapter<N, C::Components>> + Clone + Sync + Unpin + 'static,
|
||||
{
|
||||
type ComponentsBuilder = C;
|
||||
type AddOns = AO;
|
||||
@ -117,14 +117,12 @@ pub struct FullNode<Node: FullNodeComponents, AddOns: NodeAddOns<Node>> {
|
||||
pub payload_builder: PayloadBuilderHandle<<Node::Types as NodeTypesWithEngine>::Engine>,
|
||||
/// Task executor for the node.
|
||||
pub task_executor: TaskExecutor,
|
||||
/// Handles to the node's rpc servers
|
||||
pub rpc_server_handles: RethRpcServerHandles,
|
||||
/// The configured rpc namespaces
|
||||
pub rpc_registry: RpcRegistry<Node, AddOns::EthApi>,
|
||||
/// The initial node config.
|
||||
pub config: NodeConfig<<Node::Types as NodeTypes>::ChainSpec>,
|
||||
/// The data dir of the node.
|
||||
pub data_dir: ChainPath<DataDirPath>,
|
||||
/// The handle to launched add-ons
|
||||
pub add_ons_handle: AddOns::Handle,
|
||||
}
|
||||
|
||||
impl<Node: FullNodeComponents, AddOns: NodeAddOns<Node>> Clone for FullNode<Node, AddOns> {
|
||||
@ -137,10 +135,9 @@ impl<Node: FullNodeComponents, AddOns: NodeAddOns<Node>> Clone for FullNode<Node
|
||||
provider: self.provider.clone(),
|
||||
payload_builder: self.payload_builder.clone(),
|
||||
task_executor: self.task_executor.clone(),
|
||||
rpc_server_handles: self.rpc_server_handles.clone(),
|
||||
rpc_registry: self.rpc_registry.clone(),
|
||||
config: self.config.clone(),
|
||||
data_dir: self.data_dir.clone(),
|
||||
add_ons_handle: self.add_ons_handle.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -155,15 +152,22 @@ where
|
||||
pub fn chain_spec(&self) -> Arc<<Node::Types as NodeTypes>::ChainSpec> {
|
||||
self.provider.chain_spec()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Engine, Node, AddOns> FullNode<Node, AddOns>
|
||||
where
|
||||
Engine: EngineTypes,
|
||||
Node: FullNodeComponents<Types: NodeTypesWithEngine<Engine = Engine>>,
|
||||
AddOns: RethRpcAddOns<Node>,
|
||||
{
|
||||
/// Returns the [`RpcServerHandle`] to the started rpc server.
|
||||
pub const fn rpc_server_handle(&self) -> &RpcServerHandle {
|
||||
&self.rpc_server_handles.rpc
|
||||
&self.add_ons_handle.rpc_server_handles.rpc
|
||||
}
|
||||
|
||||
/// Returns the [`AuthServerHandle`] to the started authenticated engine API server.
|
||||
pub const fn auth_server_handle(&self) -> &AuthServerHandle {
|
||||
&self.rpc_server_handles.auth
|
||||
&self.add_ons_handle.rpc_server_handles.auth
|
||||
}
|
||||
|
||||
/// Returns the [`EngineApiClient`] interface for the authenticated engine API.
|
||||
@ -188,3 +192,17 @@ where
|
||||
self.auth_server_handle().ipc_client().await
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node: FullNodeComponents, AddOns: NodeAddOns<Node>> Deref for FullNode<Node, AddOns> {
|
||||
type Target = AddOns::Handle;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.add_ons_handle
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node: FullNodeComponents, AddOns: NodeAddOns<Node>> DerefMut for FullNode<Node, AddOns> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.add_ons_handle
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,31 +1,35 @@
|
||||
//! Builder support for rpc components.
|
||||
|
||||
use std::{
|
||||
fmt,
|
||||
fmt::{self, Debug},
|
||||
marker::PhantomData,
|
||||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
use alloy_rpc_types::engine::ClientVersionV1;
|
||||
use futures::TryFutureExt;
|
||||
use reth_node_api::{BuilderProvider, FullNodeComponents, NodeTypes, NodeTypesWithEngine};
|
||||
use reth_node_api::{
|
||||
AddOnsContext, FullNodeComponents, NodeAddOns, NodeTypes, NodeTypesWithEngine,
|
||||
};
|
||||
use reth_node_core::{
|
||||
node_config::NodeConfig,
|
||||
rpc::{
|
||||
api::EngineApiServer,
|
||||
eth::{EthApiTypes, FullEthApiServer},
|
||||
},
|
||||
rpc::eth::{EthApiTypes, FullEthApiServer},
|
||||
version::{CARGO_PKG_VERSION, CLIENT_CODE, NAME_CLIENT, VERGEN_GIT_SHA},
|
||||
};
|
||||
use reth_payload_builder::PayloadBuilderHandle;
|
||||
use reth_provider::providers::ProviderNodeTypes;
|
||||
use reth_rpc::EthApi;
|
||||
use reth_rpc_api::eth::helpers::AddDevSigners;
|
||||
use reth_rpc_builder::{
|
||||
auth::{AuthRpcModule, AuthServerHandle},
|
||||
config::RethRpcServerConfig,
|
||||
RpcModuleBuilder, RpcRegistryInner, RpcServerHandle, TransportRpcModules,
|
||||
};
|
||||
use reth_rpc_layer::JwtSecret;
|
||||
use reth_rpc_engine_api::{capabilities::EngineCapabilities, EngineApi};
|
||||
use reth_tasks::TaskExecutor;
|
||||
use reth_tracing::tracing::{debug, info};
|
||||
|
||||
use crate::{EthApiBuilderCtx, RpcAddOns};
|
||||
use crate::EthApiBuilderCtx;
|
||||
|
||||
/// Contains the handles to the spawned RPC servers.
|
||||
///
|
||||
@ -292,102 +296,232 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch the rpc servers.
|
||||
pub async fn launch_rpc_servers<Node, Engine, EthApi>(
|
||||
node: Node,
|
||||
engine_api: Engine,
|
||||
config: &NodeConfig<<Node::Types as NodeTypes>::ChainSpec>,
|
||||
jwt_secret: JwtSecret,
|
||||
add_ons: RpcAddOns<Node, EthApi>,
|
||||
) -> eyre::Result<(RethRpcServerHandles, RpcRegistry<Node, EthApi>)>
|
||||
where
|
||||
Node: FullNodeComponents<Types: ProviderNodeTypes> + Clone,
|
||||
Engine: EngineApiServer<<Node::Types as NodeTypesWithEngine>::Engine>,
|
||||
EthApi: EthApiBuilderProvider<Node> + FullEthApiServer,
|
||||
{
|
||||
let auth_config = config.rpc.auth_server_config(jwt_secret)?;
|
||||
let module_config = config.rpc.transport_rpc_module_config();
|
||||
debug!(target: "reth::cli", http=?module_config.http(), ws=?module_config.ws(), "Using RPC module config");
|
||||
|
||||
let (mut modules, mut auth_module, registry) = RpcModuleBuilder::default()
|
||||
.with_provider(node.provider().clone())
|
||||
.with_pool(node.pool().clone())
|
||||
.with_network(node.network().clone())
|
||||
.with_events(node.provider().clone())
|
||||
.with_executor(node.task_executor().clone())
|
||||
.with_evm_config(node.evm_config().clone())
|
||||
.with_block_executor(node.block_executor().clone())
|
||||
.build_with_auth_server(module_config, engine_api, EthApi::eth_api_builder());
|
||||
|
||||
let mut registry = RpcRegistry { registry };
|
||||
let ctx = RpcContext {
|
||||
node: node.clone(),
|
||||
config,
|
||||
registry: &mut registry,
|
||||
modules: &mut modules,
|
||||
auth_module: &mut auth_module,
|
||||
};
|
||||
|
||||
let RpcAddOns { hooks, .. } = add_ons;
|
||||
let RpcHooks { on_rpc_started, extend_rpc_modules } = hooks;
|
||||
|
||||
extend_rpc_modules.extend_rpc_modules(ctx)?;
|
||||
|
||||
let server_config = config.rpc.rpc_server_config();
|
||||
let cloned_modules = modules.clone();
|
||||
let launch_rpc = server_config.start(&cloned_modules).map_ok(|handle| {
|
||||
if let Some(path) = handle.ipc_endpoint() {
|
||||
info!(target: "reth::cli", %path, "RPC IPC server started");
|
||||
}
|
||||
if let Some(addr) = handle.http_local_addr() {
|
||||
info!(target: "reth::cli", url=%addr, "RPC HTTP server started");
|
||||
}
|
||||
if let Some(addr) = handle.ws_local_addr() {
|
||||
info!(target: "reth::cli", url=%addr, "RPC WS server started");
|
||||
}
|
||||
handle
|
||||
});
|
||||
|
||||
let launch_auth = auth_module.clone().start_server(auth_config).map_ok(|handle| {
|
||||
let addr = handle.local_addr();
|
||||
if let Some(ipc_endpoint) = handle.ipc_endpoint() {
|
||||
info!(target: "reth::cli", url=%addr, ipc_endpoint=%ipc_endpoint,"RPC auth server started");
|
||||
} else {
|
||||
info!(target: "reth::cli", url=%addr, "RPC auth server started");
|
||||
}
|
||||
handle
|
||||
});
|
||||
|
||||
// launch servers concurrently
|
||||
let (rpc, auth) = futures::future::try_join(launch_rpc, launch_auth).await?;
|
||||
let handles = RethRpcServerHandles { rpc, auth };
|
||||
|
||||
let ctx = RpcContext {
|
||||
node,
|
||||
config,
|
||||
registry: &mut registry,
|
||||
modules: &mut modules,
|
||||
auth_module: &mut auth_module,
|
||||
};
|
||||
|
||||
on_rpc_started.on_rpc_started(ctx, handles.clone())?;
|
||||
|
||||
Ok((handles, registry))
|
||||
/// Handle to the launched RPC servers.
|
||||
#[derive(Clone)]
|
||||
pub struct RpcHandle<Node: FullNodeComponents, EthApi: EthApiTypes> {
|
||||
/// Handles to launched servers.
|
||||
pub rpc_server_handles: RethRpcServerHandles,
|
||||
/// Configured RPC modules.
|
||||
pub rpc_registry: RpcRegistry<Node, EthApi>,
|
||||
}
|
||||
|
||||
/// Provides builder for the core `eth` API type.
|
||||
pub trait EthApiBuilderProvider<N: FullNodeComponents>: BuilderProvider<N> + EthApiTypes {
|
||||
/// Returns the eth api builder.
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn eth_api_builder() -> Box<dyn Fn(&EthApiBuilderCtx<N, Self>) -> Self + Send>;
|
||||
}
|
||||
impl<Node: FullNodeComponents, EthApi: EthApiTypes> Deref for RpcHandle<Node, EthApi> {
|
||||
type Target = RpcRegistry<Node, EthApi>;
|
||||
|
||||
impl<N, F> EthApiBuilderProvider<N> for F
|
||||
where
|
||||
N: FullNodeComponents,
|
||||
for<'a> F: BuilderProvider<N, Ctx<'a> = &'a EthApiBuilderCtx<N, Self>> + EthApiTypes,
|
||||
{
|
||||
fn eth_api_builder() -> Box<dyn Fn(&EthApiBuilderCtx<N, Self>) -> Self + Send> {
|
||||
F::builder()
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.rpc_registry
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node: FullNodeComponents, EthApi: EthApiTypes> Debug for RpcHandle<Node, EthApi>
|
||||
where
|
||||
RpcRegistry<Node, EthApi>: Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("RpcHandle")
|
||||
.field("rpc_server_handles", &self.rpc_server_handles)
|
||||
.field("rpc_registry", &self.rpc_registry)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
/// Node add-ons containing RPC server configuration, with customizable eth API handler.
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub struct RpcAddOns<Node: FullNodeComponents, EthApi: EthApiTypes> {
|
||||
/// Additional RPC add-ons.
|
||||
pub hooks: RpcHooks<Node, EthApi>,
|
||||
/// Builder for `EthApi`
|
||||
eth_api_builder: Box<dyn FnOnce(&EthApiBuilderCtx<Node>) -> EthApi + Send + Sync>,
|
||||
_pd: PhantomData<(Node, EthApi)>,
|
||||
}
|
||||
|
||||
impl<Node: FullNodeComponents, EthApi: EthApiTypes> Debug for RpcAddOns<Node, EthApi> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("RpcAddOns")
|
||||
.field("hooks", &self.hooks)
|
||||
.field("eth_api_builder", &"...")
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node: FullNodeComponents, EthApi: EthApiTypes> RpcAddOns<Node, EthApi> {
|
||||
/// Creates a new instance of the RPC add-ons.
|
||||
pub fn new(
|
||||
eth_api_builder: impl FnOnce(&EthApiBuilderCtx<Node>) -> EthApi + Send + Sync + 'static,
|
||||
) -> Self {
|
||||
Self {
|
||||
hooks: RpcHooks::default(),
|
||||
eth_api_builder: Box::new(eth_api_builder),
|
||||
_pd: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the hook that is run once the rpc server is started.
|
||||
pub fn on_rpc_started<F>(mut self, hook: F) -> Self
|
||||
where
|
||||
F: FnOnce(RpcContext<'_, Node, EthApi>, RethRpcServerHandles) -> eyre::Result<()>
|
||||
+ Send
|
||||
+ 'static,
|
||||
{
|
||||
self.hooks.set_on_rpc_started(hook);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the hook that is run to configure the rpc modules.
|
||||
pub fn extend_rpc_modules<F>(mut self, hook: F) -> Self
|
||||
where
|
||||
F: FnOnce(RpcContext<'_, Node, EthApi>) -> eyre::Result<()> + Send + 'static,
|
||||
{
|
||||
self.hooks.set_extend_rpc_modules(hook);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<Node: FullNodeComponents, EthApi: EthApiTypes + EthApiBuilder<Node>> Default
|
||||
for RpcAddOns<Node, EthApi>
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self::new(EthApi::build)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N, EthApi> NodeAddOns<N> for RpcAddOns<N, EthApi>
|
||||
where
|
||||
N: FullNodeComponents<Types: ProviderNodeTypes>,
|
||||
EthApi: EthApiTypes + FullEthApiServer + AddDevSigners + Unpin + 'static,
|
||||
{
|
||||
type Handle = RpcHandle<N, EthApi>;
|
||||
|
||||
async fn launch_add_ons(self, ctx: AddOnsContext<'_, N>) -> eyre::Result<Self::Handle> {
|
||||
let AddOnsContext { node, config, beacon_engine_handle, jwt_secret } = ctx;
|
||||
|
||||
let client = ClientVersionV1 {
|
||||
code: CLIENT_CODE,
|
||||
name: NAME_CLIENT.to_string(),
|
||||
version: CARGO_PKG_VERSION.to_string(),
|
||||
commit: VERGEN_GIT_SHA.to_string(),
|
||||
};
|
||||
|
||||
let engine_api = EngineApi::new(
|
||||
node.provider().clone(),
|
||||
config.chain.clone(),
|
||||
beacon_engine_handle.clone(),
|
||||
node.payload_builder().clone().into(),
|
||||
node.pool().clone(),
|
||||
Box::new(node.task_executor().clone()),
|
||||
client,
|
||||
EngineCapabilities::default(),
|
||||
node.engine_validator().clone(),
|
||||
);
|
||||
info!(target: "reth::cli", "Engine API handler initialized");
|
||||
|
||||
let auth_config = config.rpc.auth_server_config(*jwt_secret)?;
|
||||
let module_config = config.rpc.transport_rpc_module_config();
|
||||
debug!(target: "reth::cli", http=?module_config.http(), ws=?module_config.ws(), "Using RPC module config");
|
||||
|
||||
let (mut modules, mut auth_module, registry) = RpcModuleBuilder::default()
|
||||
.with_provider(node.provider().clone())
|
||||
.with_pool(node.pool().clone())
|
||||
.with_network(node.network().clone())
|
||||
.with_events(node.provider().clone())
|
||||
.with_executor(node.task_executor().clone())
|
||||
.with_evm_config(node.evm_config().clone())
|
||||
.with_block_executor(node.block_executor().clone())
|
||||
.build_with_auth_server(module_config, engine_api, self.eth_api_builder);
|
||||
|
||||
// in dev mode we generate 20 random dev-signer accounts
|
||||
if config.dev.dev {
|
||||
registry.eth_api().with_dev_accounts();
|
||||
}
|
||||
|
||||
let mut registry = RpcRegistry { registry };
|
||||
let ctx = RpcContext {
|
||||
node: node.clone(),
|
||||
config,
|
||||
registry: &mut registry,
|
||||
modules: &mut modules,
|
||||
auth_module: &mut auth_module,
|
||||
};
|
||||
|
||||
let RpcHooks { on_rpc_started, extend_rpc_modules } = self.hooks;
|
||||
|
||||
extend_rpc_modules.extend_rpc_modules(ctx)?;
|
||||
|
||||
let server_config = config.rpc.rpc_server_config();
|
||||
let cloned_modules = modules.clone();
|
||||
let launch_rpc = server_config.start(&cloned_modules).map_ok(|handle| {
|
||||
if let Some(path) = handle.ipc_endpoint() {
|
||||
info!(target: "reth::cli", %path, "RPC IPC server started");
|
||||
}
|
||||
if let Some(addr) = handle.http_local_addr() {
|
||||
info!(target: "reth::cli", url=%addr, "RPC HTTP server started");
|
||||
}
|
||||
if let Some(addr) = handle.ws_local_addr() {
|
||||
info!(target: "reth::cli", url=%addr, "RPC WS server started");
|
||||
}
|
||||
handle
|
||||
});
|
||||
|
||||
let launch_auth = auth_module.clone().start_server(auth_config).map_ok(|handle| {
|
||||
let addr = handle.local_addr();
|
||||
if let Some(ipc_endpoint) = handle.ipc_endpoint() {
|
||||
info!(target: "reth::cli", url=%addr, ipc_endpoint=%ipc_endpoint,"RPC auth server started");
|
||||
} else {
|
||||
info!(target: "reth::cli", url=%addr, "RPC auth server started");
|
||||
}
|
||||
handle
|
||||
});
|
||||
|
||||
// launch servers concurrently
|
||||
let (rpc, auth) = futures::future::try_join(launch_rpc, launch_auth).await?;
|
||||
|
||||
let handles = RethRpcServerHandles { rpc, auth };
|
||||
|
||||
let ctx = RpcContext {
|
||||
node: node.clone(),
|
||||
config,
|
||||
registry: &mut registry,
|
||||
modules: &mut modules,
|
||||
auth_module: &mut auth_module,
|
||||
};
|
||||
|
||||
on_rpc_started.on_rpc_started(ctx, handles.clone())?;
|
||||
|
||||
Ok(RpcHandle { rpc_server_handles: handles, rpc_registry: registry })
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper trait implemented for add-ons producing [`RpcHandle`]. Used by common node launcher
|
||||
/// implementations.
|
||||
pub trait RethRpcAddOns<N: FullNodeComponents>:
|
||||
NodeAddOns<N, Handle = RpcHandle<N, Self::EthApi>>
|
||||
{
|
||||
/// eth API implementation.
|
||||
type EthApi: EthApiTypes;
|
||||
|
||||
/// Returns a mutable reference to RPC hooks.
|
||||
fn hooks_mut(&mut self) -> &mut RpcHooks<N, Self::EthApi>;
|
||||
}
|
||||
|
||||
impl<N: FullNodeComponents, EthApi: EthApiTypes> RethRpcAddOns<N> for RpcAddOns<N, EthApi>
|
||||
where
|
||||
Self: NodeAddOns<N, Handle = RpcHandle<N, EthApi>>,
|
||||
{
|
||||
type EthApi = EthApi;
|
||||
|
||||
fn hooks_mut(&mut self) -> &mut RpcHooks<N, Self::EthApi> {
|
||||
&mut self.hooks
|
||||
}
|
||||
}
|
||||
|
||||
/// A `EthApi` that knows how to build itself from [`EthApiBuilderCtx`].
|
||||
pub trait EthApiBuilder<N: FullNodeComponents>: 'static {
|
||||
/// Builds the `EthApi` from the given context.
|
||||
fn build(ctx: &EthApiBuilderCtx<N>) -> Self;
|
||||
}
|
||||
|
||||
impl<N: FullNodeComponents> EthApiBuilder<N> for EthApi<N::Provider, N::Pool, N::Network, N::Evm> {
|
||||
fn build(ctx: &EthApiBuilderCtx<N>) -> Self {
|
||||
Self::with_spawner(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ use clap::Parser;
|
||||
use reth_node_builder::{engine_tree_config::TreeConfig, EngineNodeLauncher};
|
||||
use reth_optimism_cli::{chainspec::OpChainSpecParser, Cli};
|
||||
use reth_optimism_node::{args::RollupArgs, node::OptimismAddOns, OptimismNode};
|
||||
use reth_optimism_rpc::SequencerClient;
|
||||
use reth_provider::providers::BlockchainProvider2;
|
||||
|
||||
use tracing as _;
|
||||
@ -34,17 +33,7 @@ fn main() {
|
||||
let handle = builder
|
||||
.with_types_and_provider::<OptimismNode, BlockchainProvider2<_>>()
|
||||
.with_components(OptimismNode::components(rollup_args))
|
||||
.with_add_ons(OptimismAddOns::new(sequencer_http_arg.clone()))
|
||||
.extend_rpc_modules(move |ctx| {
|
||||
// register sequencer tx forwarder
|
||||
if let Some(sequencer_http) = sequencer_http_arg {
|
||||
ctx.registry
|
||||
.eth_api()
|
||||
.set_sequencer_client(SequencerClient::new(sequencer_http))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.with_add_ons(OptimismAddOns::new(sequencer_http_arg))
|
||||
.launch_with_fn(|builder| {
|
||||
let launcher = EngineNodeLauncher::new(
|
||||
builder.task_executor().clone(),
|
||||
@ -58,20 +47,8 @@ fn main() {
|
||||
handle.node_exit_future.await
|
||||
}
|
||||
false => {
|
||||
let handle = builder
|
||||
.node(OptimismNode::new(rollup_args.clone()))
|
||||
.extend_rpc_modules(move |ctx| {
|
||||
// register sequencer tx forwarder
|
||||
if let Some(sequencer_http) = sequencer_http_arg {
|
||||
ctx.registry
|
||||
.eth_api()
|
||||
.set_sequencer_client(SequencerClient::new(sequencer_http))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.launch()
|
||||
.await?;
|
||||
let handle =
|
||||
builder.node(OptimismNode::new(rollup_args.clone())).launch().await?;
|
||||
|
||||
handle.node_exit_future.await
|
||||
}
|
||||
|
||||
@ -13,7 +13,8 @@ use reth_node_builder::{
|
||||
NetworkBuilder, PayloadServiceBuilder, PoolBuilder, PoolBuilderConfigOverrides,
|
||||
},
|
||||
node::{FullNodeTypes, NodeTypes, NodeTypesWithEngine},
|
||||
BuilderContext, Node, PayloadBuilderConfig,
|
||||
rpc::{RethRpcAddOns, RpcAddOns, RpcHandle},
|
||||
BuilderContext, Node, NodeAdapter, NodeComponentsBuilder, PayloadBuilderConfig,
|
||||
};
|
||||
use reth_optimism_chainspec::OpChainSpec;
|
||||
use reth_optimism_consensus::OptimismBeaconConsensus;
|
||||
@ -97,7 +98,9 @@ where
|
||||
OptimismEngineValidatorBuilder,
|
||||
>;
|
||||
|
||||
type AddOns = OptimismAddOns;
|
||||
type AddOns = OptimismAddOns<
|
||||
NodeAdapter<N, <Self::ComponentsBuilder as NodeComponentsBuilder<N>>::Components>,
|
||||
>;
|
||||
|
||||
fn components_builder(&self) -> Self::ComponentsBuilder {
|
||||
let Self { args } = self;
|
||||
@ -119,25 +122,43 @@ impl NodeTypesWithEngine for OptimismNode {
|
||||
}
|
||||
|
||||
/// Add-ons w.r.t. optimism.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct OptimismAddOns {
|
||||
sequencer_http: Option<String>,
|
||||
#[derive(Debug)]
|
||||
pub struct OptimismAddOns<N: FullNodeComponents>(pub RpcAddOns<N, OpEthApi<N>>);
|
||||
|
||||
impl<N: FullNodeComponents> Default for OptimismAddOns<N> {
|
||||
fn default() -> Self {
|
||||
Self::new(None)
|
||||
}
|
||||
}
|
||||
|
||||
impl OptimismAddOns {
|
||||
impl<N: FullNodeComponents> OptimismAddOns<N> {
|
||||
/// Create a new instance with the given `sequencer_http` URL.
|
||||
pub const fn new(sequencer_http: Option<String>) -> Self {
|
||||
Self { sequencer_http }
|
||||
}
|
||||
|
||||
/// Returns the sequencer HTTP URL.
|
||||
pub fn sequencer_http(&self) -> Option<&str> {
|
||||
self.sequencer_http.as_deref()
|
||||
pub fn new(sequencer_http: Option<String>) -> Self {
|
||||
Self(RpcAddOns::new(move |ctx| OpEthApi::new(ctx, sequencer_http)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: FullNodeComponents> NodeAddOns<N> for OptimismAddOns {
|
||||
impl<N: FullNodeComponents<Types: NodeTypes<ChainSpec = OpChainSpec>>> NodeAddOns<N>
|
||||
for OptimismAddOns<N>
|
||||
{
|
||||
type Handle = RpcHandle<N, OpEthApi<N>>;
|
||||
|
||||
async fn launch_add_ons(
|
||||
self,
|
||||
ctx: reth_node_api::AddOnsContext<'_, N>,
|
||||
) -> eyre::Result<Self::Handle> {
|
||||
self.0.launch_add_ons(ctx).await
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: FullNodeComponents<Types: NodeTypes<ChainSpec = OpChainSpec>>> RethRpcAddOns<N>
|
||||
for OptimismAddOns<N>
|
||||
{
|
||||
type EthApi = OpEthApi<N>;
|
||||
|
||||
fn hooks_mut(&mut self) -> &mut reth_node_builder::rpc::RpcHooks<N, Self::EthApi> {
|
||||
self.0.hooks_mut()
|
||||
}
|
||||
}
|
||||
|
||||
/// A regular optimism evm and executor builder.
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
use alloy_genesis::Genesis;
|
||||
use alloy_primitives::{Address, B256};
|
||||
use reth::{rpc::types::engine::PayloadAttributes, tasks::TaskManager};
|
||||
use reth_e2e_test_utils::{transaction::TransactionTestContext, wallet::Wallet, NodeHelperType};
|
||||
use reth_e2e_test_utils::{
|
||||
transaction::TransactionTestContext, wallet::Wallet, Adapter, NodeHelperType,
|
||||
};
|
||||
use reth_optimism_chainspec::OpChainSpecBuilder;
|
||||
use reth_optimism_node::{
|
||||
node::OptimismAddOns, OptimismBuiltPayload, OptimismNode, OptimismPayloadBuilderAttributes,
|
||||
@ -11,7 +13,7 @@ use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
/// Optimism Node Helper type
|
||||
pub(crate) type OpNode = NodeHelperType<OptimismNode, OptimismAddOns>;
|
||||
pub(crate) type OpNode = NodeHelperType<OptimismNode, OptimismAddOns<Adapter<OptimismNode>>>;
|
||||
|
||||
pub(crate) async fn setup(num_nodes: usize) -> eyre::Result<(Vec<OpNode>, TaskManager, Wallet)> {
|
||||
let genesis: Genesis = serde_json::from_str(include_str!("../assets/genesis.json")).unwrap();
|
||||
|
||||
@ -17,7 +17,7 @@ use op_alloy_network::Optimism;
|
||||
use reth_chainspec::EthereumHardforks;
|
||||
use reth_evm::ConfigureEvm;
|
||||
use reth_network_api::NetworkInfo;
|
||||
use reth_node_api::{BuilderProvider, FullNodeComponents, FullNodeTypes, NodeTypes};
|
||||
use reth_node_api::{FullNodeComponents, FullNodeTypes, NodeTypes};
|
||||
use reth_node_builder::EthApiBuilderCtx;
|
||||
use reth_primitives::Header;
|
||||
use reth_provider::{
|
||||
@ -38,7 +38,6 @@ use reth_tasks::{
|
||||
TaskSpawner,
|
||||
};
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
use tokio::sync::OnceCell;
|
||||
|
||||
use crate::{OpEthApiError, OpTxBuilder, SequencerClient};
|
||||
|
||||
@ -67,13 +66,12 @@ pub struct OpEthApi<N: FullNodeComponents> {
|
||||
inner: Arc<EthApiNodeBackend<N>>,
|
||||
/// Sequencer client, configured to forward submitted transactions to sequencer of given OP
|
||||
/// network.
|
||||
sequencer_client: Arc<OnceCell<SequencerClient>>,
|
||||
sequencer_client: Option<SequencerClient>,
|
||||
}
|
||||
|
||||
impl<N: FullNodeComponents> OpEthApi<N> {
|
||||
/// Creates a new instance for given context.
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub fn with_spawner(ctx: &EthApiBuilderCtx<N, Self>) -> Self {
|
||||
pub fn new(ctx: &EthApiBuilderCtx<N>, sequencer_http: Option<String>) -> Self {
|
||||
let blocking_task_pool =
|
||||
BlockingTaskPool::build().expect("failed to build blocking task pool");
|
||||
|
||||
@ -93,7 +91,7 @@ impl<N: FullNodeComponents> OpEthApi<N> {
|
||||
ctx.config.proof_permits,
|
||||
);
|
||||
|
||||
Self { inner: Arc::new(inner), sequencer_client: Arc::new(OnceCell::new()) }
|
||||
Self { inner: Arc::new(inner), sequencer_client: sequencer_http.map(SequencerClient::new) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -246,18 +244,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> BuilderProvider<N> for OpEthApi<N>
|
||||
where
|
||||
Self: Send,
|
||||
N: FullNodeComponents,
|
||||
{
|
||||
type Ctx<'a> = &'a EthApiBuilderCtx<N, Self>;
|
||||
|
||||
fn builder() -> Box<dyn for<'a> Fn(Self::Ctx<'a>) -> Self + Send> {
|
||||
Box::new(Self::with_spawner)
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: FullNodeComponents> fmt::Debug for OpEthApi<N> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("OpEthApi").finish_non_exhaustive()
|
||||
|
||||
@ -81,17 +81,9 @@ impl<N> OpEthApi<N>
|
||||
where
|
||||
N: FullNodeComponents,
|
||||
{
|
||||
/// Sets a [`SequencerClient`] for `eth_sendRawTransaction` to forward transactions to.
|
||||
pub fn set_sequencer_client(
|
||||
&self,
|
||||
sequencer_client: SequencerClient,
|
||||
) -> Result<(), tokio::sync::SetError<SequencerClient>> {
|
||||
self.sequencer_client.set(sequencer_client)
|
||||
}
|
||||
|
||||
/// Returns the [`SequencerClient`] if one is set.
|
||||
pub fn raw_tx_forwarder(&self) -> Option<SequencerClient> {
|
||||
self.sequencer_client.get().cloned()
|
||||
self.sequencer_client.clone()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use reth_evm::ConfigureEvm;
|
||||
use reth_primitives::Header;
|
||||
use reth_provider::{BlockReader, CanonStateSubscriptions, EvmEnvProvider, StateProviderFactory};
|
||||
@ -11,9 +9,8 @@ use reth_rpc_eth_types::{
|
||||
use reth_tasks::TaskSpawner;
|
||||
|
||||
/// Alias for `eth` namespace API builder.
|
||||
pub type DynEthApiBuilder<Provider, Pool, EvmConfig, Network, Tasks, Events, EthApi> = Box<
|
||||
dyn Fn(&EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks, Events, EthApi>) -> EthApi,
|
||||
>;
|
||||
pub type DynEthApiBuilder<Provider, Pool, EvmConfig, Network, Tasks, Events, EthApi> =
|
||||
Box<dyn FnOnce(&EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks, Events>) -> EthApi>;
|
||||
|
||||
/// Handlers for core, filter and pubsub `eth` namespace APIs.
|
||||
#[derive(Debug, Clone)]
|
||||
@ -87,7 +84,6 @@ where
|
||||
executor,
|
||||
events,
|
||||
cache,
|
||||
_rpc_ty_builders: PhantomData,
|
||||
};
|
||||
|
||||
let api = eth_api_builder(&ctx);
|
||||
|
||||
@ -152,6 +152,7 @@
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fmt::Debug,
|
||||
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
|
||||
time::{Duration, SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
//! Context required for building `eth` namespace APIs.
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use reth_chain_state::CanonStateSubscriptions;
|
||||
use reth_chainspec::ChainSpecProvider;
|
||||
use reth_storage_api::BlockReaderIdExt;
|
||||
@ -14,7 +12,7 @@ use crate::{
|
||||
|
||||
/// Context for building the `eth` namespace API.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks, Events, Eth> {
|
||||
pub struct EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks, Events> {
|
||||
/// Database handle.
|
||||
pub provider: Provider,
|
||||
/// Mempool handle.
|
||||
@ -31,12 +29,10 @@ pub struct EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks, Events, E
|
||||
pub events: Events,
|
||||
/// RPC cache handle.
|
||||
pub cache: EthStateCache,
|
||||
/// RPC type builders.
|
||||
pub _rpc_ty_builders: PhantomData<Eth>,
|
||||
}
|
||||
|
||||
impl<Provider, Pool, EvmConfig, Network, Tasks, Events, Eth>
|
||||
EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks, Events, Eth>
|
||||
impl<Provider, Pool, EvmConfig, Network, Tasks, Events>
|
||||
EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks, Events>
|
||||
where
|
||||
Provider: BlockReaderIdExt + Clone,
|
||||
{
|
||||
@ -46,53 +42,14 @@ where
|
||||
Provider: ChainSpecProvider + 'static,
|
||||
Tasks: TaskSpawner,
|
||||
Events: CanonStateSubscriptions,
|
||||
{
|
||||
FeeHistoryCacheBuilder::build(self)
|
||||
}
|
||||
|
||||
/// Returns a new [`GasPriceOracle`] for the context.
|
||||
pub fn new_gas_price_oracle(&self) -> GasPriceOracle<Provider> {
|
||||
GasPriceOracleBuilder::build(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds `eth_` core api component [`GasPriceOracle`], for given context.
|
||||
#[derive(Debug)]
|
||||
pub struct GasPriceOracleBuilder;
|
||||
|
||||
impl GasPriceOracleBuilder {
|
||||
/// Builds a [`GasPriceOracle`], for given context.
|
||||
pub fn build<Provider, Pool, EvmConfig, Network, Tasks, Events, Eth>(
|
||||
ctx: &EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks, Events, Eth>,
|
||||
) -> GasPriceOracle<Provider>
|
||||
where
|
||||
Provider: BlockReaderIdExt + Clone,
|
||||
{
|
||||
GasPriceOracle::new(ctx.provider.clone(), ctx.config.gas_oracle, ctx.cache.clone())
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds `eth_` core api component [`FeeHistoryCache`], for given context.
|
||||
#[derive(Debug)]
|
||||
pub struct FeeHistoryCacheBuilder;
|
||||
|
||||
impl FeeHistoryCacheBuilder {
|
||||
/// Builds a [`FeeHistoryCache`], for given context.
|
||||
pub fn build<Provider, Pool, EvmConfig, Network, Tasks, Events, Eth>(
|
||||
ctx: &EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks, Events, Eth>,
|
||||
) -> FeeHistoryCache
|
||||
where
|
||||
Provider: ChainSpecProvider + BlockReaderIdExt + Clone + 'static,
|
||||
Tasks: TaskSpawner,
|
||||
Events: CanonStateSubscriptions,
|
||||
{
|
||||
let fee_history_cache =
|
||||
FeeHistoryCache::new(ctx.cache.clone(), ctx.config.fee_history_cache);
|
||||
FeeHistoryCache::new(self.cache.clone(), self.config.fee_history_cache);
|
||||
|
||||
let new_canonical_blocks = ctx.events.canonical_state_stream();
|
||||
let new_canonical_blocks = self.events.canonical_state_stream();
|
||||
let fhc = fee_history_cache.clone();
|
||||
let provider = ctx.provider.clone();
|
||||
ctx.executor.spawn_critical(
|
||||
let provider = self.provider.clone();
|
||||
self.executor.spawn_critical(
|
||||
"cache canonical blocks for fee history task",
|
||||
Box::pin(async move {
|
||||
fee_history_cache_new_blocks_task(fhc, new_canonical_blocks, provider).await;
|
||||
@ -101,4 +58,9 @@ impl FeeHistoryCacheBuilder {
|
||||
|
||||
fee_history_cache
|
||||
}
|
||||
|
||||
/// Returns a new [`GasPriceOracle`] for the context.
|
||||
pub fn new_gas_price_oracle(&self) -> GasPriceOracle<Provider> {
|
||||
GasPriceOracle::new(self.provider.clone(), self.config.gas_oracle, self.cache.clone())
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ use std::sync::Arc;
|
||||
use alloy_network::AnyNetwork;
|
||||
use alloy_primitives::U256;
|
||||
use derive_more::Deref;
|
||||
use reth_node_api::{BuilderProvider, FullNodeComponents};
|
||||
use reth_primitives::BlockNumberOrTag;
|
||||
use reth_provider::{BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider};
|
||||
use reth_rpc_eth_api::{
|
||||
@ -19,7 +18,7 @@ use reth_rpc_eth_types::{
|
||||
};
|
||||
use reth_tasks::{
|
||||
pool::{BlockingTaskGuard, BlockingTaskPool},
|
||||
TaskExecutor, TaskSpawner, TokioTaskExecutor,
|
||||
TaskSpawner, TokioTaskExecutor,
|
||||
};
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
@ -95,7 +94,7 @@ where
|
||||
{
|
||||
/// Creates a new, shareable instance.
|
||||
pub fn with_spawner<Tasks, Events>(
|
||||
ctx: &EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks, Events, Self>,
|
||||
ctx: &EthApiBuilderCtx<Provider, Pool, EvmConfig, Network, Tasks, Events>,
|
||||
) -> Self
|
||||
where
|
||||
Tasks: TaskSpawner + Clone + 'static,
|
||||
@ -163,25 +162,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> BuilderProvider<N> for EthApi<N::Provider, N::Pool, N::Network, N::Evm>
|
||||
where
|
||||
N: FullNodeComponents,
|
||||
{
|
||||
type Ctx<'a> = &'a EthApiBuilderCtx<
|
||||
N::Provider,
|
||||
N::Pool,
|
||||
N::Evm,
|
||||
N::Network,
|
||||
TaskExecutor,
|
||||
N::Provider,
|
||||
Self,
|
||||
>;
|
||||
|
||||
fn builder() -> Box<dyn for<'a> Fn(Self::Ctx<'a>) -> Self + Send> {
|
||||
Box::new(Self::with_spawner)
|
||||
}
|
||||
}
|
||||
|
||||
/// Container type `EthApi`
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct EthApiInner<Provider, Pool, Network, EvmConfig> {
|
||||
|
||||
@ -36,7 +36,8 @@ use reth::{
|
||||
builder::{
|
||||
components::{ComponentsBuilder, EngineValidatorBuilder, PayloadServiceBuilder},
|
||||
node::{NodeTypes, NodeTypesWithEngine},
|
||||
BuilderContext, FullNodeTypes, Node, NodeBuilder, PayloadBuilderConfig,
|
||||
BuilderContext, FullNodeTypes, Node, NodeAdapter, NodeBuilder, NodeComponentsBuilder,
|
||||
PayloadBuilderConfig,
|
||||
},
|
||||
providers::{CanonStateSubscriptions, StateProviderFactory},
|
||||
tasks::TaskManager,
|
||||
@ -241,7 +242,9 @@ where
|
||||
EthereumConsensusBuilder,
|
||||
CustomEngineValidatorBuilder,
|
||||
>;
|
||||
type AddOns = EthereumAddOns;
|
||||
type AddOns = EthereumAddOns<
|
||||
NodeAdapter<N, <Self::ComponentsBuilder as NodeComponentsBuilder<N>>::Components>,
|
||||
>;
|
||||
|
||||
fn components_builder(&self) -> Self::ComponentsBuilder {
|
||||
ComponentsBuilder::default()
|
||||
|
||||
Reference in New Issue
Block a user