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(zkstack): Run update without ecosystem #3346

Open
wants to merge 3 commits into
base: matias/refactor-chain-commands
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion zkstack_cli/crates/config/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub const ZKSYNC_ERA_GIT_REPO: &str = "https://github.com/matter-labs/zksync-era
/// Name of the docker-compose file inside zksync repository
pub const DOCKER_COMPOSE_FILE: &str = "docker-compose.yml";
/// Path to the config file with mnemonic for localhost wallets
pub(crate) const CONFIGS_PATH: &str = "etc/env/file_based";
pub const CONFIGS_PATH: &str = "etc/env/file_based";
/// Path to the docker-compose file for grafana
pub const ERA_OBSERVABILITY_COMPOSE_FILE: &str = "era-observability/docker-compose.yml";
/// Path to era observability repository
Expand Down
66 changes: 36 additions & 30 deletions zkstack_cli/crates/zkstack/src/commands/update.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::path::Path;
use std::path::{Path, PathBuf};

use anyhow::{Context, Ok};
use anyhow::Ok;
use common::{
db::migrate_db,
git, logger,
spinner::Spinner,
yaml::{merge_yaml, ConfigDiff},
};
use config::{
zkstack_config::ZkStackConfig, ChainConfig, EcosystemConfig, CONTRACTS_FILE, EN_CONFIG_FILE,
zkstack_config::ZkStackConfig, ChainConfig, CONFIGS_PATH, CONTRACTS_FILE, EN_CONFIG_FILE,
ERA_OBSERBAVILITY_DIR, GENERAL_FILE, GENESIS_FILE, SECRETS_FILE,
};
use xshell::Shell;
Expand All @@ -18,32 +18,47 @@ use crate::{
consts::{PROVER_MIGRATIONS, SERVER_MIGRATIONS},
messages::{
msg_diff_contracts_config, msg_diff_genesis_config, msg_diff_secrets, msg_updating_chain,
MSG_CHAIN_NOT_FOUND_ERR, MSG_DIFF_EN_CONFIG, MSG_DIFF_EN_GENERAL_CONFIG,
MSG_DIFF_GENERAL_CONFIG, MSG_PULLING_ZKSYNC_CODE_SPINNER,
MSG_UPDATING_ERA_OBSERVABILITY_SPINNER, MSG_UPDATING_SUBMODULES_SPINNER,
MSG_UPDATING_ZKSYNC, MSG_ZKSYNC_UPDATED,
MSG_DIFF_EN_CONFIG, MSG_DIFF_EN_GENERAL_CONFIG, MSG_DIFF_GENERAL_CONFIG,
MSG_PULLING_ZKSYNC_CODE_SPINNER, MSG_UPDATING_ERA_OBSERVABILITY_SPINNER,
MSG_UPDATING_SUBMODULES_SPINNER, MSG_UPDATING_ZKSYNC, MSG_ZKSYNC_UPDATED,
},
};

pub async fn run(shell: &Shell, args: UpdateArgs) -> anyhow::Result<()> {
logger::info(MSG_UPDATING_ZKSYNC);
let ecosystem = ZkStackConfig::ecosystem(shell)?;
let config = ZkStackConfig::from_file(shell)?;
let link_to_code = config.link_to_code();
let default_configs_path = link_to_code.join(CONFIGS_PATH);

if !args.only_config {
update_repo(shell, &ecosystem)?;
update_repo(shell, link_to_code)?;
let path_to_era_observability = shell.current_dir().join(ERA_OBSERBAVILITY_DIR);
if shell.path_exists(path_to_era_observability.clone()) {
let spinner = Spinner::new(MSG_UPDATING_ERA_OBSERVABILITY_SPINNER);
git::pull(shell, path_to_era_observability)?;
spinner.finish();
}
}

let general_config_path = ecosystem.get_default_configs_path().join(GENERAL_FILE);
let external_node_config_path = ecosystem.get_default_configs_path().join(EN_CONFIG_FILE);
let genesis_config_path = ecosystem.get_default_configs_path().join(GENESIS_FILE);
let contracts_config_path = ecosystem.get_default_configs_path().join(CONTRACTS_FILE);
let secrets_path = ecosystem.get_default_configs_path().join(SECRETS_FILE);

for chain in ecosystem.list_of_chains() {
logger::step(msg_updating_chain(&chain));
let chain = ecosystem
.load_chain(Some(chain))
.context(MSG_CHAIN_NOT_FOUND_ERR)?;
let general_config_path = default_configs_path.join(GENERAL_FILE);
let external_node_config_path = default_configs_path.join(EN_CONFIG_FILE);
let genesis_config_path = default_configs_path.join(GENESIS_FILE);
let contracts_config_path = default_configs_path.join(CONTRACTS_FILE);
let secrets_path = default_configs_path.join(SECRETS_FILE);

let chains = match config {
ZkStackConfig::EcosystemConfig(ecosystem) => {
let mut chains = vec![];
for chain_name in ecosystem.list_of_chains() {
chains.push(ecosystem.load_chain(Some(chain_name))?);
}
chains
}
ZkStackConfig::ChainConfig(chain) => vec![chain],
};

for chain in chains {
logger::step(msg_updating_chain(&chain.name));
update_chain(
shell,
&chain,
Expand All @@ -56,21 +71,12 @@ pub async fn run(shell: &Shell, args: UpdateArgs) -> anyhow::Result<()> {
.await?;
}

let path_to_era_observability = shell.current_dir().join(ERA_OBSERBAVILITY_DIR);
if shell.path_exists(path_to_era_observability.clone()) {
let spinner = Spinner::new(MSG_UPDATING_ERA_OBSERVABILITY_SPINNER);
git::pull(shell, path_to_era_observability)?;
spinner.finish();
}

logger::outro(MSG_ZKSYNC_UPDATED);

Ok(())
}

fn update_repo(shell: &Shell, ecosystem: &EcosystemConfig) -> anyhow::Result<()> {
let link_to_code = ecosystem.link_to_code.clone();

fn update_repo(shell: &Shell, link_to_code: PathBuf) -> anyhow::Result<()> {
let spinner = Spinner::new(MSG_PULLING_ZKSYNC_CODE_SPINNER);
git::pull(shell, link_to_code.clone())?;
spinner.finish();
Expand Down