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): Add --dev flag to chain init and genesis #3152

Merged
merged 4 commits into from
Oct 23, 2024
Merged
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
19 changes: 8 additions & 11 deletions zkstack_cli/crates/zkstack/completion/_zkstack.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,10 @@ _arguments "${_arguments_options[@]}" : \
'--observability=[Enable Grafana]' \
'--chain=[Chain to use]:CHAIN: ' \
'--resume[]' \
'-u[Use default database urls and names]' \
'--use-default[Use default database urls and names]' \
'-d[]' \
'--dont-drop[]' \
'--ecosystem-only[Initialize ecosystem only and skip chain initialization (chain can be initialized later with \`chain init\` subcommand)]' \
'--dev[Deploy ecosystem using all defaults. Suitable for local development]' \
'--dev[Use defaults for all options and flags. Suitable for local development]' \
'--no-port-reallocation[Do not reallocate ports]' \
'-v[Verbose mode]' \
'--verbose[Verbose mode]' \
Expand Down Expand Up @@ -286,11 +284,10 @@ _arguments "${_arguments_options[@]}" : \
'--l1-rpc-url=[L1 RPC URL]:L1_RPC_URL: ' \
'--chain=[Chain to use]:CHAIN: ' \
'--resume[]' \
'-u[Use default database urls and names]' \
'--use-default[Use default database urls and names]' \
'-d[]' \
'--dont-drop[]' \
'--no-port-reallocation[Do not reallocate ports]' \
'--dev[Use defaults for all options and flags. Suitable for local development]' \
'-v[Verbose mode]' \
'--verbose[Verbose mode]' \
'--ignore-prerequisites[Ignores prerequisites checks]' \
Expand All @@ -312,8 +309,8 @@ _arguments "${_arguments_options[@]}" : \
'--server-db-name=[Server database name]:SERVER_DB_NAME: ' \
'--l1-rpc-url=[L1 RPC URL]:L1_RPC_URL: ' \
'--chain=[Chain to use]:CHAIN: ' \
'-u[Use default database urls and names]' \
'--use-default[Use default database urls and names]' \
'-d[Use default database urls and names]' \
'--dev[Use default database urls and names]' \
'-d[]' \
'--dont-drop[]' \
'--no-port-reallocation[Do not reallocate ports]' \
Expand Down Expand Up @@ -357,8 +354,8 @@ _arguments "${_arguments_options[@]}" : \
'--server-db-url=[Server database url without database name]:SERVER_DB_URL: ' \
'--server-db-name=[Server database name]:SERVER_DB_NAME: ' \
'--chain=[Chain to use]:CHAIN: ' \
'-u[Use default database urls and names]' \
'--use-default[Use default database urls and names]' \
'-d[Use default database urls and names]' \
'--dev[Use default database urls and names]' \
'-d[]' \
'--dont-drop[]' \
'-v[Verbose mode]' \
Expand All @@ -381,8 +378,8 @@ _arguments "${_arguments_options[@]}" : \
'--server-db-url=[Server database url without database name]:SERVER_DB_URL: ' \
'--server-db-name=[Server database name]:SERVER_DB_NAME: ' \
'--chain=[Chain to use]:CHAIN: ' \
'-u[Use default database urls and names]' \
'--use-default[Use default database urls and names]' \
'-d[Use default database urls and names]' \
'--dev[Use default database urls and names]' \
'-d[]' \
'--dont-drop[]' \
'-v[Verbose mode]' \
Expand Down
7 changes: 3 additions & 4 deletions zkstack_cli/crates/zkstack/completion/zkstack.fish
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,9 @@ 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 init" -s o -l observability -d 'Enable Grafana' -r -f -a "{true\t'',false\t''}"
complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from init" -l chain -d 'Chain to use' -r
complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from init" -l resume
complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from init" -s u -l use-default -d 'Use default database urls and names'
complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from init" -s d -l dont-drop
complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from init" -l ecosystem-only -d 'Initialize ecosystem only and skip chain initialization (chain can be initialized later with `chain init` subcommand)'
complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from init" -l dev -d 'Deploy ecosystem using all defaults. Suitable for local development'
complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from init" -l dev -d 'Use defaults for all options and flags. Suitable for local development'
complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from init" -l no-port-reallocation -d 'Do not reallocate ports'
complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from init" -s v -l verbose -d 'Verbose mode'
complete -c zkstack -n "__fish_zkstack_using_subcommand ecosystem; and __fish_seen_subcommand_from init" -l ignore-prerequisites -d 'Ignores prerequisites checks'
Expand Down Expand Up @@ -185,9 +184,9 @@ 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 l1-rpc-url -d 'L1 RPC URL' -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 u -l use-default -d 'Use default database urls and names'
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -s d -l dont-drop
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l no-port-reallocation -d 'Do not reallocate ports'
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l dev -d 'Use defaults for all options and flags. Suitable for local development'
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -s v -l verbose -d 'Verbose mode'
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -l ignore-prerequisites -d 'Ignores prerequisites checks'
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from init" -s h -l help -d 'Print help (see more with \'--help\')'
Expand All @@ -196,7 +195,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 genesis" -l server-db-url -d 'Server database url without database name' -r
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from genesis" -l server-db-name -d 'Server database name' -r
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from genesis" -l chain -d 'Chain to use' -r
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from genesis" -s u -l use-default -d 'Use default database urls and names'
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from genesis" -s d -l dev -d 'Use default database urls and names'
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from genesis" -s d -l dont-drop
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from genesis" -s v -l verbose -d 'Verbose mode'
complete -c zkstack -n "__fish_zkstack_using_subcommand chain; and __fish_seen_subcommand_from genesis" -l ignore-prerequisites -d 'Ignores prerequisites checks'
Expand Down
10 changes: 5 additions & 5 deletions zkstack_cli/crates/zkstack/completion/zkstack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ _zkstack() {
return 0
;;
zkstack__chain__genesis)
opts="-u -d -v -h --server-db-url --server-db-name --use-default --dont-drop --verbose --chain --ignore-prerequisites --help init-database server help"
opts="-d -d -v -h --server-db-url --server-db-name --dev --dont-drop --verbose --chain --ignore-prerequisites --help init-database server help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -1523,7 +1523,7 @@ _zkstack() {
return 0
;;
zkstack__chain__genesis__init__database)
opts="-u -d -v -h --server-db-url --server-db-name --use-default --dont-drop --verbose --chain --ignore-prerequisites --help"
opts="-d -d -v -h --server-db-url --server-db-name --dev --dont-drop --verbose --chain --ignore-prerequisites --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -1819,7 +1819,7 @@ _zkstack() {
return 0
;;
zkstack__chain__init)
opts="-a -u -d -v -h --verify --verifier --verifier-url --verifier-api-key --resume --additional-args --server-db-url --server-db-name --use-default --dont-drop --deploy-paymaster --l1-rpc-url --no-port-reallocation --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 --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 @@ -1877,7 +1877,7 @@ _zkstack() {
return 0
;;
zkstack__chain__init__configs)
opts="-u -d -v -h --server-db-url --server-db-name --use-default --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 --verbose --chain --ignore-prerequisites --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -4829,7 +4829,7 @@ _zkstack() {
return 0
;;
zkstack__ecosystem__init)
opts="-a -u -d -o -v -h --deploy-erc20 --deploy-ecosystem --ecosystem-contracts-path --l1-rpc-url --verify --verifier --verifier-url --verifier-api-key --resume --additional-args --deploy-paymaster --server-db-url --server-db-name --use-default --dont-drop --ecosystem-only --dev --observability --no-port-reallocation --verbose --chain --ignore-prerequisites --help"
opts="-a -d -o -v -h --deploy-erc20 --deploy-ecosystem --ecosystem-contracts-path --l1-rpc-url --verify --verifier --verifier-url --verifier-api-key --resume --additional-args --deploy-paymaster --server-db-url --server-db-name --dont-drop --ecosystem-only --dev --observability --no-port-reallocation --verbose --chain --ignore-prerequisites --help"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down
4 changes: 2 additions & 2 deletions zkstack_cli/crates/zkstack/src/commands/chain/args/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct GenesisArgs {
#[clap(long, help = MSG_SERVER_DB_NAME_HELP)]
pub server_db_name: Option<String>,
#[clap(long, short, help = MSG_USE_DEFAULT_DATABASES_HELP)]
pub use_default: bool,
pub dev: bool,
#[clap(long, short, action)]
pub dont_drop: bool,
}
Expand All @@ -30,7 +30,7 @@ impl GenesisArgs {
pub fn fill_values_with_prompt(self, config: &ChainConfig) -> GenesisArgsFinal {
let DBNames { server_name, .. } = generate_db_names(config);
let chain_name = config.name.clone();
if self.use_default {
if self.dev {
GenesisArgsFinal {
server_db: DatabaseConfig::new(DATABASE_SERVER_URL.clone(), server_name),
dont_drop: self.dont_drop,
Expand Down
73 changes: 50 additions & 23 deletions zkstack_cli/crates/zkstack/src/commands/chain/args/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use crate::{
commands::chain::args::genesis::{GenesisArgs, GenesisArgsFinal},
defaults::LOCAL_RPC_URL,
messages::{
MSG_DEPLOY_PAYMASTER_PROMPT, MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP,
MSG_DEPLOY_PAYMASTER_PROMPT, MSG_DEV_ARG_HELP, MSG_L1_RPC_URL_HELP,
MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT, MSG_NO_PORT_REALLOCATION_HELP,
MSG_SERVER_DB_NAME_HELP, MSG_SERVER_DB_URL_HELP,
},
};

Expand All @@ -22,45 +23,70 @@ pub struct InitArgs {
#[clap(flatten)]
#[serde(flatten)]
pub forge_args: ForgeScriptArgs,
#[clap(flatten, next_help_heading = MSG_GENESIS_ARGS_HELP)]
#[serde(flatten)]
pub genesis_args: GenesisArgs,
#[clap(long, help = MSG_SERVER_DB_URL_HELP)]
pub server_db_url: Option<Url>,
#[clap(long, help = MSG_SERVER_DB_NAME_HELP)]
pub server_db_name: Option<String>,
#[clap(long, short, action)]
pub dont_drop: bool,
#[clap(long, default_missing_value = "true", num_args = 0..=1)]
pub deploy_paymaster: Option<bool>,
#[clap(long, help = MSG_L1_RPC_URL_HELP)]
pub l1_rpc_url: Option<String>,
#[clap(long, help = MSG_NO_PORT_REALLOCATION_HELP)]
pub no_port_reallocation: bool,
#[clap(long, help = MSG_DEV_ARG_HELP)]
pub dev: bool,
}

impl InitArgs {
pub fn get_genesis_args(&self) -> GenesisArgs {
GenesisArgs {
server_db_url: self.server_db_url.clone(),
server_db_name: self.server_db_name.clone(),
dev: self.dev,
dont_drop: self.dont_drop,
}
}

pub fn fill_values_with_prompt(self, config: &ChainConfig) -> InitArgsFinal {
let deploy_paymaster = self.deploy_paymaster.unwrap_or_else(|| {
common::PromptConfirm::new(MSG_DEPLOY_PAYMASTER_PROMPT)
.default(true)
.ask()
});
let genesis = self.get_genesis_args();

let deploy_paymaster = if self.dev {
true
} else {
self.deploy_paymaster.unwrap_or_else(|| {
common::PromptConfirm::new(MSG_DEPLOY_PAYMASTER_PROMPT)
.default(true)
.ask()
})
};

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 {
prompt = prompt.default(LOCAL_RPC_URL);
}
prompt
.validate_with(|val: &String| -> Result<(), String> {
Url::parse(val)
.map(|_| ())
.map_err(|_| MSG_L1_RPC_URL_INVALID_ERR.to_string())
})
.ask()
});
let l1_rpc_url = if self.dev {
LOCAL_RPC_URL.to_string()
} else {
self.l1_rpc_url.unwrap_or_else(|| {
let mut prompt = Prompt::new(MSG_L1_RPC_URL_PROMPT);
if config.l1_network == L1Network::Localhost {
prompt = prompt.default(LOCAL_RPC_URL);
}
prompt
.validate_with(|val: &String| -> Result<(), String> {
Url::parse(val)
.map(|_| ())
.map_err(|_| MSG_L1_RPC_URL_INVALID_ERR.to_string())
})
.ask()
})
};

InitArgsFinal {
forge_args: self.forge_args,
genesis_args: self.genesis_args.fill_values_with_prompt(config),
genesis_args: genesis.fill_values_with_prompt(config),
deploy_paymaster,
l1_rpc_url,
no_port_reallocation: self.no_port_reallocation,
dev: self.dev,
}
}
}
Expand All @@ -72,4 +98,5 @@ pub struct InitArgsFinal {
pub deploy_paymaster: bool,
pub l1_rpc_url: String,
pub no_port_reallocation: bool,
pub dev: bool,
}
24 changes: 18 additions & 6 deletions zkstack_cli/crates/zkstack/src/commands/ecosystem/args/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use crate::{
defaults::LOCAL_RPC_URL,
messages::{
MSG_DEPLOY_ECOSYSTEM_PROMPT, MSG_DEPLOY_ERC20_PROMPT, MSG_DEV_ARG_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, MSG_OBSERVABILITY_HELP,
MSG_OBSERVABILITY_PROMPT,
MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT,
MSG_NO_PORT_REALLOCATION_HELP, MSG_OBSERVABILITY_HELP, MSG_OBSERVABILITY_PROMPT,
MSG_SERVER_DB_NAME_HELP, MSG_SERVER_DB_URL_HELP,
},
};

Expand Down Expand Up @@ -86,9 +86,12 @@ pub struct EcosystemInitArgs {
/// Deploy Paymaster contract
#[clap(long, default_missing_value = "true", num_args = 0..=1)]
pub deploy_paymaster: Option<bool>,
#[clap(flatten, next_help_heading = MSG_GENESIS_ARGS_HELP)]
#[serde(flatten)]
pub genesis_args: GenesisArgs,
#[clap(long, help = MSG_SERVER_DB_URL_HELP)]
pub server_db_url: Option<Url>,
#[clap(long, help = MSG_SERVER_DB_NAME_HELP)]
pub server_db_name: Option<String>,
#[clap(long, short, action)]
pub dont_drop: bool,
/// Initialize ecosystem only and skip chain initialization (chain can be initialized later with `chain init` subcommand)
#[clap(long, default_value_t = false)]
pub ecosystem_only: bool,
Expand All @@ -101,6 +104,15 @@ pub struct EcosystemInitArgs {
}

impl EcosystemInitArgs {
pub fn get_genesis_args(&self) -> GenesisArgs {
GenesisArgs {
server_db_url: self.server_db_url.clone(),
server_db_name: self.server_db_name.clone(),
dev: self.dev,
dont_drop: self.dont_drop,
}
}

pub fn fill_values_with_prompt(self, l1_network: L1Network) -> EcosystemInitArgsFinal {
let deploy_erc20 = if self.dev {
true
Expand Down
9 changes: 6 additions & 3 deletions zkstack_cli/crates/zkstack/src/commands/ecosystem/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,10 @@ async fn init_chains(
};
// Set default values for dev mode
let mut deploy_paymaster = init_args.deploy_paymaster;
let mut genesis_args = init_args.genesis_args.clone();
let mut genesis_args = init_args.get_genesis_args().clone();
if final_init_args.dev {
deploy_paymaster = Some(true);
genesis_args.use_default = true;
genesis_args.dev = true;
}
// Can't initialize multiple chains with the same DB
if list_of_chains.len() > 1 {
Expand All @@ -359,10 +359,13 @@ async fn init_chains(

let chain_init_args = chain::args::init::InitArgs {
forge_args: final_init_args.forge_args.clone(),
genesis_args: genesis_args.clone(),
server_db_url: genesis_args.server_db_url.clone(),
server_db_name: genesis_args.server_db_name.clone(),
dont_drop: genesis_args.dont_drop,
deploy_paymaster,
l1_rpc_url: Some(final_init_args.ecosystem.l1_rpc_url.clone()),
no_port_reallocation: final_init_args.no_port_reallocation,
dev: final_init_args.dev,
};
let final_chain_init_args = chain_init_args.fill_values_with_prompt(&chain_config);

Expand Down
4 changes: 2 additions & 2 deletions zkstack_cli/crates/zkstack/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub(super) const MSG_SELECTED_CONFIG: &str = "Selected config";
pub(super) const MSG_CHAIN_NOT_INITIALIZED: &str =
"Chain not initialized. Please create a chain first";
pub(super) const MSG_ARGS_VALIDATOR_ERR: &str = "Invalid arguments";
pub(super) const MSG_DEV_ARG_HELP: &str =
"Use defaults for all options and flags. Suitable for local development";

/// Autocomplete message
pub(super) fn msg_generate_autocomplete_file(filename: &str) -> String {
Expand Down Expand Up @@ -61,8 +63,6 @@ pub(super) fn msg_path_to_zksync_does_not_exist_err(path: &str) -> String {
pub(super) const MSG_L1_RPC_URL_HELP: &str = "L1 RPC URL";
pub(super) const MSG_NO_PORT_REALLOCATION_HELP: &str = "Do not reallocate ports";
pub(super) const MSG_GENESIS_ARGS_HELP: &str = "Genesis options";
pub(super) const MSG_DEV_ARG_HELP: &str =
"Deploy ecosystem using all defaults. Suitable for local development";
pub(super) const MSG_OBSERVABILITY_HELP: &str = "Enable Grafana";
pub(super) const MSG_OBSERVABILITY_PROMPT: &str = "Do you want to setup observability? (Grafana)";
pub(super) const MSG_DEPLOY_ECOSYSTEM_PROMPT: &str =
Expand Down
Loading