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): [WIP] Make chain init independent from ecosystem #3231

Draft
wants to merge 27 commits into
base: matias/separate-chain-create
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d305c83
Update link to code in init_configs
matias-gonz Oct 29, 2024
b4bf47a
Update l1_network in distribute_eth
matias-gonz Oct 29, 2024
89e7eaa
Update l1_network in mint_base_token
matias-gonz Oct 29, 2024
93970f3
Update link_to_code in register_chain
matias-gonz Oct 29, 2024
97a9e19
Update path_to_foundry in register_chain
matias-gonz Oct 29, 2024
3f35ab9
Update path_to_foundry in accept_admin
matias-gonz Oct 29, 2024
187603e
Update path_to_foundry in set_token_multiplier_setter
matias-gonz Oct 29, 2024
4521114
Update link_to_code in deploy_l2_contracts
matias-gonz Oct 29, 2024
b5f4e8d
lint
matias-gonz Nov 5, 2024
e21ec41
Add contracts path placeholder
matias-gonz Nov 6, 2024
0a1a027
Add prompt_ecosystem_contracts_path
matias-gonz Oct 30, 2024
dcb3836
Add ecosystem_contracts_path arg
matias-gonz Nov 6, 2024
26a8bf8
Merge branch 'matias/separate-chain-create' of github.com:matter-labs…
matias-gonz Nov 7, 2024
72fd941
Reorder functions
matias-gonz Nov 7, 2024
c1793f9
Fix CI
matias-gonz Nov 8, 2024
2b10f23
Merge branch 'matias/separate-chain-create' of github.com:matter-labs…
matias-gonz Nov 11, 2024
b55dd6f
fmt
matias-gonz Nov 11, 2024
3c2d4a0
Merge branch 'matias/separate-chain-create' of github.com:matter-labs…
matias-gonz Nov 13, 2024
3a65f21
Fix ecosystem_contracts_path
matias-gonz Nov 15, 2024
464bdfa
Remove ecosystem contracts path from ci
matias-gonz Nov 15, 2024
34409c5
Fix prompt when ecosystem exists
matias-gonz Nov 15, 2024
3cea484
lint
matias-gonz Nov 15, 2024
48490c1
Refactor distribute_eth and mint_base_token
matias-gonz Nov 15, 2024
4b83c2a
Add wallets_path to InitArgs
matias-gonz Nov 15, 2024
a42517c
lint
matias-gonz Nov 15, 2024
a43532f
Make wallets_path non optional
matias-gonz Nov 15, 2024
542df91
Add wallets to register_chain
matias-gonz Nov 15, 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
6 changes: 5 additions & 1 deletion zkstack_cli/crates/config/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
FileConfigWithDefaultName, ReadConfig, ReadConfigWithBasePath, SaveConfig,
SaveConfigWithBasePath, ZkStackConfig,
},
utils::find_file,
utils::{find_file, get_preexisting_ecosystem_contracts_path},
ContractsConfig, EcosystemConfig, GeneralConfig, GenesisConfig, SecretsConfig, WalletsConfig,
};

Expand Down Expand Up @@ -151,6 +151,10 @@ impl ChainConfig {
config.save_with_base_path(shell, path)
}

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

fn get_internal(&self) -> ChainConfigInternal {
ChainConfigInternal {
id: self.id,
Expand Down
24 changes: 16 additions & 8 deletions zkstack_cli/crates/config/src/ecosystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +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,
utils::{find_file, get_preexisting_ecosystem_contracts_path},
ChainConfig, ChainConfigInternal, ContractsConfig, WalletsConfig,
};

Expand Down Expand Up @@ -197,7 +197,7 @@ impl EcosystemConfig {
}

pub fn get_wallets(&self) -> anyhow::Result<WalletsConfig> {
let path = self.config.join(WALLETS_FILE);
let path = self.get_wallets_path();
if self.get_shell().path_exists(&path) {
return WalletsConfig::read(self.get_shell(), &path);
}
Expand All @@ -211,7 +211,7 @@ impl EcosystemConfig {
}

pub fn get_contracts_config(&self) -> anyhow::Result<ContractsConfig> {
ContractsConfig::read(self.get_shell(), self.config.join(CONTRACTS_FILE))
ContractsConfig::read(self.get_shell(), self.get_contracts_path())
}

pub fn path_to_foundry(&self) -> PathBuf {
Expand Down Expand Up @@ -242,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 @@ -272,6 +272,14 @@ impl EcosystemConfig {
wallet_creation: self.wallet_creation,
}
}

pub fn get_contracts_path(&self) -> PathBuf {
self.config.join(CONTRACTS_FILE)
}

pub fn get_wallets_path(&self) -> PathBuf {
self.config.join(WALLETS_FILE)
}
}

/// Result of checking if the ecosystem exists.
Expand Down
14 changes: 13 additions & 1 deletion zkstack_cli/crates/config/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::path::PathBuf;
use std::path::{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);
Expand All @@ -15,3 +18,12 @@ pub fn find_file(shell: &Shell, path_buf: PathBuf, file_name: &str) -> Result<Pa
find_file(shell, path.to_path_buf(), file_name)
}
}

