Skip to content

Commit

Permalink
feat: optionally load rollup config from file
Browse files Browse the repository at this point in the history
  • Loading branch information
merklefruit committed Aug 25, 2024
1 parent 8be7253 commit 721bd66
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions bin/op-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ reth-node-ethereum.workspace = true

# OP Stack Dependencies
superchain-registry = { workspace = true, default-features = false }

# Misc
serde_json = "1.0.125"
25 changes: 19 additions & 6 deletions bin/op-rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]

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

use clap::Parser;
use eyre::{bail, Result};
use eyre::{bail, Context, Result};
use reth::cli::Cli;
use reth_node_ethereum::EthereumNode;
use rollup::{Driver, HeraArgsExt, HERA_EXEX_ID};
use serde_json::from_reader;
use superchain_registry::ROLLUP_CONFIGS;
use tracing::{info, warn};
use tracing::{debug, info, warn};

use rollup::{Driver, HeraArgsExt, HERA_EXEX_ID};

/// The Reth CLI arguments with optional Hera Execution Extension support.
#[derive(Debug, Clone, Parser)]
Expand All @@ -38,8 +40,19 @@ fn main() -> Result<()> {
bail!("Hera Execution Extension configuration is required when the `hera` flag is set");
};

let Some(cfg) = ROLLUP_CONFIGS.get(&hera_args.l2_chain_id).cloned().map(Arc::new) else {
bail!("Rollup configuration not found for L2 chain ID: {}", hera_args.l2_chain_id);
let cfg = match &hera_args.l2_config_file {
Some(path) => {
info!("Loading l2 config from file: {:?}", path);
let file = File::open(path).wrap_err("Failed to open l2 config file")?;
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(&hera_args.l2_chain_id).cloned() else {
bail!("Failed to find l2 config for chain ID {}", hera_args.l2_chain_id);
};
Arc::new(cfg)
}
};

let node = EthereumNode::default();
Expand Down
7 changes: 6 additions & 1 deletion crates/rollup/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ pub struct HeraArgsExt {
#[clap(long = "hera.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,
Expand All @@ -46,7 +51,7 @@ pub struct HeraArgsExt {
#[clap(
long = "hera.validation-mode",
default_value = "trusted",
requires_ifs([("engine-api", "l2-engine-api-url"), ("engine-api", "l2-engine-jwt-secret")]),
requires_ifs([("engine-api", "l2_engine_api_url"), ("engine-api", "l2_engine_jwt_secret")]),
)]
pub validation_mode: ValidationMode,

Expand Down

0 comments on commit 721bd66

Please sign in to comment.