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): Make chain create independent from ecosystem #3210

Open
wants to merge 24 commits into
base: matias/refactor-chain-commands
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
027bd85
Update CreateChainArgs
matias-gonz Oct 21, 2024
38084c4
lint autocomplete
matias-gonz Oct 31, 2024
cc3082b
generate autocomplete
matias-gonz Oct 31, 2024
86b9a18
lint
matias-gonz Oct 31, 2024
7426f9d
Merge branch 'main' into matias/separate-chain-create
matias-gonz Oct 31, 2024
48c3765
Lint autocomplete
matias-gonz Oct 31, 2024
070e6a8
Merge branch 'matias/separate-chain-create' of github.com:matter-labs…
matias-gonz Oct 31, 2024
38c02dd
Add link_to_code
matias-gonz Oct 31, 2024
5283211
Add chain path and era_chain_id to CreateChainArgs
matias-gonz Oct 21, 2024
0a890a4
Fix resolve_link_to_code
matias-gonz Oct 23, 2024
9e1d0b9
Add number_of_chains to ChainCreateArgsFinal
matias-gonz Oct 21, 2024
a15b7f2
Fix set_as_default
matias-gonz Oct 23, 2024
9d25c9b
Add l1_network to ChainCreateArgsFinal
matias-gonz Oct 21, 2024
a8d4496
Add evm-emulator arg to ci
matias-gonz Oct 31, 2024
bcd91de
Merge branch 'matias/refactor-chain-commands' of github.com:matter-la…
matias-gonz Oct 31, 2024
b429086
Fix internal_id
matias-gonz Oct 31, 2024
c962182
Merge branch 'main' into matias/separate-chain-create
matias-gonz Nov 5, 2024
01e18f5
lint
matias-gonz Nov 5, 2024
860e6f6
Merge branch 'matias/refactor-chain-commands' of github.com:matter-la…
matias-gonz Nov 5, 2024
b58b8d1
Merge branch 'matias/refactor-chain-commands' of github.com:matter-la…
matias-gonz Nov 7, 2024
d3b8eef
Merge branch 'matias/refactor-chain-commands' of github.com:matter-la…
matias-gonz Nov 11, 2024
099c351
Fix internal_id
matias-gonz Nov 11, 2024
3243f96
Make link_to_code accessible from crate only
matias-gonz Nov 11, 2024
73711ef
Merge branch 'matias/refactor-chain-commands' of github.com:matter-la…
matias-gonz Nov 13, 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
15 changes: 10 additions & 5 deletions .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,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 Down Expand Up @@ -262,7 +263,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 init \
--deploy-paymaster \
Expand All @@ -283,7 +285,8 @@ jobs:
--base-token-price-nominator 314 \
--base-token-price-denominator 1000 \
--set-as-default false \
--ignore-prerequisites
--ignore-prerequisites \
--evm-emulator false

ci_run zkstack chain init \
--deploy-paymaster \
Expand All @@ -304,7 +307,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 @@ -339,7 +343,8 @@ jobs:
--base-token-price-nominator 314 \
--base-token-price-denominator 1000 \
--set-as-default false \
--ignore-prerequisites
--ignore-prerequisites \
--evm-emulator false

