Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(rpc): expose ethapi in node builder for op customisation #9444

Merged
merged 25 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0f89de1
feat: API scaffolding
mattsse Jul 10, 2024
758eaf4
Merge branch 'main' into matt/builder3
emhane Jul 10, 2024
57de37f
Add NodeAddOns generic to NodeComponentsBuilder
emhane Jul 10, 2024
1e94e8d
Move eth config and builder ctx to reth-rpc-eth-types & make RpcRegis…
emhane Jul 11, 2024
a4115f2
Remove NodeAddOnBuilders trait and defer instantiation of eth api bui…
emhane Jul 12, 2024
28b7116
fixup! Remove NodeAddOnBuilders trait and defer instantiation of eth …
emhane Jul 12, 2024
a97ba95
Fix conflicts
emhane Jul 12, 2024
5955c2c
Fix lint for lib
emhane Jul 12, 2024
8008698
Fix docs
emhane Jul 12, 2024
2ba7df9
Merge branch 'main' into emhane/node-addons
emhane Jul 12, 2024
8dd44b5
Plug-in OpEthApi to node builder
emhane Jul 12, 2024
4e5ad50
Fix lint remaining targets
emhane Jul 13, 2024
a90a55a
Fix spelling
emhane Jul 13, 2024
9f67cf1
fixup! Fix spelling
emhane Jul 13, 2024
c9a2a7c
Enable optimism feature for reth-optimism-rpc in reth-node-optimism
emhane Jul 13, 2024
dd96713
fixup! Enable optimism feature for reth-optimism-rpc in reth-node-opt…
emhane Jul 13, 2024
31b8a12
Fix doctests
emhane Jul 13, 2024
64f5eee
Merge branch 'main' into emhane/node-addons
emhane Jul 14, 2024
4c23365
Remove unused trait
emhane Jul 14, 2024
86843a6
Remove redundant trait SpawnEthApi
emhane Jul 14, 2024
7c3ef13
Merge branch 'main' into emhane/node-addons
mattsse Jul 16, 2024
abca52d
fix merge
mattsse Jul 16, 2024
e7d65aa
Remove outdated todo
emhane Jul 16, 2024
ceb6faf
Separate adding components and add-ons to builder
emhane Jul 16, 2024
79abbe8
Merge branch 'emhane/node-addons' of github.com:paradigmxyz/reth into…
emhane Jul 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/ethereum/node/tests/it/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ fn test_basic_setup() {
let _builder = NodeBuilder::new(config)
.with_database(db)
.with_types::<EthereumNode>()
.with_components::<_, EthereumAddOns>(EthereumNode::components())
.with_components(EthereumNode::components())
.with_add_ons::<EthereumAddOns>()
emhane marked this conversation as resolved.
Show resolved Hide resolved
.on_component_initialized(move |ctx| {
let _provider = ctx.provider();
println!("{msg}");
Expand Down
3 changes: 2 additions & 1 deletion crates/ethereum/node/tests/it/exex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ fn basic_exex() {
let _builder = NodeBuilder::new(config)
.with_database(db)
.with_types::<EthereumNode>()
.with_components::<_, EthereumAddOns>(EthereumNode::components())
.with_components(EthereumNode::components())
.with_add_ons::<EthereumAddOns>()
.install_exex("dummy", move |ctx| future::ok(DummyExEx { _ctx: ctx }))
.check_launch();
}
29 changes: 25 additions & 4 deletions crates/node/builder/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ where
where
N: Node<RethFullAdapter<DB, N>>,
{
self.with_types().with_components(node.components_builder())
self.with_types().with_components(node.components_builder()).with_add_ons::<N::AddOns>()
}
}

Expand Down Expand Up @@ -270,7 +270,7 @@ where
where
N: Node<RethFullAdapter<DB, N>>,
{
self.with_types().with_components(node.components_builder())
self.with_types().with_components(node.components_builder()).with_add_ons::<N::AddOns>()
}

/// Launches a preconfigured [Node]
Expand Down Expand Up @@ -314,16 +314,37 @@ where
T: NodeTypes,
{
/// Advances the state of the node builder to the next state where all components are configured
pub fn with_components<CB, AO>(
pub fn with_components<CB>(
self,
components_builder: CB,
) -> WithLaunchContext<NodeBuilderWithComponents<RethFullAdapter<DB, T>, CB, ()>>
where
CB: NodeComponentsBuilder<RethFullAdapter<DB, T>>,
{
WithLaunchContext {
builder: self.builder.with_components(components_builder),
task_executor: self.task_executor,
}
}
}

impl<T, DB, CB> WithLaunchContext<NodeBuilderWithComponents<RethFullAdapter<DB, T>, CB, ()>>
where
DB: Database + DatabaseMetrics + DatabaseMetadata + Clone + Unpin + 'static,
T: NodeTypes,
CB: NodeComponentsBuilder<RethFullAdapter<DB, T>>,
{
/// 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,
) -> WithLaunchContext<NodeBuilderWithComponents<RethFullAdapter<DB, T>, CB, AO>>
where
CB: NodeComponentsBuilder<RethFullAdapter<DB, T>>,
AO: NodeAddOns<NodeAdapter<RethFullAdapter<DB, T>, CB::Components>>,
{
WithLaunchContext {
builder: self.builder.with_components(components_builder),
builder: self.builder.with_add_ons::<AO>(),
task_executor: self.task_executor,
}
}
Expand Down
36 changes: 28 additions & 8 deletions crates/node/builder/src/builder/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,9 @@ impl<T: FullNodeTypes> NodeBuilderWithTypes<T> {
}

/// Advances the state of the node builder to the next state where all components are configured
pub fn with_components<CB, AO>(
self,
components_builder: CB,
) -> NodeBuilderWithComponents<T, CB, AO>
pub fn with_components<CB>(self, components_builder: CB) -> NodeBuilderWithComponents<T, CB, ()>
where
CB: NodeComponentsBuilder<T>,
AO: NodeAddOns<NodeAdapter<T, CB::Components>>,
{
let Self { config, adapter } = self;

Expand All @@ -56,7 +52,7 @@ impl<T: FullNodeTypes> NodeBuilderWithTypes<T> {
components_builder,
add_ons: AddOns {
hooks: NodeHooks::default(),
rpc: RpcAddOns { _eth_api: PhantomData, hooks: RpcHooks::default() },
rpc: RpcAddOns { _eth_api: PhantomData::<()>, hooks: RpcHooks::default() },
exexs: Vec::new(),
},
}
Expand Down Expand Up @@ -165,6 +161,32 @@ pub struct NodeBuilderWithComponents<
pub(crate) add_ons: AddOns<NodeAdapter<T, CB::Components>, AO>,
emhane marked this conversation as resolved.
Show resolved Hide resolved
}

impl<T, CB> NodeBuilderWithComponents<T, CB, ()>
where
T: FullNodeTypes,
CB: NodeComponentsBuilder<T>,
{
/// 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) -> NodeBuilderWithComponents<T, CB, AO>
where
AO: NodeAddOns<NodeAdapter<T, CB::Components>>,
{
let Self { config, adapter, components_builder, .. } = self;

NodeBuilderWithComponents {
config,
adapter,
components_builder,
add_ons: AddOns {
hooks: NodeHooks::default(),
rpc: RpcAddOns { _eth_api: PhantomData::<AO::EthApi>, hooks: RpcHooks::default() },
exexs: Vec::new(),
},
}
}
}

impl<T, CB, AO> NodeBuilderWithComponents<T, CB, AO>
where
T: FullNodeTypes,
Expand Down Expand Up @@ -247,8 +269,6 @@ where
}
}

// TODO impl install hook functions.

impl<T, CB, AO> NodeBuilderWithComponents<T, CB, AO>
where
T: FullNodeTypes,
Expand Down
3 changes: 2 additions & 1 deletion crates/optimism/node/tests/it/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ fn test_basic_setup() {
let _builder = NodeBuilder::new(config)
.with_database(db)
.with_types::<OptimismNode>()
.with_components::<_, OptimismAddOns>(OptimismNode::components(Default::default()))
.with_components(OptimismNode::components(Default::default()))
.with_add_ons::<OptimismAddOns>()
.on_component_initialized(move |ctx| {
let _provider = ctx.provider();
Ok(())
Expand Down
5 changes: 2 additions & 3 deletions examples/custom-evm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,8 @@ async fn main() -> eyre::Result<()> {
// configure the node with regular ethereum types
.with_types::<EthereumNode>()
// use default ethereum components but with our executor
.with_components::<_, EthereumAddOns>(
EthereumNode::components().executor(MyExecutorBuilder::default()),
)
.with_components(EthereumNode::components().executor(MyExecutorBuilder::default()))
.with_add_ons::<EthereumAddOns>()
.launch()
.await
.unwrap();
Expand Down
5 changes: 2 additions & 3 deletions examples/custom-node-components/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ fn main() {
.with_types::<EthereumNode>()
// Configure the components of the node
// use default ethereum components but use our custom pool
.with_components::<_, EthereumAddOns>(
EthereumNode::components().pool(CustomPoolBuilder::default()),
)
.with_components(EthereumNode::components().pool(CustomPoolBuilder::default()))
.with_add_ons::<EthereumAddOns>()
.launch()
.await?;

Expand Down
3 changes: 2 additions & 1 deletion examples/custom-payload-builder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ fn main() {
.with_types::<EthereumNode>()
// Configure the components of the node
// use default ethereum components but use our custom payload builder
.with_components::<_, EthereumAddOns>(
.with_components(
EthereumNode::components().payload(CustomPayloadBuilder::default()),
)
.with_add_ons::<EthereumAddOns>()
.launch()
.await?;

Expand Down
5 changes: 2 additions & 3 deletions examples/stateful-precompile/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,8 @@ async fn main() -> eyre::Result<()> {
// configure the node with regular ethereum types
.with_types::<EthereumNode>()
// use default ethereum components but with our executor
.with_components::<_, EthereumAddOns>(
EthereumNode::components().executor(MyExecutorBuilder::default()),
)
.with_components(EthereumNode::components().executor(MyExecutorBuilder::default()))
.with_add_ons::<EthereumAddOns>()
.launch()
.await
.unwrap();
Expand Down
Loading