pub fn get_preexisting_ecosystem_contracts_path(
link_to_code: &Path,
l1_network: L1Network,
) -> PathBuf {
link_to_code
.join(ECOSYSTEM_PATH)
.join(format!("{}.yaml", l1_network.to_string().to_lowercase()))
}
3 changes: 3 additions & 0 deletions zkstack_cli/crates/zkstack/completion/_zkstack.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ _arguments "${_arguments_options[@]}" : \
'--server-db-name=[Server database name]:SERVER_DB_NAME:_default' \
'--deploy-paymaster=[]' \
'--l1-rpc-url=[L1 RPC URL]:L1_RPC_URL:_default' \
'--ecosystem-contracts-path=[Ecosystem contracts path]:ECOSYSTEM_CONTRACTS_PATH:_default' \
'--wallets-path=[Wallets path]:WALLETS_PATH:_default' \
'--chain=[Chain to use]:CHAIN:_default' \
'--resume[]' \
'-d[]' \
Expand All @@ -312,6 +314,7 @@ _arguments "${_arguments_options[@]}" : \
'--server-db-url=[Server database url without database name]:SERVER_DB_URL:_default' \
'--server-db-name=[Server database name]:SERVER_DB_NAME:_default' \
'--l1-rpc-url=[L1 RPC URL]:L1_RPC_URL:_default' \
'--ecosystem-contracts-path=[Ecosystem contracts path]:ECOSYSTEM_CONTRACTS_PATH:_default' \
'--chain=[Chain to use]:CHAIN:_default' \
'-d[Use default database urls and names]' \
'--dev[Use default database urls and names]' \
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 @@ -187,6 +187,8 @@ 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 init" -l server-db-name -d 'Server database name' -r
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l deploy-paymaster -r -f -a "{true\t'',false\t''}"
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l l1-rpc-url -d 'L1 RPC URL' -r
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l ecosystem-contracts-path -d 'Ecosystem contracts path' -r
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l wallets-path -d 'Wallets path' -r
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l chain -d 'Chain to use' -r
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l resume
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -s d -l dont-drop
Expand Down
16 changes: 14 additions & 2 deletions zkstack_cli/crates/zkstack/completion/zkstack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2555,7 +2555,7 @@ _zkstack() {
return 0
;;
zkstack__chain__init)
opts="-a -d -v -h --verify --verifier --verifier-url --verifier-api-key --resume --additional-args --server-db-url --server-db-name --dont-drop --deploy-paymaster --l1-rpc-url --no-port-reallocation --dev --verbose --chain --ignore-prerequisites --help configs help"
opts="-a -d -v -h --verify --verifier --verifier-url --verifier-api-key --resume --additional-args --server-db-url --server-db-name --dont-drop --deploy-paymaster --l1-rpc-url --no-port-reallocation --ecosystem-contracts-path --wallets-path --dev --verbose --chain --ignore-prerequisites --help configs help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -2601,6 +2601,14 @@ _zkstack() {
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--ecosystem-contracts-path)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--wallets-path)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--chain)
COMPREPLY=($(compgen -f "${cur}"))
return 0
Expand All @@ -2613,7 +2621,7 @@ _zkstack() {
return 0
;;
zkstack__chain__init__configs)
opts="-d -d -v -h --server-db-url --server-db-name --dev --dont-drop --l1-rpc-url --no-port-reallocation --verbose --chain --ignore-prerequisites --help"
opts="-d -d -v -h --server-db-url --server-db-name --dev --dont-drop --l1-rpc-url --no-port-reallocation --ecosystem-contracts-path --verbose --chain --ignore-prerequisites --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand All @@ -2631,6 +2639,10 @@ _zkstack() {
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--ecosystem-contracts-path)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--chain)
COMPREPLY=($(compgen -f "${cur}"))
return 0
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
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
63 changes: 54 additions & 9 deletions zkstack_cli/crates/zkstack/src/commands/chain/args/init/configs.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
use std::path::PathBuf;

