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): Add update command #2440

Merged
merged 40 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e5011d1
Add update command
matias-gonz Jul 16, 2024
da3be62
Add merge_yaml
matias-gonz Jul 18, 2024
6e729e9
Add save_updated_config
matias-gonz Jul 18, 2024
53fe0d5
Fix diff
matias-gonz Jul 18, 2024
ee9c4eb
Merge branch 'main' into matias-zk-toolbox-update
matias-gonz Jul 19, 2024
bd18341
Merge branch 'main' into matias-zk-toolbox-update
matias-gonz Jul 23, 2024
29213c2
Merge branch 'main' into matias-zk-toolbox-update
matias-gonz Jul 24, 2024
67a86f6
Update all chains
matias-gonz Jul 24, 2024
eb7da9f
Merge branch 'main' into matias-zk-toolbox-update
matias-gonz Jul 24, 2024
e13a204
Update name
matias-gonz Jul 24, 2024
fe4564b
Merge branch 'main' into matias-zk-toolbox-update
matias-gonz Jul 24, 2024
dbf7528
Merge branch 'matias-zk-toolbox-update' of github.com:matter-labs/zks…
matias-gonz Jul 24, 2024
0573e91
Merge branch 'main' into matias-zk-toolbox-update
matias-gonz Jul 25, 2024
263d17b
Merge branch 'matias-zk-toolbox-update' of github.com:matter-labs/zks…
matias-gonz Jul 25, 2024
6d3ca5e
Use shell instead of std
matias-gonz Jul 25, 2024
5178d9c
Make constants public
matias-gonz Jul 25, 2024
bf47f8b
Add check_diff for genesis config
matias-gonz Jul 25, 2024
33795be
Add Diff.print()
matias-gonz Jul 25, 2024
0ac6ff3
Add warnings for contracts and secrets
matias-gonz Jul 25, 2024
a18b204
Add update external node config
matias-gonz Jul 25, 2024
1f87c95
Add update_config
matias-gonz Jul 26, 2024
e6ab62c
Add merge_yaml tests
matias-gonz Jul 26, 2024
3e98763
Add test
matias-gonz Jul 26, 2024
4223adc
Add parent keys to diff
matias-gonz Jul 26, 2024
923de1a
Merge branch 'main' of github.com:matter-labs/zksync-era into matias-…
matias-gonz Jul 26, 2024
f7f55b0
Update ConfigDiff
matias-gonz Jul 26, 2024
4b3330c
Merge branch 'main' into matias-zk-toolbox-update
matias-gonz Jul 26, 2024
507d22d
Refactor merge_yaml
matias-gonz Jul 26, 2024
7ef4d35
Merge branch 'main' into matias-zk-toolbox-update
matias-gonz Jul 26, 2024
48186f5
Update path_to_external_node_config
matias-gonz Jul 26, 2024
255bf65
Merge branch 'matias-zk-toolbox-update' of github.com:matter-labs/zks…
matias-gonz Jul 26, 2024
55e3c95
Update GeneralConfig.print
matias-gonz Jul 26, 2024
74b6fad
add general
Deniallugo Jul 26, 2024
9b87baf
Update
Deniallugo Jul 26, 2024
c01e4df
Use git pull from origin branch
Deniallugo Jul 26, 2024
7207656
Add only-config argument
matias-gonz Jul 26, 2024
5fd4e6e
Add support for EN general config
matias-gonz Jul 26, 2024
f822a94
Merge branch 'main' into matias-zk-toolbox-update
matias-gonz Jul 26, 2024
73a2ce4
Merge pull request #2514 from matter-labs/deniallugo-tests
matias-gonz Jul 26, 2024
cf633e7
Lint
matias-gonz Jul 26, 2024
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
4 changes: 4 additions & 0 deletions zk_toolbox/crates/config/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ impl ChainConfig {
self.configs.join(GENERAL_FILE)
}

pub fn path_to_genesis_config(&self) -> PathBuf {
self.configs.join(GENESIS_FILE)
}

pub fn path_to_secrets_config(&self) -> PathBuf {
self.configs.join(SECRETS_FILE)
}
Expand Down
54 changes: 46 additions & 8 deletions zk_toolbox/crates/zk_inception/src/commands/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ use common::{
logger,
spinner::Spinner,
};
use config::{ChainConfig, EcosystemConfig, GENERAL_FILE};
use config::{ChainConfig, EcosystemConfig, GENERAL_FILE, GENESIS_FILE};
use xshell::Shell;

