Skip to content
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ab05449
refactor: first relax iter
lean-apple May 12, 2025
97da9ed
refactor: add default type for OppAddons
lean-apple May 13, 2025
b13dd5a
Merge branch 'paradigmxyz:main' into main
lean-apple May 14, 2025
e6277c5
Merge branch 'paradigmxyz:main' into main
lean-apple May 14, 2025
f021412
feat: init EngineApiSender
lean-apple May 14, 2025
9bf1107
Merge branch 'paradigmxyz:main' into main
lean-apple May 15, 2025
8d13e14
refactor: change from engine api sender to engine api fn
lean-apple May 15, 2025
a75eb9e
docs: update doc
lean-apple May 15, 2025
011099c
Merge branch 'paradigmxyz:main' into main
lean-apple May 17, 2025
1721560
Merge branch 'paradigmxyz:main' into main
lean-apple May 21, 2025
0517a8c
docs: init example
lean-apple May 21, 2025
52b1447
docs: remove useless comment
lean-apple May 21, 2025
7ca23ce
Merge branch 'main' into custome-api-builder
lean-apple May 21, 2025
40033c3
fix: fix taplo
lean-apple May 21, 2025
2576918
Merge branch 'main' of github.com:lean-apple/reth
lean-apple May 24, 2025
3f8f2c3
Merge branch 'main' into custome-api-builder
lean-apple May 24, 2025
9898c10
Merge branch 'main' of github.com:lean-apple/reth
lean-apple May 24, 2025
bf4b4e7
Merge branch 'main' into custome-api-builder
lean-apple May 24, 2025
319bbc8
feat: complete engine api ext example
lean-apple May 24, 2025
1bca3eb
Merge branch 'main' of github.com:lean-apple/reth
lean-apple May 30, 2025
cd8bf69
Merge branch 'main' into custome-api-builder
lean-apple May 30, 2025
25ecb7f
refactor: simplify and use directly EngineApiFn instead of EngineApiB…
lean-apple May 30, 2025
0401f27
fix: remove unused deps
lean-apple May 30, 2025
0b299ca
feat: draft to add NodeAddons impl for AddOns with EngineApiFn
lean-apple May 30, 2025
dd23df3
refactor: rempve duplicate traits by relaxing defaults on OpAddons
lean-apple May 30, 2025
47ac69e
fix: use checklaunch
lean-apple May 30, 2025
7b113b9
chore: fmt with updated nightly
lean-apple May 30, 2025
8c4fea6
style: renaming to explicit example name
lean-apple May 30, 2025
563a737
style: rename to EngineApiExt
lean-apple May 30, 2025
977a657
docs: wording
lean-apple May 30, 2025
9c65f3c
Merge branch 'main' into custome-api-builder
lean-apple Jun 3, 2025
412936f
Update examples/engine-api-access/src/main.rs
lean-apple Jun 3, 2025
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
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ members = [
"examples/custom-rlpx-subprotocol",
"examples/custom-node",
"examples/db-access",
"examples/engine-api-access",
"examples/exex-hello-world",
"examples/exex-subscription",
"examples/exex-test",
Expand Down
45 changes: 45 additions & 0 deletions crates/node/builder/src/engine_api_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//! `EngineApiBuilder` callback wrapper
//!
//! Wraps an `EngineApiBuilder` to provide access to the built Engine API instance.

use crate::rpc::EngineApiBuilder;
use eyre::Result;
use reth_node_api::{AddOnsContext, FullNodeComponents};
use reth_rpc_api::IntoEngineApiRpcModule;

/// Provides access to an `EngineApi` instance with a callback
#[derive(Debug)]
pub struct EngineApiExt<B, F> {
/// The inner builder that constructs the actual `EngineApi`
inner: B,
/// Optional callback function to execute with the built API
callback: Option<F>,
}

impl<B, F> EngineApiExt<B, F> {
/// Creates a new wrapper that calls `callback` when the API is built.
pub const fn new(inner: B, callback: F) -> Self {
Self { inner, callback: Some(callback) }
}
}

impl<N, B, F> EngineApiBuilder<N> for EngineApiExt<B, F>
where
B: EngineApiBuilder<N>,
N: FullNodeComponents,
B::EngineApi: IntoEngineApiRpcModule + Send + Sync + Clone + 'static,
F: FnOnce(B::EngineApi) + Send + Sync + 'static,
{
type EngineApi = B::EngineApi;

/// Builds the `EngineApi` and executes the callback if present.
async fn build_engine_api(mut self, ctx: &AddOnsContext<'_, N>) -> Result<Self::EngineApi> {
let api = self.inner.build_engine_api(ctx).await?;

if let Some(callback) = self.callback.take() {
callback(api.clone());
}

Ok(api)
}
}
4 changes: 4 additions & 0 deletions crates/node/builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ pub mod hooks;
pub mod node;
pub use node::*;

/// Support for accessing the EngineApi outside the RPC server context.
mod engine_api_ext;
pub use engine_api_ext::EngineApiExt;

/// Support for configuring the components of a node.
pub mod components;
pub use components::{NodeComponents, NodeComponentsBuilder};
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use reth_payload_builder::PayloadStore;
use reth_rpc_engine_api::{EngineApi, EngineCapabilities};

/// Builder for basic [`OpEngineApi`] implementation.
#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct OpEngineApiBuilder<EV> {
engine_validator_builder: EV,
}
Expand Down
30 changes: 30 additions & 0 deletions examples/engine-api-access/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "example-engine-api-access"
version = "0.0.0"
publish = false
edition.workspace = true
license.workspace = true

