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: re-work engine #120

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
535 changes: 352 additions & 183 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ kona-driver = { git = "https://github.com/anton-rs/kona", branch = "rf/test/op-a
hilo = { version = "0.11.0", path = "crates/hilo", default-features = false }
hilo-net = { version = "0.11.0", path = "crates/net", default-features = false }
hilo-driver = { version = "0.11.0", path = "crates/driver", default-features = false }
hilo-engine = { version = "0.11.0", path = "crates/engine", default-features = false }

# Kona
kona-derive = { version = "0.0.6", default-features = false }
Expand All @@ -56,11 +57,13 @@ alloy-rlp = { version = "0.3.9", default-features = false }
alloy-eips = { version = "0.6.4", default-features = false }
alloy-serde = { version = "0.6.4", default-features = false }
alloy-signer = { version = "0.6.4", default-features = false }
alloy-network = { version = "0.6.4", default-features = false }
alloy-provider = { version = "0.6.4", default-features = false }
alloy-primitives = { version = "0.8.12", default-features = false }
alloy-consensus = { version = "0.6.4", default-features = false }
alloy-rpc-types = { version = "0.6.4", default-features = false }
alloy-transport = { version = "0.6.4", default-features = false }
alloy-rpc-client = { version = "0.6.4", default-features = false }
alloy-primitives = { version = "0.8.12", default-features = false }
alloy-rpc-types-eth = { version = "0.6.4", default-features = false }
alloy-node-bindings = { version = "0.6.4", default-features = false }
alloy-transport-http = { version = "0.6.4", default-features = false }
Expand All @@ -75,12 +78,12 @@ alloy-rpc-types-engine = { version = "0.6.4", default-features = false }
# op-alloy-rpc-types-engine = { version = "0.6.7", default-features = false }

op-alloy-genesis = { git = "https://github.com/alloy-rs/op-alloy", branch = "main", default-features = false }
op-alloy-provider = { git = "https://github.com/alloy-rs/op-alloy", branch = "main", default-features = false }
op-alloy-protocol = { git = "https://github.com/alloy-rs/op-alloy", branch = "main", default-features = false }
op-alloy-registry = { git = "https://github.com/alloy-rs/op-alloy", branch = "main", default-features = false }
op-alloy-consensus = { git = "https://github.com/alloy-rs/op-alloy", branch = "main", default-features = false }
op-alloy-rpc-types-engine = { git = "https://github.com/alloy-rs/op-alloy", branch = "main", default-features = false }


# Reth
reth-provider = { git = "https://github.com/paradigmxyz/reth", rev = "7ae8ce1" }
reth-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "7ae8ce1" }
Expand Down Expand Up @@ -114,6 +117,8 @@ clap = "4.5.20"
tokio = "1.41.0"
futures = "0.3.31"
reqwest = "0.12.9"
tower = "0.5"
http-body-util = "0.1.2"
parking_lot = "0.12.3"
async-trait = "0.1.83"
futures-timer = "3.0.3"
Expand Down
7 changes: 7 additions & 0 deletions bin/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@ rust-version.workspace = true

[dependencies]
# Local
hilo-engine.workspace = true
# hilo-net.workspace = true
# hilo = { workspace = true, features = ["registry"] }

# Alloy
op-alloy-genesis.workspace = true
op-alloy-registry.workspace = true

# Workspace
url.workspace = true
eyre.workspace = true
tracing.workspace = true
serde_json = { workspace = true, features = ["std"] }
clap = { workspace = true, features = ["derive", "env"] }
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
tracing-subscriber = { workspace = true, features = ["env-filter", "fmt"] }
Expand Down
116 changes: 116 additions & 0 deletions bin/node/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//! CLI arguments for the Hilo Node.

use std::{fs::File, path::PathBuf, sync::Arc};

use clap::Parser;
use eyre::{bail, Context, Result};
use serde_json::from_reader;
use tracing::debug;
use url::Url;

use op_alloy_genesis::RollupConfig;
use op_alloy_registry::ROLLUP_CONFIGS;

use hilo_engine::ValidationMode;

/// The default L2 chain ID to use. This corresponds to OP Mainnet.
pub const DEFAULT_L2_CHAIN_ID: u64 = 10;

/// The default L1 RPC URL to use.
pub const DEFAULT_L1_RPC_URL: &str = "https://cloudflare-eth.com";

/// The default L2 RPC URL to use.
pub const DEFAULT_L2_RPC_URL: &str = "https://optimism.llamarpc.com/";

/// The default L1 Beacon Client RPC URL to use.
pub const DEFAULT_L1_BEACON_CLIENT_URL: &str = "http://localhost:5052/";

/// CLI Arguments.
#[derive(Parser, Clone, Debug)]
#[command(author, version, about, long_about = None)]
pub(crate) struct NodeArgs {
/// A port to serve prometheus metrics on.
#[clap(
long,
short = 'm',
default_value = "9090",
help = "The port to serve prometheus metrics on"
)]
pub metrics_port: u16,

/// Chain ID of the L2 network
#[clap(long = "l2-chain-id", default_value_t = DEFAULT_L2_CHAIN_ID)]
pub l2_chain_id: u64,

