Skip to content

Commit

Permalink
feat(contract-verifier): Add file based config for contract verifier (#…
Browse files Browse the repository at this point in the history
…2415)

## What ❔
Add file based config for contract verifier
  • Loading branch information
matias-gonz authored Jul 10, 2024
1 parent a040f09 commit f4410e3
Show file tree
Hide file tree
Showing 19 changed files with 112 additions and 152 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions core/bin/contract-verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ zksync_contract_verifier_lib.workspace = true
zksync_queued_job_processor.workspace = true
zksync_utils.workspace = true
zksync_vlog.workspace = true
zksync_core_leftovers.workspace = true

anyhow.workspace = true
tokio = { workspace = true, features = ["full"] }
Expand Down
32 changes: 19 additions & 13 deletions core/bin/contract-verifier/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use std::{cell::RefCell, time::Duration};

use anyhow::Context as _;
use anyhow::Context;
use futures::{channel::mpsc, executor::block_on, SinkExt, StreamExt};
use structopt::StructOpt;
use tokio::sync::watch;
use zksync_config::{
configs::{ObservabilityConfig, PrometheusConfig},
ApiConfig, ContractVerifierConfig,
};
use zksync_config::configs::PrometheusConfig;
use zksync_contract_verifier_lib::ContractVerifier;
use zksync_core_leftovers::temp_config_store::{load_database_secrets, load_general_config};
use zksync_dal::{ConnectionPool, Core, CoreDal};
use zksync_env_config::FromEnv;
use zksync_queued_job_processor::JobProcessor;
use zksync_utils::{wait_for_tasks::ManagedTasks, workspace_dir_or_current_dir};
use zksync_vlog::prometheus::PrometheusExporterConfig;
Expand Down Expand Up @@ -109,26 +106,34 @@ async fn update_compiler_versions(connection_pool: &ConnectionPool<Core>) {
transaction.commit().await.unwrap();
}

use zksync_config::configs::DatabaseSecrets;

