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_cli): Refactor ecosystem chain and external node configs: 3 layered chain #3087

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
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
16 changes: 8 additions & 8 deletions .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ jobs:
- name: Run server
run: |
ci_run zkstack dev config-writer --path ${{ matrix.vm_mode == 'NEW' && 'etc/env/file_based/overrides/tests/loadtest-new.yaml' || 'etc/env/file_based/overrides/tests/loadtest-old.yaml' }} --chain legacy
ci_run zkstack server --uring --chain=legacy --components api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads &>server.log &
ci_run zkstack chain server --uring --chain=legacy --components api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads &>server.log &
ci_run sleep 60

- name: Perform loadtest
Expand Down Expand Up @@ -351,23 +351,23 @@ jobs:

- name: Initialize Contract verifier
run: |
ci_run zkstack contract-verifier init --zksolc-version=v1.5.3 --zkvyper-version=v1.5.4 --solc-version=0.8.26 --vyper-version=v0.3.10 --era-vm-solc-version=0.8.26-1.0.1 --only --chain era
ci_run zkstack contract-verifier run --chain era &> ${{ env.SERVER_LOGS_DIR }}/contract-verifier-rollup.log &
ci_run zkstack chain contract-verifier init --zksolc-version=v1.5.3 --zkvyper-version=v1.5.4 --solc-version=0.8.26 --vyper-version=v0.3.10 --era-vm-solc-version=0.8.26-1.0.1 --only --chain era
ci_run zkstack chain contract-verifier run --chain era &> ${{ env.SERVER_LOGS_DIR }}/contract-verifier-rollup.log &

- name: Run servers
run: |
ci_run zkstack server --ignore-prerequisites --chain era &> ${{ env.SERVER_LOGS_DIR }}/rollup.log &
ci_run zkstack server --ignore-prerequisites --chain validium &> ${{ env.SERVER_LOGS_DIR }}/validium.log &
ci_run zkstack server --ignore-prerequisites --chain custom_token &> ${{ env.SERVER_LOGS_DIR }}/custom_token.log &
ci_run zkstack server --ignore-prerequisites --chain consensus \
ci_run zkstack chain server --ignore-prerequisites --chain era &> ${{ env.SERVER_LOGS_DIR }}/rollup.log &
ci_run zkstack chain server --ignore-prerequisites --chain validium &> ${{ env.SERVER_LOGS_DIR }}/validium.log &
ci_run zkstack chain server --ignore-prerequisites --chain custom_token &> ${{ env.SERVER_LOGS_DIR }}/custom_token.log &
ci_run zkstack chain server --ignore-prerequisites --chain consensus \
--components=api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads,vm_runner_bwip,vm_playground,da_dispatcher,consensus \
&> ${{ env.SERVER_LOGS_DIR }}/consensus.log &

ci_run sleep 5

- name: Setup attester committee for the consensus chain
run: |
ci_run zkstack consensus set-attester-committee --chain consensus --from-genesis &> ${{ env.INTEGRATION_TESTS_LOGS_DIR }}/consensus.log
ci_run zkstack chain consensus set-attester-committee --chain consensus --from-genesis &> ${{ env.INTEGRATION_TESTS_LOGS_DIR }}/consensus.log

- name: Run integration tests
run: |
Expand Down
31 changes: 30 additions & 1 deletion zkstack_cli/crates/config/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{
path::{Path, PathBuf},
};

use anyhow::bail;
use serde::{Deserialize, Serialize, Serializer};
use types::{BaseToken, L1BatchCommitmentMode, L1Network, ProverMode, WalletCreation};
use xshell::Shell;
Expand All @@ -18,7 +19,8 @@ use crate::{
FileConfigWithDefaultName, ReadConfig, ReadConfigWithBasePath, SaveConfig,
SaveConfigWithBasePath, ZkStackConfig,
},
ContractsConfig, GeneralConfig, GenesisConfig, SecretsConfig, WalletsConfig,
utils::find_file,
ContractsConfig, EcosystemConfig, GeneralConfig, GenesisConfig, SecretsConfig, WalletsConfig,
};

/// Chain configuration file. This file is created in the chain
Expand All @@ -33,6 +35,8 @@ pub struct ChainConfigInternal {
pub prover_version: ProverMode,
pub configs: PathBuf,
pub rocks_db_path: PathBuf,
pub l1_network: Option<L1Network>,
pub link_to_code: Option<PathBuf>,
pub external_node_config_path: Option<PathBuf>,
pub artifacts_path: Option<PathBuf>,
pub l1_batch_commit_data_generator_mode: L1BatchCommitmentMode,
Expand Down Expand Up @@ -97,6 +101,7 @@ impl ChainConfig {
}
anyhow::bail!("Wallets configs has not been found");
}

