diff --git a/Cargo.lock b/Cargo.lock index b512cc2..9172453 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2793,6 +2793,7 @@ dependencies = [ "async-trait", "eyre", "futures", + "hilo-engine", "hilo-providers-alloy", "hilo-providers-local", "kona-derive", @@ -2815,6 +2816,7 @@ dependencies = [ name = "hilo-engine" version = "0.11.0" dependencies = [ + "alloy-consensus", "alloy-eips", "alloy-network", "alloy-primitives", @@ -2824,6 +2826,7 @@ dependencies = [ "alloy-rpc-types-eth", "alloy-transport-http", "http-body-util", + "kona-driver", "op-alloy-provider", "op-alloy-rpc-types-engine", "thiserror 2.0.3", @@ -2865,6 +2868,7 @@ dependencies = [ "alloy-transport", "ctrlc", "hilo-driver", + "hilo-engine", "op-alloy-genesis", "op-alloy-registry", "serde", diff --git a/crates/driver/Cargo.toml b/crates/driver/Cargo.toml index 6d5ea4b..0e19258 100644 --- a/crates/driver/Cargo.toml +++ b/crates/driver/Cargo.toml @@ -14,6 +14,7 @@ rust-version.workspace = true [dependencies] # Local +hilo-engine.workspace = true hilo-providers-local.workspace = true hilo-providers-alloy.workspace = true diff --git a/crates/driver/src/driver.rs b/crates/driver/src/driver.rs index 3605a27..19f1e1b 100644 --- a/crates/driver/src/driver.rs +++ b/crates/driver/src/driver.rs @@ -5,16 +5,17 @@ use kona_derive::{errors::PipelineErrorKind, traits::SignalReceiver, types::Rese use kona_driver::{Driver, DriverPipeline, PipelineCursor, TipCursor}; use std::sync::Arc; +use hilo_engine::{EngineApi, HiloExecutorConstructor}; use hilo_providers_local::{InMemoryChainProvider, InMemoryL2ChainProvider}; use crate::{ - ChainNotification, Config, ConfigError, Context, HiloDerivationPipeline, HiloExecutor, - HiloExecutorConstructor, HiloPipeline, StandaloneContext, + ChainNotification, Config, ConfigError, Context, HiloDerivationPipeline, HiloPipeline, + StandaloneContext, }; /// A driver from [kona_driver] that uses hilo-types. pub type KonaDriver = - Driver; + Driver; /// An error that can happen when running the driver. #[derive(Debug, thiserror::Error)] diff --git a/crates/driver/src/executor.rs b/crates/driver/src/executor.rs deleted file mode 100644 index 2b0a0c6..0000000 --- a/crates/driver/src/executor.rs +++ /dev/null @@ -1,62 +0,0 @@ -//! Executor types. - -use alloy_consensus::{Header, Sealed}; -use alloy_primitives::B256; -use kona_driver::{Executor, ExecutorConstructor}; -use op_alloy_rpc_types_engine::OpPayloadAttributes; - -/// An executor error. -#[derive(Debug, thiserror::Error)] -pub enum ExecutorError { - /// An error occurred while executing the payload. - #[error("An error occurred while executing the payload")] - PayloadError, - /// An error occurred while computing the output root. - #[error("An error occurred while computing the output root")] - OutputRootError, -} - -/// An executor wrapper type. -#[derive(Default, Debug)] -pub struct HiloExecutor {} - -impl HiloExecutor { - /// Creates a new executor. - pub const fn new() -> Self { - Self {} - } -} - -impl Executor for HiloExecutor { - type Error = ExecutorError; - - /// Execute the given payload attributes. - fn execute_payload(&mut self, _: OpPayloadAttributes) -> Result<&Header, Self::Error> { - todo!() - } - - /// Computes the output root. - fn compute_output_root(&mut self) -> Result { - todo!() - } -} - -/// An executor constructor. -#[derive(Default, Debug)] -pub struct HiloExecutorConstructor { - // todo: see kona executor constructor -} - -impl HiloExecutorConstructor { - /// Creates a new executor constructor. - pub const fn new() -> Self { - Self {} - } -} - -impl ExecutorConstructor for HiloExecutorConstructor { - /// Constructs the executor. - fn new_executor(&self, _: Sealed
) -> HiloExecutor { - todo!() - } -} diff --git a/crates/driver/src/lib.rs b/crates/driver/src/lib.rs index d59f34b..2b04da0 100644 --- a/crates/driver/src/lib.rs +++ b/crates/driver/src/lib.rs @@ -9,9 +9,6 @@ extern crate tracing; mod config; pub use config::{Config, ConfigError}; -mod executor; -pub use executor::{HiloExecutor, HiloExecutorConstructor}; - mod driver; pub use driver::{DriverError, HiloDriver}; diff --git a/crates/engine/Cargo.toml b/crates/engine/Cargo.toml index 2ac7f7d..e453758 100644 --- a/crates/engine/Cargo.toml +++ b/crates/engine/Cargo.toml @@ -13,8 +13,12 @@ repository.workspace = true rust-version.workspace = true [dependencies] +# Kona +kona-driver.workspace = true + # Alloy alloy-eips.workspace = true +alloy-consensus.workspace = true alloy-network.workspace = true alloy-rpc-client.workspace = true alloy-rpc-types-eth.workspace = true @@ -23,6 +27,7 @@ alloy-primitives = { workspace = true, features = ["map"] } alloy-transport-http = { workspace = true, features = ["jwt-auth"] } alloy-rpc-types-engine = { workspace = true, features = ["jwt", "serde"] } +# Op Alloy op-alloy-provider.workspace = true op-alloy-rpc-types-engine.workspace = true diff --git a/crates/engine/src/api.rs b/crates/engine/src/api.rs index a2a8cd5..16bb524 100644 --- a/crates/engine/src/api.rs +++ b/crates/engine/src/api.rs @@ -5,8 +5,9 @@ use tower::ServiceBuilder; use tracing::warn; use url::Url; +use alloy_consensus::Header; use alloy_network::AnyNetwork; -use alloy_primitives::Bytes; +use alloy_primitives::{Bytes, B256}; use alloy_provider::RootProvider; use alloy_rpc_client::RpcClient; use alloy_rpc_types_engine::{ForkchoiceState, JwtSecret}; @@ -17,8 +18,9 @@ use alloy_transport_http::{ }, AuthLayer, AuthService, Http, HyperClient, }; +use kona_driver::Executor; use op_alloy_provider::ext::engine::OpEngineApi; -use op_alloy_rpc_types_engine::OpAttributesWithParent; +use op_alloy_rpc_types_engine::{OpAttributesWithParent, OpPayloadAttributes}; /// A Hyper HTTP client with a JWT authentication layer. type HyperAuthClient> = HyperClient>>; @@ -37,6 +39,31 @@ pub enum ValidationError { RpcError, } +/// An executor error. +#[derive(Debug, thiserror::Error)] +pub enum ExecutorError { + /// An error occurred while executing the payload. + #[error("An error occurred while executing the payload")] + PayloadError, + /// An error occurred while computing the output root. + #[error("An error occurred while computing the output root")] + OutputRootError, +} + +impl Executor for EngineApi { + type Error = ExecutorError; + + /// Execute the given payload attributes. + fn execute_payload(&mut self, _: OpPayloadAttributes) -> Result<&Header, Self::Error> { + todo!() + } + + /// Computes the output root. + fn compute_output_root(&mut self) -> Result { + todo!() + } +} + impl EngineApi { /// Creates a new [`EngineApi`] from the provided [Url] and [JwtSecret]. pub fn new_http(url: Url, jwt: JwtSecret) -> Self { diff --git a/crates/engine/src/constructor.rs b/crates/engine/src/constructor.rs new file mode 100644 index 0000000..b8238a5 --- /dev/null +++ b/crates/engine/src/constructor.rs @@ -0,0 +1,31 @@ +//! A constructor wrapping the engine api client. + +use crate::EngineApi; +use alloy_consensus::{Header, Sealed}; +use alloy_rpc_types_engine::JwtSecret; +use kona_driver::ExecutorConstructor; +use url::Url; + +/// An executor constructor. +#[derive(Clone, Debug)] +pub struct HiloExecutorConstructor { + /// The L2 engine API URL + pub l2_engine_url: Url, + /// Engine API JWT Secret. + /// This is used to authenticate with the engine API + pub jwt_secret: JwtSecret, +} + +impl HiloExecutorConstructor { + /// Creates a new executor constructor. + pub const fn new_http(engine: Url, jwt: JwtSecret) -> Self { + Self { l2_engine_url: engine, jwt_secret: jwt } + } +} + +impl ExecutorConstructor for HiloExecutorConstructor { + /// Constructs the executor. + fn new_executor(&self, _: Sealed
) -> EngineApi { + EngineApi::new_http(self.l2_engine_url.clone(), self.jwt_secret) + } +} diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 4d162d6..7a1adce 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -6,6 +6,9 @@ mod validation; pub use validation::ValidationMode; +mod constructor; +pub use constructor::HiloExecutorConstructor; + mod api; pub use api::EngineApi; diff --git a/crates/node/Cargo.toml b/crates/node/Cargo.toml index 5186f0c..f7b5e31 100644 --- a/crates/node/Cargo.toml +++ b/crates/node/Cargo.toml @@ -14,6 +14,7 @@ rust-version.workspace = true [dependencies] # Local +hilo-engine.workspace = true hilo-driver.workspace = true # Alloy diff --git a/crates/node/src/config.rs b/crates/node/src/config.rs index af8247e..d61a832 100644 --- a/crates/node/src/config.rs +++ b/crates/node/src/config.rs @@ -2,6 +2,7 @@ use crate::SyncMode; use alloy_rpc_types_engine::JwtSecret; +use hilo_engine::HiloExecutorConstructor; use op_alloy_genesis::RollupConfig; use serde::{Deserialize, Serialize}; use url::Url; @@ -54,6 +55,13 @@ pub struct Config { pub cache_size: usize, } +impl Config { + /// Constructs a new [HiloExecutorConstructor] from the config. + pub fn executor(&self) -> HiloExecutorConstructor { + HiloExecutorConstructor::new_http(self.l2_engine_url.clone(), self.jwt_secret) + } +} + impl From for hilo_driver::Config { fn from(config: Config) -> Self { hilo_driver::Config { diff --git a/crates/node/src/node.rs b/crates/node/src/node.rs index 12c731f..947754e 100644 --- a/crates/node/src/node.rs +++ b/crates/node/src/node.rs @@ -1,7 +1,7 @@ //! Contains the core `Node` runner. use crate::{Config, NodeError, SyncMode}; -use hilo_driver::{HiloDriver, HiloExecutorConstructor}; +use hilo_driver::HiloDriver; use tokio::sync::watch::{channel, Receiver}; /// The core node runner. @@ -89,7 +89,7 @@ impl Node { /// Creates and starts the [HiloDriver] which handles the derivation sync process. async fn start_driver(&self) -> Result<(), NodeError> { let cfg = self.config.clone().into(); - let exec = HiloExecutorConstructor::new(); + let exec = self.config.executor(); let mut driver = HiloDriver::standalone(cfg, exec).await?; driver.start().await?; Ok(())