diff --git a/bin/host/Cargo.toml b/bin/host/Cargo.toml index 988f362e1f..2edbc0a7c1 100644 --- a/bin/host/Cargo.toml +++ b/bin/host/Cargo.toml @@ -18,4 +18,3 @@ tokio = { version = "1.37.0", features = ["full"] } clap = { version = "4.5.4", features = ["derive", "env"] } serde = { version = "1.0.198", features = ["derive"] } tracing-subscriber = "0.3.18" - diff --git a/bin/host/src/cli/mod.rs b/bin/host/src/cli/mod.rs new file mode 100644 index 0000000000..bc95895542 --- /dev/null +++ b/bin/host/src/cli/mod.rs @@ -0,0 +1,74 @@ +//! This module contains all CLI-specific code for the host binary. + +use alloy_primitives::B256; +use clap::{ArgAction, Parser}; +use serde::Serialize; +use std::path::PathBuf; + +mod parser; +pub(crate) use parser::parse_b256; + +mod types; +pub(crate) use types::{Network, RpcKind}; + +mod tracing_util; +pub(crate) use tracing_util::init_tracing_subscriber; + +/// The host binary CLI application arguments. +#[derive(Parser, Serialize)] +pub struct HostCli { + /// Verbosity level (0-4) + #[arg(long, short, help = "Verbosity level (0-4)", action = ArgAction::Count)] + pub v: u8, + /// The rollup chain parameters + #[clap(long)] + pub rollup_config: PathBuf, + /// Predefined network selection. + #[clap(long)] + pub network: Network, + /// The Data Directory for preimage data storage. Default uses in-memory storage. + #[clap(long)] + pub data_dir: Option, + /// Address of L2 JSON-RPC endpoint to use (eth and debug namespace required). + #[clap(long)] + pub l2_node_address: String, + /// Hash of the L1 head block. Derivation stops after this block is processed. + #[clap(long, value_parser = parse_b256)] + pub l1_head: B256, + /// Hash of the L2 block at the L2 Output Root. + #[clap(long, value_parser = parse_b256)] + pub l2_head: B256, + /// Agreed L2 Output Root to start derivation from. + #[clap(long, value_parser = parse_b256)] + pub l2_output_root: B256, + /// Claimed L2 output root to validate + #[clap(long, value_parser = parse_b256)] + pub l2_claim: B256, + /// Number of the L2 block that the claim is from. + #[clap(long)] + pub l2_block_number: u64, + //// Path to the genesis file. + #[clap(long)] + pub l2_genesis_path: PathBuf, + /// Address of L1 JSON-RPC endpoint to use (eth namespace required) + #[clap(long)] + pub l1_node_address: String, + /// Address of the L1 Beacon API endpoint to use. + #[clap(long)] + pub l1_beacon_address: String, + /// Trust the L1 RPC, sync faster at risk of malicious/buggy RPC providing bad or inconsistent + /// L1 data + #[clap(long)] + pub l1_trust_rpc: bool, + /// The kind of RPC provider, used to inform optimal transactions receipts fetching, and thus + /// reduce costs. + #[clap(long)] + pub l1_rpc_provider_kind: RpcKind, + /// Run the specified client program as a separate process detached from the host. Default is + /// to run the client program in the host process. + #[clap(long)] + pub exec: String, + /// Run in pre-image server mode without executing any client program. + #[clap(long)] + pub server: bool, +} diff --git a/bin/host/src/parser.rs b/bin/host/src/cli/parser.rs similarity index 100% rename from bin/host/src/parser.rs rename to bin/host/src/cli/parser.rs diff --git a/bin/host/src/cli/tracing_util.rs b/bin/host/src/cli/tracing_util.rs new file mode 100644 index 0000000000..1deadeadca --- /dev/null +++ b/bin/host/src/cli/tracing_util.rs @@ -0,0 +1,24 @@ +//! Contains utilities for initializing the tracing subscriber. + +use anyhow::{anyhow, Result}; +use tracing::Level; + +/// Initializes the tracing subscriber +/// +/// # Arguments +/// * `verbosity_level` - The verbosity level (0-4) +/// +/// # Returns +/// * `Result<()>` - Ok if successful, Err otherwise. +pub fn init_tracing_subscriber(verbosity_level: u8) -> Result<()> { + let subscriber = tracing_subscriber::fmt() + .with_max_level(match verbosity_level { + 0 => Level::ERROR, + 1 => Level::WARN, + 2 => Level::INFO, + 3 => Level::DEBUG, + _ => Level::TRACE, + }) + .finish(); + tracing::subscriber::set_global_default(subscriber).map_err(|e| anyhow!(e)) +} diff --git a/bin/host/src/types.rs b/bin/host/src/cli/types.rs similarity index 100% rename from bin/host/src/types.rs rename to bin/host/src/cli/types.rs diff --git a/bin/host/src/main.rs b/bin/host/src/main.rs index c8c056a126..39adb427e8 100644 --- a/bin/host/src/main.rs +++ b/bin/host/src/main.rs @@ -1,100 +1,13 @@ -use crate::{ - parser::parse_b256, - types::{Network, RpcKind}, -}; -use alloy_primitives::B256; -use anyhow::{anyhow, Result}; -use clap::{ArgAction, Parser}; -use serde::Serialize; -use std::path::PathBuf; -use tracing::Level; +use crate::cli::{init_tracing_subscriber, HostCli}; +use anyhow::Result; +use clap::Parser; -mod parser; -mod types; +mod cli; #[tokio::main] async fn main() -> Result<()> { - let _cli = Cli::parse(); - let _ = init_tracing_subscriber(_cli.v); + let HostCli { v: tracing_verbosity, .. } = HostCli::parse(); + let _ = init_tracing_subscriber(tracing_verbosity); tracing::info!("host telemetry initialized"); Ok(()) } - -/// Initializes the tracing subscriber -/// -/// # Arguments -/// * `verbosity_level` - The verbosity level (0-4) -/// -/// # Returns -/// * `Result<()>` - Ok if successful, Err otherwise. -fn init_tracing_subscriber(verbosity_level: u8) -> Result<()> { - let subscriber = tracing_subscriber::fmt() - .with_max_level(match verbosity_level { - 0 => Level::ERROR, - 1 => Level::WARN, - 2 => Level::INFO, - 3 => Level::DEBUG, - _ => Level::TRACE, - }) - .finish(); - tracing::subscriber::set_global_default(subscriber).map_err(|e| anyhow!(e)) -} - -/// The host binary CLI application arguments. -#[derive(Parser, Serialize)] -pub struct Cli { - /// Verbosity level (0-4) - #[arg(long, short, help = "Verbosity level (0-4)", action = ArgAction::Count)] - v: u8, - /// The rollup chain parameters - #[clap(long)] - pub rollup_config: PathBuf, - /// Predefined network selection. - #[clap(long)] - pub network: Network, - /// The Data Directory for preimage data storage. Default uses in-memory storage. - #[clap(long)] - pub data_dir: Option, - /// Address of L2 JSON-RPC endpoint to use (eth and debug namespace required). - #[clap(long)] - pub l2_node_address: String, - /// Hash of the L1 head block. Derivation stops after this block is processed. - #[clap(long, value_parser = parse_b256)] - pub l1_head: B256, - /// Hash of the L2 block at the L2 Output Root. - #[clap(long, value_parser = parse_b256)] - pub l2_head: B256, - /// Agreed L2 Output Root to start derivation from. - #[clap(long, value_parser = parse_b256)] - pub l2_output_root: B256, - /// Claimed L2 output root to validate - #[clap(long, value_parser = parse_b256)] - pub l2_claim: B256, - /// Number of the L2 block that the claim is from. - #[clap(long)] - pub l2_block_number: u64, - //// Path to the genesis file. - #[clap(long)] - pub l2_genesis_path: PathBuf, - /// Address of L1 JSON-RPC endpoint to use (eth namespace required) - #[clap(long)] - pub l1_node_address: String, - /// Address of the L1 Beacon API endpoint to use. - #[clap(long)] - pub l1_beacon_address: String, - /// Trust the L1 RPC, sync faster at risk of malicious/buggy RPC providing bad or inconsistent - /// L1 data - #[clap(long)] - pub l1_trust_rpc: bool, - /// The kind of RPC provider, used to inform optimal transactions receipts fetching, and thus - /// reduce costs. - #[clap(long)] - pub l1_rpc_provider_kind: RpcKind, - /// Run the specified client program as a separate process detached from the host. Default is - /// to run the client program in the host process. - #[clap(long)] - pub exec: String, - /// Run in pre-image server mode without executing any client program. - #[clap(long)] - pub server: bool, -}