Skip to content

Commit 6fb2710

Browse files
authored
feat: move RPC launch to add-ons (paradigmxyz#11532)
1 parent a235f72 commit 6fb2710

File tree

27 files changed

+535
-506
lines changed

27 files changed

+535
-506
lines changed

Cargo.lock

Lines changed: 13 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/e2e-test-utils/src/lib.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ use reth::{
77
args::{DiscoveryArgs, NetworkArgs, RpcServerArgs},
88
builder::{NodeBuilder, NodeConfig, NodeHandle},
99
network::PeersHandleProvider,
10-
rpc::api::eth::{helpers::AddDevSigners, FullEthApiServer},
1110
tasks::TaskManager,
1211
};
1312
use reth_chainspec::{EthChainSpec, EthereumHardforks};
1413
use reth_db::{test_utils::TempDatabase, DatabaseEnv};
1514
use reth_node_builder::{
16-
components::NodeComponentsBuilder, rpc::EthApiBuilderProvider, FullNodeTypesAdapter, Node,
17-
NodeAdapter, NodeAddOns, NodeComponents, NodeTypesWithDBAdapter, NodeTypesWithEngine,
18-
RethFullAdapter,
15+
components::NodeComponentsBuilder, rpc::RethRpcAddOns, FullNodeTypesAdapter, Node, NodeAdapter,
16+
NodeComponents, NodeTypesWithDBAdapter, NodeTypesWithEngine, RethFullAdapter,
1917
};
2018
use reth_provider::providers::BlockchainProvider;
2119
use tracing::{span, Level};
@@ -56,10 +54,7 @@ where
5654
TmpNodeAdapter<N>,
5755
Components: NodeComponents<TmpNodeAdapter<N>, Network: PeersHandleProvider>,
5856
>,
59-
N::AddOns: NodeAddOns<
60-
Adapter<N>,
61-
EthApi: FullEthApiServer + AddDevSigners + EthApiBuilderProvider<Adapter<N>>,
62-
>,
57+
N::AddOns: RethRpcAddOns<Adapter<N>>,
6358
{
6459
let tasks = TaskManager::current();
6560
let exec = tasks.executor();
@@ -115,7 +110,8 @@ type TmpNodeAdapter<N> = FullNodeTypesAdapter<
115110
BlockchainProvider<NodeTypesWithDBAdapter<N, TmpDB>>,
116111
>;
117112

118-
type Adapter<N> = NodeAdapter<
113+
/// Type alias for a `NodeAdapter`
114+
pub type Adapter<N> = NodeAdapter<
119115
RethFullAdapter<TmpDB, N>,
120116
<<N as Node<TmpNodeAdapter<N>>>::ComponentsBuilder as NodeComponentsBuilder<
121117
RethFullAdapter<TmpDB, N>,

crates/e2e-test-utils/src/node.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use reth::{
1818
},
1919
};
2020
use reth_chainspec::EthereumHardforks;
21-
use reth_node_builder::{NodeAddOns, NodeTypesWithEngine};
21+
use reth_node_builder::{rpc::RethRpcAddOns, NodeTypesWithEngine};
2222
use reth_stages_types::StageId;
2323
use tokio_stream::StreamExt;
2424

@@ -32,7 +32,7 @@ use crate::{
3232
pub struct NodeTestContext<Node, AddOns>
3333
where
3434
Node: FullNodeComponents,
35-
AddOns: NodeAddOns<Node>,
35+
AddOns: RethRpcAddOns<Node>,
3636
{
3737
/// The core structure representing the full node.
3838
pub inner: FullNode<Node, AddOns>,
@@ -52,7 +52,7 @@ where
5252
Node: FullNodeComponents,
5353
Node::Types: NodeTypesWithEngine<ChainSpec: EthereumHardforks, Engine = Engine>,
5454
Node::Network: PeersHandleProvider,
55-
AddOns: NodeAddOns<Node>,
55+
AddOns: RethRpcAddOns<Node>,
5656
{
5757
/// Creates a new test node
5858
pub async fn new(node: FullNode<Node, AddOns>) -> eyre::Result<Self> {
@@ -67,7 +67,7 @@ where
6767
canonical_stream: node.provider.canonical_state_stream(),
6868
_marker: PhantomData::<Engine>,
6969
},
70-
rpc: RpcTestContext { inner: node.rpc_registry },
70+
rpc: RpcTestContext { inner: node.add_ons_handle.rpc_registry },
7171
})
7272
}
7373

crates/ethereum/node/src/node.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ use reth_ethereum_engine_primitives::{
1111
};
1212
use reth_evm_ethereum::execute::EthExecutorProvider;
1313
use reth_network::NetworkHandle;
14-
use reth_node_api::{ConfigureEvm, EngineValidator, FullNodeComponents, NodeAddOns};
14+
use reth_node_api::{ConfigureEvm, EngineValidator, FullNodeComponents, NodeTypesWithDB};
1515
use reth_node_builder::{
1616
components::{
1717
ComponentsBuilder, ConsensusBuilder, EngineValidatorBuilder, ExecutorBuilder,
1818
NetworkBuilder, PayloadServiceBuilder, PoolBuilder,
1919
},
2020
node::{FullNodeTypes, NodeTypes, NodeTypesWithEngine},
21-
BuilderContext, Node, PayloadBuilderConfig, PayloadTypes,
21+
rpc::RpcAddOns,
22+
BuilderContext, Node, NodeAdapter, NodeComponentsBuilder, PayloadBuilderConfig, PayloadTypes,
2223
};
2324
use reth_payload_builder::{PayloadBuilderHandle, PayloadBuilderService};
2425
use reth_primitives::Header;
@@ -77,17 +78,19 @@ impl NodeTypesWithEngine for EthereumNode {
7778
}
7879

7980
/// Add-ons w.r.t. l1 ethereum.
80-
#[derive(Debug, Clone, Default)]
81-
#[non_exhaustive]
82-
pub struct EthereumAddOns;
83-
84-
impl<N: FullNodeComponents> NodeAddOns<N> for EthereumAddOns {
85-
type EthApi = EthApi<N::Provider, N::Pool, NetworkHandle, N::Evm>;
86-
}
81+
pub type EthereumAddOns<N> = RpcAddOns<
82+
N,
83+
EthApi<
84+
<N as FullNodeTypes>::Provider,
85+
<N as FullNodeComponents>::Pool,
86+
NetworkHandle,
87+
<N as FullNodeComponents>::Evm,
88+
>,
89+
>;
8790

8891
impl<Types, N> Node<N> for EthereumNode
8992
where
90-
Types: NodeTypesWithEngine<Engine = EthEngineTypes, ChainSpec = ChainSpec>,
93+
Types: NodeTypesWithDB + NodeTypesWithEngine<Engine = EthEngineTypes, ChainSpec = ChainSpec>,
9194
N: FullNodeTypes<Types = Types>,
9295
{
9396
type ComponentsBuilder = ComponentsBuilder<
@@ -100,7 +103,9 @@ where
100103
EthereumEngineValidatorBuilder,
101104
>;
102105

103-
type AddOns = EthereumAddOns;
106+
type AddOns = EthereumAddOns<
107+
NodeAdapter<N, <Self::ComponentsBuilder as NodeComponentsBuilder<N>>::Components>,
108+
>;
104109

105110
fn components_builder(&self) -> Self::ComponentsBuilder {
106111
Self::components()

crates/ethereum/node/tests/e2e/dev.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ use futures::StreamExt;
66
use reth::{args::DevArgs, core::rpc::eth::helpers::EthTransactions};
77
use reth_chainspec::ChainSpec;
88
use reth_e2e_test_utils::setup;
9-
use reth_node_api::{FullNodeComponents, NodeAddOns};
10-
use reth_node_builder::{EngineNodeLauncher, FullNode, NodeBuilder, NodeConfig, NodeHandle};
9+
use reth_node_api::FullNodeComponents;
10+
use reth_node_builder::{
11+
rpc::RethRpcAddOns, EngineNodeLauncher, FullNode, NodeBuilder, NodeConfig, NodeHandle,
12+
};
1113
use reth_node_ethereum::{node::EthereumAddOns, EthereumNode};
1214
use reth_provider::{providers::BlockchainProvider2, CanonStateSubscriptions};
1315
use reth_tasks::TaskManager;
@@ -53,7 +55,7 @@ async fn can_run_dev_node_new_engine() -> eyre::Result<()> {
5355
async fn assert_chain_advances<N, AddOns>(node: FullNode<N, AddOns>)
5456
where
5557
N: FullNodeComponents<Provider: CanonStateSubscriptions>,
56-
AddOns: NodeAddOns<N, EthApi: EthTransactions>,
58+
AddOns: RethRpcAddOns<N, EthApi: EthTransactions>,
5759
{
5860
let mut notifications = node.provider.canonical_state_stream();
5961

crates/exex/test-utils/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ where
142142
TestConsensusBuilder,
143143
EthereumEngineValidatorBuilder,
144144
>;
145-
type AddOns = EthereumAddOns;
145+
type AddOns = EthereumAddOns<
146+
NodeAdapter<N, <Self::ComponentsBuilder as NodeComponentsBuilder<N>>::Components>,
147+
>;
146148

147149
fn components_builder(&self) -> Self::ComponentsBuilder {
148150
ComponentsBuilder::default()

crates/node/api/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ workspace = true
1212

1313
[dependencies]
1414
# reth
15+
reth-beacon-consensus.workspace = true
16+
reth-consensus.workspace = true
1517
reth-evm.workspace = true
1618
reth-provider.workspace = true
1719
reth-engine-primitives.workspace = true
@@ -23,3 +25,8 @@ reth-rpc-eth-api.workspace = true
2325
reth-network-api.workspace = true
2426
reth-node-types.workspace = true
2527
reth-primitives.workspace = true
28+
reth-node-core.workspace = true
29+
30+
alloy-rpc-types-engine.workspace = true
31+
32+
eyre.workspace = true

crates/node/api/src/node.rs

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
//! Traits for configuring a node.
22
3-
use std::marker::PhantomData;
3+
use std::{future::Future, marker::PhantomData};
44

5+
use alloy_rpc_types_engine::JwtSecret;
6+
use reth_beacon_consensus::BeaconConsensusEngineHandle;
7+
use reth_consensus::Consensus;
8+
use reth_engine_primitives::EngineValidator;
59
use reth_evm::execute::BlockExecutorProvider;
610
use reth_network_api::FullNetwork;
7-
use reth_node_types::{NodeTypesWithDB, NodeTypesWithEngine};
11+
use reth_node_core::node_config::NodeConfig;
12+
use reth_node_types::{NodeTypes, NodeTypesWithDB, NodeTypesWithEngine};
813
use reth_payload_builder::PayloadBuilderHandle;
914
use reth_primitives::Header;
1015
use reth_provider::FullProvider;
11-
use reth_rpc_eth_api::EthApiTypes;
1216
use reth_tasks::TaskExecutor;
1317
use reth_transaction_pool::TransactionPool;
1418

@@ -54,9 +58,15 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
5458
/// The type that knows how to execute blocks.
5559
type Executor: BlockExecutorProvider;
5660

61+
/// The consensus type of the node.
62+
type Consensus: Consensus + Clone + Unpin + 'static;
63+
5764
/// Network API.
5865
type Network: FullNetwork;
5966

67+
/// Validator for the engine API.
68+
type EngineValidator: EngineValidator<<Self::Types as NodeTypesWithEngine>::Engine>;
69+
6070
/// Returns the transaction pool of the node.
6171
fn pool(&self) -> &Self::Pool;
6272

@@ -66,8 +76,8 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
6676
/// Returns the node's executor type.
6777
fn block_executor(&self) -> &Self::Executor;
6878

69-
/// Returns the provider of the node.
70-
fn provider(&self) -> &Self::Provider;
79+
/// Returns the node's consensus type.
80+
fn consensus(&self) -> &Self::Consensus;
7181

7282
/// Returns the handle to the network
7383
fn network(&self) -> &Self::Network;
@@ -77,37 +87,46 @@ pub trait FullNodeComponents: FullNodeTypes + Clone + 'static {
7787
&self,
7888
) -> &PayloadBuilderHandle<<Self::Types as NodeTypesWithEngine>::Engine>;
7989

90+
/// Returns the engine validator.
91+
fn engine_validator(&self) -> &Self::EngineValidator;
92+
93+
/// Returns the provider of the node.
94+
fn provider(&self) -> &Self::Provider;
95+
8096
/// Returns handle to runtime.
8197
fn task_executor(&self) -> &TaskExecutor;
8298
}
8399

84-
/// Customizable node add-on types.
85-
pub trait NodeAddOns<N: FullNodeComponents>: Send + Sync + Unpin + Clone + 'static {
86-
/// The core `eth` namespace API type to install on the RPC server (see
87-
/// `reth_rpc_eth_api::EthApiServer`).
88-
type EthApi: EthApiTypes + Send + Clone;
89-
}
90-
91-
impl<N: FullNodeComponents> NodeAddOns<N> for () {
92-
type EthApi = ();
100+
/// Context passed to [`NodeAddOns::launch_add_ons`],
101+
#[derive(Debug)]
102+
pub struct AddOnsContext<'a, N: FullNodeComponents> {
103+
/// Node with all configured components.
104+
pub node: &'a N,
105+
/// Node configuration.
106+
pub config: &'a NodeConfig<<N::Types as NodeTypes>::ChainSpec>,
107+
/// Handle to the beacon consensus engine.
108+
pub beacon_engine_handle:
109+
&'a BeaconConsensusEngineHandle<<N::Types as NodeTypesWithEngine>::Engine>,
110+
/// JWT secret for the node.
111+
pub jwt_secret: &'a JwtSecret,
93112
}
94113

95-
/// Returns the builder for type.
96-
pub trait BuilderProvider<N: FullNodeComponents>: Send {
97-
/// Context required to build type.
98-
type Ctx<'a>;
99-
100-
/// Returns builder for type.
101-
#[allow(clippy::type_complexity)]
102-
fn builder() -> Box<dyn for<'a> Fn(Self::Ctx<'a>) -> Self + Send>;
114+
/// Customizable node add-on types.
115+
pub trait NodeAddOns<N: FullNodeComponents>: Send {
116+
/// Handle to add-ons.
117+
type Handle: Send + Sync + Clone;
118+
119+
/// Configures and launches the add-ons.
120+
fn launch_add_ons(
121+
self,
122+
ctx: AddOnsContext<'_, N>,
123+
) -> impl Future<Output = eyre::Result<Self::Handle>> + Send;
103124
}
104125

105-
impl<N: FullNodeComponents> BuilderProvider<N> for () {
106-
type Ctx<'a> = ();
126+
impl<N: FullNodeComponents> NodeAddOns<N> for () {
127+
type Handle = ();
107128

108-
fn builder() -> Box<dyn for<'a> Fn(Self::Ctx<'a>) -> Self + Send> {
109-
Box::new(noop_builder)
129+
async fn launch_add_ons(self, _components: AddOnsContext<'_, N>) -> eyre::Result<Self::Handle> {
130+
Ok(())
110131
}
111132
}
112-
113-
const fn noop_builder(_: ()) {}

0 commit comments

Comments
 (0)