-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zk_toolbox): Add subcommands and flags for chain registration (#…
…2946) ## What ❔ Added subcommands: `zki chain init configs` - just creates configs with an intention to run chain initialization manually via subcommands `zki chain register-chain` - runs steps from `RegisterHyperchain.s.sol` `zki chain accept-chain-ownership` - accepts ownership for `DiamondProxy` `zki chain genesis database` - initializes database only, performs migration (uses values from args or `secrets.yaml`) `zki chain genesis server` - runs server --genesis Added flags: `zki ecosystem init --ecosystem-only` - runs `init` only for ecosystem (skips `init` for chain) Other changes: * Fixed issue with `--wallet_path` value ignored * Nullify database names if `zki ecosystem init` is used for multiple chains * Zeroify some addresses in `contracts.yaml` when copying from ecosystem during init ## Why ❔ These changes allow us to run the chain registration process for externally hosted chains. Not ideal yet, but the process goes like this: L1 side: * Init ecosystem: `zki ecosystem create && zki ecosystem init --ecosystem-only && zki chain init configs` * Fill in wallets * Register chain: `zki chain register-chain` * Deploy L2 contracts: `zki chain deploy-l2-contracts` * Share `contracts.yaml` L2 side: * Init ecosystem: `zki ecosystem create && zki ecosystem init --ecosystem-only && zki chain init configs` * Fill in wallets * Copy `contracts.yaml` * Accept ownership: `zki chain accept-chain-ownership` * Initialize databases: `zki chain genesis database` * Run server genesis: `zki chain genesis server` ## Checklist - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`.
- Loading branch information
1 parent
8d24eb5
commit 057705e
Showing
19 changed files
with
732 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
zk_toolbox/crates/zk_inception/src/commands/chain/accept_chain_ownership.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use anyhow::Context; | ||
use common::{forge::ForgeScriptArgs, logger, spinner::Spinner}; | ||
use config::EcosystemConfig; | ||
use xshell::Shell; | ||
|
||
use crate::{ | ||
accept_ownership::accept_admin, | ||
messages::{ | ||
MSG_ACCEPTING_ADMIN_SPINNER, MSG_CHAIN_NOT_INITIALIZED, MSG_CHAIN_OWNERSHIP_TRANSFERRED, | ||
MSG_L1_SECRETS_MUST_BE_PRESENTED, | ||
}, | ||
}; | ||
|
||
pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { | ||
let ecosystem_config = EcosystemConfig::from_file(shell)?; | ||
let chain_config = ecosystem_config | ||
.load_current_chain() | ||
.context(MSG_CHAIN_NOT_INITIALIZED)?; | ||
let contracts = chain_config.get_contracts_config()?; | ||
let secrets = chain_config.get_secrets_config()?; | ||
let l1_rpc_url = secrets | ||
.l1 | ||
.context(MSG_L1_SECRETS_MUST_BE_PRESENTED)? | ||
.l1_rpc_url | ||
.expose_str() | ||
.to_string(); | ||
|
||
let spinner = Spinner::new(MSG_ACCEPTING_ADMIN_SPINNER); | ||
accept_admin( | ||
shell, | ||
&ecosystem_config, | ||
contracts.l1.chain_admin_addr, | ||
chain_config.get_wallets_config()?.governor_private_key(), | ||
contracts.l1.diamond_proxy_addr, | ||
&args, | ||
l1_rpc_url.clone(), | ||
) | ||
.await?; | ||
spinner.finish(); | ||
logger::success(MSG_CHAIN_OWNERSHIP_TRANSFERRED); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
zk_toolbox/crates/zk_inception/src/commands/chain/args/init/configs.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use clap::Parser; | ||
use common::Prompt; | ||
use config::ChainConfig; | ||
use serde::{Deserialize, Serialize}; | ||
use types::L1Network; | ||
use url::Url; | ||
|
||
use crate::{ | ||
commands::chain::args::{ | ||
genesis::{GenesisArgs, GenesisArgsFinal}, | ||
init::InitArgsFinal, | ||
}, | ||
defaults::LOCAL_RPC_URL, | ||
messages::{ | ||
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 | ||
}, | ||
}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize, Parser)] | ||
pub struct InitConfigsArgs { | ||
#[clap(flatten, next_help_heading = MSG_GENESIS_ARGS_HELP)] | ||
#[serde(flatten)] | ||
pub genesis_args: GenesisArgs, | ||
#[clap(long, help = MSG_L1_RPC_URL_HELP)] | ||
pub l1_rpc_url: Option<String>, | ||
#[clap(long, help = MSG_NO_PORT_REALLOCATION_HELP, default_value = "false", default_missing_value = "true", num_args = 0..=1)] | ||
pub no_port_reallocation: bool, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
pub struct InitConfigsArgsFinal { | ||
pub genesis_args: GenesisArgsFinal, | ||
pub l1_rpc_url: String, | ||
pub no_port_reallocation: bool, | ||
} | ||
|
||
impl InitConfigsArgs { | ||
pub fn fill_values_with_prompt(self, config: &ChainConfig) -> 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 { | ||
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() | ||
}); | ||
|
||
InitConfigsArgsFinal { | ||
genesis_args: self.genesis_args.fill_values_with_prompt(config), | ||
l1_rpc_url, | ||
no_port_reallocation: self.no_port_reallocation, | ||
} | ||
} | ||
} | ||
|
||
impl InitConfigsArgsFinal { | ||
pub fn from_chain_init_args(init_args: &InitArgsFinal) -> InitConfigsArgsFinal { | ||
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, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 2 additions & 56 deletions
58
zk_toolbox/crates/zk_inception/src/commands/chain/common.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.