diff --git a/Cargo.lock b/Cargo.lock index 85268325c..be7d8a8c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2860,7 +2860,6 @@ dependencies = [ "axum", "cargo_metadata", "clap", - "dotenvy", "evm_arithmetization", "futures", "ops", @@ -2872,7 +2871,6 @@ dependencies = [ "serde_json", "serde_path_to_error", "tokio", - "toml", "tracing", "tracing-subscriber", "vergen", @@ -3303,7 +3301,6 @@ dependencies = [ "paladin-core", "proof_gen", "serde", - "trace_decoder", "tracing", "zero_bin_common", ] @@ -5136,7 +5133,6 @@ dependencies = [ "nunny", "plonky2", "plonky2_maybe_rayon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "pretty_env_logger", "prover", "rlp", "serde", @@ -5814,6 +5810,7 @@ dependencies = [ "cargo_metadata", "clap", "directories", + "dotenvy", "evm_arithmetization", "futures", "lru", @@ -5822,10 +5819,11 @@ dependencies = [ "proof_gen", "serde", "serde_json", + "serde_path_to_error", "thiserror", "tokio", - "trace_decoder", "tracing", + "tracing-subscriber", "vergen", ] diff --git a/trace_decoder/Cargo.toml b/trace_decoder/Cargo.toml index 4febd85f2..8bdeaf022 100644 --- a/trace_decoder/Cargo.toml +++ b/trace_decoder/Cargo.toml @@ -50,7 +50,6 @@ criterion = { workspace = true } glob = "0.3.1" libtest-mimic = "0.7.3" plonky2_maybe_rayon = { workspace = true } -pretty_env_logger = { workspace = true } prover = { workspace = true } serde_json = { workspace = true } serde_path_to_error = { workspace = true } diff --git a/zero_bin/common/Cargo.toml b/zero_bin/common/Cargo.toml index 0b389cf9f..c66397ca1 100644 --- a/zero_bin/common/Cargo.toml +++ b/zero_bin/common/Cargo.toml @@ -14,15 +14,18 @@ anyhow = { workspace = true } async-stream = { workspace = true } cargo_metadata = { workspace = true } clap = { workspace = true } +dotenvy = { workspace = true } futures = { workspace = true } lru = { workspace = true } once_cell = { workspace = true } plonky2 = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } +serde_path_to_error = { workspace = true } thiserror = { workspace = true } tokio = { workspace = true } tracing = { workspace = true } +tracing-subscriber = { workspace = true } vergen = { workspace = true } directories = "5.0.1" @@ -30,24 +33,22 @@ directories = "5.0.1" # Local dependencies evm_arithmetization = { workspace = true } proof_gen = { workspace = true } -trace_decoder = { workspace = true } [build-dependencies] +anyhow = { workspace = true } cargo_metadata = { workspace = true } vergen = { workspace = true } -anyhow = { workspace = true } + [features] default = ["eth_mainnet"] eth_mainnet = [ "evm_arithmetization/eth_mainnet", "proof_gen/eth_mainnet", - "trace_decoder/eth_mainnet", ] cdk_erigon = [ "evm_arithmetization/cdk_erigon", "proof_gen/cdk_erigon", - "trace_decoder/cdk_erigon", ] [lints] diff --git a/zero_bin/common/src/env.rs b/zero_bin/common/src/env.rs new file mode 100644 index 000000000..f1356247e --- /dev/null +++ b/zero_bin/common/src/env.rs @@ -0,0 +1,16 @@ +use std::io; + +use dotenvy::dotenv; +use tracing::warn; + +/// Attempt to load in the local `.env` if present and set any environment +/// variables specified inside of it. +/// +/// To keep things simple, any IO error we will treat as the file not existing +/// and continue moving on without the `env` variables set. +pub fn load_dotenvy_vars_if_present() { + match dotenv() { + Ok(_) | Err(dotenvy::Error::Io(io::Error { .. })) => (), + Err(e) => warn!("Found local `.env` file but was unable to parse it! (err: {e})",), + } +} diff --git a/zero_bin/common/src/fs.rs b/zero_bin/common/src/fs.rs index 7603f5100..6d274903e 100644 --- a/zero_bin/common/src/fs.rs +++ b/zero_bin/common/src/fs.rs @@ -1,7 +1,22 @@ +use std::fs::File; use std::path::PathBuf; +use proof_gen::proof_types::GeneratedBlockProof; + pub fn generate_block_proof_file_name(directory: &Option<&str>, block_height: u64) -> PathBuf { let mut path = PathBuf::from(directory.unwrap_or("")); path.push(format!("b{}.zkproof", block_height)); path } + +pub fn get_previous_proof(path: Option) -> anyhow::Result> { + if path.is_none() { + return Ok(None); + } + + let path = path.unwrap(); + let file = File::open(path)?; + let des = &mut serde_json::Deserializer::from_reader(&file); + let proof: GeneratedBlockProof = serde_path_to_error::deserialize(des)?; + Ok(Some(proof)) +} diff --git a/zero_bin/common/src/lib.rs b/zero_bin/common/src/lib.rs index 42ce661d7..d810ecb53 100644 --- a/zero_bin/common/src/lib.rs +++ b/zero_bin/common/src/lib.rs @@ -1,10 +1,12 @@ pub mod block_interval; pub mod debug_utils; +pub mod env; pub mod fs; pub mod parsing; pub mod pre_checks; pub mod prover_state; pub mod provider; +pub mod tracing; pub mod version; /// Size of the channel used to send block prover inputs to the per block diff --git a/zero_bin/leader/src/init.rs b/zero_bin/common/src/tracing.rs similarity index 92% rename from zero_bin/leader/src/init.rs rename to zero_bin/common/src/tracing.rs index f93914895..6c3f9a8bc 100644 --- a/zero_bin/leader/src/init.rs +++ b/zero_bin/common/src/tracing.rs @@ -1,5 +1,6 @@ use tracing_subscriber::{prelude::*, util::SubscriberInitExt, EnvFilter}; -pub(crate) fn tracing() { + +pub fn init() { tracing_subscriber::Registry::default() .with( tracing_subscriber::fmt::layer() diff --git a/zero_bin/leader/Cargo.toml b/zero_bin/leader/Cargo.toml index 5b9a67f34..c90d70948 100644 --- a/zero_bin/leader/Cargo.toml +++ b/zero_bin/leader/Cargo.toml @@ -10,20 +10,18 @@ categories.workspace = true build = "../common/build.rs" [dependencies] -paladin-core = { workspace = true } -clap = { workspace = true } -tracing = { workspace = true } -tracing-subscriber = { workspace = true } +alloy = { workspace = true } anyhow = { workspace = true } +axum = { workspace = true } +clap = { workspace = true } +futures = { workspace = true } +paladin-core = { workspace = true } serde = { workspace = true } -dotenvy = { workspace = true } -tokio = { workspace = true } serde_json = { workspace = true } serde_path_to_error = { workspace = true } -futures = { workspace = true } -alloy.workspace = true -axum = { workspace = true } -toml = { workspace = true } +tokio = { workspace = true } +tracing = { workspace = true } +tracing-subscriber = { workspace = true } # Local dependencies evm_arithmetization = { workspace = true } diff --git a/zero_bin/leader/src/main.rs b/zero_bin/leader/src/main.rs index c0311b15c..b230009cc 100644 --- a/zero_bin/leader/src/main.rs +++ b/zero_bin/leader/src/main.rs @@ -1,17 +1,16 @@ +use std::env; use std::sync::Arc; -use std::{env, io}; -use std::{fs::File, path::PathBuf}; use anyhow::Result; use clap::Parser; use cli::Command; use client::RpcParams; -use dotenvy::dotenv; use ops::register; use paladin::runtime::Runtime; -use proof_gen::proof_types::GeneratedBlockProof; use prover::ProverConfig; -use tracing::{info, warn}; +use tracing::info; +use zero_bin_common::env::load_dotenvy_vars_if_present; +use zero_bin_common::fs::get_previous_proof; use zero_bin_common::{ block_interval::BlockInterval, prover_state::persistence::set_circuit_cache_dir_env_if_not_set, }; @@ -22,26 +21,13 @@ use crate::client::{client_main, LeaderConfig}; mod cli; mod client; mod http; -mod init; mod stdio; -fn get_previous_proof(path: Option) -> Result> { - if path.is_none() { - return Ok(None); - } - - let path = path.unwrap(); - let file = File::open(path)?; - let des = &mut serde_json::Deserializer::from_reader(&file); - let proof: GeneratedBlockProof = serde_path_to_error::deserialize(des)?; - Ok(Some(proof)) -} - #[tokio::main] async fn main() -> Result<()> { load_dotenvy_vars_if_present(); set_circuit_cache_dir_env_if_not_set()?; - init::tracing(); + zero_bin_common::tracing::init(); let args: Vec = env::args().collect(); @@ -127,15 +113,3 @@ async fn main() -> Result<()> { Ok(()) } - -/// Attempt to load in the local `.env` if present and set any environment -/// variables specified inside of it. -/// -/// To keep things simple, any IO error we will treat as the file not existing -/// and continue moving on without the `env` variables set. -fn load_dotenvy_vars_if_present() { - match dotenv() { - Ok(_) | Err(dotenvy::Error::Io(io::Error { .. })) => (), - Err(e) => warn!("Found local `.env` file but was unable to parse it! (err: {e})",), - } -} diff --git a/zero_bin/ops/Cargo.toml b/zero_bin/ops/Cargo.toml index 4e7bef01a..14b59eadd 100644 --- a/zero_bin/ops/Cargo.toml +++ b/zero_bin/ops/Cargo.toml @@ -9,15 +9,14 @@ keywords.workspace = true categories.workspace = true [dependencies] +keccak-hash = { workspace = true } paladin-core = { workspace = true } serde = { workspace = true } tracing = { workspace = true } -keccak-hash = { workspace = true } # Local dependencies evm_arithmetization = { workspace = true } proof_gen = { workspace = true } -trace_decoder = { workspace = true } zero_bin_common = { workspace = true } [features] @@ -25,12 +24,10 @@ default = ["eth_mainnet"] eth_mainnet = [ "evm_arithmetization/eth_mainnet", "proof_gen/eth_mainnet", - "trace_decoder/eth_mainnet", "zero_bin_common/eth_mainnet", ] cdk_erigon = [ "evm_arithmetization/cdk_erigon", "proof_gen/cdk_erigon", - "trace_decoder/cdk_erigon", "zero_bin_common/cdk_erigon", ] diff --git a/zero_bin/rpc/Cargo.toml b/zero_bin/rpc/Cargo.toml index 8d4444bb6..64e494ca8 100644 --- a/zero_bin/rpc/Cargo.toml +++ b/zero_bin/rpc/Cargo.toml @@ -16,6 +16,7 @@ anyhow = { workspace = true } clap = { workspace = true } futures = { workspace = true } hex = { workspace = true } +itertools = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } tokio = { workspace = true } @@ -23,7 +24,6 @@ tower = { workspace = true, features = ["retry"] } tracing = { workspace = true } tracing-subscriber = { workspace = true } url = { workspace = true } -itertools = { workspace = true } # Local dependencies compat = { workspace = true } @@ -34,9 +34,9 @@ trace_decoder = { workspace = true } zero_bin_common = { workspace = true } [build-dependencies] +anyhow = { workspace = true } cargo_metadata = { workspace = true } vergen = { workspace = true } -anyhow = { workspace = true } [features] default = ["eth_mainnet"] diff --git a/zero_bin/verifier/Cargo.toml b/zero_bin/verifier/Cargo.toml index 80d64df1f..259c6d3f5 100644 --- a/zero_bin/verifier/Cargo.toml +++ b/zero_bin/verifier/Cargo.toml @@ -6,22 +6,22 @@ edition = "2021" build = "../common/build.rs" [dependencies] +anyhow = { workspace = true } clap = { workspace = true } -tracing = { workspace = true } -tracing-subscriber = { workspace = true } dotenvy = { workspace = true } -anyhow = { workspace = true } serde_json = { workspace = true } serde_path_to_error = { workspace = true } +tracing = { workspace = true } +tracing-subscriber = { workspace = true } # Local dependencies proof_gen = { workspace = true } zero_bin_common = { workspace = true } [build-dependencies] +anyhow = { workspace = true } cargo_metadata = { workspace = true } vergen = { workspace = true } -anyhow = { workspace = true } [features] diff --git a/zero_bin/worker/src/init.rs b/zero_bin/worker/src/init.rs deleted file mode 100644 index f93914895..000000000 --- a/zero_bin/worker/src/init.rs +++ /dev/null @@ -1,11 +0,0 @@ -use tracing_subscriber::{prelude::*, util::SubscriberInitExt, EnvFilter}; -pub(crate) fn tracing() { - tracing_subscriber::Registry::default() - .with( - tracing_subscriber::fmt::layer() - .with_ansi(false) - .compact() - .with_filter(EnvFilter::from_default_env()), - ) - .init(); -} diff --git a/zero_bin/worker/src/main.rs b/zero_bin/worker/src/main.rs index 08b125ad9..3ea4c7cae 100644 --- a/zero_bin/worker/src/main.rs +++ b/zero_bin/worker/src/main.rs @@ -9,9 +9,7 @@ use zero_bin_common::prover_state::{ cli::CliProverStateConfig, persistence::{set_circuit_cache_dir_env_if_not_set, CIRCUIT_VERSION}, }; -use zero_bin_common::version; - -mod init; +use zero_bin_common::{tracing, version}; // TODO: https://github.com/0xPolygonZero/zk_evm/issues/302 // this should probably be removed. @@ -40,7 +38,7 @@ async fn main() -> Result<()> { } dotenv().ok(); - init::tracing(); + tracing::init(); set_circuit_cache_dir_env_if_not_set()?; let args = Cli::parse();