#[derive(StructOpt)]
#[structopt(name = "ZKsync contract code verifier", author = "Matter Labs")]
struct Opt {
/// Number of jobs to process. If None, runs indefinitely.
#[structopt(long)]
jobs_number: Option<usize>,
/// Path to the configuration file.
#[structopt(long)]
config_path: Option<std::path::PathBuf>,
/// Path to the secrets file.
#[structopt(long)]
secrets_path: Option<std::path::PathBuf>,
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let opt = Opt::from_args();

let verifier_config = ContractVerifierConfig::from_env().context("ContractVerifierConfig")?;
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 verifier_config = general_config
.contract_verifier
.context("ContractVerifierConfig")?;
let prometheus_config = PrometheusConfig {
listener_port: verifier_config.prometheus_port,
..ApiConfig::from_env().context("ApiConfig")?.prometheus
..general_config.api_config.context("ApiConfig")?.prometheus
};
let database_secrets = DatabaseSecrets::from_env().context("DatabaseSecrets")?;
let pool = ConnectionPool::<Core>::singleton(
database_secrets
.master_url()
Expand All @@ -138,8 +143,9 @@ async fn main() -> anyhow::Result<()> {
.await
.unwrap();

let observability_config =
ObservabilityConfig::from_env().context("ObservabilityConfig::from_env()")?;
let observability_config = general_config
.observability
.context("ObservabilityConfig")?;
let log_format: zksync_vlog::LogFormat = observability_config
.log_format
.parse()
Expand Down
2 changes: 2 additions & 0 deletions core/lib/zksync_core_leftovers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ categories.workspace = true
zksync_dal.workspace = true
zksync_config.workspace = true
zksync_protobuf.workspace = true
zksync_protobuf_config.workspace = true
zksync_env_config.workspace = true
zksync_node_genesis.workspace = true

anyhow.workspace = true
Expand Down
76 changes: 72 additions & 4 deletions core/lib/zksync_core_leftovers/src/temp_config_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ use zksync_config::{
house_keeper::HouseKeeperConfig,
vm_runner::BasicWitnessInputProducerConfig,
wallets::{AddressWallet, EthSender, StateKeeper, Wallet, Wallets},
CommitmentGeneratorConfig, ExternalPriceApiClientConfig, FriProofCompressorConfig,
FriProverConfig, FriProverGatewayConfig, FriWitnessGeneratorConfig,
FriWitnessVectorGeneratorConfig, GeneralConfig, ObservabilityConfig, PrometheusConfig,
ProofDataHandlerConfig, ProtectiveReadsWriterConfig, PruningConfig, SnapshotRecoveryConfig,
CommitmentGeneratorConfig, DatabaseSecrets, ExternalPriceApiClientConfig,
FriProofCompressorConfig, FriProverConfig, FriProverGatewayConfig,
FriWitnessGeneratorConfig, FriWitnessVectorGeneratorConfig, GeneralConfig,
ObservabilityConfig, PrometheusConfig, ProofDataHandlerConfig, ProtectiveReadsWriterConfig,
PruningConfig, SnapshotRecoveryConfig,
},
ApiConfig, BaseTokenAdjusterConfig, ContractVerifierConfig, DADispatcherConfig, DBConfig,
EthConfig, EthWatchConfig, GasAdjusterConfig, ObjectStoreConfig, PostgresConfig,
SnapshotsCreatorConfig,
};
use zksync_env_config::FromEnv;
use zksync_protobuf::repr::ProtoRepr;
use zksync_protobuf_config::proto::secrets::Secrets;

pub fn decode_yaml_repr<T: ProtoRepr>(yaml: &str) -> anyhow::Result<T::Type> {
let d = serde_yaml::Deserializer::from_str(yaml);
Expand Down Expand Up @@ -141,3 +144,68 @@ impl TempConfigStore {
}
}
}

fn load_env_config() -> anyhow::Result<TempConfigStore> {
Ok(TempConfigStore {
postgres_config: PostgresConfig::from_env().ok(),
health_check_config: HealthCheckConfig::from_env().ok(),
merkle_tree_api_config: MerkleTreeApiConfig::from_env().ok(),
web3_json_rpc_config: Web3JsonRpcConfig::from_env().ok(),
circuit_breaker_config: CircuitBreakerConfig::from_env().ok(),
mempool_config: MempoolConfig::from_env().ok(),
network_config: NetworkConfig::from_env().ok(),
contract_verifier: ContractVerifierConfig::from_env().ok(),
operations_manager_config: OperationsManagerConfig::from_env().ok(),
state_keeper_config: StateKeeperConfig::from_env().ok(),
house_keeper_config: HouseKeeperConfig::from_env().ok(),
fri_proof_compressor_config: FriProofCompressorConfig::from_env().ok(),
fri_prover_config: FriProverConfig::from_env().ok(),
fri_prover_group_config: FriProverGroupConfig::from_env().ok(),
fri_prover_gateway_config: FriProverGatewayConfig::from_env().ok(),
fri_witness_vector_generator: FriWitnessVectorGeneratorConfig::from_env().ok(),
fri_witness_generator_config: FriWitnessGeneratorConfig::from_env().ok(),
prometheus_config: PrometheusConfig::from_env().ok(),
proof_data_handler_config: ProofDataHandlerConfig::from_env().ok(),
api_config: ApiConfig::from_env().ok(),
db_config: DBConfig::from_env().ok(),
eth_sender_config: EthConfig::from_env().ok(),
eth_watch_config: EthWatchConfig::from_env().ok(),
gas_adjuster_config: GasAdjusterConfig::from_env().ok(),
observability: ObservabilityConfig::from_env().ok(),
snapshot_creator: SnapshotsCreatorConfig::from_env().ok(),
da_dispatcher_config: DADispatcherConfig::from_env().ok(),
protective_reads_writer_config: ProtectiveReadsWriterConfig::from_env().ok(),
basic_witness_input_producer_config: BasicWitnessInputProducerConfig::from_env().ok(),
core_object_store: ObjectStoreConfig::from_env().ok(),
base_token_adjuster_config: BaseTokenAdjusterConfig::from_env().ok(),
commitment_generator: None,
pruning: None,
snapshot_recovery: None,
external_price_api_client_config: ExternalPriceApiClientConfig::from_env().ok(),
})
}

pub fn load_general_config(path: Option<std::path::PathBuf>) -> anyhow::Result<GeneralConfig> {
match path {
Some(path) => {
let yaml = std::fs::read_to_string(path).context("Failed to read general config")?;
decode_yaml_repr::<zksync_protobuf_config::proto::general::GeneralConfig>(&yaml)
}
None => Ok(load_env_config()
.context("general config from env")?
.general()),
}
}

pub fn load_database_secrets(path: Option<std::path::PathBuf>) -> anyhow::Result<DatabaseSecrets> {
match path {
Some(path) => {
let yaml = std::fs::read_to_string(path).context("Failed to read secrets")?;
let secrets = decode_yaml_repr::<Secrets>(&yaml).context("Failed to parse secrets")?;
Ok(secrets
.database
.context("failed to parse database secrets")?)
}
None => DatabaseSecrets::from_env(),
}
}
23 changes: 6 additions & 17 deletions prover/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 prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ members = [
"proof_fri_compressor",
"prover_cli",
"prover_version",
"config",
]

resolver = "2"
Expand Down Expand Up @@ -94,10 +93,8 @@ zksync_utils = { path = "../core/lib/utils" }
zksync_eth_client = { path = "../core/lib/eth_client" }
zksync_contracts = { path = "../core/lib/contracts" }
zksync_core_leftovers = { path = "../core/lib/zksync_core_leftovers" }
zksync_protobuf_config = { path = "../core/lib/protobuf_config" }

# Prover workspace dependencies
zksync_prover_config = { path = "config" }
zksync_prover_dal = { path = "prover_dal" }
zksync_prover_fri_types = { path = "prover_fri_types" }
zksync_prover_fri_utils = { path = "prover_fri_utils" }
Expand Down
17 changes: 0 additions & 17 deletions prover/config/Cargo.toml

This file was deleted.

Loading

0 comments on commit f4410e3

Please sign in to comment.