From f9dcab60b71470ae264e4465a766f4d9a9312a53 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Mon, 29 Jul 2024 17:58:49 +0530 Subject: [PATCH] fix review comments --- zero_bin/common/src/lib.rs | 1 + zero_bin/common/src/version.rs | 12 ++++++ zero_bin/leader/Cargo.toml | 2 +- zero_bin/leader/src/main.rs | 48 +++++----------------- zero_bin/rpc/Cargo.toml | 2 +- zero_bin/rpc/build.rs | 30 -------------- zero_bin/rpc/src/main.rs | 52 +++--------------------- zero_bin/verifier/Cargo.toml | 2 +- zero_bin/verifier/build.rs | 30 -------------- zero_bin/verifier/src/main.rs | 48 +++------------------- zero_bin/{leader/build.rs => version.rs} | 2 +- zero_bin/worker/Cargo.toml | 2 +- zero_bin/worker/build.rs | 30 -------------- zero_bin/worker/src/main.rs | 48 +++------------------- 14 files changed, 45 insertions(+), 264 deletions(-) create mode 100644 zero_bin/common/src/version.rs delete mode 100644 zero_bin/rpc/build.rs delete mode 100644 zero_bin/verifier/build.rs rename zero_bin/{leader/build.rs => version.rs} (92%) delete mode 100644 zero_bin/worker/build.rs diff --git a/zero_bin/common/src/lib.rs b/zero_bin/common/src/lib.rs index 1b0b18e9b..5570a5d5f 100644 --- a/zero_bin/common/src/lib.rs +++ b/zero_bin/common/src/lib.rs @@ -3,3 +3,4 @@ pub mod debug_utils; pub mod fs; pub mod parsing; pub mod prover_state; +pub mod version; diff --git a/zero_bin/common/src/version.rs b/zero_bin/common/src/version.rs new file mode 100644 index 000000000..94e9529c1 --- /dev/null +++ b/zero_bin/common/src/version.rs @@ -0,0 +1,12 @@ +pub fn print_version( + evm_arithmetization_package_version: &str, + rustc_commit_hash: &str, + rustc_timestamp: &str, +) { + println!( + "Evm Arithmetization package version: {:?}", + evm_arithmetization_package_version + ); + println!("Build Commit Hash: {:?}", rustc_commit_hash); + println!("Build Timestamp: {:?}", rustc_timestamp); +} diff --git a/zero_bin/leader/Cargo.toml b/zero_bin/leader/Cargo.toml index aa7624397..7ebfc95b4 100644 --- a/zero_bin/leader/Cargo.toml +++ b/zero_bin/leader/Cargo.toml @@ -7,7 +7,7 @@ license.workspace = true repository.workspace = true keywords.workspace = true categories.workspace = true -build = "build.rs" +build = "../version.rs" [dependencies] paladin-core = { workspace = true } diff --git a/zero_bin/leader/src/main.rs b/zero_bin/leader/src/main.rs index 94f02b729..94b6945ba 100644 --- a/zero_bin/leader/src/main.rs +++ b/zero_bin/leader/src/main.rs @@ -11,6 +11,7 @@ use paladin::runtime::Runtime; use proof_gen::proof_types::GeneratedBlockProof; use tracing::{info, warn}; use zero_bin_common::block_interval::BlockInterval; +use zero_bin_common::version; use crate::client::{client_main, ProofParams}; @@ -20,9 +21,7 @@ mod http; mod init; mod stdio; -const EVM_ARITH_VER_KEY: &str = "EVM_ARITHMETIZATION_PKG_VER"; -const VERGEN_BUILD_TIMESTAMP: &str = "VERGEN_BUILD_TIMESTAMP"; -const VERGEN_RUSTC_COMMIT_HASH: &str = "VERGEN_RUSTC_COMMIT_HASH"; +const EVM_ARITHMETIZATION_PKG_VER: &str = "EVM_ARITHMETIZATION_PKG_VER"; fn get_previous_proof(path: Option) -> Result> { if path.is_none() { @@ -41,36 +40,14 @@ async fn main() -> Result<()> { load_dotenvy_vars_if_present(); init::tracing(); - if env::var_os(EVM_ARITH_VER_KEY).is_none() { + if env::var_os(EVM_ARITHMETIZATION_PKG_VER).is_none() { // Safety: // - we're early enough in main that nothing else should race unsafe { env::set_var( - EVM_ARITH_VER_KEY, - // see build.rs - env!("EVM_ARITHMETIZATION_PACKAGE_VERSION"), - ); - } - } - if env::var_os(VERGEN_BUILD_TIMESTAMP).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - VERGEN_BUILD_TIMESTAMP, - // see build.rs - env!("VERGEN_BUILD_TIMESTAMP"), - ); - } - } - if env::var_os(VERGEN_RUSTC_COMMIT_HASH).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - VERGEN_RUSTC_COMMIT_HASH, - // see build.rs - env!("VERGEN_RUSTC_COMMIT_HASH"), + EVM_ARITHMETIZATION_PKG_VER, + // see version.rs + env!("EVM_ARITHMETIZATION_PKG_VER"), ); } } @@ -85,14 +62,11 @@ async fn main() -> Result<()> { } match args.command { - Command::Version {} => { - println!( - "Evm Arithmetization package version: {}", - env::var(EVM_ARITH_VER_KEY)? - ); - println!("Build Commit Hash: {}", env::var(VERGEN_RUSTC_COMMIT_HASH)?); - println!("Build Timestamp: {}", env::var(VERGEN_BUILD_TIMESTAMP)?); - } + Command::Version {} => version::print_version( + env!("EVM_ARITHMETIZATION_PKG_VER"), + env!("VERGEN_RUSTC_COMMIT_HASH"), + env!("VERGEN_BUILD_TIMESTAMP"), + ), Command::Stdio { previous_proof, save_inputs_on_error, diff --git a/zero_bin/rpc/Cargo.toml b/zero_bin/rpc/Cargo.toml index cba6c926c..2dce86d99 100644 --- a/zero_bin/rpc/Cargo.toml +++ b/zero_bin/rpc/Cargo.toml @@ -7,7 +7,7 @@ license.workspace = true repository.workspace = true keywords.workspace = true categories.workspace = true -build = "build.rs" +build = "../version.rs" [dependencies] __compat_primitive_types = { workspace = true } diff --git a/zero_bin/rpc/build.rs b/zero_bin/rpc/build.rs deleted file mode 100644 index da63d6e21..000000000 --- a/zero_bin/rpc/build.rs +++ /dev/null @@ -1,30 +0,0 @@ -use anyhow::Context as _; -use vergen::{BuildBuilder, Emitter, RustcBuilder}; - -fn main() -> anyhow::Result<()> { - let build_timestamp = BuildBuilder::default().build_timestamp(true).build()?; - let rust_commit_hash = RustcBuilder::default().commit_hash(true).build()?; - - Emitter::default() - .add_instructions(&build_timestamp)? - .add_instructions(&rust_commit_hash)? - .emit()?; - - let meta = cargo_metadata::MetadataCommand::new() - .exec() - .context("failed to probe cargo-metadata")?; - let version = &meta - .packages - .iter() - .find(|it| it.name == "evm_arithmetization") - .context("couldn't find evm_arithmetization package")? - .version; - println!( - "cargo::rustc-env=EVM_ARITHMETIZATION_PACKAGE_VERSION={}.{}.x", - // patch version change should not prompt circuits regeneration - version.major, - version.minor - ); - - Ok(()) -} diff --git a/zero_bin/rpc/src/main.rs b/zero_bin/rpc/src/main.rs index cdb671ffd..893c44535 100644 --- a/zero_bin/rpc/src/main.rs +++ b/zero_bin/rpc/src/main.rs @@ -7,10 +7,7 @@ use rpc::{retry::build_http_retry_provider, RpcType}; use tracing_subscriber::{prelude::*, EnvFilter}; use url::Url; use zero_bin_common::block_interval::BlockInterval; - -const EVM_ARITH_VER_KEY: &str = "EVM_ARITHMETIZATION_PKG_VER"; -const VERGEN_BUILD_TIMESTAMP: &str = "VERGEN_BUILD_TIMESTAMP"; -const VERGEN_RUSTC_COMMIT_HASH: &str = "VERGEN_RUSTC_COMMIT_HASH"; +use zero_bin_common::version; #[derive(Parser)] pub enum Cli { @@ -47,14 +44,11 @@ impl Cli { /// Execute the cli command. pub async fn execute(self) -> anyhow::Result<()> { match self { - Self::Version {} => { - println!( - "Evm Arithmetization package version: {}", - env::var(EVM_ARITH_VER_KEY)? - ); - println!("Build Commit Hash: {}", env::var(VERGEN_RUSTC_COMMIT_HASH)?); - println!("Build Timestamp: {}", env::var(VERGEN_BUILD_TIMESTAMP)?); - } + Self::Version {} => version::print_version( + env!("EVM_ARITHMETIZATION_PKG_VER"), + env!("VERGEN_RUSTC_COMMIT_HASH"), + env!("VERGEN_BUILD_TIMESTAMP"), + ), Self::Fetch { start_block, end_block, @@ -92,40 +86,6 @@ impl Cli { #[tokio::main] async fn main() -> anyhow::Result<()> { - if env::var_os(EVM_ARITH_VER_KEY).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - EVM_ARITH_VER_KEY, - // see build.rs - env!("EVM_ARITHMETIZATION_PACKAGE_VERSION"), - ); - } - } - if env::var_os(VERGEN_BUILD_TIMESTAMP).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - VERGEN_BUILD_TIMESTAMP, - // see build.rs - env!("VERGEN_BUILD_TIMESTAMP"), - ); - } - } - if env::var_os(VERGEN_RUSTC_COMMIT_HASH).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - VERGEN_RUSTC_COMMIT_HASH, - // see build.rs - env!("VERGEN_RUSTC_COMMIT_HASH"), - ); - } - } - tracing_subscriber::Registry::default() .with( tracing_subscriber::fmt::layer() diff --git a/zero_bin/verifier/Cargo.toml b/zero_bin/verifier/Cargo.toml index c1a76f56a..d55e681bc 100644 --- a/zero_bin/verifier/Cargo.toml +++ b/zero_bin/verifier/Cargo.toml @@ -3,7 +3,7 @@ name = "verifier" authors = ["Polygon Zero "] version = "0.1.0" edition = "2021" -build = "build.rs" +build = "../version.rs" [dependencies] clap = { workspace = true } diff --git a/zero_bin/verifier/build.rs b/zero_bin/verifier/build.rs deleted file mode 100644 index da63d6e21..000000000 --- a/zero_bin/verifier/build.rs +++ /dev/null @@ -1,30 +0,0 @@ -use anyhow::Context as _; -use vergen::{BuildBuilder, Emitter, RustcBuilder}; - -fn main() -> anyhow::Result<()> { - let build_timestamp = BuildBuilder::default().build_timestamp(true).build()?; - let rust_commit_hash = RustcBuilder::default().commit_hash(true).build()?; - - Emitter::default() - .add_instructions(&build_timestamp)? - .add_instructions(&rust_commit_hash)? - .emit()?; - - let meta = cargo_metadata::MetadataCommand::new() - .exec() - .context("failed to probe cargo-metadata")?; - let version = &meta - .packages - .iter() - .find(|it| it.name == "evm_arithmetization") - .context("couldn't find evm_arithmetization package")? - .version; - println!( - "cargo::rustc-env=EVM_ARITHMETIZATION_PACKAGE_VERSION={}.{}.x", - // patch version change should not prompt circuits regeneration - version.major, - version.minor - ); - - Ok(()) -} diff --git a/zero_bin/verifier/src/main.rs b/zero_bin/verifier/src/main.rs index 99d9cfb87..6f5d9db0a 100644 --- a/zero_bin/verifier/src/main.rs +++ b/zero_bin/verifier/src/main.rs @@ -7,62 +7,24 @@ use dotenvy::dotenv; use proof_gen::proof_types::GeneratedBlockProof; use serde_json::Deserializer; use tracing::info; +use zero_bin_common::version; mod cli; mod init; use cli::Command; -const EVM_ARITH_VER_KEY: &str = "EVM_ARITHMETIZATION_PKG_VER"; -const VERGEN_BUILD_TIMESTAMP: &str = "VERGEN_BUILD_TIMESTAMP"; -const VERGEN_RUSTC_COMMIT_HASH: &str = "VERGEN_RUSTC_COMMIT_HASH"; - fn main() -> Result<()> { dotenv().ok(); init::tracing(); let args = cli::Cli::parse(); - if env::var_os(EVM_ARITH_VER_KEY).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - EVM_ARITH_VER_KEY, - // see build.rs - env!("EVM_ARITHMETIZATION_PACKAGE_VERSION"), - ); - } - } - if env::var_os(VERGEN_BUILD_TIMESTAMP).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - VERGEN_BUILD_TIMESTAMP, - // see build.rs - env!("VERGEN_BUILD_TIMESTAMP"), - ); - } - } - if env::var_os(VERGEN_RUSTC_COMMIT_HASH).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - VERGEN_RUSTC_COMMIT_HASH, - // see build.rs - env!("VERGEN_RUSTC_COMMIT_HASH"), - ); - } - } - if let Some(Command::Version {}) = args.command { - println!( - "Evm Arithmetization package version: {}", - env::var(EVM_ARITH_VER_KEY)? + version::print_version( + env!("EVM_ARITHMETIZATION_PKG_VER"), + env!("VERGEN_RUSTC_COMMIT_HASH"), + env!("VERGEN_BUILD_TIMESTAMP"), ); - println!("Build Commit Hash: {}", env::var(VERGEN_RUSTC_COMMIT_HASH)?); - println!("Build Timestamp: {}", env::var(VERGEN_BUILD_TIMESTAMP)?); return Ok(()); } diff --git a/zero_bin/leader/build.rs b/zero_bin/version.rs similarity index 92% rename from zero_bin/leader/build.rs rename to zero_bin/version.rs index da63d6e21..c3e7b006d 100644 --- a/zero_bin/leader/build.rs +++ b/zero_bin/version.rs @@ -20,7 +20,7 @@ fn main() -> anyhow::Result<()> { .context("couldn't find evm_arithmetization package")? .version; println!( - "cargo::rustc-env=EVM_ARITHMETIZATION_PACKAGE_VERSION={}.{}.x", + "cargo::rustc-env=EVM_ARITHMETIZATION_PKG_VER={}.{}.x", // patch version change should not prompt circuits regeneration version.major, version.minor diff --git a/zero_bin/worker/Cargo.toml b/zero_bin/worker/Cargo.toml index 1dc01077f..9d85f2197 100644 --- a/zero_bin/worker/Cargo.toml +++ b/zero_bin/worker/Cargo.toml @@ -7,7 +7,7 @@ license.workspace = true repository.workspace = true keywords.workspace = true categories.workspace = true -build = "build.rs" +build = "../version.rs" [dependencies] paladin-core = { workspace = true } diff --git a/zero_bin/worker/build.rs b/zero_bin/worker/build.rs deleted file mode 100644 index da63d6e21..000000000 --- a/zero_bin/worker/build.rs +++ /dev/null @@ -1,30 +0,0 @@ -use anyhow::Context as _; -use vergen::{BuildBuilder, Emitter, RustcBuilder}; - -fn main() -> anyhow::Result<()> { - let build_timestamp = BuildBuilder::default().build_timestamp(true).build()?; - let rust_commit_hash = RustcBuilder::default().commit_hash(true).build()?; - - Emitter::default() - .add_instructions(&build_timestamp)? - .add_instructions(&rust_commit_hash)? - .emit()?; - - let meta = cargo_metadata::MetadataCommand::new() - .exec() - .context("failed to probe cargo-metadata")?; - let version = &meta - .packages - .iter() - .find(|it| it.name == "evm_arithmetization") - .context("couldn't find evm_arithmetization package")? - .version; - println!( - "cargo::rustc-env=EVM_ARITHMETIZATION_PACKAGE_VERSION={}.{}.x", - // patch version change should not prompt circuits regeneration - version.major, - version.minor - ); - - Ok(()) -} diff --git a/zero_bin/worker/src/main.rs b/zero_bin/worker/src/main.rs index 92e401843..b4092c078 100644 --- a/zero_bin/worker/src/main.rs +++ b/zero_bin/worker/src/main.rs @@ -6,6 +6,7 @@ use dotenvy::dotenv; use ops::register; use paladin::runtime::WorkerRuntime; use zero_bin_common::prover_state::cli::CliProverStateConfig; +use zero_bin_common::version; mod init; @@ -15,10 +16,6 @@ mod init; #[global_allocator] static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc; -const EVM_ARITH_VER_KEY: &str = "EVM_ARITHMETIZATION_PKG_VER"; -const VERGEN_BUILD_TIMESTAMP: &str = "VERGEN_BUILD_TIMESTAMP"; -const VERGEN_RUSTC_COMMIT_HASH: &str = "VERGEN_RUSTC_COMMIT_HASH"; - #[derive(Parser)] struct Cli { #[command(subcommand)] @@ -40,47 +37,12 @@ async fn main() -> Result<()> { init::tracing(); let args = Cli::parse(); - if env::var_os(EVM_ARITH_VER_KEY).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - EVM_ARITH_VER_KEY, - // see build.rs - env!("EVM_ARITHMETIZATION_PACKAGE_VERSION"), - ); - } - } - if env::var_os(VERGEN_BUILD_TIMESTAMP).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - VERGEN_BUILD_TIMESTAMP, - // see build.rs - env!("VERGEN_BUILD_TIMESTAMP"), - ); - } - } - if env::var_os(VERGEN_RUSTC_COMMIT_HASH).is_none() { - // Safety: - // - we're early enough in main that nothing else should race - unsafe { - env::set_var( - VERGEN_RUSTC_COMMIT_HASH, - // see build.rs - env!("VERGEN_RUSTC_COMMIT_HASH"), - ); - } - } - if let Some(Command::Version {}) = args.command { - println!( - "Evm Arithmetization package version: {}", - env::var(EVM_ARITH_VER_KEY)? + version::print_version( + env!("EVM_ARITHMETIZATION_PKG_VER"), + env!("VERGEN_RUSTC_COMMIT_HASH"), + env!("VERGEN_BUILD_TIMESTAMP"), ); - println!("Build Commit Hash: {}", env::var(VERGEN_RUSTC_COMMIT_HASH)?); - println!("Build Timestamp: {}", env::var(VERGEN_BUILD_TIMESTAMP)?); return Ok(()); }