Skip to content

Commit

Permalink
feat(zk_toolbox): use configs from the main repo (#2470)
Browse files Browse the repository at this point in the history
## What ❔

Use general, genesis, and secrets configs from the main repository and
not the copypastes.
## Why ❔

It allows us easily maintain the upcoming changes 

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `zk fmt` and `zk lint`.

---------

Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo authored Jul 26, 2024
1 parent 97cc2e2 commit 4222d13
Show file tree
Hide file tree
Showing 63 changed files with 531 additions and 624 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion core/lib/basic_types/src/commitment.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use serde::{Deserialize, Serialize};
use strum::{Display, EnumIter};

use crate::{
ethabi,
web3::contract::{Detokenize, Error as ContractError},
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,
Expand Down
2 changes: 1 addition & 1 deletion core/lib/config/src/configs/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
SnapshotsCreatorConfig,
};

#[derive(Debug, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
pub struct GeneralConfig {
pub postgres_config: Option<PostgresConfig>,
pub api_config: Option<ApiConfig>,
Expand Down
8 changes: 5 additions & 3 deletions core/lib/config/src/configs/secrets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SensitiveUrl> {
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.
Expand Down
15 changes: 14 additions & 1 deletion core/lib/protobuf_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<H256> {
Expand Down Expand Up @@ -71,3 +74,13 @@ pub fn encode_yaml_repr<T: ProtoRepr>(value: &T::Type) -> anyhow::Result<Vec<u8>
serialize_proto(&T::build(value), &mut s)?;
Ok(buffer)
}

fn serialize_proto<T: ReflectMessage, S: serde::Serializer>(
x: &T,
s: S,
) -> Result<S::Ok, S::Error> {
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)
}
5 changes: 1 addition & 4 deletions core/lib/protobuf_config/src/secrets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@ impl ProtoRepr for proto::DatabaseSecrets {
.map(str::parse::<SensitiveUrl>)
.transpose()
.context("master_url")?;
let mut server_replica_url = self
let server_replica_url = self
.server_replica_url
.as_deref()
.map(str::parse::<SensitiveUrl>)
.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()
Expand Down
12 changes: 6 additions & 6 deletions prover/Cargo.lock

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

2 changes: 1 addition & 1 deletion prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
48 changes: 13 additions & 35 deletions zk_toolbox/Cargo.lock

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

9 changes: 6 additions & 3 deletions zk_toolbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions zk_toolbox/crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 15 additions & 3 deletions zk_toolbox/crates/common/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -72,6 +74,7 @@ impl<'a> Cmd<'a> {
Self {
inner: cmd,
force_run: false,
piped_std_err: false,
}
}

Expand All @@ -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<K: AsRef<OsStr>, V: AsRef<OsStr>>(mut self, key: K, value: V) -> Self {
self.inner = self.inner.env(key, value);
Expand All @@ -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)
Expand Down Expand Up @@ -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<Output> {
fn run_low_level_process_command(mut command: Command, piped_std_err: bool) -> io::Result<Output> {
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()
}
Expand Down
2 changes: 1 addition & 1 deletion zk_toolbox/crates/common/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl DatabaseConfig {
}

/// Create a new `Db` instance from a URL.
pub fn from_url(url: Url) -> anyhow::Result<Self> {
pub fn from_url(url: &Url) -> anyhow::Result<Self> {
let name = url
.path_segments()
.ok_or(anyhow!("Failed to parse database name from URL"))?
Expand Down
Loading

0 comments on commit 4222d13

Please sign in to comment.