Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: --version in the CLI #632

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 64 additions & 2 deletions Cargo.lock

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

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ criterion = "0.5.1"
dotenvy = "0.15.7"
either = "1.12.0"
enum-as-inner = "0.6.0"
enumn = "0.1.13"
env_logger = "0.11.3"
eth_trie = "0.4.0"
ethereum-types = "0.14.1"
Expand Down Expand Up @@ -88,7 +87,6 @@ serde = "1.0.203"
serde-big-array = "0.5.1"
serde_json = "1.0.118"
serde_path_to_error = "0.1.16"
serde_with = "3.8.1"
sha2 = "0.10.8"
static_assertions = "1.1.0"
thiserror = "1.0.61"
Expand All @@ -101,7 +99,6 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
u4 = "0.1.0"
uint = "0.9.5"
url = "2.5.2"
vergen = { version = "9.0.0", features = ["build", "rustc"] }
winnow = "0.6.13"

# local dependencies
Expand Down
3 changes: 1 addition & 2 deletions zero/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ tower = { workspace = true, features = ["retry"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
url = { workspace = true }
vergen = { workspace = true }

# Local dependencies
compat = { workspace = true }
Expand All @@ -57,7 +56,7 @@ jemallocator = "0.5.4"
[build-dependencies]
anyhow = { workspace = true }
cargo_metadata = { workspace = true }
vergen = { workspace = true }
vergen-git2 = { version = "1.0.0", features = ["build"] }


[features]
Expand Down
31 changes: 5 additions & 26 deletions zero/build.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
use anyhow::Context as _;
use vergen::{BuildBuilder, Emitter, RustcBuilder};
use vergen_git2::{BuildBuilder, Emitter, Git2Builder};

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)?
fn main() -> Result<(), Box<dyn std::error::Error>> {
Emitter::new()
.add_instructions(&BuildBuilder::default().build_timestamp(true).build()?)?
.add_instructions(&Git2Builder::default().describe(true, true, None).build()?)?
.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_PKG_VER={}.{}.x",
// patch version change should not prompt circuits regeneration
version.major,
version.minor
);

Ok(())
}
13 changes: 0 additions & 13 deletions zero/src/bin/leader.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
zk_evm_common::check_chain_features!();

use std::env;
use std::sync::Arc;

use anyhow::Result;
Expand All @@ -15,7 +14,6 @@ use zero::{
block_interval::BlockInterval, prover_state::persistence::set_circuit_cache_dir_env_if_not_set,
};
use zero::{fs::get_previous_proof, ops::register};
use zero::{prover_state::persistence::CIRCUIT_VERSION, version};

