From 05d452b646eb9fd92007d3c2ece087a9f65df14f Mon Sep 17 00:00:00 2001 From: n0x <54751288+N0xMare@users.noreply.github.com> Date: Wed, 24 Apr 2024 20:24:01 -0400 Subject: [PATCH] WIP host tracking (#136) * WIP init commit for host tracking * add telemetry * address comments * address more comments and add docs --- Cargo.lock | 119 +++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 +- bin/host/.gitkeep | 0 bin/host/Cargo.toml | 21 ++++++++ bin/host/src/main.rs | 100 ++++++++++++++++++++++++++++++++++ bin/host/src/parser.rs | 13 +++++ bin/host/src/types.rs | 16 ++++++ 7 files changed, 270 insertions(+), 1 deletion(-) delete mode 100644 bin/host/.gitkeep create mode 100644 bin/host/Cargo.toml create mode 100644 bin/host/src/main.rs create mode 100644 bin/host/src/parser.rs create mode 100644 bin/host/src/types.rs diff --git a/Cargo.lock b/Cargo.lock index b876173f..d9ce869d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -382,6 +382,54 @@ dependencies = [ "tracing", ] +[[package]] +name = "anstream" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "anyhow" version = "1.0.82" @@ -718,6 +766,52 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.60", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "const-hex" version = "1.11.3" @@ -1479,6 +1573,19 @@ dependencies = [ "unsigned-varint", ] +[[package]] +name = "kona-host" +version = "0.1.0" +dependencies = [ + "alloy-primitives", + "anyhow", + "clap", + "serde", + "tokio", + "tracing", + "tracing-subscriber", +] + [[package]] name = "kona-mpt" version = "0.0.1" @@ -2462,6 +2569,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "subtle" version = "2.5.0" @@ -2853,6 +2966,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "valuable" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 2c17072c..a0f399ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["crates/*"] +members = ["crates/*", "bin/host"] exclude = ["examples/minimal", "examples/simple-revm", "fpvm-tests/cannon-rs-tests"] resolver = "2" diff --git a/bin/host/.gitkeep b/bin/host/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/bin/host/Cargo.toml b/bin/host/Cargo.toml new file mode 100644 index 00000000..988f362e --- /dev/null +++ b/bin/host/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "kona-host" +version = "0.1.0" +edition.workspace = true +license.workspace = true +authors.workspace = true +repository.workspace = true +homepage.workspace = true +exclude.workspace = true + +[dependencies] +# workspace +anyhow.workspace = true +tracing.workspace = true +alloy-primitives = { workspace = true, features = ["serde"] } + +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/main.rs b/bin/host/src/main.rs new file mode 100644 index 00000000..1a4d5006 --- /dev/null +++ b/bin/host/src/main.rs @@ -0,0 +1,100 @@ +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; + +mod parser; +mod types; + +#[tokio::main] +async fn main() -> Result<()> { + let _cli = Cli::parse(); + let _ = init_tracing_subscriber(_cli.v); + 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, +} diff --git a/bin/host/src/parser.rs b/bin/host/src/parser.rs new file mode 100644 index 00000000..858db121 --- /dev/null +++ b/bin/host/src/parser.rs @@ -0,0 +1,13 @@ +use alloy_primitives::B256; +use std::str::FromStr; + +/// Parse string slices into alloy_primitives bytes +/// +/// # Arguments +/// * `s` - string slice +/// +/// # Returns +/// * `Result` - Ok if successful, Err otherwise. +pub fn parse_b256(s: &str) -> Result { + B256::from_str(s).map_err(|_| format!("Invalid B256 value: {}", s)) +} \ No newline at end of file diff --git a/bin/host/src/types.rs b/bin/host/src/types.rs new file mode 100644 index 00000000..a0580df1 --- /dev/null +++ b/bin/host/src/types.rs @@ -0,0 +1,16 @@ +use clap::ValueEnum; +use serde::Serialize; + +/// Available networks. +#[derive(Debug, Clone, ValueEnum, Serialize)] +pub enum Network { + /// Optimism Mainnet + Optimism, +} + +/// Available RPC provider types. +#[derive(Debug, Clone, ValueEnum, Serialize)] +pub enum RpcKind { + /// debug alloy provider + DebugRpc, +} \ No newline at end of file