pub fn get_contracts_config(&self) -> anyhow::Result<ContractsConfig> {
ContractsConfig::read_with_base_path(self.get_shell(), &self.configs)
}
Expand Down Expand Up @@ -153,6 +158,8 @@ impl ChainConfig {
rocks_db_path: self.rocks_db_path.clone(),
external_node_config_path: self.external_node_config_path.clone(),
artifacts_path: Some(self.artifacts.clone()),
l1_network: Some(self.l1_network),
link_to_code: Some(self.link_to_code.clone()),
l1_batch_commit_data_generator_mode: self.l1_batch_commit_data_generator_mode,
base_token: self.base_token.clone(),
wallet_creation: self.wallet_creation,
Expand All @@ -161,6 +168,28 @@ impl ChainConfig {
}
}

impl ChainConfigInternal {
pub fn from_file(shell: &Shell) -> anyhow::Result<ChainConfigInternal> {
let Ok(path) = find_file(shell, shell.current_dir(), CONFIG_NAME) else {
bail!("Chain config not found")
};

shell.change_dir(&path);

match ChainConfigInternal::read(shell, CONFIG_NAME) {
Ok(config) => Ok(config),
Err(err) => {
if let Ok(ecosystem) = EcosystemConfig::read(shell, CONFIG_NAME) {
let chain = ecosystem.load_current_chain()?;
Ok(chain.get_internal())
} else {
Err(err)
}
}
}
}
}

impl FileConfigWithDefaultName for ChainConfigInternal {
const FILE_NAME: &'static str = CONFIG_NAME;
}
Expand Down
4 changes: 2 additions & 2 deletions zkstack_cli/crates/config/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ pub(crate) const LOCAL_APPS_PATH: &str = "apps/";
pub(crate) const LOCAL_CHAINS_PATH: &str = "chains/";
pub(crate) const LOCAL_CONFIGS_PATH: &str = "configs/";
pub(crate) const LOCAL_GENERATED_PATH: &str = ".generated/";
pub(crate) const LOCAL_DB_PATH: &str = "db/";
pub(crate) const LOCAL_ARTIFACTS_PATH: &str = "artifacts/";
pub const LOCAL_DB_PATH: &str = "db/";
pub const LOCAL_ARTIFACTS_PATH: &str = "artifacts/";

/// Name of apps config file
pub const APPS_CONFIG_FILE: &str = "apps.yaml";
Expand Down
15 changes: 1 addition & 14 deletions zkstack_cli/crates/config/src/ecosystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{
output::{ERC20Tokens, Erc20Token},
},
traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig, ZkStackConfig},
utils::find_file,
ChainConfig, ChainConfigInternal, ContractsConfig, WalletsConfig,
};

Expand Down Expand Up @@ -282,20 +283,6 @@ pub fn get_default_era_chain_id() -> L2ChainId {
L2ChainId::from(ERA_CHAIN_ID)
}

// Find file in all parents repository and return necessary path or an empty error if nothing has been found
fn find_file(shell: &Shell, path_buf: PathBuf, file_name: &str) -> Result<PathBuf, ()> {
let _dir = shell.push_dir(path_buf);
if shell.path_exists(file_name) {
Ok(shell.current_dir())
} else {
let current_dir = shell.current_dir();
let Some(path) = current_dir.parent() else {
return Err(());
};
find_file(shell, path.to_path_buf(), file_name)
}
}

