Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(zk_toolbox): Some small nit #2023

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions zk_toolbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ toml = "0.8.12"
url = { version = "2.5.0", features = ["serde"] }
xshell = "0.2.6"
futures = "0.3.30"
thiserror = "1.0.57"
6 changes: 6 additions & 0 deletions zk_toolbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ If contracts were deployed by a third party (e.g., MatterLabs), you may need to
`zk_inception chain genesis`

This ensures proper initialization of the server.

### Zk Server

For running the chain: `zk_inception server`

You can specify the chain you are running by providing `--chain <chain_name>` argument
2 changes: 2 additions & 0 deletions zk_toolbox/crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ pub mod files;
pub mod forge;
mod prerequisites;
mod prompt;
mod slugify;
mod term;
pub mod wallets;

pub use prerequisites::check_prerequisites;
pub use prompt::{init_prompt_theme, Prompt, PromptConfirm, PromptSelect};
pub use slugify::slugify;
pub use term::{logger, spinner};
3 changes: 3 additions & 0 deletions zk_toolbox/crates/common/src/slugify.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn slugify(data: &str) -> String {
data.trim().replace(" ", "-")
}
4 changes: 2 additions & 2 deletions zk_toolbox/crates/zk_inception/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ tokio.workspace = true
strum_macros.workspace = true
strum.workspace = true
toml.workspace = true
url = "2.5.0"
thiserror = "1.0.57"
url.workspace = true
thiserror.workspace = true
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{path::PathBuf, str::FromStr};

use clap::Parser;
use common::{Prompt, PromptConfirm, PromptSelect};
use common::{slugify, Prompt, PromptConfirm, PromptSelect};
use ethers::types::H160;
use serde::{Deserialize, Serialize};
use strum::IntoEnumIterator;
Expand Down Expand Up @@ -39,9 +39,10 @@ pub struct ChainCreateArgs {

impl ChainCreateArgs {
pub fn fill_values_with_prompt(self, number_of_chains: u32) -> ChainCreateArgsFinal {
let chain_name = self
let mut chain_name = self
.chain_name
.unwrap_or_else(|| Prompt::new("How do you want to name the chain?").ask());
chain_name = slugify(&chain_name);

let chain_id = self.chain_id.unwrap_or_else(|| {
Prompt::new("What's the chain id?")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Parser;
use common::Prompt;
use common::{slugify, Prompt};
use serde::{Deserialize, Serialize};
use url::Url;

Expand Down Expand Up @@ -47,27 +47,27 @@ impl GenesisArgs {
.default(DATABASE_SERVER_URL)
.ask()
});
let server_db_name = self.server_db_name.unwrap_or_else(|| {
let server_db_name = slugify(&self.server_db_name.unwrap_or_else(|| {
Prompt::new(&format!(
"Please provide server database name for chain {chain_name}"
))
.default(&server_name)
.ask()
});
}));
let prover_db_url = self.prover_db_url.unwrap_or_else(|| {
Prompt::new(&format!(
"Please provide prover database url for chain {chain_name}"
))
.default(DATABASE_PROVER_URL)
.ask()
});
let prover_db_name = self.prover_db_name.unwrap_or_else(|| {
let prover_db_name = slugify(&self.prover_db_name.unwrap_or_else(|| {
Prompt::new(&format!(
"Please provide prover database name for chain {chain_name}"
))
.default(&prover_name)
.ask()
});
}));
GenesisArgsFinal {
server_db_url,
server_db_name,
Expand Down
4 changes: 3 additions & 1 deletion zk_toolbox/crates/zk_inception/src/commands/chain/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ pub async fn genesis(
.await?;
spinner.finish();

let spinner = Spinner::new("Running server genesis...");
let spinner = Spinner::new(
"Starting the genesis of the server. Building the entire server may take a lot of time...",
);
run_server_genesis(config, shell)?;
spinner.finish();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::PathBuf;

use clap::Parser;
use common::{Prompt, PromptConfirm, PromptSelect};
use common::{slugify, Prompt, PromptConfirm, PromptSelect};
use serde::{Deserialize, Serialize};
use strum::IntoEnumIterator;
use strum_macros::{Display, EnumIter};
Expand Down Expand Up @@ -33,9 +33,10 @@ pub struct EcosystemCreateArgs {

impl EcosystemCreateArgs {
pub fn fill_values_with_prompt(mut self) -> EcosystemCreateArgsFinal {
let ecosystem_name = self
let mut ecosystem_name = self
.ecosystem_name
.unwrap_or_else(|| Prompt::new("How do you want to name the ecosystem?").ask());
ecosystem_name = slugify(&ecosystem_name);

let link_to_code = self.link_to_code.unwrap_or_else(|| {
let link_to_code_selection = PromptSelect::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl EcosystemInitArgs {
.ask()
});
let deploy_erc20 = self.deploy_erc20.unwrap_or_else(|| {
PromptConfirm::new("Do you want to deploy ERC20?")
PromptConfirm::new("Do you want to deploy test ERC20?")
.default(true)
.ask()
});
Expand Down
16 changes: 15 additions & 1 deletion zk_toolbox/crates/zk_inception/src/commands/ecosystem/create.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::path::Path;
use std::{path::PathBuf, str::FromStr};

use anyhow::bail;
Expand Down Expand Up @@ -48,7 +49,9 @@ fn create(args: EcosystemCreateArgs, shell: &Shell) -> anyhow::Result<()> {
spinner.finish();
link_to_code
} else {
PathBuf::from_str(&args.link_to_code)?
let path = PathBuf::from_str(&args.link_to_code)?;
update_submodules_recursive(shell, &path)?;
path
};

let spinner = Spinner::new("Creating initial configurations...");
Expand Down Expand Up @@ -108,3 +111,14 @@ fn clone_era_repo(shell: &Shell) -> anyhow::Result<PathBuf> {
.run()?;
Ok(shell.current_dir().join("zksync-era"))
}

fn update_submodules_recursive(shell: &Shell, link_to_code: &Path) -> anyhow::Result<()> {
let _dir_guard = shell.push_dir(link_to_code);
Cmd::new(cmd!(
shell,
"git submodule update --init --recursive
"
))
.run()?;
Ok(())
}
Deniallugo marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ fn init(
let spinner = Spinner::new("Installing and building dependencies...");
install_yarn_dependencies(shell, &ecosystem_config.link_to_code)?;
build_system_contracts(shell, &ecosystem_config.link_to_code)?;
build_l1_contracts(shell, &ecosystem_config.link_to_code)?;
spinner.finish();

let contracts = deploy_ecosystem(
Expand Down Expand Up @@ -322,3 +323,9 @@ fn build_system_contracts(shell: &Shell, link_to_code: &Path) -> anyhow::Result<
let _dir_guard = shell.push_dir(link_to_code.join("contracts"));
Cmd::new(cmd!(shell, "yarn sc build")).run()
}

// TODO remove it and use proper paths in constants
fn build_l1_contracts(shell: &Shell, link_to_code: &Path) -> anyhow::Result<()> {
let _dir_guard = shell.push_dir(link_to_code.join("contracts"));
Cmd::new(cmd!(shell, "yarn l1 build")).run()
}
Loading