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 and chain configs: 3 layered chain #3087

Draft
wants to merge 44 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f56e9c2
Migrate server to chain
matias-gonz Oct 13, 2024
409e768
Migrate contract verifier to chain
matias-gonz Oct 13, 2024
2d4f8fc
Migrate consensus to chain
matias-gonz Oct 13, 2024
ba8b707
fmt
matias-gonz Oct 13, 2024
8d238d5
Fix consensus proto
matias-gonz Oct 13, 2024
5b314a6
Fix consensus command
matias-gonz Oct 15, 2024
8f7d9f7
Add ZkStackConfig enum
matias-gonz Oct 15, 2024
ca2f0e8
fmt
matias-gonz Oct 15, 2024
8f046fd
Refactor deploy paymaster
matias-gonz Oct 17, 2024
62e69be
Refactor chain commands
matias-gonz Oct 17, 2024
06ddc2c
rollback consensus
matias-gonz Oct 17, 2024
1b12e6e
Refactor chain consensus setup
matias-gonz Oct 18, 2024
c2f326c
Merge branch 'main' into matias/refactor-3-layered-chain
matias-gonz Oct 18, 2024
4e94f2e
Update CreateChainArgs
matias-gonz Oct 21, 2024
45bfa7b
Add era_chain_id to CreateChainArgs
matias-gonz Oct 21, 2024
6a39175
Add number_of_chains to ChainCreateArgsFinal
matias-gonz Oct 21, 2024
a40d963
Add l1_network to ChainCreateArgsFinal
matias-gonz Oct 21, 2024
6f25abb
Add link_to_code to ChainCreateArgsFinal
matias-gonz Oct 23, 2024
b32eb3d
Fix resolve_link_to_code
matias-gonz Oct 23, 2024
26a7172
Fix set_as_default
matias-gonz Oct 23, 2024
337b615
Merge branch 'main' of github.com:matter-labs/zksync-era into matias/…
matias-gonz Oct 25, 2024
0f0af15
Merge branch 'main' into matias/refactor-3-layered-chain
matias-gonz Oct 28, 2024
3061053
Merge branch 'main' into matias/refactor-3-layered-chain
matias-gonz Oct 29, 2024
c4e07c9
Fix evm emulator
matias-gonz Oct 29, 2024
3d24cdd
lint
matias-gonz Oct 29, 2024
bc8bb53
Merge branch 'main' into matias/refactor-3-layered-chain
matias-gonz Oct 29, 2024
58200d8
Fix CI
matias-gonz Oct 29, 2024
db44b09
Update link to code in init_configs
matias-gonz Oct 29, 2024
1fa3e74
Update l1_network in distribute_eth
matias-gonz Oct 29, 2024
ead4878
Update l1_network in mint_base_token
matias-gonz Oct 29, 2024
fabfa90
Update link_to_code in register_chain
matias-gonz Oct 29, 2024
9249bce
Update path_to_foundry in register_chain
matias-gonz Oct 29, 2024
0224d3c
Update path_to_foundry in accept_admin
matias-gonz Oct 29, 2024
e2f0d1f
Update path_to_foundry in set_token_multiplier_setter
matias-gonz Oct 29, 2024
a1ab65b
Update link_to_code in deploy_l2_contracts
matias-gonz Oct 29, 2024
a93e767
fmt
matias-gonz Oct 29, 2024
dbdadf8
Fix ci
matias-gonz Oct 29, 2024
90416db
lint
matias-gonz Oct 30, 2024
2e11732
Add prompt_ecosystem_contracts_path
matias-gonz Oct 30, 2024
7357ef1
Merge branch 'main' into matias/refactor-3-layered-chain
matias-gonz Oct 30, 2024
39fd31e
Fix yarn lock
matias-gonz Oct 30, 2024
a4ebbe8
Add newline
matias-gonz Oct 30, 2024
527135a
fix yarn lock
matias-gonz Oct 30, 2024
0b1370d
Merge branch 'main' into matias/refactor-3-layered-chain
matias-gonz Oct 30, 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
29 changes: 17 additions & 12 deletions .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ jobs:
--base-token-price-denominator 1 \
--set-as-default false \
--ignore-prerequisites \
--legacy-bridge
--legacy-bridge \
--evm-emulator false

ci_run zkstack ecosystem init --dev --verbose
ci_run zkstack dev contracts --test-contracts
Expand All @@ -152,7 +153,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 @@ -258,6 +259,7 @@ jobs:
--base-token-price-nominator 1 \
--base-token-price-denominator 1 \
--set-as-default false \
--evm-emulator false \
--ignore-prerequisites

ci_run zkstack chain init \
Expand All @@ -279,7 +281,8 @@ jobs:
--base-token-price-nominator 3 \
--base-token-price-denominator 2 \
--set-as-default false \
--ignore-prerequisites
--ignore-prerequisites \
--evm-emulator false

ci_run zkstack chain init \
--deploy-paymaster \
Expand All @@ -300,7 +303,8 @@ jobs:
--base-token-price-nominator 1 \
--base-token-price-denominator 1 \
--set-as-default false \
--ignore-prerequisites
--ignore-prerequisites \
--evm-emulator false

ci_run zkstack chain build-transactions --chain offline_chain --l1-rpc-url http://127.0.0.1:8545

