Skip to content

Commit

Permalink
Merge pull request #130 from anton-rs/rf/fix/engine
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell authored Nov 26, 2024
2 parents 73eab8a + e4dc89b commit 349fcf4
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 72 deletions.
4 changes: 4 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 crates/driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ rust-version.workspace = true

[dependencies]
# Local
hilo-engine.workspace = true
hilo-providers-local.workspace = true
hilo-providers-alloy.workspace = true

Expand Down
7 changes: 4 additions & 3 deletions crates/driver/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HiloExecutor, HiloExecutorConstructor, HiloPipeline, HiloDerivationPipeline>;
Driver<EngineApi, HiloExecutorConstructor, HiloPipeline, HiloDerivationPipeline>;

/// An error that can happen when running the driver.
#[derive(Debug, thiserror::Error)]
Expand Down
62 changes: 0 additions & 62 deletions crates/driver/src/executor.rs

This file was deleted.

3 changes: 0 additions & 3 deletions crates/driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
5 changes: 5 additions & 0 deletions crates/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
31 changes: 29 additions & 2 deletions crates/engine/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<B = Full<Bytes>> = HyperClient<B, AuthService<Client<HttpConnector, B>>>;
Expand All @@ -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<B256, Self::Error> {
todo!()
}
}

impl EngineApi {
/// Creates a new [`EngineApi`] from the provided [Url] and [JwtSecret].
pub fn new_http(url: Url, jwt: JwtSecret) -> Self {
Expand Down
31 changes: 31 additions & 0 deletions crates/engine/src/constructor.rs
Original file line number Diff line number Diff line change
@@ -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<EngineApi> for HiloExecutorConstructor {
/// Constructs the executor.
fn new_executor(&self, _: Sealed<Header>) -> EngineApi {
EngineApi::new_http(self.l2_engine_url.clone(), self.jwt_secret)
}
}
3 changes: 3 additions & 0 deletions crates/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
mod validation;
pub use validation::ValidationMode;

mod constructor;
pub use constructor::HiloExecutorConstructor;

mod api;
pub use api::EngineApi;

Expand Down
1 change: 1 addition & 0 deletions crates/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ rust-version.workspace = true

[dependencies]
# Local
hilo-engine.workspace = true
hilo-driver.workspace = true

# Alloy
Expand Down
8 changes: 8 additions & 0 deletions crates/node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Config> for hilo_driver::Config {
fn from(config: Config) -> Self {
hilo_driver::Config {
Expand Down
4 changes: 2 additions & 2 deletions crates/node/src/node.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit 349fcf4

Please sign in to comment.