ci_run zkstack chain init \
--deploy-paymaster \
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
2 changes: 2 additions & 0 deletions zkstack_cli/crates/zkstack/completion/_zkstack.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ in-file\:"Specify file with wallets"))' \
'--base-token-price-denominator=[Base token denominator]:BASE_TOKEN_PRICE_DENOMINATOR:_default' \
'--set-as-default=[Set as default chain]' \
'--evm-emulator=[Enable EVM emulator]' \
'--l1-network=[L1 Network]:L1_NETWORK:(localhost sepolia holesky mainnet)' \
'--start-containers=[Start reth and postgres containers after creation]' \
'--chain=[Chain to use]:CHAIN:_default' \
'--legacy-bridge[]' \
Expand Down Expand Up @@ -243,6 +244,7 @@ in-file\:"Specify file with wallets"))' \
'--base-token-price-denominator=[Base token denominator]:BASE_TOKEN_PRICE_DENOMINATOR:_default' \
'--set-as-default=[Set as default chain]' \
'--evm-emulator=[Enable EVM emulator]' \
'--l1-network=[L1 Network]:L1_NETWORK:(localhost sepolia holesky mainnet)' \
'--chain=[Chain to use]:CHAIN:_default' \
'--legacy-bridge[]' \
'-v[Verbose mode]' \
Expand Down
2 changes: 2 additions & 0 deletions zkstack_cli/crates/zkstack/completion/zkstack.fish
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_se
complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l base-token-price-denominator -d 'Base token denominator' -r
complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l set-as-default -d 'Set as default chain' -r -f -a "{true\t'',false\t''}"
complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l evm-emulator -d 'Enable EVM emulator' -r -f -a "{true\t'',false\t''}"
complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l l1-network -d 'L1 Network' -r -f -a "{localhost\t'',sepolia\t'',holesky\t'',mainnet\t''}"
complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l start-containers -d 'Start reth and postgres containers after creation' -r -f -a "{true\t'',false\t''}"
complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l chain -d 'Chain to use' -r
complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from create" -l legacy-bridge
Expand Down Expand Up @@ -159,6 +160,7 @@ complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_s
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -l base-token-price-denominator -d 'Base token denominator' -r
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -l set-as-default -d 'Set as default chain' -r -f -a "{true\t'',false\t''}"
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -l evm-emulator -d 'Enable EVM emulator' -r -f -a "{true\t'',false\t''}"
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -l l1-network -d 'L1 Network' -r -f -a "{localhost\t'',sepolia\t'',holesky\t'',mainnet\t''}"
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -l chain -d 'Chain to use' -r
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -l legacy-bridge
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from create" -s v -l verbose -d 'Verbose mode'
Expand Down
12 changes: 10 additions & 2 deletions zkstack_cli/crates/zkstack/completion/zkstack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,7 @@ _zkstack() {
return 0
;;
zkstack__chain__create)
opts="-v -h --chain-name --chain-id --prover-mode --wallet-creation --wallet-path --l1-batch-commit-data-generator-mode --base-token-address --base-token-price-nominator --base-token-price-denominator --set-as-default --legacy-bridge --evm-emulator --verbose --chain --ignore-prerequisites --help"
opts="-v -h --chain-name --chain-id --prover-mode --wallet-creation --wallet-path --l1-batch-commit-data-generator-mode --base-token-address --base-token-price-nominator --base-token-price-denominator --set-as-default --legacy-bridge --evm-emulator --l1-network --verbose --chain --ignore-prerequisites --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -1713,6 +1713,10 @@ _zkstack() {
COMPREPLY=($(compgen -W "true false" -- "${cur}"))
return 0
;;
--l1-network)
COMPREPLY=($(compgen -W "localhost sepolia holesky mainnet" -- "${cur}"))
return 0
;;
--chain)
COMPREPLY=($(compgen -f "${cur}"))
return 0
Expand Down Expand Up @@ -5309,7 +5313,7 @@ _zkstack() {
return 0
;;
zkstack__ecosystem__create)
opts="-v -h --ecosystem-name --l1-network --link-to-code --chain-name --chain-id --prover-mode --wallet-creation --wallet-path --l1-batch-commit-data-generator-mode --base-token-address --base-token-price-nominator --base-token-price-denominator --set-as-default --legacy-bridge --evm-emulator --start-containers --verbose --chain --ignore-prerequisites --help"
opts="-v -h --ecosystem-name --l1-network --link-to-code --chain-name --chain-id --prover-mode --wallet-creation --wallet-path --l1-batch-commit-data-generator-mode --base-token-address --base-token-price-nominator --base-token-price-denominator --set-as-default --legacy-bridge --evm-emulator --l1-network --start-containers --verbose --chain --ignore-prerequisites --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -5385,6 +5389,10 @@ _zkstack() {
COMPREPLY=($(compgen -W "true false" -- "${cur}"))
return 0
;;
--l1-network)
COMPREPLY=($(compgen -W "localhost sepolia holesky mainnet" -- "${cur}"))
return 0
;;
--start-containers)
COMPREPLY=($(compgen -W "true false" -- "${cur}"))
return 0
Expand Down
82 changes: 46 additions & 36 deletions zkstack_cli/crates/zkstack/src/commands/chain/args/create.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
use std::{
path::{Path, PathBuf},
str::FromStr,
};
use std::{path::PathBuf, str::FromStr};

