Skip to content

Commit ef21c1a

Browse files
authored
chore(zkstack): Use trait for zkstack config (#4449)
## What ❔ Before for chain/ecosystem trait we had only `link_to_code` and all other path has been calculated from this link. Now it's a trait, that allows to implement custom paths for `link_to_code`, `contracts`, `configs` ## Why ❔ For supporting different ways of initialization, we need to support different path. e.g. we have zksync_os, where we will be able to pass custom `contracts_path`. For docker based deployment we will be able to calculate custom path inside containers. ## Is this a breaking change? - [ ] Yes - [ ] No ## Operational changes <!-- Any config changes? Any new flags? Any changes to any scripts? --> <!-- Please add anything that non-Matter Labs entities running their own ZK Chain may need to know --> ## 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 `zkstack dev fmt` and `zkstack dev lint`. --------- Signed-off-by: Danil <[email protected]>
1 parent 5a19f51 commit ef21c1a

File tree

120 files changed

+610
-473
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+610
-473
lines changed

zkstack_cli/crates/common/src/contracts.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ use xshell::{cmd, Shell};
44

55
use crate::cmd::Cmd;
66

7-
pub fn build_l1_contracts(shell: Shell, link_to_code: &Path) -> anyhow::Result<()> {
8-
let _dir_guard = shell.push_dir(link_to_code.join("contracts/l1-contracts"));
7+
pub fn build_l1_contracts(shell: Shell, link_to_contracts: &Path) -> anyhow::Result<()> {
8+
let _dir_guard = shell.push_dir(link_to_contracts.join("l1-contracts"));
99
// Do not update era-contract's lockfile to avoid dirty submodule
1010
// Note, tha the v26 contracts depend on the node_modules to be present at the time of the compilation.
1111
Cmd::new(cmd!(shell, "yarn install --frozen-lockfile")).run()?;
1212
Ok(Cmd::new(cmd!(shell, "yarn build:foundry")).run()?)
1313
}
1414

15-
pub fn build_l1_da_contracts(shell: Shell, link_to_code: &Path) -> anyhow::Result<()> {
16-
let _dir_guard = shell.push_dir(link_to_code.join("contracts/da-contracts"));
15+
pub fn build_l1_da_contracts(shell: Shell, link_to_contracts: &Path) -> anyhow::Result<()> {
16+
let _dir_guard = shell.push_dir(link_to_contracts.join("da-contracts"));
1717
Ok(Cmd::new(cmd!(shell, "forge build")).run()?)
1818
}
1919

20-
pub fn build_l2_contracts(shell: Shell, link_to_code: &Path) -> anyhow::Result<()> {
21-
let _dir_guard = shell.push_dir(link_to_code.join("contracts/l2-contracts"));
20+
pub fn build_l2_contracts(shell: Shell, link_to_contracts: &Path) -> anyhow::Result<()> {
21+
let _dir_guard = shell.push_dir(link_to_contracts.join("l2-contracts"));
2222
Cmd::new(cmd!(shell, "yarn build:foundry")).run()?;
2323
Ok(())
2424
}
2525

26-
pub fn build_system_contracts(shell: Shell, link_to_code: &Path) -> anyhow::Result<()> {
27-
let _dir_guard = shell.push_dir(link_to_code.join("contracts/system-contracts"));
26+
pub fn build_system_contracts(shell: Shell, link_to_contracts: &Path) -> anyhow::Result<()> {
27+
let _dir_guard = shell.push_dir(link_to_contracts.join("system-contracts"));
2828
Ok(Cmd::new(cmd!(shell, "yarn build:foundry")).run()?)
2929
}

zkstack_cli/crates/config/src/apps.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use xshell::Shell;
55

66
use crate::{
77
consts::{APPS_CONFIG_FILE, DEFAULT_EXPLORER_PORT, DEFAULT_PORTAL_PORT, LOCAL_CONFIGS_PATH},
8-
traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig, ZkStackConfigTrait},
8+
traits::{FileConfigTrait, FileConfigWithDefaultName, ReadConfig, SaveConfig},
99
};
1010

1111
/// Ecosystem level configuration for the apps (portal and explorer).
@@ -20,7 +20,7 @@ pub struct AppEcosystemConfig {
2020
pub http_port: u16,
2121
}
2222

23-
impl ZkStackConfigTrait for AppsEcosystemConfig {}
23+
impl FileConfigTrait for AppsEcosystemConfig {}
2424
impl FileConfigWithDefaultName for AppsEcosystemConfig {
2525
const FILE_NAME: &'static str = APPS_CONFIG_FILE;
2626
}

zkstack_cli/crates/config/src/chain.rs

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ use zksync_basic_types::L2ChainId;
1212

1313
use crate::{
1414
consts::{
15-
CONFIG_NAME, CONTRACTS_FILE, EN_CONFIG_FILE, GENERAL_FILE, GENESIS_FILE,
16-
L1_CONTRACTS_FOUNDRY, SECRETS_FILE, WALLETS_FILE,
15+
CONFIG_NAME, CONTRACTS_FILE, CONTRACTS_PATH, EN_CONFIG_FILE, GENERAL_FILE, GENESIS_FILE,
16+
L1_CONTRACTS_FOUNDRY_INSIDE_CONTRACTS, SECRETS_FILE, WALLETS_FILE,
1717
},
1818
create_localhost_wallets,
1919
gateway::GatewayConfig,
2020
traits::{
21-
FileConfigWithDefaultName, ReadConfig, ReadConfigWithBasePath, SaveConfig,
22-
SaveConfigWithBasePath, ZkStackConfigTrait,
21+
FileConfigTrait, FileConfigWithDefaultName, ReadConfig, ReadConfigWithBasePath, SaveConfig,
22+
SaveConfigWithBasePath,
2323
},
2424
ContractsConfig, EcosystemConfig, GatewayChainConfig, GeneralConfig, GenesisConfig,
25-
SecretsConfig, WalletsConfig, GATEWAY_CHAIN_FILE,
25+
SecretsConfig, WalletsConfig, ZkStackConfigTrait, CONFIGS_PATH, GATEWAY_CHAIN_FILE,
2626
};
2727

2828
/// Chain configuration file. This file is created in the chain
@@ -61,19 +61,19 @@ pub struct ChainConfig {
6161
pub chain_id: L2ChainId,
6262
pub prover_version: ProverMode,
6363
pub l1_network: L1Network,
64-
pub self_path: PathBuf,
65-
pub link_to_code: PathBuf,
6664
pub rocks_db_path: PathBuf,
6765
pub artifacts: PathBuf,
6866
pub configs: PathBuf,
6967
pub external_node_config_path: Option<PathBuf>,
7068
pub l1_batch_commit_data_generator_mode: L1BatchCommitmentMode,
7169
pub base_token: BaseToken,
7270
pub wallet_creation: WalletCreation,
73-
pub shell: OnceCell<Shell>,
7471
pub legacy_bridge: Option<bool>,
7572
pub evm_emulator: bool,
7673
pub tight_ports: bool,
74+
shell: OnceCell<Shell>,
75+
self_path: PathBuf,
76+
link_to_code: PathBuf,
7777
}
7878

7979
#[derive(Debug, Clone)]
@@ -93,6 +93,49 @@ impl Serialize for ChainConfig {
9393
}
9494

9595
impl ChainConfig {
96+
#[allow(clippy::too_many_arguments)]
97+
pub fn new(
98+
id: u32,
99+
name: String,
100+
chain_id: L2ChainId,
101+
prover_version: ProverMode,
102+
l1_network: L1Network,
103+
self_path: PathBuf,
104+
link_to_code: PathBuf,
105+
rocks_db_path: PathBuf,
106+
artifacts: PathBuf,
107+
configs: PathBuf,
108+
external_node_config_path: Option<PathBuf>,
109+
l1_batch_commit_data_generator_mode: L1BatchCommitmentMode,
110+
base_token: BaseToken,
111+
wallet_creation: WalletCreation,
112+
shell: OnceCell<Shell>,
113+
legacy_bridge: Option<bool>,
114+
evm_emulator: bool,
115+
tight_ports: bool,
116+
) -> Self {
117+
Self {
118+
id,
119+
name,
120+
chain_id,
121+
prover_version,
122+
l1_network,
123+
self_path,
124+
link_to_code,
125+
rocks_db_path,
126+
artifacts,
127+
configs,
128+
external_node_config_path,
129+
l1_batch_commit_data_generator_mode,
130+
base_token,
131+
wallet_creation,
132+
shell,
133+
legacy_bridge,
134+
evm_emulator,
135+
tight_ports,
136+
}
137+
}
138+
96139
pub(crate) fn get_shell(&self) -> &Shell {
97140
self.shell.get().expect("Not initialized")
98141
}
@@ -118,10 +161,6 @@ impl ChainConfig {
118161
anyhow::bail!("Wallets configs has not been found");
119162
}
120163

121-
pub fn get_preexisting_ecosystem_contracts_path(&self) -> PathBuf {
122-
todo!()
123-
}
124-
125164
pub fn get_contracts_config(&self) -> anyhow::Result<ContractsConfig> {
126165
ContractsConfig::read_with_base_path(self.get_shell(), &self.configs)
127166
}
@@ -162,10 +201,6 @@ impl ChainConfig {
162201
self.configs.join(GATEWAY_CHAIN_FILE)
163202
}
164203

165-
pub fn path_to_l1_foundry(&self) -> PathBuf {
166-
self.link_to_code.join(L1_CONTRACTS_FOUNDRY)
167-
}
168-
169204
pub fn save(&self, shell: &Shell, path: impl AsRef<Path>) -> anyhow::Result<()> {
170205
let config = self.get_internal();
171206
config.save(shell, path)
@@ -262,4 +297,23 @@ impl FileConfigWithDefaultName for ChainConfigInternal {
262297
const FILE_NAME: &'static str = CONFIG_NAME;
263298
}
264299

265-
impl ZkStackConfigTrait for ChainConfigInternal {}
300+
impl FileConfigTrait for ChainConfigInternal {}
301+
302+
impl ZkStackConfigTrait for ChainConfig {
303+
fn link_to_code(&self) -> PathBuf {
304+
self.link_to_code.clone()
305+
}
306+
307+
fn default_configs_path(&self) -> PathBuf {
308+
self.link_to_code().join(CONFIGS_PATH)
309+
}
310+
311+
fn contracts_path(&self) -> PathBuf {
312+
self.link_to_code().join(CONTRACTS_PATH)
313+
}
314+
315+
fn path_to_l1_foundry(&self) -> PathBuf {
316+
self.contracts_path()
317+
.join(L1_CONTRACTS_FOUNDRY_INSIDE_CONTRACTS)
318+
}
319+
}

zkstack_cli/crates/config/src/consts.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub(crate) const LOCAL_CONFIGS_PATH: &str = "configs/";
4242
pub(crate) const LOCAL_GENERATED_PATH: &str = ".generated/";
4343
pub(crate) const LOCAL_DB_PATH: &str = "db/";
4444
pub(crate) const LOCAL_ARTIFACTS_PATH: &str = "artifacts/";
45+
pub(crate) const CONTRACTS_PATH: &str = "contracts/";
4546

4647
/// Name of apps config file
4748
pub const APPS_CONFIG_FILE: &str = "apps.yaml";
@@ -105,8 +106,8 @@ pub const EXPLORER_BATCHES_PROCESSING_POLLING_INTERVAL: u64 = 1000;
105106
/// Path to ecosystem contacts
106107
pub(crate) const ECOSYSTEM_PATH: &str = "etc/env/ecosystems";
107108

108-
/// Path to l1 contracts foundry folder inside zksync-era
109-
pub(crate) const L1_CONTRACTS_FOUNDRY: &str = "contracts/l1-contracts";
109+
pub(crate) const L1_CONTRACTS_FOUNDRY_INSIDE_CONTRACTS: &str = "l1-contracts";
110+
110111
/// Path to proving networks contracts
111112
pub(crate) const PROVING_NETWORKS_PATH: &str = "proof-manager-contracts";
112113
/// Path to proving networks contracts deploy script

zkstack_cli/crates/config/src/contracts.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
},
1616
register_chain::output::RegisterChainOutput,
1717
},
18-
traits::{FileConfigWithDefaultName, ZkStackConfigTrait},
18+
traits::{FileConfigTrait, FileConfigWithDefaultName},
1919
};
2020

2121
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
@@ -215,7 +215,7 @@ impl FileConfigWithDefaultName for ContractsConfig {
215215
const FILE_NAME: &'static str = CONTRACTS_FILE;
216216
}
217217

218-
impl ZkStackConfigTrait for ContractsConfig {}
218+
impl FileConfigTrait for ContractsConfig {}
219219

220220
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
221221
pub struct EcosystemContracts {
@@ -248,7 +248,7 @@ pub struct EcosystemContracts {
248248
pub server_notifier_proxy_addr: Option<Address>,
249249
}
250250

251-
impl ZkStackConfigTrait for EcosystemContracts {}
251+
impl FileConfigTrait for EcosystemContracts {}
252252

253253
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
254254
pub struct BridgesContracts {

zkstack_cli/crates/config/src/docker_compose.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::HashMap;
22

33
use serde::{Deserialize, Serialize};
44

5-
use crate::traits::ZkStackConfigTrait;
5+
use crate::traits::FileConfigTrait;
66

77
#[derive(Debug, Default, Serialize, Deserialize, Clone)]
88
pub struct DockerComposeConfig {
@@ -36,7 +36,7 @@ pub struct DockerComposeService {
3636
pub other: serde_json::Value,
3737
}
3838

39-
impl ZkStackConfigTrait for DockerComposeConfig {}
39+
impl FileConfigTrait for DockerComposeConfig {}
4040

4141
impl DockerComposeConfig {
4242
pub fn add_service(&mut self, name: &str, service: DockerComposeService) {

0 commit comments

Comments
 (0)