[dependencies]
# reth
reth-db = { workspace = true, features = ["op", "test-utils"] }
reth-node-builder.workspace = true
reth-optimism-consensus.workspace = true
reth-tasks.workspace = true
reth-node-api.workspace = true
reth-rpc-api.workspace = true
reth-tracing.workspace = true
reth-provider.workspace = true
reth-optimism-node.workspace = true
reth-optimism-chainspec.workspace = true

# alloy
alloy-rpc-types-engine.workspace = true

async-trait.workspace = true
clap = { workspace = true, features = ["derive"] }
eyre.workspace = true
jsonrpsee.workspace = true
futures.workspace = true
serde_json.workspace = true
tokio = { workspace = true, features = ["sync"] }
49 changes: 49 additions & 0 deletions examples/engine-api-access/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//! Example demonstrating how to access the Engine API instance during construction.
//!
//! Run with
//!
//! ```sh
//! cargo run -p engine-api-access
//! ```

use reth_db::test_utils::create_test_rw_db;
use reth_node_builder::{EngineApiExt, FullNodeComponents, NodeBuilder, NodeConfig};
use reth_optimism_chainspec::BASE_MAINNET;
use reth_optimism_node::{
args::RollupArgs,
node::{OpAddOns, OpEngineValidatorBuilder},
OpEngineApiBuilder, OpNode,
};
use tokio::sync::oneshot;

#[tokio::main]
async fn main() {
// Op node configuration and setup
let config = NodeConfig::new(BASE_MAINNET.clone());
let db = create_test_rw_db();
let args = RollupArgs::default();
let op_node = OpNode::new(args);

let (engine_api_tx, _engine_api_rx) = oneshot::channel();

let engine_api =
EngineApiExt::new(OpEngineApiBuilder::<OpEngineValidatorBuilder>::default(), move |api| {
let _ = engine_api_tx.send(api);
});

let _builder = NodeBuilder::new(config)
.with_database(db)
.with_types::<OpNode>()
.with_components(op_node.components())
.with_add_ons(OpAddOns::default().with_engine_api(engine_api))
.on_component_initialized(move |ctx| {
let _provider = ctx.provider();
Ok(())
})
.on_node_started(|_full_node| Ok(()))
.on_rpc_started(|_ctx, handles| {
let _client = handles.rpc.http_client();
Ok(())
})
.check_launch();
}
Loading