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

feat(zk_toolbox): Small adjustment for zk toolbox #2424

Merged
merged 7 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
5 changes: 5 additions & 0 deletions .github/workflows/ci-zk-toolbox-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,18 @@ jobs:
echo $(pwd)/bin >> $GITHUB_PATH
echo IN_DOCKER=1 >> .env


- name: Start services
run: |
ci_localnet_up
ci_run sccache --start-server

- name: Initialize ecosystem
run: |
ci_run git config --global --add safe.directory /usr/src/zksync
ci_run git config --global --add safe.directory /usr/src/zksync/contracts/system-contracts
ci_run git config --global --add safe.directory /usr/src/zksync/contracts

ci_run zk_inception ecosystem init --deploy-paymaster --deploy-erc20 \
--deploy-ecosystem --l1-rpc-url=http://reth:8545 \
--server-db-url=postgres://postgres:notsecurepassword@postgres:5432 \
Expand Down
4 changes: 2 additions & 2 deletions core/lib/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const STATE_TRANSITION_CONTRACT_FILE: (&str, &str) = (
"IStateTransitionManager.sol/IStateTransitionManager.json",
);
const ZKSYNC_HYPERCHAIN_CONTRACT_FILE: (&str, &str) = (
"state-transition/",
"chain-interfaces/IZkSyncHyperchain.sol/IZkSyncHyperchain.json",
"state-transition/chain-interfaces",
"IZkSyncHyperchain.sol/IZkSyncHyperchain.json",
);
const DIAMOND_INIT_CONTRACT_FILE: (&str, &str) = (
"state-transition",
Expand Down
8 changes: 7 additions & 1 deletion zk_toolbox/crates/common/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ impl<'a> Cmd<'a> {
let output = if global_config().verbose || self.force_run {
logger::debug(format!("Running: {}", self.inner));
logger::new_empty_line();
run_low_level_process_command(self.inner.into())?
let output = run_low_level_process_command(self.inner.into())?;
if let Ok(data) = String::from_utf8(output.stderr.clone()) {
if !data.is_empty() {
logger::info(data)
}
}
output
} else {
// Command will be logged manually.
self.inner.set_quiet(true);
Expand Down
31 changes: 31 additions & 0 deletions zk_toolbox/crates/common/src/git.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::path::PathBuf;

use xshell::{cmd, Shell};

use crate::cmd::Cmd;

pub fn clone(
shell: &Shell,
path: PathBuf,
repository: &str,
name: &str,
) -> anyhow::Result<PathBuf> {
let _dir = shell.push_dir(path);
Cmd::new(cmd!(
shell,
"git clone --recurse-submodules {repository} {name}"
))
.run()?;
Ok(shell.current_dir().join(name))
}

pub fn submodule_update(shell: &Shell, link_to_code: PathBuf) -> anyhow::Result<()> {
let _dir_guard = shell.push_dir(link_to_code);
Cmd::new(cmd!(
shell,
"git submodule update --init --recursive
"
))
.run()?;
Ok(())
}
1 change: 1 addition & 0 deletions zk_toolbox/crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod docker;
pub mod ethereum;
pub mod files;
pub mod forge;
pub mod git;
pub mod server;
pub mod wallets;

Expand Down
9 changes: 6 additions & 3 deletions zk_toolbox/crates/config/src/ecosystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ impl EcosystemConfig {
pub fn from_file(shell: &Shell) -> Result<Self, EcosystemConfigFromFileError> {
let path = PathBuf::from(CONFIG_NAME);
if !shell.path_exists(path) {
return Err(EcosystemConfigFromFileError::NotExists);
return Err(EcosystemConfigFromFileError::NotExists {
path: shell.current_dir(),
});
}

let mut config = EcosystemConfig::read(shell, CONFIG_NAME)
Expand Down Expand Up @@ -229,8 +231,9 @@ impl EcosystemConfig {
/// Result of checking if the ecosystem exists.
#[derive(Error, Debug)]
pub enum EcosystemConfigFromFileError {
#[error("Ecosystem configuration not found")]
NotExists,
#[error("Ecosystem configuration not found (Could not find 'ZkStack.toml' in {path:?}: Make sure you have created an ecosystem & are in the new folder `cd path/to/ecosystem/name`)"
)]
NotExists { path: PathBuf },
#[error("Invalid ecosystem configuration")]
InvalidConfig { source: anyhow::Error },
}
Expand Down
21 changes: 6 additions & 15 deletions zk_toolbox/crates/zk_inception/src/commands/chain/init.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use anyhow::Context;
use common::{
cmd::Cmd,
config::global_config,
forge::{Forge, ForgeScriptArgs},
logger,
git, logger,
spinner::Spinner,
};
use config::{
Expand All @@ -15,7 +14,7 @@ use config::{
traits::{ReadConfig, SaveConfig, SaveConfigWithBasePath},
ChainConfig, ContractsConfig, EcosystemConfig,
};
use xshell::{cmd, Shell};
use xshell::Shell;

use crate::{
accept_ownership::accept_admin,
Expand All @@ -26,9 +25,9 @@ use crate::{
initialize_bridges,
},
messages::{
msg_initializing_chain, MSG_ACCEPTING_ADMIN_SPINNER, MSG_BUILDING_L1_CONTRACTS,
MSG_CHAIN_INITIALIZED, MSG_CHAIN_NOT_FOUND_ERR, MSG_GENESIS_DATABASE_ERR,
MSG_REGISTERING_CHAIN_SPINNER, MSG_SELECTED_CONFIG,
msg_initializing_chain, MSG_ACCEPTING_ADMIN_SPINNER, MSG_CHAIN_INITIALIZED,
MSG_CHAIN_NOT_FOUND_ERR, MSG_GENESIS_DATABASE_ERR, MSG_REGISTERING_CHAIN_SPINNER,
MSG_SELECTED_CONFIG,
},
utils::forge::{check_the_balance, fill_forge_private_key},
};
Expand All @@ -43,6 +42,7 @@ pub(crate) async fn run(args: InitArgs, shell: &Shell) -> anyhow::Result<()> {

logger::note(MSG_SELECTED_CONFIG, logger::object_to_string(&chain_config));
logger::info(msg_initializing_chain(""));
git::submodule_update(shell, config.link_to_code.clone())?;

init(&mut args, shell, &config, &chain_config).await?;

Expand All @@ -57,7 +57,6 @@ pub async fn init(
chain_config: &ChainConfig,
) -> anyhow::Result<()> {
copy_configs(shell, &ecosystem_config.link_to_code, &chain_config.configs)?;
build_l1_contracts(shell, ecosystem_config)?;

let mut genesis_config = chain_config.get_genesis_config()?;
genesis_config.update_from_chain_config(chain_config);
Expand Down Expand Up @@ -161,11 +160,3 @@ async fn register_chain(
contracts.set_chain_contracts(&register_chain_output);
Ok(())
}

fn build_l1_contracts(shell: &Shell, ecosystem_config: &EcosystemConfig) -> anyhow::Result<()> {
let _dir_guard = shell.push_dir(ecosystem_config.path_to_foundry());
let spinner = Spinner::new(MSG_BUILDING_L1_CONTRACTS);
Cmd::new(cmd!(shell, "yarn build")).run()?;
spinner.finish();
Ok(())
}
2 changes: 2 additions & 0 deletions zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ pub enum ChainCommands {
/// Run server genesis
Genesis(GenesisArgs),
/// Initialize bridges on l2
#[command(alias = "bridge")]
InitializeBridges(ForgeScriptArgs),
/// Initialize bridges on l2
#[command(alias = "paymaster")]
DeployPaymaster(ForgeScriptArgs),
}

Expand Down
3 changes: 3 additions & 0 deletions zk_toolbox/crates/zk_inception/src/commands/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,8 @@ fn copy_dockerfile(shell: &Shell, link_to_code: PathBuf) -> anyhow::Result<()> {

let data = docker_compose_text.replace(original_source, new_source);
shell.write_file(DOCKER_COMPOSE_FILE, data)?;
// For some reasons our docker-compose sometimes required .env file while we are investigating this behaviour
// it's better to create file and don't make the life of customers harder
shell.write_file(".env", "")?;
Ok(())
}
44 changes: 13 additions & 31 deletions zk_toolbox/crates/zk_inception/src/commands/ecosystem/create.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use std::{
path::{Path, PathBuf},
str::FromStr,
};
use std::{path::PathBuf, str::FromStr};

use anyhow::bail;
use common::{cmd::Cmd, logger, spinner::Spinner};
use common::{git, logger, spinner::Spinner};
use config::{
create_local_configs_dir, create_wallets, get_default_era_chain_id,
traits::SaveConfigWithBasePath, EcosystemConfig, EcosystemConfigFromFileError,
ZKSYNC_ERA_GIT_REPO,
};
use xshell::{cmd, Shell};
use xshell::Shell;

use crate::{
commands::{
Expand All @@ -22,7 +19,7 @@ use crate::{
},
},
messages::{
MSG_CLONING_ERA_REPO_SPINNER, MSG_CREATED_ECOSYSTEM, MSG_CREATING_DEFAULT_CHAIN_SPINNER,
msg_created_ecosystem, MSG_CLONING_ERA_REPO_SPINNER, MSG_CREATING_DEFAULT_CHAIN_SPINNER,
MSG_CREATING_ECOSYSTEM, MSG_CREATING_INITIAL_CONFIGURATIONS_SPINNER,
MSG_ECOSYSTEM_ALREADY_EXISTS_ERR, MSG_ECOSYSTEM_CONFIG_INVALID_ERR, MSG_SELECTED_CONFIG,
MSG_STARTING_CONTAINERS_SPINNER,
Expand All @@ -35,7 +32,7 @@ pub fn run(args: EcosystemCreateArgs, shell: &Shell) -> anyhow::Result<()> {
Err(EcosystemConfigFromFileError::InvalidConfig { .. }) => {
bail!(MSG_ECOSYSTEM_CONFIG_INVALID_ERR)
}
Err(EcosystemConfigFromFileError::NotExists) => create(args, shell)?,
Err(EcosystemConfigFromFileError::NotExists { .. }) => create(args, shell)?,
};

Ok(())
Expand All @@ -55,12 +52,17 @@ fn create(args: EcosystemCreateArgs, shell: &Shell) -> anyhow::Result<()> {

let link_to_code = if args.link_to_code.is_empty() {
let spinner = Spinner::new(MSG_CLONING_ERA_REPO_SPINNER);
let link_to_code = clone_era_repo(shell)?;
let link_to_code = git::clone(
shell,
shell.current_dir(),
ZKSYNC_ERA_GIT_REPO,
"zksync-era",
)?;
spinner.finish();
link_to_code
} else {
let path = PathBuf::from_str(&args.link_to_code)?;
update_submodules_recursive(shell, &path)?;
git::submodule_update(shell, path.clone())?;
path
};

Expand Down Expand Up @@ -109,26 +111,6 @@ fn create(args: EcosystemCreateArgs, shell: &Shell) -> anyhow::Result<()> {
spinner.finish();
}

logger::outro(MSG_CREATED_ECOSYSTEM);
Ok(())
}

fn clone_era_repo(shell: &Shell) -> anyhow::Result<PathBuf> {
Cmd::new(cmd!(
shell,
"git clone --recurse-submodules {ZKSYNC_ERA_GIT_REPO}"
))
.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()?;
logger::outro(msg_created_ecosystem(&ecosystem_name));
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use common::{
cmd::Cmd,
config::global_config,
forge::{Forge, ForgeScriptArgs},
logger,
git, logger,
spinner::Spinner,
Prompt,
};
Expand Down Expand Up @@ -54,6 +54,8 @@ use crate::{
pub async fn run(args: EcosystemInitArgs, shell: &Shell) -> anyhow::Result<()> {
let ecosystem_config = EcosystemConfig::from_file(shell)?;

git::submodule_update(shell, ecosystem_config.link_to_code.clone())?;

let initial_deployment_config = match ecosystem_config.get_initial_deployment_config() {
Ok(config) => config,
Err(_) => create_initial_deployments_config(shell, &ecosystem_config.config)?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub enum EcosystemCommands {
/// deploying necessary contracts and performing on-chain operations
Init(EcosystemInitArgs),
/// Change the default chain
#[command(alias = "cd")]
ChangeDefaultChain(ChangeDefaultChain),
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Context;
use common::{check_prover_prequisites, cmd::Cmd, logger, spinner::Spinner};
use common::{check_prover_prequisites, cmd::Cmd, git, logger, spinner::Spinner};
use config::{traits::SaveConfigWithBasePath, EcosystemConfig};
use xshell::{cmd, Shell};

Expand Down Expand Up @@ -38,19 +38,15 @@ pub(crate) async fn run(shell: &Shell, args: InitBellmanCudaArgs) -> anyhow::Res

fn clone_bellman_cuda(shell: &Shell) -> anyhow::Result<String> {
let spinner = Spinner::new(MSG_CLONING_BELLMAN_CUDA_SPINNER);
Cmd::new(cmd!(
let path = git::clone(
shell,
"git clone https://github.com/matter-labs/era-bellman-cuda"
))
.run()?;
shell.current_dir(),
"https://github.com/matter-labs/era-bellman-cuda",
BELLMAN_CUDA_DIR,
)?;
spinner.finish();

Ok(shell
.current_dir()
.join(BELLMAN_CUDA_DIR)
.to_str()
.context(MSG_BELLMAN_CUDA_DIR_ERR)?
.to_string())
Ok(path.to_str().context(MSG_BELLMAN_CUDA_DIR_ERR)?.to_string())
}

fn build_bellman_cuda(shell: &Shell, bellman_cuda_dir: &str) -> anyhow::Result<()> {
Expand Down
2 changes: 2 additions & 0 deletions zk_toolbox/crates/zk_inception/src/commands/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ pub enum ProverCommands {
/// Initialize prover
Init(Box<ProverInitArgs>),
/// Generate setup keys
#[command(alias = "sk")]
GenerateSK,
/// Run prover
Run(ProverRunArgs),
/// Initialize bellman-cuda
#[command(alias = "cuda")]
InitBellmanCuda(Box<InitBellmanCudaArgs>),
}

Expand Down
9 changes: 5 additions & 4 deletions zk_toolbox/crates/zk_inception/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,21 @@ struct Inception {
#[derive(Subcommand, Debug)]
pub enum InceptionSubcommands {
/// Ecosystem related commands
#[command(subcommand)]
#[command(subcommand, alias = "e")]
Ecosystem(EcosystemCommands),
/// Chain related commands
#[command(subcommand)]
#[command(subcommand, alias = "c")]
Chain(ChainCommands),
/// Prover related commands
#[command(subcommand)]
#[command(subcommand, alias = "p")]
Prover(ProverCommands),
/// Run server
Server(RunServerArgs),
// Run External Node
#[command(subcommand)]
#[command(subcommand, alias = "en")]
ExternalNode(ExternalNodeCommands),
/// Run containers for local development
#[command(subcommand, alias = "up")]
Containers,
}

Expand Down
7 changes: 5 additions & 2 deletions zk_toolbox/crates/zk_inception/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ pub(super) const MSG_L1_NETWORK_PROMPT: &str = "Select the L1 network";
pub(super) const MSG_START_CONTAINERS_PROMPT: &str =
"Do you want to start containers after creating the ecosystem?";
pub(super) const MSG_CREATING_ECOSYSTEM: &str = "Creating ecosystem";
pub(super) const MSG_CREATED_ECOSYSTEM: &str = "Ecosystem created successfully";

pub fn msg_created_ecosystem(name: &str) -> String {
format!("Ecosystem {name} created successfully (All subsequent commands should be executed from ecosystem folder `cd path/to/ecosystem/name`)")
Deniallugo marked this conversation as resolved.
Show resolved Hide resolved
}

pub(super) const MSG_CLONING_ERA_REPO_SPINNER: &str = "Cloning zksync-era repository...";
pub(super) const MSG_CREATING_INITIAL_CONFIGURATIONS_SPINNER: &str =
"Creating initial configurations...";
Expand Down Expand Up @@ -185,7 +189,6 @@ pub(super) const MSG_FAILED_TO_FIND_ECOSYSTEM_ERR: &str = "Failed to find ecosys
/// Server related messages
pub(super) const MSG_STARTING_SERVER: &str = "Starting server";
pub(super) const MSG_FAILED_TO_RUN_SERVER_ERR: &str = "Failed to start server";
pub(super) const MSG_BUILDING_L1_CONTRACTS: &str = "Building L1 contracts...";
pub(super) const MSG_PREPARING_EN_CONFIGS: &str = "Preparing External Node config";

/// Forge utils related messages
Expand Down
Loading
Loading