pub fn get_link_to_prover(config: &EcosystemConfig) -> PathBuf {
let link_to_code = config.link_to_code.clone();
let mut link_to_prover = link_to_code.into_os_string();
Expand Down
2 changes: 2 additions & 0 deletions zkstack_cli/crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod general;
mod genesis;
mod manipulations;
mod secrets;
mod utils;
mod wallet_creation;
mod wallets;

Expand All @@ -34,3 +35,4 @@ pub mod external_node;
pub mod forge_interface;
pub mod portal;
pub mod traits;
pub mod zkstack_config;
17 changes: 17 additions & 0 deletions zkstack_cli/crates/config/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::path::PathBuf;

use xshell::Shell;

// Find file in all parents repository and return necessary path or an empty error if nothing has been found
pub fn find_file(shell: &Shell, path_buf: PathBuf, file_name: &str) -> Result<PathBuf, ()> {
let _dir = shell.push_dir(path_buf);
if shell.path_exists(file_name) {
Ok(shell.current_dir())
} else {
let current_dir = shell.current_dir();
let Some(path) = current_dir.parent() else {
return Err(());
};
find_file(shell, path.to_path_buf(), file_name)
}
}
55 changes: 55 additions & 0 deletions zkstack_cli/crates/config/src/zkstack_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use anyhow::Context;
use xshell::Shell;

use crate::{ChainConfig, ChainConfigInternal, EcosystemConfig};

pub enum ZkStackConfig {
EcosystemConfig(EcosystemConfig),
ChainConfig(ChainConfig),
}

impl ZkStackConfig {
fn from_file(shell: &Shell) -> anyhow::Result<ZkStackConfig> {
if let Ok(ecosystem) = EcosystemConfig::from_file(shell) {
Ok(ZkStackConfig::EcosystemConfig(ecosystem))
} else {
let chain_internal = ChainConfigInternal::from_file(shell)?;

let l1_network = chain_internal.l1_network.context("L1 Network not found")?;
let link_to_code = chain_internal
.link_to_code
.context("Link to code not found")?;
let artifacts = chain_internal
.artifacts_path
.context("Artifacts path not found")?;

let chain = ChainConfig {
id: chain_internal.id,
name: chain_internal.name,
chain_id: chain_internal.chain_id,
prover_version: chain_internal.prover_version,
configs: chain_internal.configs,
rocks_db_path: chain_internal.rocks_db_path,
external_node_config_path: chain_internal.external_node_config_path,
l1_network,
l1_batch_commit_data_generator_mode: chain_internal
.l1_batch_commit_data_generator_mode,
base_token: chain_internal.base_token,
wallet_creation: chain_internal.wallet_creation,
legacy_bridge: chain_internal.legacy_bridge,
link_to_code,
artifacts,
shell: shell.clone().into(),
};

Ok(ZkStackConfig::ChainConfig(chain))
}
}

pub fn load_current_chain(shell: &Shell) -> anyhow::Result<ChainConfig> {
match ZkStackConfig::from_file(shell)? {
ZkStackConfig::EcosystemConfig(ecosystem) => ecosystem.load_current_chain(),
ZkStackConfig::ChainConfig(chain) => Ok(chain),
}
}
}
2 changes: 1 addition & 1 deletion zkstack_cli/crates/zkstack/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() -> eyre::Result<()> {
.write_to_file(outdir.join("consensus_registry_abi.rs"))?;

zksync_protobuf_build::Config {
input_root: "src/commands/consensus/proto".into(),
input_root: "src/commands/chain/consensus/proto".into(),
proto_root: "zksync/toolbox/consensus".into(),
dependencies: vec!["::zksync_protobuf_config::proto".parse().unwrap()],
protobuf_crate: "::zksync_protobuf".parse().unwrap(),
Expand Down
2 changes: 0 additions & 2 deletions zkstack_cli/crates/zkstack/src/commands/args/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
pub use containers::*;
pub use run_server::*;
pub use update::*;

mod containers;
mod run_server;
mod update;
49 changes: 40 additions & 9 deletions zkstack_cli/crates/zkstack/src/commands/chain/args/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use serde::{Deserialize, Serialize};
use slugify_rs::slugify;
use strum::{Display, EnumIter, IntoEnumIterator};
use types::{BaseToken, L1BatchCommitmentMode, L1Network, ProverMode, WalletCreation};
use zksync_basic_types::H160;
use xshell::Shell;
use zksync_basic_types::{L2ChainId, H160};

use crate::{
defaults::L2_CHAIN_ID,
Expand All @@ -19,12 +20,13 @@ use crate::{
MSG_BASE_TOKEN_PRICE_NOMINATOR_PROMPT, MSG_BASE_TOKEN_SELECTION_PROMPT, MSG_CHAIN_ID_HELP,
MSG_CHAIN_ID_PROMPT, MSG_CHAIN_ID_VALIDATOR_ERR, MSG_CHAIN_NAME_PROMPT,
MSG_L1_BATCH_COMMIT_DATA_GENERATOR_MODE_PROMPT, MSG_L1_COMMIT_DATA_GENERATOR_MODE_HELP,
MSG_NUMBER_VALIDATOR_GREATHER_THAN_ZERO_ERR, MSG_NUMBER_VALIDATOR_NOT_ZERO_ERR,
MSG_PROVER_MODE_HELP, MSG_PROVER_VERSION_PROMPT, MSG_SET_AS_DEFAULT_HELP,
MSG_SET_AS_DEFAULT_PROMPT, MSG_WALLET_CREATION_HELP, MSG_WALLET_CREATION_PROMPT,
MSG_WALLET_CREATION_VALIDATOR_ERR, MSG_WALLET_PATH_HELP, MSG_WALLET_PATH_INVALID_ERR,
MSG_WALLET_PATH_PROMPT,
MSG_L1_NETWORK_HELP, MSG_L1_NETWORK_PROMPT, MSG_NUMBER_VALIDATOR_GREATHER_THAN_ZERO_ERR,
MSG_NUMBER_VALIDATOR_NOT_ZERO_ERR, MSG_PROVER_MODE_HELP, MSG_PROVER_VERSION_PROMPT,
MSG_SET_AS_DEFAULT_HELP, MSG_SET_AS_DEFAULT_PROMPT, MSG_WALLET_CREATION_HELP,
MSG_WALLET_CREATION_PROMPT, MSG_WALLET_CREATION_VALIDATOR_ERR, MSG_WALLET_PATH_HELP,
MSG_WALLET_PATH_INVALID_ERR, MSG_WALLET_PATH_PROMPT,
},
utils::link_to_code::get_link_to_code,
};

// We need to duplicate it for using enum inside the arguments
Expand Down Expand Up @@ -67,20 +69,28 @@ pub struct ChainCreateArgs {
pub(crate) set_as_default: Option<bool>,
#[clap(long, default_value = "false")]
pub(crate) legacy_bridge: bool,
#[clap(long, help = MSG_L1_NETWORK_HELP, value_enum)]
pub l1_network: Option<L1Network>,
}

impl ChainCreateArgs {
pub fn fill_values_with_prompt(
self,
shell: &Shell,
number_of_chains: u32,
l1_network: &L1Network,
l1_network: Option<L1Network>,
possible_erc20: Vec<Erc20Token>,
chains_path: Option<PathBuf>,
link_to_code: Option<String>,
era_chain_id: L2ChainId,
) -> anyhow::Result<ChainCreateArgsFinal> {
let mut chain_name = self
.chain_name
.unwrap_or_else(|| Prompt::new(MSG_CHAIN_NAME_PROMPT).ask());
chain_name = slugify!(&chain_name, separator = "_");

let chain_path = chains_path.unwrap_or_default().join(&chain_name);

let chain_id = self
.chain_id
.map(|v| match v {
Expand All @@ -93,8 +103,16 @@ impl ChainCreateArgs {
.ask()
});

let l1_network = l1_network.unwrap_or_else(|| {
self.l1_network.unwrap_or_else(|| {
PromptSelect::new(MSG_L1_NETWORK_PROMPT, L1Network::iter()).ask()
})
});

let link_to_code = link_to_code.unwrap_or_else(|| get_link_to_code(shell));

let wallet_creation = if let Some(wallet) = self.wallet_creation {
if wallet == WalletCreation::Localhost && *l1_network != L1Network::Localhost {
if wallet == WalletCreation::Localhost && l1_network != L1Network::Localhost {
bail!(MSG_WALLET_CREATION_VALIDATOR_ERR);
} else {
wallet
Expand All @@ -104,7 +122,7 @@ impl ChainCreateArgs {
MSG_WALLET_CREATION_PROMPT,
WalletCreation::iter().filter(|wallet| {
// Disable localhost wallets for external networks
if *l1_network == L1Network::Localhost {
if l1_network == L1Network::Localhost {
true
} else {
*wallet != WalletCreation::Localhost
Expand Down Expand Up @@ -212,6 +230,9 @@ impl ChainCreateArgs {
};

let set_as_default = self.set_as_default.unwrap_or_else(|| {
if number_of_chains == 0 {
return true;
}
PromptConfirm::new(MSG_SET_AS_DEFAULT_PROMPT)
.default(true)
.ask()
Expand All @@ -227,6 +248,11 @@ impl ChainCreateArgs {
base_token,
set_as_default,
legacy_bridge: self.legacy_bridge,
chain_path,
era_chain_id,
number_of_chains,
l1_network,
link_to_code,
})
}
}
Expand All @@ -242,6 +268,11 @@ pub struct ChainCreateArgsFinal {
pub base_token: BaseToken,
pub set_as_default: bool,
pub legacy_bridge: bool,
pub chain_path: PathBuf,
pub era_chain_id: L2ChainId,
pub number_of_chains: u32,
pub l1_network: L1Network,
pub link_to_code: String,
}

#[derive(Debug, Clone, EnumIter, Display, PartialEq, Eq)]
Expand Down
1 change: 1 addition & 0 deletions zkstack_cli/crates/zkstack/src/commands/chain/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod build_transactions;
pub mod create;
pub mod genesis;
pub mod init;
pub mod run_server;
Loading