diff --git a/Cargo.lock b/Cargo.lock index 3cdfe491c993..7786119557c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6339,24 +6339,24 @@ dependencies = [ [[package]] name = "strum" -version = "0.24.1" +version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" dependencies = [ "strum_macros", ] [[package]] name = "strum_macros" -version = "0.24.3" +version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ - "heck 0.4.1", + "heck 0.5.0", "proc-macro2 1.0.69", "quote 1.0.33", "rustversion", - "syn 1.0.109", + "syn 2.0.38", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 49b2cc50c567..e731bf6533b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -167,7 +167,7 @@ sha3 = "0.10.8" sqlx = "0.7.3" static_assertions = "1.1" structopt = "0.3.20" -strum = "0.24" +strum = "0.26" tempfile = "3.0.2" test-casing = "0.1.2" test-log = "0.2.15" diff --git a/core/lib/basic_types/src/commitment.rs b/core/lib/basic_types/src/commitment.rs index 873dff2313a2..eca339f40f42 100644 --- a/core/lib/basic_types/src/commitment.rs +++ b/core/lib/basic_types/src/commitment.rs @@ -1,4 +1,5 @@ use serde::{Deserialize, Serialize}; +use strum::{Display, EnumIter}; use crate::{ ethabi, @@ -6,7 +7,7 @@ use crate::{ U256, }; -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, EnumIter, Display)] pub enum L1BatchCommitmentMode { #[default] Rollup, diff --git a/core/lib/config/src/configs/general.rs b/core/lib/config/src/configs/general.rs index 122d1e278553..5707b5c70492 100644 --- a/core/lib/config/src/configs/general.rs +++ b/core/lib/config/src/configs/general.rs @@ -18,7 +18,7 @@ use crate::{ SnapshotsCreatorConfig, }; -#[derive(Debug, PartialEq)] +#[derive(Debug, Clone, PartialEq)] pub struct GeneralConfig { pub postgres_config: Option, pub api_config: Option, diff --git a/core/lib/config/src/configs/secrets.rs b/core/lib/config/src/configs/secrets.rs index 02bb52e00718..71197f5d9306 100644 --- a/core/lib/config/src/configs/secrets.rs +++ b/core/lib/config/src/configs/secrets.rs @@ -30,9 +30,11 @@ impl DatabaseSecrets { /// Returns a copy of the replica database URL as a `Result` to simplify error propagation. pub fn replica_url(&self) -> anyhow::Result { - self.server_replica_url - .clone() - .context("Replica DB URL is absent") + if let Some(replica_url) = &self.server_replica_url { + Ok(replica_url.clone()) + } else { + self.master_url() + } } /// Returns a copy of the prover database URL as a `Result` to simplify error propagation. diff --git a/core/lib/protobuf_config/src/lib.rs b/core/lib/protobuf_config/src/lib.rs index 839f3e3cf8ca..e910b5760d31 100644 --- a/core/lib/protobuf_config/src/lib.rs +++ b/core/lib/protobuf_config/src/lib.rs @@ -40,7 +40,10 @@ mod wallets; use std::{path::PathBuf, str::FromStr}; use anyhow::Context; -use zksync_protobuf::{serde::serialize_proto, ProtoRepr}; +use zksync_protobuf::{ + build::{prost_reflect, prost_reflect::ReflectMessage, serde}, + ProtoRepr, +}; use zksync_types::{H160, H256}; fn parse_h256(bytes: &str) -> anyhow::Result { @@ -71,3 +74,13 @@ pub fn encode_yaml_repr(value: &T::Type) -> anyhow::Result serialize_proto(&T::build(value), &mut s)?; Ok(buffer) } + +fn serialize_proto( + x: &T, + s: S, +) -> Result { + let opts = prost_reflect::SerializeOptions::new() + .use_proto_field_name(true) + .stringify_64_bit_integers(false); + x.transcode_to_dynamic().serialize_with_options(s, &opts) +} diff --git a/core/lib/protobuf_config/src/secrets.rs b/core/lib/protobuf_config/src/secrets.rs index 43f537a5fbfa..3047c0093bb0 100644 --- a/core/lib/protobuf_config/src/secrets.rs +++ b/core/lib/protobuf_config/src/secrets.rs @@ -41,15 +41,12 @@ impl ProtoRepr for proto::DatabaseSecrets { .map(str::parse::) .transpose() .context("master_url")?; - let mut server_replica_url = self + let server_replica_url = self .server_replica_url .as_deref() .map(str::parse::) .transpose() .context("replica_url")?; - if server_replica_url.is_none() { - server_replica_url.clone_from(&server_url) - } let prover_url = self .prover_url .as_deref() diff --git a/prover/Cargo.lock b/prover/Cargo.lock index 0afe435859d6..d3023bba6dc9 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -6043,24 +6043,24 @@ dependencies = [ [[package]] name = "strum" -version = "0.24.1" +version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" dependencies = [ "strum_macros", ] [[package]] name = "strum_macros" -version = "0.24.3" +version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ - "heck 0.4.1", + "heck 0.5.0", "proc-macro2 1.0.85", "quote 1.0.36", "rustversion", - "syn 1.0.109", + "syn 2.0.66", ] [[package]] diff --git a/prover/Cargo.toml b/prover/Cargo.toml index c06c0774639a..824ce4c4451a 100644 --- a/prover/Cargo.toml +++ b/prover/Cargo.toml @@ -47,7 +47,7 @@ serde_json = "1.0" sha3 = "0.10.8" sqlx = { version = "0.7.3", default-features = false } structopt = "0.3.26" -strum = { version = "0.24" } +strum = { version = "0.26" } tempfile = "3" tokio = "1" toml_edit = "0.14.4" diff --git a/zk_toolbox/Cargo.lock b/zk_toolbox/Cargo.lock index 375e35b060c2..0c6b1b0a0cbb 100644 --- a/zk_toolbox/Cargo.lock +++ b/zk_toolbox/Cargo.lock @@ -667,7 +667,7 @@ dependencies = [ "serde_json", "serde_yaml", "sqlx", - "strum_macros 0.26.4", + "strum", "thiserror", "tokio", "toml", @@ -692,13 +692,14 @@ dependencies = [ "rand", "serde", "serde_json", - "strum 0.26.3", - "strum_macros 0.26.4", + "strum", "thiserror", "types", "url", "xshell", + "zksync_basic_types", "zksync_config", + "zksync_protobuf", "zksync_protobuf_config", ] @@ -1403,7 +1404,7 @@ dependencies = [ "rlp", "serde", "serde_json", - "strum 0.26.3", + "strum", "syn 2.0.68", "tempfile", "thiserror", @@ -4928,35 +4929,13 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" -[[package]] -name = "strum" -version = "0.24.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" -dependencies = [ - "strum_macros 0.24.3", -] - [[package]] name = "strum" version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" dependencies = [ - "strum_macros 0.26.4", -] - -[[package]] -name = "strum_macros" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" -dependencies = [ - "heck 0.4.1", - "proc-macro2", - "quote", - "rustversion", - "syn 1.0.109", + "strum_macros", ] [[package]] @@ -5549,9 +5528,9 @@ dependencies = [ "clap", "ethers", "serde", - "strum 0.26.3", - "strum_macros 0.26.4", + "strum", "thiserror", + "zksync_basic_types", ] [[package]] @@ -6280,14 +6259,14 @@ dependencies = [ "serde_json", "serde_yaml", "slugify-rs", - "strum 0.26.3", - "strum_macros 0.26.4", + "strum", "thiserror", "tokio", "toml", "types", "url", "xshell", + "zksync_basic_types", "zksync_config", ] @@ -6301,8 +6280,7 @@ dependencies = [ "config", "human-panic", "serde", - "strum 0.26.3", - "strum_macros 0.26.4", + "strum", "tokio", "url", "xshell", @@ -6335,7 +6313,7 @@ dependencies = [ "serde", "serde_json", "serde_with", - "strum 0.24.1", + "strum", "thiserror", "tiny-keccak", "url", @@ -6510,7 +6488,7 @@ dependencies = [ "secp256k1", "serde", "serde_json", - "strum 0.24.1", + "strum", "thiserror", "tracing", "zksync_basic_types", diff --git a/zk_toolbox/Cargo.toml b/zk_toolbox/Cargo.toml index 138a8e3af129..0c5e2188c66a 100644 --- a/zk_toolbox/Cargo.toml +++ b/zk_toolbox/Cargo.toml @@ -25,12 +25,16 @@ keywords = ["zk", "cryptography", "blockchain", "ZKStack", "ZKsync"] common = { path = "crates/common" } config = { path = "crates/config" } types = { path = "crates/types" } + +# ZkSync deps zksync_config = { path = "../core/lib/config" } zksync_protobuf_config = { path = "../core/lib/protobuf_config" } +zksync_basic_types = { path = "../core/lib/basic_types" } +zksync_protobuf = "=0.1.0-rc.4" # External dependencies anyhow = "1.0.82" -clap = { version = "4.4", features = ["derive", "wrap_help"] } +clap = { version = "4.4", features = ["derive", "wrap_help", "string"] } slugify-rs = "0.0.3" cliclack = "0.2.5" console = "0.15.8" @@ -44,8 +48,7 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" serde_yaml = "0.9" sqlx = { version = "0.7.4", features = ["runtime-tokio", "migrate", "postgres"] } -strum = { version = "0.26.2", features = ["derive"] } -strum_macros = "0.26.2" +strum = { version = "0.26", features = ["derive"] } thiserror = "1.0.57" tokio = { version = "1.37", features = ["full"] } toml = "0.8.12" diff --git a/zk_toolbox/crates/common/Cargo.toml b/zk_toolbox/crates/common/Cargo.toml index 6b362905160f..3d9d406f6234 100644 --- a/zk_toolbox/crates/common/Cargo.toml +++ b/zk_toolbox/crates/common/Cargo.toml @@ -22,9 +22,9 @@ serde.workspace = true serde_json.workspace = true serde_yaml.workspace = true sqlx.workspace = true -strum_macros.workspace = true tokio.workspace = true toml.workspace = true url.workspace = true xshell.workspace = true -thiserror = "1.0.57" +thiserror.workspace = true +strum.workspace = true diff --git a/zk_toolbox/crates/common/src/cmd.rs b/zk_toolbox/crates/common/src/cmd.rs index ca0f285882a3..7bf0147b69c0 100644 --- a/zk_toolbox/crates/common/src/cmd.rs +++ b/zk_toolbox/crates/common/src/cmd.rs @@ -19,6 +19,8 @@ use crate::{ pub struct Cmd<'a> { inner: xshell::Cmd<'a>, force_run: bool, + // For resume functionality we must pipe the output, otherwise it only shows less information + piped_std_err: bool, } #[derive(thiserror::Error, Debug)] @@ -72,6 +74,7 @@ impl<'a> Cmd<'a> { Self { inner: cmd, force_run: false, + piped_std_err: false, } } @@ -81,6 +84,11 @@ impl<'a> Cmd<'a> { self } + pub fn with_piped_std_err(mut self) -> Self { + self.piped_std_err = true; + self + } + /// Set env variables for the command. pub fn env, V: AsRef>(mut self, key: K, value: V) -> Self { self.inner = self.inner.env(key, value); @@ -93,7 +101,7 @@ impl<'a> Cmd<'a> { let output = if global_config().verbose || self.force_run { logger::debug(format!("Running: {}", self.inner)); logger::new_empty_line(); - let output = run_low_level_process_command(self.inner.into())?; + let output = run_low_level_process_command(self.inner.into(), self.piped_std_err)?; if let Ok(data) = String::from_utf8(output.stderr.clone()) { if !data.is_empty() { logger::info(data) @@ -152,9 +160,13 @@ fn check_output_status(command_text: &str, output: &std::process::Output) -> Cmd Ok(()) } -fn run_low_level_process_command(mut command: Command) -> io::Result { +fn run_low_level_process_command(mut command: Command, piped_std_err: bool) -> io::Result { command.stdout(Stdio::inherit()); - command.stderr(Stdio::piped()); + if piped_std_err { + command.stderr(Stdio::piped()); + } else { + command.stderr(Stdio::inherit()); + } let child = command.spawn()?; child.wait_with_output() } diff --git a/zk_toolbox/crates/common/src/db.rs b/zk_toolbox/crates/common/src/db.rs index c0a681bc74c0..eda5471170dd 100644 --- a/zk_toolbox/crates/common/src/db.rs +++ b/zk_toolbox/crates/common/src/db.rs @@ -27,7 +27,7 @@ impl DatabaseConfig { } /// Create a new `Db` instance from a URL. - pub fn from_url(url: Url) -> anyhow::Result { + pub fn from_url(url: &Url) -> anyhow::Result { let name = url .path_segments() .ok_or(anyhow!("Failed to parse database name from URL"))? diff --git a/zk_toolbox/crates/common/src/ethereum.rs b/zk_toolbox/crates/common/src/ethereum.rs index 451bc311145f..c035d588370d 100644 --- a/zk_toolbox/crates/common/src/ethereum.rs +++ b/zk_toolbox/crates/common/src/ethereum.rs @@ -13,7 +13,7 @@ use crate::wallets::Wallet; pub fn create_ethers_client( private_key: H256, l1_rpc: String, - chain_id: Option, + chain_id: Option, ) -> anyhow::Result, ethers::prelude::Wallet>> { let mut wallet = LocalWallet::from_bytes(private_key.as_bytes())?; if let Some(chain_id) = chain_id { @@ -27,7 +27,7 @@ pub async fn distribute_eth( main_wallet: Wallet, addresses: Vec
, l1_rpc: String, - chain_id: u32, + chain_id: u64, amount: u128, ) -> anyhow::Result<()> { let client = create_ethers_client(main_wallet.private_key.unwrap(), l1_rpc, Some(chain_id))?; diff --git a/zk_toolbox/crates/common/src/forge.rs b/zk_toolbox/crates/common/src/forge.rs index de91c0e72500..f00921a0bf20 100644 --- a/zk_toolbox/crates/common/src/forge.rs +++ b/zk_toolbox/crates/common/src/forge.rs @@ -12,7 +12,7 @@ use ethers::{ utils::{hex, hex::ToHex}, }; use serde::{Deserialize, Serialize}; -use strum_macros::Display; +use strum::Display; use xshell::{cmd, Shell}; use crate::{ @@ -62,16 +62,24 @@ impl ForgeScript { if self.args.resume { let mut args = args_no_resume.clone(); args.push(ForgeScriptArg::Resume.to_string()); - let res = Cmd::new(cmd!(shell, "forge script {script_path} --legacy {args...}")).run(); + let res = Cmd::new(cmd!(shell, "forge script {script_path} --legacy {args...}")) + .with_piped_std_err() + .run(); if !res.resume_not_successful_because_has_not_began() { return Ok(res?); } } - let res = Cmd::new(cmd!( + let mut cmd = Cmd::new(cmd!( shell, "forge script {script_path} --legacy {args_no_resume...}" - )) - .run(); + )); + + if self.args.resume { + cmd = cmd.with_piped_std_err(); + } + + let res = cmd.run(); + // We won't catch this error if resume is not set. if res.proposal_error() { return Ok(()); } diff --git a/zk_toolbox/crates/config/Cargo.toml b/zk_toolbox/crates/config/Cargo.toml index 32cce24b3152..57fbc778334e 100644 --- a/zk_toolbox/crates/config/Cargo.toml +++ b/zk_toolbox/crates/config/Cargo.toml @@ -19,10 +19,12 @@ rand.workspace = true serde.workspace = true serde_json.workspace = true strum.workspace = true -strum_macros.workspace = true thiserror.workspace = true types.workspace = true url.workspace = true xshell.workspace = true -zksync_config.workspace = true + zksync_protobuf_config.workspace = true +zksync_protobuf.workspace = true +zksync_config.workspace = true +zksync_basic_types.workspace = true diff --git a/zk_toolbox/crates/config/src/chain.rs b/zk_toolbox/crates/config/src/chain.rs index 01dc1cae6434..e8b6df00644d 100644 --- a/zk_toolbox/crates/config/src/chain.rs +++ b/zk_toolbox/crates/config/src/chain.rs @@ -4,20 +4,17 @@ use std::{ }; use serde::{Deserialize, Serialize, Serializer}; -use types::{ - BaseToken, ChainId, L1BatchCommitDataGeneratorMode, L1Network, ProverMode, WalletCreation, -}; +use types::{BaseToken, L1BatchCommitmentMode, L1Network, ProverMode, WalletCreation}; use xshell::Shell; -use zksync_config::configs::GeneralConfig as ZkSyncGeneralConfig; -use zksync_protobuf_config::{decode_yaml_repr, encode_yaml_repr}; +use zksync_basic_types::L2ChainId; use crate::{ - consts::{ - CONFIG_NAME, CONTRACTS_FILE, GENERAL_FILE, GENESIS_FILE, L1_CONTRACTS_FOUNDRY, - SECRETS_FILE, WALLETS_FILE, - }, + consts::{CONFIG_NAME, GENERAL_FILE, L1_CONTRACTS_FOUNDRY, SECRETS_FILE, WALLETS_FILE}, create_localhost_wallets, - traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig, SaveConfigWithBasePath}, + traits::{ + FileConfigWithDefaultName, ReadConfig, ReadConfigWithBasePath, SaveConfig, + SaveConfigWithBasePath, ZkToolboxConfig, + }, ContractsConfig, GeneralConfig, GenesisConfig, SecretsConfig, WalletsConfig, }; @@ -29,12 +26,12 @@ pub struct ChainConfigInternal { // needs for local setups only pub id: u32, pub name: String, - pub chain_id: ChainId, + pub chain_id: L2ChainId, pub prover_version: ProverMode, pub configs: PathBuf, pub rocks_db_path: PathBuf, pub external_node_config_path: Option, - pub l1_batch_commit_data_generator_mode: L1BatchCommitDataGeneratorMode, + pub l1_batch_commit_data_generator_mode: L1BatchCommitmentMode, pub base_token: BaseToken, pub wallet_creation: WalletCreation, } @@ -45,14 +42,14 @@ pub struct ChainConfigInternal { pub struct ChainConfig { pub id: u32, pub name: String, - pub chain_id: ChainId, + pub chain_id: L2ChainId, pub prover_version: ProverMode, pub l1_network: L1Network, pub link_to_code: PathBuf, pub rocks_db_path: PathBuf, pub configs: PathBuf, pub external_node_config_path: Option, - pub l1_batch_commit_data_generator_mode: L1BatchCommitDataGeneratorMode, + pub l1_batch_commit_data_generator_mode: L1BatchCommitmentMode, pub base_token: BaseToken, pub wallet_creation: WalletCreation, pub shell: OnceCell, @@ -73,11 +70,11 @@ impl ChainConfig { } pub fn get_genesis_config(&self) -> anyhow::Result { - GenesisConfig::read(self.get_shell(), self.configs.join(GENESIS_FILE)) + GenesisConfig::read_with_base_path(self.get_shell(), &self.configs) } pub fn get_general_config(&self) -> anyhow::Result { - GeneralConfig::read(self.get_shell(), self.configs.join(GENERAL_FILE)) + GeneralConfig::read_with_base_path(self.get_shell(), &self.configs) } pub fn get_wallets_config(&self) -> anyhow::Result { @@ -93,11 +90,11 @@ impl ChainConfig { anyhow::bail!("Wallets configs has not been found"); } pub fn get_contracts_config(&self) -> anyhow::Result { - ContractsConfig::read(self.get_shell(), self.configs.join(CONTRACTS_FILE)) + ContractsConfig::read_with_base_path(self.get_shell(), &self.configs) } pub fn get_secrets_config(&self) -> anyhow::Result { - SecretsConfig::read(self.get_shell(), self.configs.join(SECRETS_FILE)) + SecretsConfig::read_with_base_path(self.get_shell(), &self.configs) } pub fn path_to_general_config(&self) -> PathBuf { @@ -108,23 +105,8 @@ impl ChainConfig { self.configs.join(SECRETS_FILE) } - pub fn get_zksync_general_config(&self) -> anyhow::Result { - decode_yaml_repr::( - &self.configs.join(GENERAL_FILE), - false, - ) - } - - pub fn save_zksync_general_config( - &self, - general_config: &ZkSyncGeneralConfig, - ) -> anyhow::Result<()> { - let path = self.configs.join(GENERAL_FILE); - let bytes = encode_yaml_repr::( - general_config, - )?; - self.get_shell().write_file(path, bytes)?; - Ok(()) + pub fn save_general_config(&self, general_config: &GeneralConfig) -> anyhow::Result<()> { + general_config.save_with_base_path(self.get_shell(), &self.configs) } pub fn path_to_foundry(&self) -> PathBuf { @@ -160,3 +142,5 @@ impl ChainConfig { impl FileConfigWithDefaultName for ChainConfigInternal { const FILE_NAME: &'static str = CONFIG_NAME; } + +impl ZkToolboxConfig for ChainConfigInternal {} diff --git a/zk_toolbox/crates/config/src/consts.rs b/zk_toolbox/crates/config/src/consts.rs index a00274fb35f3..fecb6e78c9a5 100644 --- a/zk_toolbox/crates/config/src/consts.rs +++ b/zk_toolbox/crates/config/src/consts.rs @@ -1,5 +1,3 @@ -use types::ChainId; - /// Name of the main configuration file pub(crate) const CONFIG_NAME: &str = "ZkStack.yaml"; /// Name of the wallets file @@ -35,7 +33,7 @@ pub(crate) const ECOSYSTEM_PATH: &str = "etc/ecosystem"; /// Path to l1 contracts foundry folder inside zksync-era pub(crate) const L1_CONTRACTS_FOUNDRY: &str = "contracts/l1-contracts"; -pub(crate) const ERA_CHAIN_ID: ChainId = ChainId(270); +pub(crate) const ERA_CHAIN_ID: u32 = 270; pub(crate) const TEST_CONFIG_PATH: &str = "etc/test_config/constant/eth.json"; pub(crate) const BASE_PATH: &str = "m/44'/60'/0'"; diff --git a/zk_toolbox/crates/config/src/contracts.rs b/zk_toolbox/crates/config/src/contracts.rs index a4c00a10a455..0a0b3c22ab5b 100644 --- a/zk_toolbox/crates/config/src/contracts.rs +++ b/zk_toolbox/crates/config/src/contracts.rs @@ -8,7 +8,7 @@ use crate::{ initialize_bridges::output::InitializeBridgeOutput, register_chain::output::RegisterChainOutput, }, - traits::{FileConfig, FileConfigWithDefaultName}, + traits::{FileConfigWithDefaultName, ZkToolboxConfig}, }; #[derive(Debug, Deserialize, Serialize, Clone, Default)] @@ -89,6 +89,8 @@ impl FileConfigWithDefaultName for ContractsConfig { const FILE_NAME: &'static str = CONTRACTS_FILE; } +impl ZkToolboxConfig for ContractsConfig {} + #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)] pub struct EcosystemContracts { pub bridgehub_proxy_addr: Address, @@ -98,7 +100,7 @@ pub struct EcosystemContracts { pub diamond_cut_data: String, } -impl FileConfig for EcosystemContracts {} +impl ZkToolboxConfig for EcosystemContracts {} #[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct BridgesContracts { diff --git a/zk_toolbox/crates/config/src/ecosystem.rs b/zk_toolbox/crates/config/src/ecosystem.rs index a0121a2b25db..76d8a0c45b22 100644 --- a/zk_toolbox/crates/config/src/ecosystem.rs +++ b/zk_toolbox/crates/config/src/ecosystem.rs @@ -6,8 +6,9 @@ use std::{ use common::logger; use serde::{Deserialize, Serialize, Serializer}; use thiserror::Error; -use types::{ChainId, L1Network, ProverMode, WalletCreation}; +use types::{L1Network, ProverMode, WalletCreation}; use xshell::Shell; +use zksync_basic_types::L2ChainId; use crate::{ consts::{ @@ -17,7 +18,7 @@ use crate::{ }, create_localhost_wallets, forge_interface::deploy_ecosystem::input::{Erc20DeploymentConfig, InitialDeploymentConfig}, - traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig}, + traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig, ZkToolboxConfig}, ChainConfig, ChainConfigInternal, ContractsConfig, WalletsConfig, }; @@ -32,7 +33,7 @@ struct EcosystemConfigInternal { pub chains: PathBuf, pub config: PathBuf, pub default_chain: String, - pub era_chain_id: ChainId, + pub era_chain_id: L2ChainId, pub prover_version: ProverMode, pub wallet_creation: WalletCreation, } @@ -48,7 +49,7 @@ pub struct EcosystemConfig { pub chains: PathBuf, pub config: PathBuf, pub default_chain: String, - pub era_chain_id: ChainId, + pub era_chain_id: L2ChainId, pub prover_version: ProverMode, pub wallet_creation: WalletCreation, pub shell: OnceCell, @@ -90,6 +91,10 @@ impl FileConfigWithDefaultName for EcosystemConfig { const FILE_NAME: &'static str = CONFIG_NAME; } +impl ZkToolboxConfig for EcosystemConfigInternal {} + +impl ZkToolboxConfig for EcosystemConfig {} + impl EcosystemConfig { fn get_shell(&self) -> &Shell { self.shell.get().expect("Must be initialized") @@ -245,8 +250,8 @@ pub enum EcosystemConfigFromFileError { InvalidConfig { source: anyhow::Error }, } -pub fn get_default_era_chain_id() -> ChainId { - ERA_CHAIN_ID +pub fn get_default_era_chain_id() -> L2ChainId { + L2ChainId::from(ERA_CHAIN_ID) } // Find file in all parents repository and return necessary path or an empty error if nothing has been found diff --git a/zk_toolbox/crates/config/src/external_node.rs b/zk_toolbox/crates/config/src/external_node.rs index 87acb15e4d8c..a07ff5dc1400 100644 --- a/zk_toolbox/crates/config/src/external_node.rs +++ b/zk_toolbox/crates/config/src/external_node.rs @@ -1,23 +1,28 @@ -use std::num::NonZeroUsize; +use std::path::Path; -use serde::{Deserialize, Serialize}; -use types::{ChainId, L1BatchCommitDataGeneratorMode}; +use xshell::Shell; +pub use zksync_config::configs::en_config::ENConfig; +use zksync_protobuf_config::{decode_yaml_repr, encode_yaml_repr}; -use crate::{consts::EN_CONFIG_FILE, traits::FileConfigWithDefaultName}; +use crate::{ + consts::EN_CONFIG_FILE, + traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig}, +}; -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] -pub struct ENConfig { - // Genesis - pub l2_chain_id: ChainId, - pub l1_chain_id: u32, - pub l1_batch_commit_data_generator_mode: L1BatchCommitDataGeneratorMode, +impl FileConfigWithDefaultName for ENConfig { + const FILE_NAME: &'static str = EN_CONFIG_FILE; +} - // Main node configuration - pub main_node_url: String, - #[serde(skip_serializing_if = "Option::is_none")] - pub main_node_rate_limit_rps: Option, +impl SaveConfig for ENConfig { + fn save(&self, shell: &Shell, path: impl AsRef) -> anyhow::Result<()> { + let bytes = encode_yaml_repr::(self)?; + Ok(shell.write_file(path, bytes)?) + } } -impl FileConfigWithDefaultName for ENConfig { - const FILE_NAME: &'static str = EN_CONFIG_FILE; +impl ReadConfig for ENConfig { + fn read(shell: &Shell, path: impl AsRef) -> anyhow::Result { + let path = shell.current_dir().join(path); + decode_yaml_repr::(&path, false) + } } diff --git a/zk_toolbox/crates/config/src/forge_interface/accept_ownership/mod.rs b/zk_toolbox/crates/config/src/forge_interface/accept_ownership/mod.rs index 58b5aa1f9d49..636cffc49f89 100644 --- a/zk_toolbox/crates/config/src/forge_interface/accept_ownership/mod.rs +++ b/zk_toolbox/crates/config/src/forge_interface/accept_ownership/mod.rs @@ -1,9 +1,9 @@ use ethers::types::Address; use serde::{Deserialize, Serialize}; -use crate::traits::FileConfig; +use crate::traits::ZkToolboxConfig; -impl FileConfig for AcceptOwnershipInput {} +impl ZkToolboxConfig for AcceptOwnershipInput {} #[derive(Debug, Deserialize, Serialize, Clone)] pub struct AcceptOwnershipInput { diff --git a/zk_toolbox/crates/config/src/forge_interface/deploy_ecosystem/input.rs b/zk_toolbox/crates/config/src/forge_interface/deploy_ecosystem/input.rs index e0ad2ac70cdc..0dc117ae8cda 100644 --- a/zk_toolbox/crates/config/src/forge_interface/deploy_ecosystem/input.rs +++ b/zk_toolbox/crates/config/src/forge_interface/deploy_ecosystem/input.rs @@ -6,11 +6,11 @@ use ethers::{ }; use rand::Rng; use serde::{Deserialize, Serialize}; -use types::ChainId; +use zksync_basic_types::L2ChainId; use crate::{ consts::INITIAL_DEPLOYMENT_FILE, - traits::{FileConfig, FileConfigWithDefaultName}, + traits::{FileConfigWithDefaultName, ZkToolboxConfig}, ContractsConfig, GenesisConfig, WalletsConfig, }; @@ -61,6 +61,8 @@ impl FileConfigWithDefaultName for InitialDeploymentConfig { const FILE_NAME: &'static str = INITIAL_DEPLOYMENT_FILE; } +impl ZkToolboxConfig for InitialDeploymentConfig {} + #[derive(Debug, Deserialize, Serialize, Clone)] pub struct Erc20DeploymentConfig { pub tokens: Vec, @@ -70,6 +72,8 @@ impl FileConfigWithDefaultName for Erc20DeploymentConfig { const FILE_NAME: &'static str = INITIAL_DEPLOYMENT_FILE; } +impl ZkToolboxConfig for Erc20DeploymentConfig {} + impl Default for Erc20DeploymentConfig { fn default() -> Self { Self { @@ -111,21 +115,21 @@ pub struct Erc20DeploymentTokensConfig { #[derive(Debug, Deserialize, Serialize, Clone)] pub struct DeployL1Config { - pub era_chain_id: ChainId, + pub era_chain_id: L2ChainId, pub owner_address: Address, pub testnet_verifier: bool, pub contracts: ContractsDeployL1Config, pub tokens: TokensDeployL1Config, } -impl FileConfig for DeployL1Config {} +impl ZkToolboxConfig for DeployL1Config {} impl DeployL1Config { pub fn new( genesis_config: &GenesisConfig, wallets_config: &WalletsConfig, initial_deployment_config: &InitialDeploymentConfig, - era_chain_id: ChainId, + era_chain_id: L2ChainId, testnet_verifier: bool, ) -> Self { Self { @@ -147,16 +151,17 @@ impl DeployL1Config { .diamond_init_max_pubdata_per_batch, diamond_init_minimal_l2_gas_price: initial_deployment_config .diamond_init_minimal_l2_gas_price, - bootloader_hash: genesis_config.bootloader_hash, - default_aa_hash: genesis_config.default_aa_hash, + bootloader_hash: genesis_config.bootloader_hash.unwrap(), + default_aa_hash: genesis_config.default_aa_hash.unwrap(), diamond_init_priority_tx_max_pubdata: initial_deployment_config .diamond_init_priority_tx_max_pubdata, diamond_init_pubdata_pricing_mode: initial_deployment_config .diamond_init_pubdata_pricing_mode, - genesis_batch_commitment: genesis_config.genesis_batch_commitment, - genesis_rollup_leaf_index: genesis_config.genesis_rollup_leaf_index, - genesis_root: genesis_config.genesis_root, - latest_protocol_version: genesis_config.genesis_protocol_semantic_version.pack(), + // These values are not optional in genesis config with file based configuration + genesis_batch_commitment: genesis_config.genesis_commitment.unwrap(), + genesis_rollup_leaf_index: genesis_config.rollup_last_leaf_index.unwrap(), + genesis_root: genesis_config.genesis_root_hash.unwrap(), + latest_protocol_version: genesis_config.protocol_version.unwrap().pack(), recursion_circuits_set_vks_hash: H256::zero(), recursion_leaf_level_vk_hash: H256::zero(), recursion_node_level_vk_hash: H256::zero(), @@ -181,7 +186,7 @@ pub struct ContractsDeployL1Config { pub create2_factory_addr: Option
, pub validator_timelock_execution_delay: u64, pub genesis_root: H256, - pub genesis_rollup_leaf_index: u32, + pub genesis_rollup_leaf_index: u64, pub genesis_batch_commitment: H256, pub latest_protocol_version: U256, pub recursion_node_level_vk_hash: H256, @@ -212,7 +217,7 @@ pub struct DeployErc20Config { pub additional_addresses_for_minting: Vec
, } -impl FileConfig for DeployErc20Config {} +impl ZkToolboxConfig for DeployErc20Config {} impl DeployErc20Config { pub fn new( diff --git a/zk_toolbox/crates/config/src/forge_interface/deploy_ecosystem/output.rs b/zk_toolbox/crates/config/src/forge_interface/deploy_ecosystem/output.rs index 874414ccc1a4..77f212114916 100644 --- a/zk_toolbox/crates/config/src/forge_interface/deploy_ecosystem/output.rs +++ b/zk_toolbox/crates/config/src/forge_interface/deploy_ecosystem/output.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use crate::{ consts::ERC20_CONFIGS_FILE, - traits::{FileConfig, FileConfigWithDefaultName}, + traits::{FileConfigWithDefaultName, ZkToolboxConfig}, }; #[derive(Debug, Deserialize, Serialize, Clone)] @@ -21,7 +21,7 @@ pub struct DeployL1Output { pub deployed_addresses: DeployL1DeployedAddressesOutput, } -impl FileConfig for DeployL1Output {} +impl ZkToolboxConfig for DeployL1Output {} #[derive(Debug, Deserialize, Serialize, Clone)] pub struct DeployL1ContractsConfigOutput { @@ -96,3 +96,5 @@ pub struct DeployErc20Output { impl FileConfigWithDefaultName for DeployErc20Output { const FILE_NAME: &'static str = ERC20_CONFIGS_FILE; } + +impl ZkToolboxConfig for DeployErc20Output {} diff --git a/zk_toolbox/crates/config/src/forge_interface/initialize_bridges/input.rs b/zk_toolbox/crates/config/src/forge_interface/initialize_bridges/input.rs index e884c0a3a39e..d06e36185607 100644 --- a/zk_toolbox/crates/config/src/forge_interface/initialize_bridges/input.rs +++ b/zk_toolbox/crates/config/src/forge_interface/initialize_bridges/input.rs @@ -1,15 +1,15 @@ use ethers::types::Address; use serde::{Deserialize, Serialize}; -use types::ChainId; +use zksync_basic_types::L2ChainId; -use crate::{traits::FileConfig, ChainConfig}; +use crate::{traits::ZkToolboxConfig, ChainConfig}; -impl FileConfig for InitializeBridgeInput {} +impl ZkToolboxConfig for InitializeBridgeInput {} #[derive(Debug, Clone, Serialize, Deserialize)] pub struct InitializeBridgeInput { - pub era_chain_id: ChainId, - pub chain_id: ChainId, + pub era_chain_id: L2ChainId, + pub chain_id: L2ChainId, pub l1_shared_bridge: Address, pub bridgehub: Address, pub governance: Address, @@ -17,7 +17,7 @@ pub struct InitializeBridgeInput { } impl InitializeBridgeInput { - pub fn new(chain_config: &ChainConfig, era_chain_id: ChainId) -> anyhow::Result { + pub fn new(chain_config: &ChainConfig, era_chain_id: L2ChainId) -> anyhow::Result { let contracts = chain_config.get_contracts_config()?; let wallets = chain_config.get_wallets_config()?; Ok(Self { diff --git a/zk_toolbox/crates/config/src/forge_interface/initialize_bridges/output.rs b/zk_toolbox/crates/config/src/forge_interface/initialize_bridges/output.rs index d03474a6a089..8da3707ed706 100644 --- a/zk_toolbox/crates/config/src/forge_interface/initialize_bridges/output.rs +++ b/zk_toolbox/crates/config/src/forge_interface/initialize_bridges/output.rs @@ -1,9 +1,9 @@ use ethers::types::Address; use serde::{Deserialize, Serialize}; -use crate::traits::FileConfig; +use crate::traits::ZkToolboxConfig; -impl FileConfig for InitializeBridgeOutput {} +impl ZkToolboxConfig for InitializeBridgeOutput {} #[derive(Debug, Clone, Serialize, Deserialize)] pub struct InitializeBridgeOutput { diff --git a/zk_toolbox/crates/config/src/forge_interface/paymaster/mod.rs b/zk_toolbox/crates/config/src/forge_interface/paymaster/mod.rs index e634f1eb3dab..9631fe743180 100644 --- a/zk_toolbox/crates/config/src/forge_interface/paymaster/mod.rs +++ b/zk_toolbox/crates/config/src/forge_interface/paymaster/mod.rs @@ -1,12 +1,12 @@ use ethers::types::Address; use serde::{Deserialize, Serialize}; -use types::ChainId; +use zksync_basic_types::L2ChainId; -use crate::{traits::FileConfig, ChainConfig}; +use crate::{traits::ZkToolboxConfig, ChainConfig}; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct DeployPaymasterInput { - pub chain_id: ChainId, + pub chain_id: L2ChainId, pub l1_shared_bridge: Address, pub bridgehub: Address, } @@ -21,11 +21,12 @@ impl DeployPaymasterInput { }) } } -impl FileConfig for DeployPaymasterInput {} + +impl ZkToolboxConfig for DeployPaymasterInput {} #[derive(Debug, Serialize, Deserialize, Clone)] pub struct DeployPaymasterOutput { pub paymaster: Address, } -impl FileConfig for DeployPaymasterOutput {} +impl ZkToolboxConfig for DeployPaymasterOutput {} diff --git a/zk_toolbox/crates/config/src/forge_interface/register_chain/input.rs b/zk_toolbox/crates/config/src/forge_interface/register_chain/input.rs index 3849aa341e2b..29494ba5d8f5 100644 --- a/zk_toolbox/crates/config/src/forge_interface/register_chain/input.rs +++ b/zk_toolbox/crates/config/src/forge_interface/register_chain/input.rs @@ -1,9 +1,10 @@ use ethers::types::Address; use rand::Rng; use serde::{Deserialize, Serialize}; -use types::{ChainId, L1BatchCommitDataGeneratorMode}; +use types::L1BatchCommitmentMode; +use zksync_basic_types::L2ChainId; -use crate::{traits::FileConfig, ChainConfig, ContractsConfig}; +use crate::{traits::ZkToolboxConfig, ChainConfig, ContractsConfig}; #[derive(Debug, Deserialize, Serialize, Clone)] struct Bridgehub { @@ -14,6 +15,7 @@ struct Bridgehub { struct StateTransition { state_transition_proxy_addr: Address, } + #[derive(Debug, Deserialize, Serialize, Clone)] struct DeployedAddresses { state_transition: StateTransition, @@ -36,7 +38,7 @@ pub struct RegisterChainL1Config { #[derive(Debug, Deserialize, Serialize, Clone)] pub struct ChainL1Config { - pub chain_chain_id: ChainId, + pub chain_chain_id: L2ChainId, pub base_token_addr: Address, pub bridgehub_create_new_chain_salt: u64, pub validium_mode: bool, @@ -48,7 +50,7 @@ pub struct ChainL1Config { pub governance_min_delay: u64, } -impl FileConfig for RegisterChainL1Config {} +impl ZkToolboxConfig for RegisterChainL1Config {} impl RegisterChainL1Config { pub fn new(chain_config: &ChainConfig, contracts: &ContractsConfig) -> anyhow::Result { @@ -80,7 +82,7 @@ impl RegisterChainL1Config { // TODO verify bridgehub_create_new_chain_salt: rand::thread_rng().gen_range(0..=i64::MAX) as u64, validium_mode: chain_config.l1_batch_commit_data_generator_mode - == L1BatchCommitDataGeneratorMode::Validium, + == L1BatchCommitmentMode::Validium, validator_sender_operator_commit_eth: wallets_config.operator.address, validator_sender_operator_blobs_eth: wallets_config.blob_operator.address, }, diff --git a/zk_toolbox/crates/config/src/forge_interface/register_chain/output.rs b/zk_toolbox/crates/config/src/forge_interface/register_chain/output.rs index 2f39b76c3933..f9521b16328f 100644 --- a/zk_toolbox/crates/config/src/forge_interface/register_chain/output.rs +++ b/zk_toolbox/crates/config/src/forge_interface/register_chain/output.rs @@ -1,7 +1,7 @@ use ethers::types::Address; use serde::{Deserialize, Serialize}; -use crate::traits::FileConfig; +use crate::traits::ZkToolboxConfig; #[derive(Debug, Deserialize, Serialize, Clone)] pub struct RegisterChainOutput { @@ -10,4 +10,4 @@ pub struct RegisterChainOutput { pub chain_admin_addr: Address, } -impl FileConfig for RegisterChainOutput {} +impl ZkToolboxConfig for RegisterChainOutput {} diff --git a/zk_toolbox/crates/config/src/general.rs b/zk_toolbox/crates/config/src/general.rs index b97384f26f8c..091d18936616 100644 --- a/zk_toolbox/crates/config/src/general.rs +++ b/zk_toolbox/crates/config/src/general.rs @@ -1,57 +1,66 @@ -use std::path::PathBuf; +use std::path::{Path, PathBuf}; -use serde::{Deserialize, Serialize}; +use anyhow::Context; use url::Url; +use xshell::Shell; +pub use zksync_config::configs::GeneralConfig; +use zksync_protobuf_config::{decode_yaml_repr, encode_yaml_repr}; -use crate::{consts::GENERAL_FILE, traits::FileConfigWithDefaultName}; +use crate::{ + consts::GENERAL_FILE, + traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig}, +}; pub struct RocksDbs { pub state_keeper: PathBuf, pub merkle_tree: PathBuf, } -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct GeneralConfig { - pub db: RocksDBConfig, - pub eth: EthConfig, - pub api: ApiConfig, - #[serde(flatten)] - pub other: serde_json::Value, +pub fn set_rocks_db_config(config: &mut GeneralConfig, rocks_dbs: RocksDbs) -> anyhow::Result<()> { + config + .db_config + .as_mut() + .context("DB config is not presented")? + .state_keeper_db_path = rocks_dbs.state_keeper.to_str().unwrap().to_string(); + config + .db_config + .as_mut() + .context("DB config is not presented")? + .merkle_tree + .path = rocks_dbs.merkle_tree.to_str().unwrap().to_string(); + Ok(()) } -impl GeneralConfig { - pub fn set_rocks_db_config(&mut self, rocks_dbs: RocksDbs) -> anyhow::Result<()> { - self.db.state_keeper_db_path = rocks_dbs.state_keeper; - self.db.merkle_tree.path = rocks_dbs.merkle_tree; - Ok(()) - } - - pub fn ports_config(&self) -> PortsConfig { - PortsConfig { - web3_json_rpc_http_port: self.api.web3_json_rpc.http_port, - web3_json_rpc_ws_port: self.api.web3_json_rpc.ws_port, - healthcheck_port: self.api.healthcheck.port, - merkle_tree_port: self.api.merkle_tree.port, - prometheus_listener_port: self.api.prometheus.listener_port, - } - } - - pub fn update_ports(&mut self, ports_config: &PortsConfig) -> anyhow::Result<()> { - self.api.web3_json_rpc.http_port = ports_config.web3_json_rpc_http_port; - update_port_in_url( - &mut self.api.web3_json_rpc.http_url, - ports_config.web3_json_rpc_http_port, - )?; - self.api.web3_json_rpc.ws_port = ports_config.web3_json_rpc_ws_port; - update_port_in_url( - &mut self.api.web3_json_rpc.ws_url, - ports_config.web3_json_rpc_ws_port, - )?; - self.api.healthcheck.port = ports_config.healthcheck_port; - self.api.merkle_tree.port = ports_config.merkle_tree_port; - self.api.prometheus.listener_port = ports_config.prometheus_listener_port; - Ok(()) - } +pub fn ports_config(config: &GeneralConfig) -> Option { + let api = config.api_config.as_ref()?; + Some(PortsConfig { + web3_json_rpc_http_port: api.web3_json_rpc.http_port, + web3_json_rpc_ws_port: api.web3_json_rpc.ws_port, + healthcheck_port: api.healthcheck.port, + merkle_tree_port: api.merkle_tree.port, + prometheus_listener_port: api.prometheus.listener_port, + }) +} + +pub fn update_ports(config: &mut GeneralConfig, ports_config: &PortsConfig) -> anyhow::Result<()> { + let api = config + .api_config + .as_mut() + .context("Api config is not presented")?; + api.web3_json_rpc.http_port = ports_config.web3_json_rpc_http_port; + update_port_in_url( + &mut api.web3_json_rpc.http_url, + ports_config.web3_json_rpc_http_port, + )?; + api.web3_json_rpc.ws_port = ports_config.web3_json_rpc_ws_port; + update_port_in_url( + &mut api.web3_json_rpc.ws_url, + ports_config.web3_json_rpc_ws_port, + )?; + api.healthcheck.port = ports_config.healthcheck_port; + api.merkle_tree.port = ports_config.merkle_tree_port; + api.prometheus.listener_port = ports_config.prometheus_listener_port; + Ok(()) } fn update_port_in_url(http_url: &mut String, port: u16) -> anyhow::Result<()> { @@ -67,101 +76,6 @@ impl FileConfigWithDefaultName for GeneralConfig { const FILE_NAME: &'static str = GENERAL_FILE; } -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct RocksDBConfig { - pub state_keeper_db_path: PathBuf, - pub merkle_tree: MerkleTreeDB, - #[serde(flatten)] - pub other: serde_json::Value, -} - -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct MerkleTreeDB { - pub path: PathBuf, - #[serde(flatten)] - pub other: serde_json::Value, -} - -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct EthConfig { - pub sender: EthSender, - #[serde(flatten)] - pub other: serde_json::Value, -} - -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct EthSender { - pub proof_sending_mode: String, - pub pubdata_sending_mode: String, - #[serde(flatten)] - pub other: serde_json::Value, -} - -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct ApiConfig { - /// Configuration options for the Web3 JSON RPC servers. - pub web3_json_rpc: Web3JsonRpcConfig, - /// Configuration options for the Prometheus exporter. - pub prometheus: PrometheusConfig, - /// Configuration options for the Health check. - pub healthcheck: HealthCheckConfig, - /// Configuration options for Merkle tree API. - pub merkle_tree: MerkleTreeApiConfig, - #[serde(flatten)] - pub other: serde_json::Value, -} - -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct Web3JsonRpcConfig { - /// Port to which the HTTP RPC server is listening. - pub http_port: u16, - /// URL to access HTTP RPC server. - pub http_url: String, - /// Port to which the WebSocket RPC server is listening. - pub ws_port: u16, - /// URL to access WebSocket RPC server. - pub ws_url: String, - /// Max possible limit of entities to be requested once. - pub req_entities_limit: Option, - #[serde(flatten)] - pub other: serde_json::Value, -} - -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct PrometheusConfig { - /// Port to which the Prometheus exporter server is listening. - pub listener_port: u16, - /// URL of the push gateway. - pub pushgateway_url: String, - /// Push interval in ms. - pub push_interval_ms: Option, - #[serde(flatten)] - pub other: serde_json::Value, -} - -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct HealthCheckConfig { - /// Port to which the REST server is listening. - pub port: u16, - /// Time limit in milliseconds to mark a health check as slow and log the corresponding warning. - /// If not specified, the default value in the health check crate will be used. - pub slow_time_limit_ms: Option, - /// Time limit in milliseconds to abort a health check and return "not ready" status for the corresponding component. - /// If not specified, the default value in the health check crate will be used. - pub hard_time_limit_ms: Option, - #[serde(flatten)] - pub other: serde_json::Value, -} - -/// Configuration for the Merkle tree API. -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct MerkleTreeApiConfig { - /// Port to bind the Merkle tree API server to. - pub port: u16, - #[serde(flatten)] - pub other: serde_json::Value, -} - pub struct PortsConfig { pub web3_json_rpc_http_port: u16, pub web3_json_rpc_ws_port: u16, @@ -181,3 +95,18 @@ impl PortsConfig { } } } + +impl SaveConfig for GeneralConfig { + fn save(&self, shell: &Shell, path: impl AsRef) -> anyhow::Result<()> { + let bytes = + encode_yaml_repr::(self)?; + Ok(shell.write_file(path, bytes)?) + } +} + +impl ReadConfig for GeneralConfig { + fn read(shell: &Shell, path: impl AsRef) -> anyhow::Result { + let path = shell.current_dir().join(path); + decode_yaml_repr::(&path, false) + } +} diff --git a/zk_toolbox/crates/config/src/genesis.rs b/zk_toolbox/crates/config/src/genesis.rs index e666931870a8..1df1da85fe1f 100644 --- a/zk_toolbox/crates/config/src/genesis.rs +++ b/zk_toolbox/crates/config/src/genesis.rs @@ -1,34 +1,36 @@ -use ethers::types::{Address, H256}; -use serde::{Deserialize, Serialize}; -use types::{ChainId, L1BatchCommitDataGeneratorMode, ProtocolSemanticVersion}; +use std::path::Path; -use crate::{consts::GENESIS_FILE, traits::FileConfigWithDefaultName, ChainConfig}; +use xshell::Shell; +use zksync_basic_types::L1ChainId; +pub use zksync_config::GenesisConfig; +use zksync_protobuf_config::{decode_yaml_repr, encode_yaml_repr}; -#[derive(Debug, Deserialize, Serialize, Clone)] -pub struct GenesisConfig { - pub l2_chain_id: ChainId, - pub l1_chain_id: u32, - pub l1_batch_commit_data_generator_mode: Option, - pub bootloader_hash: H256, - pub default_aa_hash: H256, - pub fee_account: Address, - pub genesis_batch_commitment: H256, - pub genesis_rollup_leaf_index: u32, - pub genesis_root: H256, - pub genesis_protocol_version: u64, - pub genesis_protocol_semantic_version: ProtocolSemanticVersion, - #[serde(flatten)] - pub other: serde_json::Value, -} +use crate::{ + consts::GENESIS_FILE, + traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig}, + ChainConfig, +}; -impl GenesisConfig { - pub fn update_from_chain_config(&mut self, config: &ChainConfig) { - self.l2_chain_id = config.chain_id; - self.l1_chain_id = config.l1_network.chain_id(); - self.l1_batch_commit_data_generator_mode = Some(config.l1_batch_commit_data_generator_mode); - } +pub fn update_from_chain_config(genesis: &mut GenesisConfig, config: &ChainConfig) { + genesis.l2_chain_id = config.chain_id; + genesis.l1_chain_id = L1ChainId(config.l1_network.chain_id()); + genesis.l1_batch_commit_data_generator_mode = config.l1_batch_commit_data_generator_mode; } impl FileConfigWithDefaultName for GenesisConfig { const FILE_NAME: &'static str = GENESIS_FILE; } + +impl SaveConfig for GenesisConfig { + fn save(&self, shell: &Shell, path: impl AsRef) -> anyhow::Result<()> { + let bytes = encode_yaml_repr::(self)?; + Ok(shell.write_file(path, bytes)?) + } +} + +impl ReadConfig for GenesisConfig { + fn read(shell: &Shell, path: impl AsRef) -> anyhow::Result { + let path = shell.current_dir().join(path); + decode_yaml_repr::(&path, false) + } +} diff --git a/zk_toolbox/crates/config/src/lib.rs b/zk_toolbox/crates/config/src/lib.rs index a80a2b6fe5de..47d4040eb6bf 100644 --- a/zk_toolbox/crates/config/src/lib.rs +++ b/zk_toolbox/crates/config/src/lib.rs @@ -9,6 +9,7 @@ pub use manipulations::*; pub use secrets::*; pub use wallet_creation::*; pub use wallets::*; +pub use zksync_protobuf_config::{decode_yaml_repr, encode_yaml_repr}; mod chain; mod consts; diff --git a/zk_toolbox/crates/config/src/secrets.rs b/zk_toolbox/crates/config/src/secrets.rs index 98a9be6ffe61..5bcad19ad339 100644 --- a/zk_toolbox/crates/config/src/secrets.rs +++ b/zk_toolbox/crates/config/src/secrets.rs @@ -1,48 +1,54 @@ +use std::{path::Path, str::FromStr}; + +use anyhow::Context; use common::db::DatabaseConfig; -use serde::{Deserialize, Serialize}; -use url::Url; +use xshell::Shell; +use zksync_basic_types::url::SensitiveUrl; +pub use zksync_config::configs::Secrets as SecretsConfig; +use zksync_protobuf_config::{decode_yaml_repr, encode_yaml_repr}; -use crate::{consts::SECRETS_FILE, traits::FileConfigWithDefaultName}; +use crate::{ + consts::SECRETS_FILE, + traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig}, +}; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct DatabaseSecrets { - pub server_url: Url, - #[serde(skip_serializing_if = "Option::is_none")] - pub prover_url: Option, - #[serde(flatten)] - pub other: serde_json::Value, +pub fn set_databases( + secrets: &mut SecretsConfig, + server_db_config: &DatabaseConfig, + prover_db_config: &DatabaseConfig, +) -> anyhow::Result<()> { + let database = secrets + .database + .as_mut() + .context("Databases must be presented")?; + database.server_url = Some(SensitiveUrl::from(server_db_config.full_url())); + database.prover_url = Some(SensitiveUrl::from(prover_db_config.full_url())); + Ok(()) } -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct L1Secret { - pub l1_rpc_url: String, - #[serde(flatten)] - pub other: serde_json::Value, +pub fn set_l1_rpc_url(secrets: &mut SecretsConfig, l1_rpc_url: String) -> anyhow::Result<()> { + secrets + .l1 + .as_mut() + .context("L1 Secrets must be presented")? + .l1_rpc_url = SensitiveUrl::from_str(&l1_rpc_url)?; + Ok(()) } -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct SecretsConfig { - pub database: DatabaseSecrets, - pub l1: L1Secret, - #[serde(flatten)] - pub other: serde_json::Value, +impl FileConfigWithDefaultName for SecretsConfig { + const FILE_NAME: &'static str = SECRETS_FILE; } -impl SecretsConfig { - pub fn set_databases( - &mut self, - server_db_config: &DatabaseConfig, - prover_db_config: &DatabaseConfig, - ) { - self.database.server_url = server_db_config.full_url(); - self.database.prover_url = Some(prover_db_config.full_url()); - } - - pub fn set_l1_rpc_url(&mut self, l1_rpc_url: String) { - self.l1.l1_rpc_url = l1_rpc_url; +impl SaveConfig for SecretsConfig { + fn save(&self, shell: &Shell, path: impl AsRef) -> anyhow::Result<()> { + let bytes = encode_yaml_repr::(self)?; + Ok(shell.write_file(path, bytes)?) } } -impl FileConfigWithDefaultName for SecretsConfig { - const FILE_NAME: &'static str = SECRETS_FILE; +impl ReadConfig for SecretsConfig { + fn read(shell: &Shell, path: impl AsRef) -> anyhow::Result { + let path = shell.current_dir().join(path); + decode_yaml_repr::(&path, false) + } } diff --git a/zk_toolbox/crates/config/src/traits.rs b/zk_toolbox/crates/config/src/traits.rs index 772c5d964dab..1f00b39b040a 100644 --- a/zk_toolbox/crates/config/src/traits.rs +++ b/zk_toolbox/crates/config/src/traits.rs @@ -7,7 +7,8 @@ use common::files::{ use serde::{de::DeserializeOwned, Serialize}; use xshell::Shell; -pub trait FileConfig {} +// Configs that we use only inside zk toolbox, we don't have protobuf implementation for them. +pub trait ZkToolboxConfig {} pub trait FileConfigWithDefaultName { const FILE_NAME: &'static str; @@ -17,25 +18,38 @@ pub trait FileConfigWithDefaultName { } } -impl FileConfig for T where T: FileConfigWithDefaultName {} - -impl SaveConfig for T where T: FileConfig + Serialize {} - -impl SaveConfigWithComment for T where T: FileConfig + Serialize {} +impl SaveConfig for T { + fn save(&self, shell: &Shell, path: impl AsRef) -> anyhow::Result<()> { + save_with_comment(shell, path, self, "") + } +} -impl ReadConfigWithBasePath for T where T: FileConfigWithDefaultName + Clone + DeserializeOwned {} +impl ReadConfigWithBasePath for T +where + T: FileConfigWithDefaultName + Clone + ReadConfig, +{ + fn read_with_base_path(shell: &Shell, base_path: impl AsRef) -> anyhow::Result { + ::read(shell, base_path.as_ref().join(Self::FILE_NAME)) + } +} -impl SaveConfigWithBasePath for T where T: FileConfigWithDefaultName + Serialize {} +impl SaveConfigWithBasePath for T where T: FileConfigWithDefaultName + SaveConfig {} -impl SaveConfigWithCommentAndBasePath for T where T: FileConfigWithDefaultName + Serialize {} +impl SaveConfigWithCommentAndBasePath for T where + T: FileConfigWithDefaultName + Serialize + SaveConfig +{ +} +/// Reads a config file from a given path, correctly parsing file extension. +/// Supported file extensions are: `yaml`, `yml`, `toml`, `json`. pub trait ReadConfig: Sized { fn read(shell: &Shell, path: impl AsRef) -> anyhow::Result; } -/// Reads a config file from a given path, correctly parsing file extension. -/// Supported file extensions are: `yaml`, `yml`, `toml`, `json`. -impl ReadConfig for T { +impl ReadConfig for T +where + T: DeserializeOwned + Clone + ZkToolboxConfig, +{ fn read(shell: &Shell, path: impl AsRef) -> anyhow::Result { let error_context = || format!("Failed to parse config file {:?}.", path.as_ref()); @@ -53,18 +67,14 @@ impl ReadConfig for T { /// Reads a config file from a base path, correctly parsing file extension. /// Supported file extensions are: `yaml`, `yml`, `toml`, `json`. -pub trait ReadConfigWithBasePath: ReadConfig + FileConfigWithDefaultName { - fn read_with_base_path(shell: &Shell, base_path: impl AsRef) -> anyhow::Result { - ::read(shell, base_path.as_ref().join(Self::FILE_NAME)) - } +pub trait ReadConfigWithBasePath: ReadConfig + FileConfigWithDefaultName + Clone { + fn read_with_base_path(shell: &Shell, base_path: impl AsRef) -> anyhow::Result; } /// Saves a config file to a given path, correctly parsing file extension. /// Supported file extensions are: `yaml`, `yml`, `toml`, `json`. -pub trait SaveConfig: Serialize + Sized { - fn save(&self, shell: &Shell, path: impl AsRef) -> anyhow::Result<()> { - save_with_comment(shell, path, self, "") - } +pub trait SaveConfig { + fn save(&self, shell: &Shell, path: impl AsRef) -> anyhow::Result<()>; } /// Saves a config file from a base path, correctly parsing file extension. @@ -81,7 +91,16 @@ pub trait SaveConfigWithBasePath: SaveConfig + FileConfigWithDefaultName { /// Saves a config file to a given path, correctly parsing file extension. /// Supported file extensions are: `yaml`, `yml`, `toml`. -pub trait SaveConfigWithComment: Serialize + Sized { +pub trait SaveConfigWithComment: Sized { + fn save_with_comment( + &self, + shell: &Shell, + path: impl AsRef, + comment: &str, + ) -> anyhow::Result<()>; +} + +impl SaveConfigWithComment for T { fn save_with_comment( &self, shell: &Shell, diff --git a/zk_toolbox/crates/config/src/wallets.rs b/zk_toolbox/crates/config/src/wallets.rs index 91958195c232..460c4e3574a3 100644 --- a/zk_toolbox/crates/config/src/wallets.rs +++ b/zk_toolbox/crates/config/src/wallets.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use crate::{ consts::WALLETS_FILE, - traits::{FileConfig, FileConfigWithDefaultName}, + traits::{FileConfigWithDefaultName, ZkToolboxConfig}, }; #[derive(Debug, Clone, Serialize, Deserialize)] @@ -60,4 +60,6 @@ pub(crate) struct EthMnemonicConfig { pub(crate) base_path: String, } -impl FileConfig for EthMnemonicConfig {} +impl ZkToolboxConfig for EthMnemonicConfig {} + +impl ZkToolboxConfig for WalletsConfig {} diff --git a/zk_toolbox/crates/types/Cargo.toml b/zk_toolbox/crates/types/Cargo.toml index efd8f84d7088..7dc96cab768d 100644 --- a/zk_toolbox/crates/types/Cargo.toml +++ b/zk_toolbox/crates/types/Cargo.toml @@ -15,5 +15,5 @@ clap.workspace = true ethers.workspace = true serde.workspace = true strum.workspace = true -strum_macros.workspace = true thiserror.workspace = true +zksync_basic_types.workspace = true diff --git a/zk_toolbox/crates/types/src/chain_id.rs b/zk_toolbox/crates/types/src/chain_id.rs deleted file mode 100644 index 258175d3fde5..000000000000 --- a/zk_toolbox/crates/types/src/chain_id.rs +++ /dev/null @@ -1,18 +0,0 @@ -use std::fmt::Display; - -use serde::{Deserialize, Serialize}; - -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] -pub struct ChainId(pub u32); - -impl Display for ChainId { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.0) - } -} - -impl From for ChainId { - fn from(value: u32) -> Self { - Self(value) - } -} diff --git a/zk_toolbox/crates/types/src/l1_batch_commit_data_generator_mode.rs b/zk_toolbox/crates/types/src/l1_batch_commit_data_generator_mode.rs deleted file mode 100644 index cdb8f5919c2d..000000000000 --- a/zk_toolbox/crates/types/src/l1_batch_commit_data_generator_mode.rs +++ /dev/null @@ -1,22 +0,0 @@ -use clap::ValueEnum; -use serde::{Deserialize, Serialize}; -use strum_macros::EnumIter; - -#[derive( - Debug, - Serialize, - Deserialize, - Clone, - Copy, - ValueEnum, - EnumIter, - strum_macros::Display, - Default, - PartialEq, - Eq, -)] -pub enum L1BatchCommitDataGeneratorMode { - #[default] - Rollup, - Validium, -} diff --git a/zk_toolbox/crates/types/src/l1_network.rs b/zk_toolbox/crates/types/src/l1_network.rs index f7367673f6c8..822235611a33 100644 --- a/zk_toolbox/crates/types/src/l1_network.rs +++ b/zk_toolbox/crates/types/src/l1_network.rs @@ -1,6 +1,6 @@ use clap::ValueEnum; use serde::{Deserialize, Serialize}; -use strum_macros::EnumIter; +use strum::EnumIter; #[derive( Copy, @@ -15,7 +15,7 @@ use strum_macros::EnumIter; Deserialize, ValueEnum, EnumIter, - strum_macros::Display, + strum::Display, )] pub enum L1Network { #[default] @@ -26,7 +26,7 @@ pub enum L1Network { impl L1Network { #[must_use] - pub fn chain_id(&self) -> u32 { + pub fn chain_id(&self) -> u64 { match self { L1Network::Localhost => 9, L1Network::Sepolia => 11_155_111, diff --git a/zk_toolbox/crates/types/src/lib.rs b/zk_toolbox/crates/types/src/lib.rs index c405013990cf..4cc7f160a45b 100644 --- a/zk_toolbox/crates/types/src/lib.rs +++ b/zk_toolbox/crates/types/src/lib.rs @@ -1,15 +1,12 @@ mod base_token; -mod chain_id; -mod l1_batch_commit_data_generator_mode; mod l1_network; -mod protocol_version; mod prover_mode; mod wallet_creation; pub use base_token::*; -pub use chain_id::*; -pub use l1_batch_commit_data_generator_mode::*; pub use l1_network::*; -pub use protocol_version::ProtocolSemanticVersion; pub use prover_mode::*; pub use wallet_creation::*; +pub use zksync_basic_types::{ + commitment::L1BatchCommitmentMode, protocol_version::ProtocolSemanticVersion, +}; diff --git a/zk_toolbox/crates/types/src/protocol_version.rs b/zk_toolbox/crates/types/src/protocol_version.rs deleted file mode 100644 index 5b619c883a3e..000000000000 --- a/zk_toolbox/crates/types/src/protocol_version.rs +++ /dev/null @@ -1,87 +0,0 @@ -use std::{fmt, num::ParseIntError, str::FromStr}; - -use ethers::prelude::U256; -use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; - -pub const PACKED_SEMVER_MINOR_OFFSET: u32 = 32; - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] -pub struct ProtocolSemanticVersion { - pub minor: u16, - pub patch: u16, -} - -impl ProtocolSemanticVersion { - const MAJOR_VERSION: u8 = 0; - - pub fn new(minor: u16, patch: u16) -> Self { - Self { minor, patch } - } - - pub fn pack(&self) -> U256 { - (U256::from(self.minor) << U256::from(PACKED_SEMVER_MINOR_OFFSET)) | U256::from(self.patch) - } -} - -impl fmt::Display for ProtocolSemanticVersion { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}.{}.{}", Self::MAJOR_VERSION, self.minor, self.patch) - } -} - -#[derive(Debug, thiserror::Error)] -pub enum ParseProtocolSemanticVersionError { - #[error("invalid format")] - InvalidFormat, - #[error("non zero major version")] - NonZeroMajorVersion, - #[error("{0}")] - ParseIntError(ParseIntError), -} - -impl FromStr for ProtocolSemanticVersion { - type Err = ParseProtocolSemanticVersionError; - - fn from_str(s: &str) -> Result { - let parts: Vec<&str> = s.split('.').collect(); - if parts.len() != 3 { - return Err(ParseProtocolSemanticVersionError::InvalidFormat); - } - - let major = parts[0] - .parse::() - .map_err(ParseProtocolSemanticVersionError::ParseIntError)?; - if major != 0 { - return Err(ParseProtocolSemanticVersionError::NonZeroMajorVersion); - } - - let minor = parts[1] - .parse::() - .map_err(ParseProtocolSemanticVersionError::ParseIntError)?; - - let patch = parts[2] - .parse::() - .map_err(ParseProtocolSemanticVersionError::ParseIntError)?; - - Ok(ProtocolSemanticVersion { minor, patch }) - } -} - -impl<'de> Deserialize<'de> for ProtocolSemanticVersion { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - let s = String::deserialize(deserializer)?; - ProtocolSemanticVersion::from_str(&s).map_err(D::Error::custom) - } -} - -impl Serialize for ProtocolSemanticVersion { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - serializer.serialize_str(&self.to_string()) - } -} diff --git a/zk_toolbox/crates/types/src/prover_mode.rs b/zk_toolbox/crates/types/src/prover_mode.rs index d9b4fb965e8c..b6667402ba26 100644 --- a/zk_toolbox/crates/types/src/prover_mode.rs +++ b/zk_toolbox/crates/types/src/prover_mode.rs @@ -1,21 +1,11 @@ use clap::ValueEnum; use serde::{Deserialize, Serialize}; -use strum_macros::EnumIter; +use strum::EnumIter; #[derive( - Debug, - Serialize, - Deserialize, - Clone, - Copy, - ValueEnum, - EnumIter, - strum_macros::Display, - PartialEq, - Eq, + Debug, Serialize, Deserialize, Clone, Copy, ValueEnum, EnumIter, strum::Display, PartialEq, Eq, )] pub enum ProverMode { NoProofs, Gpu, - Cpu, } diff --git a/zk_toolbox/crates/types/src/wallet_creation.rs b/zk_toolbox/crates/types/src/wallet_creation.rs index 43cb5e969b93..8457d109e43b 100644 --- a/zk_toolbox/crates/types/src/wallet_creation.rs +++ b/zk_toolbox/crates/types/src/wallet_creation.rs @@ -1,6 +1,6 @@ use clap::ValueEnum; use serde::{Deserialize, Serialize}; -use strum_macros::EnumIter; +use strum::EnumIter; #[derive( Clone, @@ -15,7 +15,7 @@ use strum_macros::EnumIter; Deserialize, ValueEnum, EnumIter, - strum_macros::Display, + strum::Display, )] pub enum WalletCreation { /// Load wallets from localhost mnemonic, they are funded for localhost env diff --git a/zk_toolbox/crates/zk_inception/Cargo.toml b/zk_toolbox/crates/zk_inception/Cargo.toml index 3a8b57e162f6..2626611376fe 100644 --- a/zk_toolbox/crates/zk_inception/Cargo.toml +++ b/zk_toolbox/crates/zk_inception/Cargo.toml @@ -26,10 +26,10 @@ ethers.workspace = true common.workspace = true tokio.workspace = true types.workspace = true -strum_macros.workspace = true strum.workspace = true toml.workspace = true url.workspace = true thiserror.workspace = true zksync_config.workspace = true slugify-rs.workspace = true +zksync_basic_types.workspace = true diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/create.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/create.rs index 97a3de69c738..63f3a3736cd7 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/args/create.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/create.rs @@ -1,12 +1,11 @@ use std::{path::PathBuf, str::FromStr}; -use clap::Parser; +use clap::{Parser, ValueEnum}; use common::{Prompt, PromptConfirm, PromptSelect}; use serde::{Deserialize, Serialize}; use slugify_rs::slugify; -use strum::IntoEnumIterator; -use strum_macros::{Display, EnumIter}; -use types::{BaseToken, L1BatchCommitDataGeneratorMode, L1Network, ProverMode, WalletCreation}; +use strum::{Display, EnumIter, IntoEnumIterator}; +use types::{BaseToken, L1BatchCommitmentMode, L1Network, ProverMode, WalletCreation}; use crate::{ defaults::L2_CHAIN_ID, @@ -23,28 +22,44 @@ use crate::{ }, }; +// We need to duplicate it for using enum inside the arguments +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, EnumIter, Display, ValueEnum)] +enum L1BatchCommitmentModeInternal { + Rollup, + Validium, +} + +impl From for L1BatchCommitmentMode { + fn from(val: L1BatchCommitmentModeInternal) -> Self { + match val { + L1BatchCommitmentModeInternal::Rollup => L1BatchCommitmentMode::Rollup, + L1BatchCommitmentModeInternal::Validium => L1BatchCommitmentMode::Validium, + } + } +} + #[derive(Debug, Serialize, Deserialize, Parser)] pub struct ChainCreateArgs { #[arg(long)] - pub chain_name: Option, + chain_name: Option, #[arg(value_parser = clap::value_parser ! (u32).range(1..))] - pub chain_id: Option, + chain_id: Option, #[clap(long, help = MSG_PROVER_MODE_HELP, value_enum)] - pub prover_mode: Option, + prover_mode: Option, #[clap(long, help = MSG_WALLET_CREATION_HELP, value_enum)] - pub wallet_creation: Option, + wallet_creation: Option, #[clap(long, help = MSG_WALLET_PATH_HELP)] - pub wallet_path: Option, + wallet_path: Option, #[clap(long, help = MSG_L1_COMMIT_DATA_GENERATOR_MODE_HELP)] - pub l1_batch_commit_data_generator_mode: Option, + l1_batch_commit_data_generator_mode: Option, #[clap(long, help = MSG_BASE_TOKEN_ADDRESS_HELP)] - pub base_token_address: Option, + base_token_address: Option, #[clap(long, help = MSG_BASE_TOKEN_PRICE_NOMINATOR_HELP)] - pub base_token_price_nominator: Option, + base_token_price_nominator: Option, #[clap(long, help = MSG_BASE_TOKEN_PRICE_DENOMINATOR_HELP)] - pub base_token_price_denominator: Option, + base_token_price_denominator: Option, #[clap(long, help = MSG_SET_AS_DEFAULT_HELP, default_missing_value = "true", num_args = 0..=1)] - pub set_as_default: Option, + pub(crate) set_as_default: Option, } impl ChainCreateArgs { @@ -81,7 +96,7 @@ impl ChainCreateArgs { let l1_batch_commit_data_generator_mode = PromptSelect::new( MSG_L1_BATCH_COMMIT_DATA_GENERATOR_MODE_PROMPT, - L1BatchCommitDataGeneratorMode::iter(), + L1BatchCommitmentModeInternal::iter(), ) .ask(); @@ -139,7 +154,7 @@ impl ChainCreateArgs { chain_id, prover_version, wallet_creation, - l1_batch_commit_data_generator_mode, + l1_batch_commit_data_generator_mode: l1_batch_commit_data_generator_mode.into(), wallet_path, base_token, set_as_default, @@ -153,7 +168,7 @@ pub struct ChainCreateArgsFinal { pub chain_id: u32, pub prover_version: ProverMode, pub wallet_creation: WalletCreation, - pub l1_batch_commit_data_generator_mode: L1BatchCommitDataGeneratorMode, + pub l1_batch_commit_data_generator_mode: L1BatchCommitmentMode, pub wallet_path: Option, pub base_token: BaseToken, pub set_as_default: bool, diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/create.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/create.rs index dc8f408db3b3..70f4442cca62 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/create.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/create.rs @@ -5,8 +5,8 @@ use config::{ create_local_configs_dir, create_wallets, traits::SaveConfigWithBasePath, ChainConfig, EcosystemConfig, }; -use types::ChainId; use xshell::Shell; +use zksync_basic_types::L2ChainId; use crate::{ commands::chain::args::create::{ChainCreateArgs, ChainCreateArgsFinal}, @@ -62,7 +62,7 @@ pub(crate) fn create_chain_inner( let chain_config = ChainConfig { id: chain_id, name: default_chain_name.clone(), - chain_id: ChainId::from(args.chain_id), + chain_id: L2ChainId::from(args.chain_id), prover_version: args.prover_version, l1_network: ecosystem_config.l1_network, link_to_code: ecosystem_config.link_to_code.clone(), diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs index 4f82a92c2edc..81ac457cd884 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs @@ -15,7 +15,9 @@ use config::{ use xshell::Shell; use crate::{ - messages::{MSG_CHAIN_NOT_INITIALIZED, MSG_DEPLOYING_PAYMASTER}, + messages::{ + MSG_CHAIN_NOT_INITIALIZED, MSG_DEPLOYING_PAYMASTER, MSG_L1_SECRETS_MUST_BE_PRESENTED, + }, utils::forge::{check_the_balance, fill_forge_private_key}, }; @@ -47,7 +49,14 @@ pub async fn deploy_paymaster( let mut forge = Forge::new(&foundry_contracts_path) .script(&DEPLOY_PAYMASTER_SCRIPT_PARAMS.script(), forge_args.clone()) .with_ffi() - .with_rpc_url(secrets.l1.l1_rpc_url.clone()) + .with_rpc_url( + secrets + .l1 + .context(MSG_L1_SECRETS_MUST_BE_PRESENTED)? + .l1_rpc_url + .expose_str() + .to_string(), + ) .with_broadcast(); forge = fill_forge_private_key( diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/genesis.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/genesis.rs index b42a1138229d..3cd5440ba83d 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/genesis.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/genesis.rs @@ -9,12 +9,14 @@ use common::{ spinner::Spinner, }; use config::{ + set_databases, set_rocks_db_config, traits::{FileConfigWithDefaultName, SaveConfigWithBasePath}, ChainConfig, ContractsConfig, EcosystemConfig, GeneralConfig, GenesisConfig, SecretsConfig, WalletsConfig, }; use types::ProverMode; use xshell::Shell; +use zksync_config::configs::eth_sender::ProofSendingMode; use super::args::genesis::GenesisArgsFinal; use crate::{ @@ -55,14 +57,21 @@ pub async fn genesis( let rocks_db = recreate_rocksdb_dirs(shell, &config.rocks_db_path, RocksDBDirOption::Main) .context(MSG_RECREATE_ROCKS_DB_ERRROR)?; let mut general = config.get_general_config()?; - general.set_rocks_db_config(rocks_db)?; + set_rocks_db_config(&mut general, rocks_db)?; if config.prover_version != ProverMode::NoProofs { - general.eth.sender.proof_sending_mode = "ONLY_REAL_PROOFS".to_string(); + general + .eth + .as_mut() + .context("eth")? + .sender + .as_mut() + .context("sender")? + .proof_sending_mode = ProofSendingMode::OnlyRealProofs; } general.save_with_base_path(shell, &config.configs)?; let mut secrets = config.get_secrets_config()?; - secrets.set_databases(&args.server_db, &args.prover_db); + set_databases(&mut secrets, &args.server_db, &args.prover_db)?; secrets.save_with_base_path(shell, &config.configs)?; logger::note( diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs index 640f4a492869..bf44b5d5c999 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs @@ -11,8 +11,9 @@ use config::{ register_chain::{input::RegisterChainL1Config, output::RegisterChainOutput}, script_params::REGISTER_CHAIN_SCRIPT_PARAMS, }, + set_l1_rpc_url, traits::{ReadConfig, SaveConfig, SaveConfigWithBasePath}, - ChainConfig, ContractsConfig, EcosystemConfig, + update_from_chain_config, ChainConfig, ContractsConfig, EcosystemConfig, }; use xshell::Shell; @@ -59,7 +60,7 @@ pub async fn init( copy_configs(shell, &ecosystem_config.link_to_code, &chain_config.configs)?; let mut genesis_config = chain_config.get_genesis_config()?; - genesis_config.update_from_chain_config(chain_config); + update_from_chain_config(&mut genesis_config, chain_config); genesis_config.save_with_base_path(shell, &chain_config.configs)?; // Copy ecosystem contracts @@ -74,7 +75,7 @@ pub async fn init( ) .await?; let mut secrets = chain_config.get_secrets_config()?; - secrets.set_l1_rpc_url(init_args.l1_rpc_url.clone()); + set_l1_rpc_url(&mut secrets, init_args.l1_rpc_url.clone())?; secrets.save_with_base_path(shell, &chain_config.configs)?; let spinner = Spinner::new(MSG_REGISTERING_CHAIN_SPINNER); diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/initialize_bridges.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/initialize_bridges.rs index e81971eba7cb..b60daa9dbd61 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/initialize_bridges.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/initialize_bridges.rs @@ -18,7 +18,10 @@ use config::{ use xshell::{cmd, Shell}; use crate::{ - messages::{MSG_CHAIN_NOT_INITIALIZED, MSG_INITIALIZING_BRIDGES_SPINNER}, + messages::{ + MSG_CHAIN_NOT_INITIALIZED, MSG_INITIALIZING_BRIDGES_SPINNER, + MSG_L1_SECRETS_MUST_BE_PRESENTED, + }, utils::forge::{check_the_balance, fill_forge_private_key}, }; @@ -67,7 +70,14 @@ pub async fn initialize_bridges( forge_args.clone(), ) .with_ffi() - .with_rpc_url(secrets.l1.l1_rpc_url.clone()) + .with_rpc_url( + secrets + .l1 + .context(MSG_L1_SECRETS_MUST_BE_PRESENTED)? + .l1_rpc_url + .expose_str() + .to_string(), + ) .with_broadcast(); forge = fill_forge_private_key( diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/create.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/create.rs index d3d5fe129678..746558dd4e97 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/create.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/create.rs @@ -5,8 +5,7 @@ use clap::Parser; use common::{cmd::Cmd, logger, Prompt, PromptConfirm, PromptSelect}; use serde::{Deserialize, Serialize}; use slugify_rs::slugify; -use strum::IntoEnumIterator; -use strum_macros::EnumIter; +use strum::{EnumIter, IntoEnumIterator}; use types::{L1Network, WalletCreation}; use xshell::{cmd, Shell}; @@ -32,7 +31,9 @@ pub struct EcosystemCreateArgs { #[clap(flatten)] #[serde(flatten)] pub chain: ChainCreateArgs, - #[clap(long, help = MSG_START_CONTAINERS_HELP, default_missing_value = "true", num_args = 0..=1)] + #[clap( + long, help = MSG_START_CONTAINERS_HELP, default_missing_value = "true", num_args = 0..=1 + )] pub start_containers: Option, } diff --git a/zk_toolbox/crates/zk_inception/src/commands/external_node/init.rs b/zk_toolbox/crates/zk_inception/src/commands/external_node/init.rs index c6101e88739c..28c3e80aaab0 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/external_node/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/external_node/init.rs @@ -10,8 +10,9 @@ use xshell::Shell; use crate::{ consts::SERVER_MIGRATIONS, messages::{ - MSG_CHAIN_NOT_INITIALIZED, MSG_EXTERNAL_NODE_CONFIG_NOT_INITIALIZED, - MSG_FAILED_TO_DROP_SERVER_DATABASE_ERR, MSG_INITIALIZING_DATABASES_SPINNER, + MSG_CHAIN_NOT_INITIALIZED, MSG_DATABASE_MUST_BE_PRESENTED, + MSG_EXTERNAL_NODE_CONFIG_NOT_INITIALIZED, MSG_FAILED_TO_DROP_SERVER_DATABASE_ERR, + MSG_INITIALIZING_DATABASES_SPINNER, }, utils::rocks_db::{recreate_rocksdb_dirs, RocksDBDirOption}, }; @@ -36,7 +37,14 @@ pub async fn init(shell: &Shell, chain_config: &ChainConfig) -> anyhow::Result<( .clone() .context(MSG_EXTERNAL_NODE_CONFIG_NOT_INITIALIZED)?, )?; - let db_config = DatabaseConfig::from_url(secrets.database.server_url)?; + let db_config = DatabaseConfig::from_url( + secrets + .database + .as_ref() + .context(MSG_DATABASE_MUST_BE_PRESENTED)? + .master_url()? + .expose_url(), + )?; drop_db_if_exists(&db_config) .await .context(MSG_FAILED_TO_DROP_SERVER_DATABASE_ERR)?; diff --git a/zk_toolbox/crates/zk_inception/src/commands/external_node/prepare_configs.rs b/zk_toolbox/crates/zk_inception/src/commands/external_node/prepare_configs.rs index 09e9d1b460c4..b799a68aeb8f 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/external_node/prepare_configs.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/external_node/prepare_configs.rs @@ -1,12 +1,14 @@ -use std::path::Path; +use std::{path::Path, str::FromStr}; use anyhow::Context; use common::{config::global_config, logger}; use config::{ - external_node::ENConfig, traits::SaveConfigWithBasePath, ChainConfig, DatabaseSecrets, - EcosystemConfig, L1Secret, SecretsConfig, + external_node::ENConfig, ports_config, set_rocks_db_config, traits::SaveConfigWithBasePath, + update_ports, ChainConfig, EcosystemConfig, SecretsConfig, }; use xshell::Shell; +use zksync_basic_types::url::SensitiveUrl; +use zksync_config::configs::{DatabaseSecrets, L1Secrets}; use crate::{ commands::external_node::args::prepare_configs::{PrepareConfigArgs, PrepareConfigFinal}, @@ -48,30 +50,39 @@ fn prepare_configs( let en_config = ENConfig { l2_chain_id: genesis.l2_chain_id, l1_chain_id: genesis.l1_chain_id, - l1_batch_commit_data_generator_mode: genesis - .l1_batch_commit_data_generator_mode - .unwrap_or_default(), - main_node_url: general.api.web3_json_rpc.http_url.clone(), + l1_batch_commit_data_generator_mode: genesis.l1_batch_commit_data_generator_mode, + main_node_url: SensitiveUrl::from_str( + &general + .api_config + .as_ref() + .context("api_config")? + .web3_json_rpc + .http_url, + )?, main_node_rate_limit_rps: None, }; let mut general_en = general.clone(); - general_en.update_ports(&general.ports_config().next_empty_ports_config())?; + + update_ports( + &mut general_en, + &ports_config(&general) + .context("da")? + .next_empty_ports_config(), + )?; let secrets = SecretsConfig { - database: DatabaseSecrets { - server_url: args.db.full_url(), + consensus: None, + database: Some(DatabaseSecrets { + server_url: Some(args.db.full_url().into()), prover_url: None, - other: Default::default(), - }, - l1: L1Secret { - l1_rpc_url: args.l1_rpc_url.clone(), - other: Default::default(), - }, - other: Default::default(), + server_replica_url: None, + }), + l1: Some(L1Secrets { + l1_rpc_url: SensitiveUrl::from_str(&args.l1_rpc_url).context("l1_rpc_url")?, + }), }; secrets.save_with_base_path(shell, en_configs_path)?; let dirs = recreate_rocksdb_dirs(shell, &config.rocks_db_path, RocksDBDirOption::ExternalNode)?; - general_en.set_rocks_db_config(dirs)?; - + set_rocks_db_config(&mut general_en, dirs)?; general_en.save_with_base_path(shell, en_configs_path)?; en_config.save_with_base_path(shell, en_configs_path)?; diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs index c398b1852c61..4943c596a1d6 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/args/init.rs @@ -1,8 +1,7 @@ use clap::{Parser, ValueEnum}; use common::{logger, Prompt, PromptConfirm, PromptSelect}; use serde::{Deserialize, Serialize}; -use strum::IntoEnumIterator; -use strum_macros::EnumIter; +use strum::{EnumIter, IntoEnumIterator}; use xshell::Shell; use super::init_bellman_cuda::InitBellmanCudaArgs; @@ -55,7 +54,7 @@ pub struct ProverInitArgs { pub setup_key_config: SetupKeyConfigTmp, } -#[derive(Debug, Clone, ValueEnum, EnumIter, strum_macros::Display, PartialEq, Eq)] +#[derive(Debug, Clone, ValueEnum, EnumIter, strum::Display, PartialEq, Eq)] #[allow(clippy::upper_case_acronyms)] enum ProofStoreConfig { Local, diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/args/run.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/args/run.rs index 678c548cea64..4b485099cc80 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/args/run.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/args/run.rs @@ -13,7 +13,7 @@ pub struct ProverRunArgs { } #[derive( - Debug, Clone, ValueEnum, strum::EnumString, EnumIter, PartialEq, Eq, Copy, strum_macros::Display, + Debug, Clone, ValueEnum, strum::EnumString, EnumIter, PartialEq, Eq, Copy, strum::Display, )] pub enum ProverComponent { #[strum(to_string = "Gateway")] @@ -34,9 +34,7 @@ pub struct WitnessGeneratorArgs { pub round: Option, } -#[derive( - Debug, Clone, ValueEnum, strum::EnumString, EnumIter, PartialEq, Eq, strum_macros::Display, -)] +#[derive(Debug, Clone, ValueEnum, strum::EnumString, EnumIter, PartialEq, Eq, strum::Display)] pub enum WitnessGeneratorRound { #[strum(to_string = "All rounds")] AllRounds, diff --git a/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs b/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs index 31785338bf3e..54b53b8576db 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/prover/init.rs @@ -29,7 +29,7 @@ pub(crate) async fn run(args: ProverInitArgs, shell: &Shell) -> anyhow::Result<( .load_chain(Some(ecosystem_config.default_chain.clone())) .context(MSG_CHAIN_NOT_FOUND_ERR)?; let mut general_config = chain_config - .get_zksync_general_config() + .get_general_config() .context(MSG_GENERAL_CONFIG_NOT_FOUND_ERR)?; let setup_key_path = get_default_setup_key_path(&ecosystem_config)?; @@ -67,7 +67,7 @@ pub(crate) async fn run(args: ProverInitArgs, shell: &Shell) -> anyhow::Result<( proof_compressor_config.universal_setup_path = args.setup_key_config.setup_key_path; general_config.proof_compressor_config = Some(proof_compressor_config); - chain_config.save_zksync_general_config(&general_config)?; + chain_config.save_general_config(&general_config)?; init_bellman_cuda(shell, args.bellman_cuda_config).await?; diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index a33143b4bd66..555aade78cbb 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -129,6 +129,8 @@ pub(super) const MSG_CREATING_CHAIN_CONFIGURATIONS_SPINNER: &str = "Creating chain configurations..."; /// Chain genesis related messages +pub(super) const MSG_L1_SECRETS_MUST_BE_PRESENTED: &str = "L1 secret must be presented"; +pub(super) const MSG_DATABASE_MUST_BE_PRESENTED: &str = "Database secret must be presented"; pub(super) const MSG_SERVER_DB_URL_HELP: &str = "Server database url without database name"; pub(super) const MSG_SERVER_DB_NAME_HELP: &str = "Server database name"; pub(super) const MSG_PROVER_DB_URL_HELP: &str = "Prover database url without database name"; diff --git a/zk_toolbox/crates/zk_supervisor/Cargo.toml b/zk_toolbox/crates/zk_supervisor/Cargo.toml index d8f5d7862a04..54d9a819a7b9 100644 --- a/zk_toolbox/crates/zk_supervisor/Cargo.toml +++ b/zk_toolbox/crates/zk_supervisor/Cargo.toml @@ -17,7 +17,6 @@ common.workspace = true config.workspace = true human-panic.workspace = true strum.workspace = true -strum_macros.workspace = true tokio.workspace = true url.workspace = true xshell.workspace = true diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/new_migration.rs b/zk_toolbox/crates/zk_supervisor/src/commands/database/args/new_migration.rs index ef053ca50c77..64b7a507abea 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/args/new_migration.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/database/args/new_migration.rs @@ -1,7 +1,6 @@ use clap::{Parser, ValueEnum}; use common::{Prompt, PromptSelect}; -use strum::IntoEnumIterator; -use strum_macros::{Display, EnumIter}; +use strum::{Display, EnumIter, IntoEnumIterator}; use crate::messages::{ MSG_DATABASE_NEW_MIGRATION_DATABASE_HELP, MSG_DATABASE_NEW_MIGRATION_DB_PROMPT, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/database/drop.rs b/zk_toolbox/crates/zk_supervisor/src/commands/database/drop.rs index fb6996b40ee3..075f21d3b1a3 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/database/drop.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/database/drop.rs @@ -35,7 +35,7 @@ pub async fn run(shell: &Shell, args: DatabaseCommonArgs) -> anyhow::Result<()> pub async fn drop_database(dal: Dal) -> anyhow::Result<()> { let spinner = Spinner::new(&msg_database_loading(MSG_DATABASE_DROP_GERUND, &dal.path)); - let db = DatabaseConfig::from_url(dal.url)?; + let db = DatabaseConfig::from_url(&dal.url)?; drop_db_if_exists(&db).await?; spinner.finish(); Ok(()) diff --git a/zk_toolbox/crates/zk_supervisor/src/dals.rs b/zk_toolbox/crates/zk_supervisor/src/dals.rs index 854a6b979494..2d2af41500b4 100644 --- a/zk_toolbox/crates/zk_supervisor/src/dals.rs +++ b/zk_toolbox/crates/zk_supervisor/src/dals.rs @@ -4,7 +4,7 @@ use config::{EcosystemConfig, SecretsConfig}; use url::Url; use xshell::Shell; -use crate::messages::{MSG_CHAIN_NOT_FOUND_ERR, MSG_PROVER_URL_MUST_BE_PRESENTED}; +use crate::messages::{MSG_CHAIN_NOT_FOUND_ERR, MSG_DATABASE_MUST_BE_PRESENTED}; const CORE_DAL_PATH: &str = "core/lib/dal"; const PROVER_DAL_PATH: &str = "prover/crates/lib/prover_dal"; @@ -48,8 +48,10 @@ pub fn get_prover_dal(shell: &Shell) -> anyhow::Result { path: PROVER_DAL_PATH.to_string(), url: secrets .database - .prover_url - .context(MSG_PROVER_URL_MUST_BE_PRESENTED)? + .as_ref() + .context(MSG_DATABASE_MUST_BE_PRESENTED)? + .prover_url()? + .expose_url() .clone(), }) } @@ -59,7 +61,13 @@ pub fn get_core_dal(shell: &Shell) -> anyhow::Result { Ok(Dal { path: CORE_DAL_PATH.to_string(), - url: secrets.database.server_url.clone(), + url: secrets + .database + .as_ref() + .context(MSG_DATABASE_MUST_BE_PRESENTED)? + .master_url()? + .expose_url() + .clone(), }) } diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index 863f1c4b1aef..ecbe604a7ba3 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -37,9 +37,7 @@ pub(super) const MSG_DATABASE_RESET_GERUND: &str = "Resetting"; pub(super) const MSG_DATABASE_RESET_PAST: &str = "reset"; pub(super) const MSG_DATABASE_SETUP_GERUND: &str = "Setting up"; pub(super) const MSG_DATABASE_SETUP_PAST: &str = "set up"; - -pub(super) const MSG_PROVER_URL_MUST_BE_PRESENTED: &str = "Prover url must be presented"; - +pub(super) const MSG_DATABASE_MUST_BE_PRESENTED: &str = "Database config must be presented"; pub(super) const MSG_DATABASE_COMMON_PROVER_HELP: &str = "Prover database"; pub(super) const MSG_DATABASE_COMMON_CORE_HELP: &str = "Core database"; pub(super) const MSG_DATABASE_NEW_MIGRATION_DATABASE_HELP: &str = @@ -96,6 +94,7 @@ pub(super) const MSG_REVERT_TEST_ENABLE_CONSENSUS_HELP: &str = "Enable consensus pub(super) const MSG_REVERT_TEST_INSTALLING_DEPENDENCIES: &str = "Building and installing dependencies. This process may take a lot of time..."; pub(super) const MSG_REVERT_TEST_RUN_INFO: &str = "Running revert and restart test"; + pub(super) fn msg_revert_tests_run(external_node: bool) -> String { let base = "Running integration tests"; if external_node {