use clap::Parser;
use common::Prompt;
use config::ChainConfig;
use config::{ChainConfig, EcosystemConfig};
use serde::{Deserialize, Serialize};
use types::L1Network;
use url::Url;

use crate::{
commands::chain::args::{
genesis::{GenesisArgs, GenesisArgsFinal},
init::InitArgsFinal,
commands::{
chain::args::{
genesis::{GenesisArgs, GenesisArgsFinal},
init::InitArgsFinal,
},
ecosystem::init::prompt_ecosystem_contracts_path,
},
defaults::LOCAL_RPC_URL,
messages::{
msg_ecosystem_no_found_preexisting_contract, MSG_ECOSYSTEM_CONTRACTS_PATH_HELP,
MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR,
MSG_L1_RPC_URL_PROMPT, MSG_NO_PORT_REALLOCATION_HELP,
},
Expand All @@ -26,20 +32,27 @@ pub struct InitConfigsArgs {
pub l1_rpc_url: Option<String>,
#[clap(long, help = MSG_NO_PORT_REALLOCATION_HELP)]
pub no_port_reallocation: bool,
#[clap(long, help = MSG_ECOSYSTEM_CONTRACTS_PATH_HELP)]
pub ecosystem_contracts_path: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct InitConfigsArgsFinal {
pub genesis_args: GenesisArgsFinal,
pub l1_rpc_url: String,
pub no_port_reallocation: bool,
pub ecosystem_contracts_path: PathBuf,
}

impl InitConfigsArgs {
pub fn fill_values_with_prompt(self, config: &ChainConfig) -> InitConfigsArgsFinal {
pub fn fill_values_with_prompt(
self,
ecosystem: Option<EcosystemConfig>,
chain: &ChainConfig,
) -> anyhow::Result<InitConfigsArgsFinal> {
let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| {
let mut prompt = Prompt::new(MSG_L1_RPC_URL_PROMPT);
if config.l1_network == L1Network::Localhost {
if chain.l1_network == L1Network::Localhost {
prompt = prompt.default(LOCAL_RPC_URL);
}
prompt
Expand All @@ -51,12 +64,43 @@ impl InitConfigsArgs {
.ask()
});

InitConfigsArgsFinal {
genesis_args: self.genesis_args.fill_values_with_prompt(config),
let ecosystem_contracts_path =
get_ecosystem_contracts_path(self.ecosystem_contracts_path, ecosystem, chain)?;

Ok(InitConfigsArgsFinal {
genesis_args: self.genesis_args.fill_values_with_prompt(chain),
l1_rpc_url,
no_port_reallocation: self.no_port_reallocation,
}
ecosystem_contracts_path,
})
}
}

pub fn get_ecosystem_contracts_path(
ecosystem_contracts_path: Option<String>,
ecosystem: Option<EcosystemConfig>,
chain: &ChainConfig,
) -> anyhow::Result<PathBuf> {
let ecosystem_preexisting_configs_path = ecosystem.map_or_else(
|| chain.get_preexisting_ecosystem_contracts_path(),
|e| e.get_preexisting_ecosystem_contracts_path(),
);

let ecosystem_contracts_path =
ecosystem_contracts_path.map_or_else(prompt_ecosystem_contracts_path, |path| {
if path.is_empty() {
return None;
}
Some(PathBuf::from(path))
});

if ecosystem_contracts_path.is_none() && !ecosystem_preexisting_configs_path.exists() {
anyhow::bail!(msg_ecosystem_no_found_preexisting_contract(
&chain.l1_network.to_string()
))
}

Ok(ecosystem_contracts_path.unwrap_or(ecosystem_preexisting_configs_path))
}

impl InitConfigsArgsFinal {
Expand All @@ -65,6 +109,7 @@ impl InitConfigsArgsFinal {
genesis_args: init_args.genesis_args.clone(),
l1_rpc_url: init_args.l1_rpc_url.clone(),
no_port_reallocation: init_args.no_port_reallocation,
ecosystem_contracts_path: init_args.ecosystem_contracts_path.clone(),
}
}
}
Loading
Loading