Skip to content

Commit

Permalink
Preload chain and ecosystem config for build_transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
matias-gonz committed Nov 22, 2024
1 parent 93fab5f commit 82b028c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
46 changes: 24 additions & 22 deletions zkstack_cli/crates/zkstack/src/commands/chain/build_transactions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::Context;
use common::{git, logger, spinner::Spinner};
use config::{
copy_configs, traits::SaveConfigWithBasePath, update_from_chain_config,
zkstack_config::ZkStackConfig,
copy_configs, traits::SaveConfigWithBasePath, update_from_chain_config, ChainConfig,
EcosystemConfig,
};
use ethers::utils::hex::ToHex;
use xshell::Shell;
Expand All @@ -12,9 +12,9 @@ use crate::{
args::build_transactions::BuildTransactionsArgs, register_chain::register_chain,
},
messages::{
MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER, MSG_CHAIN_NOT_FOUND_ERR,
MSG_CHAIN_TRANSACTIONS_BUILT, MSG_CHAIN_TXN_MISSING_CONTRACT_CONFIG,
MSG_CHAIN_TXN_OUT_PATH_INVALID_ERR, MSG_PREPARING_CONFIG_SPINNER, MSG_SELECTED_CONFIG,
MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER, MSG_CHAIN_TRANSACTIONS_BUILT,
MSG_CHAIN_TXN_MISSING_CONTRACT_CONFIG, MSG_CHAIN_TXN_OUT_PATH_INVALID_ERR,
MSG_ECOSYSTEM_CONFIG_INVALID_ERR, MSG_PREPARING_CONFIG_SPINNER, MSG_SELECTED_CONFIG,
MSG_WRITING_OUTPUT_FILES_SPINNER,
},
};
Expand All @@ -27,39 +27,41 @@ const SCRIPT_CONFIG_FILE_SRC: &str =
"contracts/l1-contracts/script-config/register-hyperchain.toml";
const SCRIPT_CONFIG_FILE_DST: &str = "register-hyperchain.toml";

pub(crate) async fn run(args: BuildTransactionsArgs, shell: &Shell) -> anyhow::Result<()> {
let config = ZkStackConfig::ecosystem(shell)?;
let chain_config = config
.load_current_chain()
.context(MSG_CHAIN_NOT_FOUND_ERR)?;
pub(crate) async fn run(
args: BuildTransactionsArgs,
shell: &Shell,
chain: ChainConfig,
ecosystem: Option<EcosystemConfig>,
) -> anyhow::Result<()> {
let ecosystem = ecosystem.context(MSG_ECOSYSTEM_CONFIG_INVALID_ERR)?;

let args = args.fill_values_with_prompt(config.default_chain.clone());
let args = args.fill_values_with_prompt(ecosystem.default_chain.clone());

git::submodule_update(shell, config.link_to_code.clone())?;
git::submodule_update(shell, ecosystem.link_to_code.clone())?;

let spinner = Spinner::new(MSG_PREPARING_CONFIG_SPINNER);
copy_configs(shell, &config.link_to_code, &chain_config.configs)?;
copy_configs(shell, &ecosystem.link_to_code, &chain.configs)?;

logger::note(MSG_SELECTED_CONFIG, logger::object_to_string(&chain_config));
logger::note(MSG_SELECTED_CONFIG, logger::object_to_string(&chain));

let mut genesis_config = chain_config.get_genesis_config()?;
update_from_chain_config(&mut genesis_config, &chain_config)?;
let mut genesis_config = chain.get_genesis_config()?;
update_from_chain_config(&mut genesis_config, &chain)?;

// Copy ecosystem contracts
let mut contracts_config = config
let mut contracts_config = ecosystem
.get_contracts_config()
.context(MSG_CHAIN_TXN_MISSING_CONTRACT_CONFIG)?;
contracts_config.l1.base_token_addr = chain_config.base_token.address;
contracts_config.l1.base_token_addr = chain.base_token.address;
spinner.finish();

let spinner = Spinner::new(MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER);
let wallets = config.get_wallets()?;
let wallets = ecosystem.get_wallets()?;
let governor: String = wallets.governor.address.encode_hex_upper();

register_chain(
shell,
args.forge_args.clone(),
&chain_config,
&chain,
&mut contracts_config,
&wallets,
args.l1_rpc_url.clone(),
Expand All @@ -77,12 +79,12 @@ pub(crate) async fn run(args: BuildTransactionsArgs, shell: &Shell) -> anyhow::R
.context(MSG_CHAIN_TXN_OUT_PATH_INVALID_ERR)?;

shell.copy_file(
config.link_to_code.join(REGISTER_CHAIN_TXNS_FILE_SRC),
ecosystem.link_to_code.join(REGISTER_CHAIN_TXNS_FILE_SRC),
args.out.join(REGISTER_CHAIN_TXNS_FILE_DST),
)?;

shell.copy_file(
config.link_to_code.join(SCRIPT_CONFIG_FILE_SRC),
ecosystem.link_to_code.join(SCRIPT_CONFIG_FILE_SRC),
args.out.join(SCRIPT_CONFIG_FILE_DST),
)?;
spinner.finish();
Expand Down
4 changes: 3 additions & 1 deletion zkstack_cli/crates/zkstack/src/commands/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ pub(crate) async fn run(shell: &Shell, cmd: ChainCommands) -> anyhow::Result<()>
match cmd {
ChainCommands::Create(args) => create::run(args, shell),
ChainCommands::Init(args) => init::run(*args, shell, chain, ecosystem).await,
ChainCommands::BuildTransactions(args) => build_transactions::run(args, shell).await,
ChainCommands::BuildTransactions(args) => {
build_transactions::run(args, shell, chain, ecosystem).await
}
ChainCommands::Genesis(args) => genesis::run(args, shell, chain).await,
ChainCommands::RegisterChain(args) => register_chain::run(args, shell).await,
ChainCommands::DeployL2Contracts(args) => {
Expand Down

0 comments on commit 82b028c

Please sign in to comment.