Skip to content

Commit

Permalink
chore(zk_toolbox): Use load current chain function (matter-labs#2990)
Browse files Browse the repository at this point in the history
## What ❔

<!-- What are the changes this PR brings about? -->
<!-- Example: This PR adds a PR template to the repo. -->
<!-- (For bigger PRs adding more context is appreciated) -->

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## 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 <deniallugo@gmail.com>
  • Loading branch information
Deniallugo authored Oct 1, 2024
1 parent 8b79b9a commit cdc1288
Show file tree
Hide file tree
Showing 30 changed files with 51 additions and 72 deletions.
2 changes: 1 addition & 1 deletion core/node/eth_watch/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl EthClient for MockEthClient {
Ok(logs
.into_iter()
.filter(|log| {
log.topics.get(0) == Some(&topic1)
log.topics.first() == Some(&topic1)
&& (topic2.is_none() || log.topics.get(1) == topic2.as_ref())
})
.collect())
Expand Down
4 changes: 4 additions & 0 deletions zk_toolbox/crates/config/src/ecosystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ impl EcosystemConfig {
self.load_chain_inner(&name)
}

pub fn load_current_chain(&self) -> Option<ChainConfig> {
self.load_chain_inner(self.current_chain())
}

fn load_chain_inner(&self, name: &str) -> Option<ChainConfig> {
let path = self.chains.join(name).join(CONFIG_NAME);
let config = ChainConfigInternal::read(self.get_shell(), path.clone()).ok()?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Context;
use common::{config::global_config, git, logger, spinner::Spinner};
use common::{git, logger, spinner::Spinner};
use config::{
copy_configs, traits::SaveConfigWithBasePath, update_from_chain_config, EcosystemConfig,
};
Expand Down Expand Up @@ -27,9 +27,8 @@ const SCRIPT_CONFIG_FILE_DST: &str = "register-hyperchain.toml";

pub(crate) async fn run(args: BuildTransactionsArgs, shell: &Shell) -> anyhow::Result<()> {
let config = EcosystemConfig::from_file(shell)?;
let chain_name = global_config().chain_name.clone();
let chain_config = config
.load_chain(chain_name)
.load_current_chain()
.context(MSG_CHAIN_NOT_FOUND_ERR)?;

let args = args.fill_values_with_prompt(config.default_chain.clone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::path::Path;
use anyhow::Context;
use common::{
cmd::Cmd,
config::global_config,
forge::{Forge, ForgeScriptArgs},
spinner::Spinner,
};
Expand Down Expand Up @@ -43,10 +42,9 @@ pub async fn run(
shell: &Shell,
deploy_option: Deploy2ContractsOption,
) -> anyhow::Result<()> {
let chain_name = global_config().chain_name.clone();
let ecosystem_config = EcosystemConfig::from_file(shell)?;
let chain_config = ecosystem_config
.load_chain(chain_name)
.load_current_chain()
.context(MSG_CHAIN_NOT_INITIALIZED)?;

let mut contracts = chain_config.get_contracts_config()?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use anyhow::Context;
use common::{
config::global_config,
forge::{Forge, ForgeScriptArgs},
};
use common::forge::{Forge, ForgeScriptArgs};
use config::{
forge_interface::{
paymaster::{DeployPaymasterInput, DeployPaymasterOutput},
Expand All @@ -19,10 +16,9 @@ use crate::{
};

pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {
let chain_name = global_config().chain_name.clone();
let ecosystem_config = EcosystemConfig::from_file(shell)?;
let chain_config = ecosystem_config
.load_chain(chain_name)
.load_current_chain()
.context(MSG_CHAIN_NOT_INITIALIZED)?;
let mut contracts = chain_config.get_contracts_config()?;
deploy_paymaster(shell, &chain_config, &mut contracts, args, None, true).await?;
Expand Down
3 changes: 1 addition & 2 deletions zk_toolbox/crates/zk_inception/src/commands/chain/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ use crate::{
};

pub async fn run(args: GenesisArgs, shell: &Shell) -> anyhow::Result<()> {
let chain_name = global_config().chain_name.clone();
let ecosystem_config = EcosystemConfig::from_file(shell)?;
let chain_config = ecosystem_config
.load_chain(chain_name)
.load_current_chain()
.context(MSG_CHAIN_NOT_INITIALIZED)?;
let args = args.fill_values_with_prompt(&chain_config);

Expand Down
5 changes: 2 additions & 3 deletions zk_toolbox/crates/zk_inception/src/commands/chain/init.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Context;
use common::{config::global_config, git, logger, spinner::Spinner};
use common::{git, logger, spinner::Spinner};
use config::{
copy_configs, set_l1_rpc_url, traits::SaveConfigWithBasePath, update_from_chain_config,
ChainConfig, EcosystemConfig, DEFAULT_CONSENSUS_PORT,
Expand Down Expand Up @@ -34,10 +34,9 @@ use crate::{
};

pub(crate) async fn run(args: InitArgs, shell: &Shell) -> anyhow::Result<()> {
let chain_name = global_config().chain_name.clone();
let config = EcosystemConfig::from_file(shell)?;
let chain_config = config
.load_chain(chain_name)
.load_current_chain()
.context(MSG_CHAIN_NOT_FOUND_ERR)?;
let mut args = args.fill_values_with_prompt(&chain_config);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use anyhow::Context;
use common::{
config::global_config,
forge::{Forge, ForgeScript, ForgeScriptArgs},
logger,
spinner::Spinner,
Expand Down Expand Up @@ -30,10 +29,9 @@ lazy_static! {
}

pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {
let chain_name = global_config().chain_name.clone();
let ecosystem_config = EcosystemConfig::from_file(shell)?;
let chain_config = ecosystem_config
.load_chain(chain_name)
.load_current_chain()
.context(MSG_CHAIN_NOT_INITIALIZED)?;
let contracts_config = chain_config.get_contracts_config()?;
let l1_url = chain_config
Expand Down
5 changes: 2 additions & 3 deletions zk_toolbox/crates/zk_inception/src/commands/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{borrow::Borrow, collections::HashMap, sync::Arc};
/// Consensus registry contract operations.
/// Includes code duplicated from `zksync_node_consensus::registry::abi`.
use anyhow::Context as _;
use common::{config::global_config, logger};
use common::logger;
use config::EcosystemConfig;
use ethers::{
abi::Detokenize,
Expand Down Expand Up @@ -174,9 +174,8 @@ impl Setup {

fn new(shell: &Shell) -> anyhow::Result<Self> {
let ecosystem_config = EcosystemConfig::from_file(shell)?;
let chain_name = global_config().chain_name.clone();
let chain = ecosystem_config
.load_chain(chain_name)
.load_current_chain()
.context(messages::MSG_CHAIN_NOT_INITIALIZED)?;
let contracts = chain
.get_contracts_config()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Context;
use common::{cmd::Cmd, config::global_config, logger};
use common::{cmd::Cmd, logger};
use config::EcosystemConfig;
use xshell::{cmd, Shell};

Expand All @@ -10,7 +10,7 @@ use crate::messages::{
pub(crate) async fn run(shell: &Shell) -> anyhow::Result<()> {
let ecosystem = EcosystemConfig::from_file(shell)?;
let chain = ecosystem
.load_chain(global_config().chain_name.clone())
.load_current_chain()
.context(MSG_CHAIN_NOT_FOUND_ERR)?;

let config_path = chain.path_to_general_config();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::Path;

use anyhow::Context;
use common::{config::global_config, docker};
use common::docker;
use config::{explorer_compose::ExplorerBackendComposeConfig, EcosystemConfig};
use xshell::Shell;

Expand All @@ -13,7 +13,7 @@ use crate::messages::{
pub(crate) fn run(shell: &Shell) -> anyhow::Result<()> {
let ecosystem_config = EcosystemConfig::from_file(shell)?;
let chain_config = ecosystem_config
.load_chain(global_config().chain_name.clone())
.load_current_chain()
.context(MSG_CHAIN_NOT_FOUND_ERR)?;
let chain_name = chain_config.name.clone();
// Read chain-level explorer backend docker compose file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use anyhow::Context;
use common::{
config::global_config,
db::{drop_db_if_exists, init_db, migrate_db, DatabaseConfig},
spinner::Spinner,
};
Expand All @@ -20,9 +19,8 @@ use crate::{
pub async fn run(shell: &Shell) -> anyhow::Result<()> {
let ecosystem_config = EcosystemConfig::from_file(shell)?;

let chain = global_config().chain_name.clone();
let chain_config = ecosystem_config
.load_chain(chain)
.load_current_chain()
.context(MSG_CHAIN_NOT_INITIALIZED)?;

init(shell, &chain_config).await
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::BTreeMap, path::Path, str::FromStr};

use anyhow::Context;
use common::{config::global_config, logger};
use common::logger;
use config::{
external_node::ENConfig,
set_rocks_db_config,
Expand Down Expand Up @@ -34,10 +34,9 @@ use crate::{

pub fn run(shell: &Shell, args: PrepareConfigArgs) -> anyhow::Result<()> {
logger::info(MSG_PREPARING_EN_CONFIGS);
let chain_name = global_config().chain_name.clone();
let ecosystem_config = EcosystemConfig::from_file(shell)?;
let mut chain_config = ecosystem_config
.load_chain(chain_name)
.load_current_chain()
.context(MSG_CHAIN_NOT_INITIALIZED)?;

let args = args.fill_values_with_prompt(&chain_config);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Context;
use common::{config::global_config, logger};
use common::logger;
use config::{ChainConfig, EcosystemConfig};
use xshell::Shell;

Expand All @@ -12,9 +12,8 @@ use crate::{
pub async fn run(shell: &Shell, args: RunExternalNodeArgs) -> anyhow::Result<()> {
let ecosystem_config = EcosystemConfig::from_file(shell)?;

let chain = global_config().chain_name.clone();
let chain_config = ecosystem_config
.load_chain(chain)
.load_current_chain()
.context(MSG_CHAIN_NOT_INITIALIZED)?;

logger::info(MSG_STARTING_EN);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use anyhow::Context;
use common::{
check_prerequisites, cmd::Cmd, config::global_config, spinner::Spinner, WGET_PREREQUISITE,
};
use common::{check_prerequisites, cmd::Cmd, spinner::Spinner, WGET_PREREQUISITE};
use config::{get_link_to_prover, EcosystemConfig, GeneralConfig};
use xshell::{cmd, Shell};

Expand All @@ -14,7 +12,7 @@ use crate::messages::{
pub(crate) async fn run(shell: &Shell, args: CompressorKeysArgs) -> anyhow::Result<()> {
let ecosystem_config = EcosystemConfig::from_file(shell)?;
let chain_config = ecosystem_config
.load_chain(global_config().chain_name.clone())
.load_current_chain()
.context(MSG_CHAIN_NOT_FOUND_ERR)?;
let mut general_config = chain_config.get_general_config()?;

Expand Down
2 changes: 1 addition & 1 deletion zk_toolbox/crates/zk_inception/src/commands/prover/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub(crate) async fn run(args: ProverInitArgs, shell: &Shell) -> anyhow::Result<(
let default_compressor_key_path = get_default_compressor_keys_path(&ecosystem_config)?;

let chain_config = ecosystem_config
.load_chain(global_config().chain_name.clone())
.load_current_chain()
.context(MSG_CHAIN_NOT_FOUND_ERR)?;
let args = args.fill_values_with_prompt(shell, &default_compressor_key_path, &chain_config)?;

Expand Down
4 changes: 2 additions & 2 deletions zk_toolbox/crates/zk_inception/src/commands/prover/run.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::PathBuf;

use anyhow::{anyhow, Context};
use common::{check_prerequisites, cmd::Cmd, config::global_config, logger, GPU_PREREQUISITES};
use common::{check_prerequisites, cmd::Cmd, logger, GPU_PREREQUISITES};
use config::{get_link_to_prover, ChainConfig, EcosystemConfig};
use xshell::{cmd, Shell};

Expand All @@ -19,7 +19,7 @@ pub(crate) async fn run(args: ProverRunArgs, shell: &Shell) -> anyhow::Result<()
let args = args.fill_values_with_prompt()?;
let ecosystem_config = EcosystemConfig::from_file(shell)?;
let chain = ecosystem_config
.load_chain(global_config().chain_name.clone())
.load_current_chain()
.expect(MSG_CHAIN_NOT_FOUND_ERR);

let link_to_prover = get_link_to_prover(&ecosystem_config);
Expand Down
4 changes: 1 addition & 3 deletions zk_toolbox/crates/zk_inception/src/commands/server.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use anyhow::Context;
use common::{
config::global_config,
logger,
server::{Server, ServerMode},
};
Expand All @@ -18,9 +17,8 @@ use crate::{
pub fn run(shell: &Shell, args: RunServerArgs) -> anyhow::Result<()> {
let ecosystem_config = EcosystemConfig::from_file(shell)?;

let chain = global_config().chain_name.clone();
let chain_config = ecosystem_config
.load_chain(chain)
.load_current_chain()
.context(MSG_CHAIN_NOT_INITIALIZED)?;

logger::info(MSG_STARTING_SERVER);
Expand Down
4 changes: 2 additions & 2 deletions zk_toolbox/crates/zk_supervisor/src/commands/config_writer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Context;
use clap::Parser;
use common::{config::global_config, logger, Prompt};
use common::{logger, Prompt};
use config::{override_config, EcosystemConfig};
use xshell::Shell;

Expand All @@ -26,7 +26,7 @@ pub fn run(shell: &Shell, args: ConfigWriterArgs) -> anyhow::Result<()> {
let path = args.get_config_path().into();
let ecosystem = EcosystemConfig::from_file(shell)?;
let chain = ecosystem
.load_chain(global_config().chain_name.clone())
.load_current_chain()
.context(MSG_CHAIN_NOT_FOUND_ERR)?;
logger::step(msg_overriding_config(chain.name.clone()));
override_config(shell, path, &chain)?;
Expand Down
4 changes: 2 additions & 2 deletions zk_toolbox/crates/zk_supervisor/src/commands/prover/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
};

use anyhow::Context as _;
use common::{config::global_config, logger};
use common::logger;
use config::{ChainConfig, EcosystemConfig};
use xshell::{cmd, Shell};

Expand All @@ -13,7 +13,7 @@ use crate::messages::MSG_CHAIN_NOT_FOUND_ERR;
pub async fn run(shell: &Shell) -> anyhow::Result<()> {
let ecosystem_config = EcosystemConfig::from_file(shell)?;
let chain_config = ecosystem_config
.load_chain(global_config().chain_name.clone())
.load_current_chain()
.expect(MSG_CHAIN_NOT_FOUND_ERR);

let link_to_code = ecosystem_config.link_to_code;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use common::{
check_prerequisites, cmd::Cmd, config::global_config, logger, PROVER_CLI_PREREQUISITE,
};
use common::{check_prerequisites, cmd::Cmd, logger, PROVER_CLI_PREREQUISITE};
use config::{get_link_to_prover, EcosystemConfig};
use xshell::{cmd, Shell};

Expand All @@ -17,7 +15,7 @@ pub async fn run(shell: &Shell, args: InsertBatchArgs) -> anyhow::Result<()> {

let ecosystem_config = EcosystemConfig::from_file(shell)?;
let chain_config = ecosystem_config
.load_chain(global_config().chain_name.clone())
.load_current_chain()
.expect(MSG_CHAIN_NOT_FOUND_ERR);

let version = info::get_protocol_version(shell, &get_link_to_prover(&ecosystem_config)).await?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use common::{
check_prerequisites, cmd::Cmd, config::global_config, logger, PROVER_CLI_PREREQUISITE,
};
use common::{check_prerequisites, cmd::Cmd, logger, PROVER_CLI_PREREQUISITE};
use config::{get_link_to_prover, EcosystemConfig};
use xshell::{cmd, Shell};

Expand All @@ -17,7 +15,7 @@ pub async fn run(shell: &Shell, args: InsertVersionArgs) -> anyhow::Result<()> {

let ecosystem_config = EcosystemConfig::from_file(shell)?;
let chain_config = ecosystem_config
.load_chain(global_config().chain_name.clone())
.load_current_chain()
.expect(MSG_CHAIN_NOT_FOUND_ERR);

let version = info::get_protocol_version(shell, &get_link_to_prover(&ecosystem_config)).await?;
Expand Down
4 changes: 2 additions & 2 deletions zk_toolbox/crates/zk_supervisor/src/commands/snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Context;
use clap::Subcommand;
use common::{cmd::Cmd, config::global_config, logger};
use common::{cmd::Cmd, logger};
use config::EcosystemConfig;
use xshell::{cmd, Shell};

Expand All @@ -24,7 +24,7 @@ pub(crate) async fn run(shell: &Shell, args: SnapshotCommands) -> anyhow::Result
async fn create(shell: &Shell) -> anyhow::Result<()> {
let ecosystem = EcosystemConfig::from_file(shell)?;
let chain = ecosystem
.load_chain(global_config().chain_name.clone())
.load_current_chain()
.context(MSG_CHAIN_NOT_FOUND_ERR)?;

let config_path = chain.path_to_general_config();
Expand Down
2 changes: 1 addition & 1 deletion zk_toolbox/crates/zk_supervisor/src/commands/test/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub async fn run(shell: &Shell, args: FeesArgs) -> anyhow::Result<()> {
let ecosystem_config = EcosystemConfig::from_file(shell)?;
shell.change_dir(ecosystem_config.link_to_code.join(TS_INTEGRATION_PATH));
let chain_config = ecosystem_config
.load_chain(global_config().chain_name.clone())
.load_current_chain()
.expect(MSG_CHAIN_NOT_FOUND_ERR);

if !args.no_deps {
Expand Down
Loading

0 comments on commit cdc1288

Please sign in to comment.