use crate::messages::{
msg_updating_chain, MSG_CHAIN_NOT_FOUND_ERR, MSG_PULLING_ZKSYNC_CODE_SPINNER, MSG_SHOW_DIFF,
msg_diff_genesis_config, msg_updating_chain, MSG_CHAIN_NOT_FOUND_ERR,
MSG_PULLING_ZKSYNC_CODE_SPINNER, MSG_SHOW_DIFF, MSG_SHOW_DIFF_ADDED_FIELDS,
MSG_UPDATING_GENERAL_CONFIG, MSG_UPDATING_SUBMODULES_SPINNER, MSG_UPDATING_ZKSYNC,
MSG_ZKSYNC_UPDATED,
};
Expand All @@ -33,15 +34,20 @@ pub fn run(shell: &Shell) -> anyhow::Result<()> {
submodule_update(shell, link_to_code.clone())?;
spinner.finish();

let updated_config_path = ecosystem.get_default_configs_path().join(GENERAL_FILE);
let general_config = serde_yaml::from_str(&shell.read_file(updated_config_path)?)?;
let general_config = serde_yaml::from_str(
&shell.read_file(ecosystem.get_default_configs_path().join(GENERAL_FILE))?,
)?;

let genesis_config = serde_yaml::from_str(
&shell.read_file(ecosystem.get_default_configs_path().join(GENESIS_FILE))?,
)?;

for chain in ecosystem.list_of_chains() {
logger::info(msg_updating_chain(&chain));
let chain = ecosystem
.load_chain(Some(chain))
.context(MSG_CHAIN_NOT_FOUND_ERR)?;
update_chain(shell, &chain, &general_config)?;
update_chain(shell, &chain, &general_config, &genesis_config)?;
}

logger::outro(MSG_ZKSYNC_UPDATED);
Expand Down Expand Up @@ -82,6 +88,7 @@ fn merge_yaml(a: &mut serde_yaml::Value, b: serde_yaml::Value) -> anyhow::Result
}

fn save_updated_config(
shell: &Shell,
config: serde_yaml::Value,
path: &Path,
diff: ConfigDiff,
Expand All @@ -90,14 +97,33 @@ fn save_updated_config(
return Ok(());
}

logger::info(MSG_SHOW_DIFF);
logger::info(MSG_SHOW_DIFF_ADDED_FIELDS);
for (key, value) in diff.added_fields {
let key = key.as_str().unwrap();
logger::info(format!("{}: {:?}", key, value));
}

let general_config = serde_yaml::to_string(&config)?;
std::fs::write(path, general_config)?;
shell.write_file(path, general_config)?;

Ok(())
}

fn check_diff(diff: &ConfigDiff, msg: &str) -> anyhow::Result<()> {
Deniallugo marked this conversation as resolved.
Show resolved Hide resolved
if diff.value_diff.is_empty() && diff.added_fields.is_empty() {
return Ok(());
}

logger::warn(msg);
logger::info(MSG_SHOW_DIFF);
for (key, value) in diff.added_fields.iter() {
let key = key.as_str().unwrap();
logger::info(format!("{}: {:?}", key, value));
}
for (key, value) in diff.value_diff.iter() {
let key = key.as_str().unwrap();
logger::info(format!("{}: {:?}", key, value));
}

Ok(())
}
Expand All @@ -106,12 +132,24 @@ fn update_chain(
shell: &Shell,
chain: &ChainConfig,
general: &serde_yaml::Value,
genesis: &serde_yaml::Value,
) -> anyhow::Result<()> {
logger::info(MSG_UPDATING_GENERAL_CONFIG);
let current_general_config_path = chain.path_to_general_config();
let mut current_general_config =
serde_yaml::from_str(&shell.read_file(current_general_config_path.clone())?)?;
let diff = merge_yaml(&mut current_general_config, general.clone())?;
save_updated_config(current_general_config, &current_general_config_path, diff)?;
save_updated_config(
shell,
current_general_config,
&current_general_config_path,
diff,
)?;

let mut current_genesis_config =
serde_yaml::from_str(&shell.read_file(chain.path_to_genesis_config())?)?;
let diff = merge_yaml(&mut current_genesis_config, genesis.clone())?;
check_diff(&diff, &msg_diff_genesis_config(&chain.name))?;

Ok(())
}
10 changes: 9 additions & 1 deletion zk_toolbox/crates/zk_inception/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,15 @@ pub(super) const MSG_ZKSYNC_UPDATED: &str = "ZkSync updated successfully";
pub(super) const MSG_PULLING_ZKSYNC_CODE_SPINNER: &str = "Pulling zksync-era repo...";
pub(super) const MSG_UPDATING_SUBMODULES_SPINNER: &str = "Updating submodules...";
pub(super) const MSG_UPDATING_GENERAL_CONFIG: &str = "Updating general config";
pub(super) const MSG_SHOW_DIFF: &str = "Added the following values:";
pub(super) const MSG_SHOW_DIFF_ADDED_FIELDS: &str = "Added the following values:";
pub(super) const MSG_SHOW_DIFF: &str = "Found differences in the following fields:";

pub(super) fn msg_diff_genesis_config(chain: &str) -> String {
format!(
"Found differences between chain {} and era genesis configs. Consider updating the chain {} genesis config and re-running genesis.",
chain, chain
)
}

pub(super) fn msg_updating_chain(chain: &str) -> String {
format!("Updating chain: {}", chain)
Expand Down
Loading