use anyhow::{bail, Context};
use clap::{Parser, ValueEnum, ValueHint};
use common::{Prompt, PromptConfirm, PromptSelect};
use config::{
forge_interface::deploy_ecosystem::output::Erc20Token, traits::ReadConfigWithBasePath,
EcosystemConfig,
};
use config::forge_interface::deploy_ecosystem::output::Erc20Token;
use serde::{Deserialize, Serialize};
use slugify_rs::slugify;
use strum::{Display, EnumIter, IntoEnumIterator};
use types::{BaseToken, L1BatchCommitmentMode, L1Network, ProverMode, WalletCreation};
use xshell::Shell;
use zksync_basic_types::H160;
use zksync_config::GenesisConfig;
use zksync_basic_types::{L2ChainId, H160};

use crate::{
defaults::L2_CHAIN_ID,
Expand All @@ -26,14 +19,15 @@ use crate::{
MSG_BASE_TOKEN_PRICE_DENOMINATOR_PROMPT, MSG_BASE_TOKEN_PRICE_NOMINATOR_HELP,
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_EVM_EMULATOR_HASH_MISSING_ERR, MSG_EVM_EMULATOR_HELP, MSG_EVM_EMULATOR_PROMPT,
MSG_EVM_EMULATOR_HELP, MSG_EVM_EMULATOR_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 @@ -78,22 +72,30 @@ pub struct ChainCreateArgs {
pub(crate) legacy_bridge: bool,
#[arg(long, help = MSG_EVM_EMULATOR_HELP, default_missing_value = "true", num_args = 0..=1)]
evm_emulator: Option<bool>,
#[clap(long, help = MSG_L1_NETWORK_HELP, value_enum)]
pub l1_network: Option<L1Network>,
}

impl ChainCreateArgs {
#[allow(clippy::too_many_arguments)]
pub fn fill_values_with_prompt(
self,
shell: &Shell,
number_of_chains: u32,
l1_network: &L1Network,
internal_id: u32,
l1_network: Option<L1Network>,
possible_erc20: Vec<Erc20Token>,
link_to_code: &Path,
link_to_code: Option<String>,
chains_path: Option<PathBuf>,
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 @@ -106,8 +108,14 @@ 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()
})
});
Comment on lines +111 to +115
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks a bit odd. Why do we have two places for l1 network?


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 @@ -117,7 +125,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 @@ -224,26 +232,18 @@ impl ChainCreateArgs {
}
};

let default_genesis_config = GenesisConfig::read_with_base_path(
shell,
EcosystemConfig::default_configs_path(link_to_code),
)
.context("failed reading genesis config")?;
let has_evm_emulation_support = default_genesis_config.evm_emulator_hash.is_some();
let link_to_code = link_to_code.unwrap_or_else(|| get_link_to_code(shell));

let evm_emulator = self.evm_emulator.unwrap_or_else(|| {
if !has_evm_emulation_support {
false
} else {
PromptConfirm::new(MSG_EVM_EMULATOR_PROMPT)
.default(false)
.ask()
}
PromptConfirm::new(MSG_EVM_EMULATOR_PROMPT)
.default(false)
.ask()
});
if !has_evm_emulation_support && evm_emulator {
bail!(MSG_EVM_EMULATOR_HASH_MISSING_ERR);
}

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 @@ -260,6 +260,11 @@ impl ChainCreateArgs {
set_as_default,
legacy_bridge: self.legacy_bridge,
evm_emulator,
link_to_code,
chain_path,
era_chain_id,
internal_id,
l1_network,
})
}
}
Expand All @@ -276,6 +281,11 @@ pub struct ChainCreateArgsFinal {
pub set_as_default: bool,
pub legacy_bridge: bool,
pub evm_emulator: bool,
pub link_to_code: String,
pub chain_path: PathBuf,
pub era_chain_id: L2ChainId,
pub internal_id: u32,
pub l1_network: L1Network,
}

#[derive(Debug, Clone, EnumIter, Display, PartialEq, Eq)]
Expand Down
Loading
Loading