Expand Down Expand Up @@ -335,7 +339,8 @@ jobs:
--base-token-price-nominator 3 \
--base-token-price-denominator 2 \
--set-as-default false \
--ignore-prerequisites
--ignore-prerequisites \
--evm-emulator false

ci_run zkstack chain init \
--deploy-paymaster \
Expand All @@ -355,27 +360,27 @@ 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: |
# Override config for part of chains to test the default config as well
ci_run zkstack dev config-writer --path etc/env/file_based/overrides/tests/integration.yaml --chain era
ci_run zkstack dev config-writer --path etc/env/file_based/overrides/tests/integration.yaml --chain validium

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
35 changes: 34 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, get_preexisting_ecosystem_contracts_path},
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 @@ -100,6 +104,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 @@ -156,13 +161,41 @@ 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,
legacy_bridge: self.legacy_bridge,
evm_emulator: self.evm_emulator,
}
}

pub fn get_preexisting_ecosystem_contracts_path(&self) -> PathBuf {
get_preexisting_ecosystem_contracts_path(&self.link_to_code, self.l1_network)
}
}

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 {
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
25 changes: 6 additions & 19 deletions zkstack_cli/crates/config/src/ecosystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ use zksync_basic_types::L2ChainId;

use crate::{
consts::{
CONFIGS_PATH, CONFIG_NAME, CONTRACTS_FILE, ECOSYSTEM_PATH, ERA_CHAIN_ID,
ERC20_CONFIGS_FILE, ERC20_DEPLOYMENT_FILE, INITIAL_DEPLOYMENT_FILE, L1_CONTRACTS_FOUNDRY,
LOCAL_ARTIFACTS_PATH, LOCAL_DB_PATH, WALLETS_FILE,
CONFIGS_PATH, CONFIG_NAME, CONTRACTS_FILE, ERA_CHAIN_ID, ERC20_CONFIGS_FILE,
ERC20_DEPLOYMENT_FILE, INITIAL_DEPLOYMENT_FILE, L1_CONTRACTS_FOUNDRY, LOCAL_ARTIFACTS_PATH,
LOCAL_DB_PATH, WALLETS_FILE,
},
create_localhost_wallets,
forge_interface::deploy_ecosystem::{
input::{Erc20DeploymentConfig, InitialDeploymentConfig},
output::{ERC20Tokens, Erc20Token},
},
traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig, ZkStackConfig},
utils::{find_file, get_preexisting_ecosystem_contracts_path},
ChainConfig, ChainConfigInternal, ContractsConfig, WalletsConfig,
};

Expand Down Expand Up @@ -241,8 +242,8 @@ impl EcosystemConfig {
}

/// Path to the predefined ecosystem configs
pub fn get_preexisting_configs_path(&self) -> PathBuf {
self.link_to_code.join(ECOSYSTEM_PATH)
pub fn get_preexisting_ecosystem_contracts_path(&self) -> PathBuf {
get_preexisting_ecosystem_contracts_path(&self.link_to_code, self.l1_network)
}

pub fn get_chain_rocks_db_path(&self, chain_name: &str) -> PathBuf {
Expand Down Expand Up @@ -287,20 +288,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;
29 changes: 29 additions & 0 deletions zkstack_cli/crates/config/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::path::PathBuf;

use types::L1Network;
use xshell::Shell;

use crate::ECOSYSTEM_PATH;

// 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)
}
}

pub fn get_preexisting_ecosystem_contracts_path(
link_to_code: &PathBuf,
l1_network: L1Network,
) -> PathBuf {
link_to_code
.join(ECOSYSTEM_PATH)
.join(format!("{}.yaml", l1_network.to_string().to_lowercase()))
}
56 changes: 56 additions & 0 deletions zkstack_cli/crates/config/src/zkstack_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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(),
evm_emulator: chain_internal.evm_emulator,
};

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 @@ -26,7 +26,7 @@ fn main() -> anyhow::Result<()> {
};

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
7 changes: 4 additions & 3 deletions zkstack_cli/crates/zkstack/src/accept_ownership.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::Path;

use common::{
forge::{Forge, ForgeScript, ForgeScriptArgs},
spinner::Spinner,
Expand Down Expand Up @@ -26,7 +28,7 @@ lazy_static! {

pub async fn accept_admin(
shell: &Shell,
ecosystem_config: &EcosystemConfig,
foundry_contracts_path: &Path,
admin: Address,
governor: &Wallet,
target_address: Address,
Expand All @@ -42,8 +44,7 @@ pub async fn accept_admin(
let calldata = ACCEPT_ADMIN
.encode("chainAdminAcceptAdmin", (admin, target_address))
.unwrap();
let foundry_contracts_path = ecosystem_config.path_to_foundry();
let forge = Forge::new(&foundry_contracts_path)
let forge = Forge::new(foundry_contracts_path)
.script(
&ACCEPT_GOVERNANCE_SCRIPT_PARAMS.script(),
forge_args.clone(),
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,9 +1,7 @@
pub use autocomplete::*;
pub use containers::*;
pub use run_server::*;
pub use update::*;

mod autocomplete;
mod containers;
mod run_server;
mod update;
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {
let spinner = Spinner::new(MSG_ACCEPTING_ADMIN_SPINNER);
accept_admin(
shell,
&ecosystem_config,
&chain_config.path_to_foundry(),
contracts.l1.chain_admin_addr,
&chain_config.get_wallets_config()?.governor,
contracts.l1.diamond_proxy_addr,
Expand Down
Loading
Loading