use self::leader::*;
use crate::client::{client_main, LeaderConfig};
Expand All @@ -32,17 +30,6 @@ async fn main() -> Result<()> {
set_circuit_cache_dir_env_if_not_set()?;
zero::tracing::init();

let args: Vec<String> = env::args().collect();

if args.contains(&"--version".to_string()) {
version::print_version(
CIRCUIT_VERSION.as_str(),
env!("VERGEN_RUSTC_COMMIT_HASH"),
env!("VERGEN_BUILD_TIMESTAMP"),
);
return Ok(());
}

let args = cli::Cli::parse();

if let Command::Clean = args.command {
Expand Down
1 change: 1 addition & 0 deletions zero/src/bin/leader/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use zero::rpc::RpcType;

/// zero-bin leader config
#[derive(Parser)]
#[command(version = zero::version(), propagate_version = true)]
pub(crate) struct Cli {
#[command(subcommand)]
pub(crate) command: Command,
Expand Down
16 changes: 3 additions & 13 deletions zero/src/bin/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::env;
use std::sync::Arc;

use alloy::primitives::B256;
Expand All @@ -11,11 +10,11 @@ use clap::{Args, Parser, Subcommand, ValueHint};
use futures::StreamExt;
use tracing_subscriber::{prelude::*, EnvFilter};
use url::Url;
use zero::block_interval::BlockInterval;
use zero::block_interval::BlockIntervalStream;
use zero::prover::BlockProverInput;
use zero::provider::CachedProvider;
use zero::{block_interval::BlockInterval, prover_state::persistence::CIRCUIT_VERSION};
use zero::{rpc, version};
use zero::rpc;

use self::rpc::{retry::build_http_retry_provider, RpcType};

Expand Down Expand Up @@ -68,6 +67,7 @@ enum Command {
}

#[derive(Parser)]
#[command(version = zero::version(), propagate_version = true)]
struct Cli {
#[clap(flatten)]
pub(crate) config: RpcToolConfig,
Expand Down Expand Up @@ -203,16 +203,6 @@ impl Cli {

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let args: Vec<String> = env::args().collect();
if args.contains(&"--version".to_string()) {
version::print_version(
CIRCUIT_VERSION.as_str(),
env!("VERGEN_RUSTC_COMMIT_HASH"),
env!("VERGEN_BUILD_TIMESTAMP"),
);
return Ok(());
}

tracing_subscriber::Registry::default()
.with(
tracing_subscriber::fmt::layer()
Expand Down
16 changes: 1 addition & 15 deletions zero/src/bin/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
zk_evm_common::check_chain_features!();

use std::env;
use std::fs::File;

use anyhow::Result;
Expand All @@ -9,10 +8,7 @@ use dotenvy::dotenv;
use proof_gen::proof_types::GeneratedBlockProof;
use serde_json::Deserializer;
use tracing::info;
use zero::{
prover_state::persistence::{set_circuit_cache_dir_env_if_not_set, CIRCUIT_VERSION},
version,
};
use zero::prover_state::persistence::set_circuit_cache_dir_env_if_not_set;

use self::verifier::*;
mod verifier {
Expand All @@ -25,16 +21,6 @@ fn main() -> Result<()> {
init::tracing();
set_circuit_cache_dir_env_if_not_set()?;

let args: Vec<String> = env::args().collect();
if args.contains(&"--version".to_string()) {
version::print_version(
CIRCUIT_VERSION.as_str(),
env!("VERGEN_RUSTC_COMMIT_HASH"),
env!("VERGEN_BUILD_TIMESTAMP"),
);
return Ok(());
}

let args = cli::Cli::parse();

let file = File::open(args.file_path)?;
Expand Down
1 change: 1 addition & 0 deletions zero/src/bin/verifier/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use clap::{Parser, ValueHint};
use zero::prover_state::cli::CliProverStateConfig;

#[derive(Parser)]
#[command(version = zero::version(), propagate_version = true)]
pub(crate) struct Cli {
/// The file containing the proof to verify
#[arg(short, long, value_hint = ValueHint::FilePath)]
Expand Down
18 changes: 3 additions & 15 deletions zero/src/bin/worker.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use std::env;

use anyhow::Result;
use clap::Parser;
use dotenvy::dotenv;
use paladin::runtime::WorkerRuntime;
use zero::prover_state::{
cli::CliProverStateConfig,
persistence::{set_circuit_cache_dir_env_if_not_set, CIRCUIT_VERSION},
cli::CliProverStateConfig, persistence::set_circuit_cache_dir_env_if_not_set,
};
use zero::{ops::register, tracing, version};
use zero::{ops::register, tracing};

// TODO: https://github.com/0xPolygonZero/zk_evm/issues/302
// this should probably be removed.
Expand All @@ -17,6 +14,7 @@ use zero::{ops::register, tracing, version};
static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;

#[derive(Parser)]
#[command(version = zero::version(), propagate_version = true)]
struct Cli {
#[clap(flatten)]
paladin: paladin::config::Config,
Expand All @@ -26,16 +24,6 @@ struct Cli {

#[tokio::main]
async fn main() -> Result<()> {
let args: Vec<String> = env::args().collect();
if args.contains(&"--version".to_string()) {
version::print_version(
CIRCUIT_VERSION.as_str(),
env!("VERGEN_RUSTC_COMMIT_HASH"),
env!("VERGEN_BUILD_TIMESTAMP"),
);
return Ok(());
}

dotenv().ok();
tracing::init();
set_circuit_cache_dir_env_if_not_set()?;
Expand Down
10 changes: 9 additions & 1 deletion zero/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ pub mod prover_state;
pub mod provider;
pub mod rpc;
pub mod tracing;
pub mod version;

/// Size of the channel used to send block prover inputs to the per block
/// proving task. If the proving task is slow and can not consume inputs fast
/// enough retrieval of the block prover inputs will block until the proving
/// task consumes some of the inputs.
pub const BLOCK_CHANNEL_SIZE: usize = 16;

/// Common information for the `--version` CLI flags.
pub fn version() -> String {
let pkg_name = env!("CARGO_PKG_NAME");
let git_describe = env!("VERGEN_GIT_DESCRIBE");
let timestamp = env!("VERGEN_BUILD_TIMESTAMP");
let kernel_hash = &**prover_state::persistence::KERNEL_HASH;
format!("{pkg_name} ({git_describe}) (kernel hash: {kernel_hash}) [built: {timestamp}]")
}
Loading
Loading