Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
feat(prover): Add file based config for witness vector generator (mat…
Browse files Browse the repository at this point in the history
…ter-labs#2337)

## What ❔

Add file based config for witness vector generator
  • Loading branch information
matias-gonz authored Jun 27, 2024
1 parent e03a929 commit f86eb13
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 deletions.
2 changes: 2 additions & 0 deletions prover/Cargo.lock

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

2 changes: 2 additions & 0 deletions prover/witness_vector_generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ zksync_object_store.workspace = true
zksync_prover_fri_utils.workspace = true
zksync_utils.workspace = true
zksync_prover_fri_types.workspace = true
zksync_prover_config.workspace = true
zksync_queued_job_processor.workspace = true
vk_setup_data_generator_server_fri.workspace = true
zksync_vlog.workspace = true
Expand All @@ -30,6 +31,7 @@ tokio = { workspace = true, features = ["time", "macros"] }
futures = { workspace = true, features = ["compat"] }
ctrlc = { workspace = true, features = ["termination"] }
serde = { workspace = true, features = ["derive"] }
clap = { workspace = true, features = ["derive"] }
async-trait.workspace = true
queues.workspace = true
bincode.workspace = true
63 changes: 37 additions & 26 deletions prover/witness_vector_generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
use std::time::Duration;

use anyhow::Context as _;
use structopt::StructOpt;
use clap::Parser;
use tokio::sync::{oneshot, watch};
use zksync_config::configs::{
fri_prover_group::FriProverGroupConfig, DatabaseSecrets, FriProverConfig,
FriWitnessVectorGeneratorConfig, ObservabilityConfig,
};
use zksync_env_config::{object_store::ProverObjectStoreConfig, FromEnv};
use zksync_env_config::object_store::ProverObjectStoreConfig;
use zksync_object_store::ObjectStoreFactory;
use zksync_prover_config::{load_database_secrets, load_general_config};
use zksync_prover_dal::ConnectionPool;
use zksync_prover_fri_types::PROVER_PROTOCOL_SEMANTIC_VERSION;
use zksync_prover_fri_utils::{get_all_circuit_id_round_tuples_for, region_fetcher::get_zone};
Expand All @@ -23,21 +20,29 @@ use crate::generator::WitnessVectorGenerator;
mod generator;
mod metrics;

#[derive(Debug, StructOpt)]
#[structopt(
name = "zksync_witness_vector_generator",
about = "Tool for generating witness vectors for circuits"
)]
struct Opt {
#[derive(Debug, Parser)]
#[command(author = "Matter Labs", version)]
struct Cli {
/// Number of times `witness_vector_generator` should be run.
#[structopt(short = "n", long = "n_iterations")]
number_of_iterations: Option<usize>,
#[arg(long)]
#[arg(short)]
n_iterations: Option<usize>,
#[arg(long)]
pub(crate) config_path: Option<std::path::PathBuf>,
#[arg(long)]
pub(crate) secrets_path: Option<std::path::PathBuf>,
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let observability_config =
ObservabilityConfig::from_env().context("ObservabilityConfig::from_env()")?;
let opt = Cli::parse();

let general_config = load_general_config(opt.config_path).context("general config")?;
let database_secrets = load_database_secrets(opt.secrets_path).context("database secrets")?;

let observability_config = general_config
.observability
.context("observability config")?;
let log_format: zksync_vlog::LogFormat = observability_config
.log_format
.parse()
Expand All @@ -61,29 +66,35 @@ async fn main() -> anyhow::Result<()> {
}
let _guard = builder.build();

let opt = Opt::from_args();
let config = FriWitnessVectorGeneratorConfig::from_env()
.context("FriWitnessVectorGeneratorConfig::from_env()")?;
let config = general_config
.witness_vector_generator
.context("witness vector generator config")?;
let specialized_group_id = config.specialized_group_id;
let exporter_config = PrometheusExporterConfig::pull(config.prometheus_listener_port);

let database_secrets = DatabaseSecrets::from_env().context("DatabaseSecrets::from_env()")?;
let pool = ConnectionPool::singleton(database_secrets.prover_url()?)
.build()
.await
.context("failed to build a connection pool")?;
let object_store_config =
ProverObjectStoreConfig::from_env().context("ProverObjectStoreConfig::from_env()")?;
let object_store_config = ProverObjectStoreConfig(
general_config
.prover_config
.clone()
.context("prover config")?
.prover_object_store
.context("object store")?,
);
let object_store = ObjectStoreFactory::new(object_store_config.0)
.create_store()
.await?;
let circuit_ids_for_round_to_be_proven = FriProverGroupConfig::from_env()
.context("FriProverGroupConfig::from_env()")?
let circuit_ids_for_round_to_be_proven = general_config
.prover_group_config
.expect("prover_group_config")
.get_circuit_ids_for_group_id(specialized_group_id)
.unwrap_or_default();
let circuit_ids_for_round_to_be_proven =
get_all_circuit_id_round_tuples_for(circuit_ids_for_round_to_be_proven);
let fri_prover_config = FriProverConfig::from_env().context("FriProverConfig::from_env()")?;
let fri_prover_config = general_config.prover_config.context("prover config")?;
let zone_url = &fri_prover_config.zone_read_url;
let zone = get_zone(zone_url).await.context("get_zone()")?;

Expand Down Expand Up @@ -114,7 +125,7 @@ async fn main() -> anyhow::Result<()> {

let tasks = vec![
tokio::spawn(exporter_config.run(stop_receiver.clone())),
tokio::spawn(witness_vector_generator.run(stop_receiver, opt.number_of_iterations)),
tokio::spawn(witness_vector_generator.run(stop_receiver, opt.n_iterations)),
];

let mut tasks = ManagedTasks::new(tasks);
Expand Down

0 comments on commit f86eb13

Please sign in to comment.