/// Path to a custom L2 rollup configuration file
/// (overrides the default rollup configuration from the registry)
#[clap(long = "hera.l2-config-file")]
pub l2_config_file: Option<PathBuf>,

/// RPC URL of an L2 execution client
#[clap(long = "hera.l2-rpc-url", default_value = DEFAULT_L2_RPC_URL)]
pub l2_rpc_url: Url,

/// RPC URL of an L1 execution client
/// (This is only needed when running in Standalone mode)
#[clap(long = "hera.l1-rpc-url", default_value = DEFAULT_L1_RPC_URL)]
pub l1_rpc_url: Url,

/// URL of an L1 beacon client to fetch blobs
#[clap(long = "hera.l1-beacon-client-url", default_value = DEFAULT_L1_BEACON_CLIENT_URL)]
pub l1_beacon_client_url: Url,

/// URL of the blob archiver to fetch blobs that are expired on
/// the beacon client but still needed for processing.
///
/// Blob archivers need to implement the `blob_sidecars` API:
/// <https://ethereum.github.io/beacon-APIs/#/Beacon/getBlobSidecars>
#[clap(long = "hera.l1-blob-archiver-url")]
pub l1_blob_archiver_url: Option<Url>,

/// The payload validation mode to use.
///
/// - Trusted: rely on a trusted synced L2 execution client. Validation happens by fetching the
/// same block and comparing the results.
/// - Engine API: use a local or remote engine API of an L2 execution client. Validation
/// happens by sending the `new_payload` to the API and expecting a VALID response.
#[clap(long = "hera.validation-mode", default_value = "engine-api")]
pub validation_mode: ValidationMode,

/// URL of the engine API endpoint of an L2 execution client.
#[clap(long = "hera.l2-engine-api-url", env = "L2_ENGINE_API_URL")]
pub l2_engine_api_url: Url,

/// JWT secret for the auth-rpc endpoint of the execution client.
/// This MUST be a valid path to a file containing the hex-encoded JWT secret.
#[clap(long = "hera.l2-engine-jwt-secret", env = "L2_ENGINE_JWT_SECRET")]
pub l2_engine_jwt_secret: PathBuf,

/// The maximum **number of blocks** to keep cached in the chain provider.
///
/// This is used to limit the memory usage of the chain provider.
/// When the limit is reached, the oldest blocks are discarded.
#[clap(long = "hera.l1-chain-cache-size", default_value_t = 256)]
pub l1_chain_cache_size: usize,
}

impl NodeArgs {
/// Get the L2 rollup config, either from a file or the superchain registry.
#[allow(unused)]
pub fn get_l2_config(&self) -> Result<Arc<RollupConfig>> {
match &self.l2_config_file {
Some(path) => {
debug!("Loading l2 config from file: {:?}", path);
let file = File::open(path).wrap_err("Failed to open l2 config file")?;
Ok(Arc::new(from_reader(file).wrap_err("Failed to read l2 config file")?))
}
None => {
debug!("Loading l2 config from superchain registry");
let Some(cfg) = ROLLUP_CONFIGS.get(&self.l2_chain_id).cloned() else {
bail!("Failed to find l2 config for chain ID {}", self.l2_chain_id);
};
Ok(Arc::new(cfg))
}
}
}
}
29 changes: 4 additions & 25 deletions bin/node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,14 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]

use clap::Parser;
use eyre::Result;

mod cli;
mod telemetry;

/// CLI Arguments.
#[derive(Parser, Clone, Debug)]
#[command(author, version, about, long_about = None)]
pub(crate) struct NodeArgs {
/// The L2 chain ID to use.
#[clap(long, short = 'c', default_value = "10", help = "The L2 chain ID to use")]
pub l2_chain_id: u64,
/// A port to serve prometheus metrics on.
#[clap(
long,
short = 'm',
default_value = "9090",
help = "The port to serve prometheus metrics on"
)]
pub metrics_port: u16,
// The hilo Rollup node configuration.
// #[clap(flatten)]
// pub hilo_config: HiloArgsExt,
}

#[tokio::main]
async fn main() -> Result<()> {
async fn main() -> eyre::Result<()> {
// Parse arguments.
let args = NodeArgs::parse();
use clap::Parser;
let args = cli::NodeArgs::parse();

// Initialize the telemetry stack.
telemetry::init_stack(args.metrics_port)?;
Expand Down
20 changes: 14 additions & 6 deletions crates/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@ rust-version.workspace = true

[dependencies]
# Alloy
alloy-eips.workspace = true
alloy-network.workspace = true
alloy-rpc-client.workspace = true
alloy-rpc-types-eth.workspace = true
alloy-provider = { workspace = true, features = ["ipc", "reqwest"] }
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-provider.workspace = true
op-alloy-rpc-types-engine.workspace = true

# Misc
again.workspace = true
serde.workspace = true
futures.workspace = true
reqwest = { workspace = true, features = ["json"] }
url.workspace = true
tracing.workspace = true
tower.workspace = true
http-body-util.workspace = true
thiserror.workspace = true
serde_json.workspace = true
async-trait.workspace = true

[dev-dependencies]
tokio.workspace = true
Loading