From 1ab3f4331cad5aedb861c91e32cbcf714e7d1ad1 Mon Sep 17 00:00:00 2001 From: Danil Date: Tue, 28 May 2024 14:35:22 +0200 Subject: [PATCH] Move l1 rpc to init stage Signed-off-by: Danil --- yarn.lock | 10 +++---- .../zk_inception/src/accept_ownership.rs | 6 ++-- .../src/commands/chain/args/init.rs | 22 +++++++++++++++ .../src/commands/chain/deploy_paymaster.rs | 6 ++-- .../src/commands/chain/genesis.rs | 8 +++--- .../zk_inception/src/commands/chain/init.rs | 27 ++++++++---------- .../src/commands/chain/initialize_bridges.rs | 3 +- .../src/commands/ecosystem/args/create.rs | 20 ------------- .../src/commands/ecosystem/args/init.rs | 28 ++++++++++++++++--- .../src/commands/ecosystem/create.rs | 1 - .../src/commands/ecosystem/init.rs | 23 +++++++++++---- .../crates/zk_inception/src/configs/chain.rs | 6 ++++ .../zk_inception/src/configs/ecosystem.rs | 4 --- .../zk_inception/src/configs/manipulations.rs | 21 ++++++++------ 14 files changed, 112 insertions(+), 73 deletions(-) diff --git a/yarn.lock b/yarn.lock index 5685087aaa6c..b7e2b98c431e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2805,11 +2805,6 @@ expect "^29.0.0" pretty-format "^29.0.0" -"@types/js-yaml@^4.0.9": - version "4.0.9" - resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.9.tgz#cd82382c4f902fed9691a2ed79ec68c5898af4c2" - integrity sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg== - "@types/json-schema@^7.0.12": version "7.0.15" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841" @@ -10949,6 +10944,11 @@ yaml@^2.4.1: resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.4.1.tgz#2e57e0b5e995292c25c75d2658f0664765210eed" integrity sha512-pIXzoImaqmfOrL7teGUBt/T7ZDnyeGBWyXQBvOVhLkWLN37GXv8NMLK406UY6dS51JfcQHsmcW5cJ441bHg6Lg== +yaml@^2.4.2: + version "2.4.2" + resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.4.2.tgz#7a2b30f2243a5fc299e1f14ca58d475ed4bc5362" + integrity sha512-B3VqDZ+JAg1nZpaEmWtTXUlBneoGx6CPM9b0TENK6aoSu5t73dItudwdgmi6tHlIZZId4dZ9skcAQ2UbcyAeVA== + yargs-parser@20.2.4: version "20.2.4" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.4.tgz#b42890f14566796f85ae8e3a25290d205f154a54" diff --git a/zk_toolbox/crates/zk_inception/src/accept_ownership.rs b/zk_toolbox/crates/zk_inception/src/accept_ownership.rs index 932666db70be..8c331dd63e05 100644 --- a/zk_toolbox/crates/zk_inception/src/accept_ownership.rs +++ b/zk_toolbox/crates/zk_inception/src/accept_ownership.rs @@ -21,12 +21,13 @@ pub async fn accept_admin( governor: Option, target_address: Address, forge_args: &ForgeScriptArgs, + l1_rpc_url: String, ) -> anyhow::Result<()> { let foundry_contracts_path = ecosystem_config.path_to_foundry(); let forge = Forge::new(&foundry_contracts_path) .script(&ACCEPT_GOVERNANCE.script(), forge_args.clone()) .with_ffi() - .with_rpc_url(ecosystem_config.l1_rpc_url.clone()) + .with_rpc_url(l1_rpc_url) .with_broadcast() .with_signature("acceptAdmin()"); accept_ownership( @@ -47,12 +48,13 @@ pub async fn accept_owner( governor: Option, target_address: Address, forge_args: &ForgeScriptArgs, + l1_rpc_url: String, ) -> anyhow::Result<()> { let foundry_contracts_path = ecosystem_config.path_to_foundry(); let forge = Forge::new(&foundry_contracts_path) .script(&ACCEPT_GOVERNANCE.script(), forge_args.clone()) .with_ffi() - .with_rpc_url(ecosystem_config.l1_rpc_url.clone()) + .with_rpc_url(l1_rpc_url) .with_broadcast() .with_signature("acceptOwner()"); accept_ownership( diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/init.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/init.rs index 19956f41fa23..aaa6fb2f0ffa 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/args/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/init.rs @@ -1,8 +1,12 @@ use clap::Parser; use common::forge::ForgeScriptArgs; +use common::Prompt; use serde::{Deserialize, Serialize}; +use url::Url; use super::genesis::GenesisArgsFinal; +use crate::defaults::LOCAL_RPC_URL; +use crate::types::L1Network; use crate::{commands::chain::args::genesis::GenesisArgs, configs::ChainConfig}; #[derive(Debug, Clone, Serialize, Deserialize, Parser)] @@ -16,6 +20,8 @@ pub struct InitArgs { pub genesis_args: GenesisArgs, #[clap(long, default_missing_value = "true", num_args = 0..=1)] pub deploy_paymaster: Option, + #[clap(long, help = "L1 RPC URL")] + pub l1_rpc_url: Option, } impl InitArgs { @@ -26,10 +32,25 @@ impl InitArgs { .ask() }); + let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { + let mut prompt = Prompt::new("What is the RPC URL of the L1 network?"); + 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(|_| "Invalid RPC url".to_string()) + }) + .ask() + }); + InitArgsFinal { forge_args: self.forge_args, genesis_args: self.genesis_args.fill_values_with_prompt(config), deploy_paymaster, + l1_rpc_url, } } } @@ -39,4 +60,5 @@ pub struct InitArgsFinal { pub forge_args: ForgeScriptArgs, pub genesis_args: GenesisArgsFinal, pub deploy_paymaster: bool, + pub l1_rpc_url: String, } diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs index 1b0e78883d14..177b27cb2ff5 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs @@ -22,23 +22,23 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { let chain_config = ecosystem_config .load_chain(chain_name) .context("Chain not initialized. Please create a chain first")?; - deploy_paymaster(shell, &chain_config, &ecosystem_config, args).await + deploy_paymaster(shell, &chain_config, args).await } pub async fn deploy_paymaster( shell: &Shell, chain_config: &ChainConfig, - ecosystem_config: &EcosystemConfig, forge_args: ForgeScriptArgs, ) -> anyhow::Result<()> { let input = DeployPaymasterInput::new(chain_config)?; let foundry_contracts_path = chain_config.path_to_foundry(); input.save(shell, DEPLOY_PAYMASTER.input(&chain_config.link_to_code))?; + let secrets = chain_config.get_secrets_config()?; let mut forge = Forge::new(&foundry_contracts_path) .script(&DEPLOY_PAYMASTER.script(), forge_args.clone()) .with_ffi() - .with_rpc_url(ecosystem_config.l1_rpc_url.clone()) + .with_rpc_url(secrets.l1.l1_rpc_url.clone()) .with_broadcast(); forge = fill_forge_private_key( diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/genesis.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/genesis.rs index 160d7d6b96df..4fe2f0bbb118 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/genesis.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/genesis.rs @@ -13,7 +13,8 @@ use super::args::genesis::GenesisArgsFinal; use crate::{ commands::chain::args::genesis::GenesisArgs, configs::{ - update_general_config, update_secrets, ChainConfig, DatabasesConfig, EcosystemConfig, + update_database_secrets, update_general_config, ChainConfig, DatabasesConfig, + EcosystemConfig, }, server::{RunServer, ServerMode}, }; @@ -29,7 +30,7 @@ pub async fn run(args: GenesisArgs, shell: &Shell) -> anyhow::Result<()> { .context("Chain not initialized. Please create a chain first")?; let args = args.fill_values_with_prompt(&chain_config); - genesis(args, shell, &chain_config, &ecosystem_config).await?; + genesis(args, shell, &chain_config).await?; logger::outro("Genesis completed successfully"); Ok(()) @@ -39,7 +40,6 @@ pub async fn genesis( args: GenesisArgsFinal, shell: &Shell, config: &ChainConfig, - ecosystem_config: &EcosystemConfig, ) -> anyhow::Result<()> { // Clean the rocksdb shell.remove_path(&config.rocks_db_path)?; @@ -49,7 +49,7 @@ pub async fn genesis( .databases_config() .context("Database config was not fully generated")?; update_general_config(shell, config)?; - update_secrets(shell, config, &db_config, ecosystem_config)?; + update_database_secrets(shell, config, &db_config)?; logger::note( "Selected config:", diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs index 1f6ac66b9d2a..80776ab277df 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs @@ -8,6 +8,7 @@ use common::{ use xshell::Shell; use super::args::init::InitArgsFinal; +use crate::configs::update_l1_rpc_url_secret; use crate::forge_utils::check_the_balance; use crate::{ accept_ownership::accept_admin, @@ -50,6 +51,7 @@ pub async fn init( copy_configs(shell, &ecosystem_config.link_to_code, &chain_config.configs)?; update_genesis(shell, chain_config)?; + update_l1_rpc_url_secret(shell, chain_config, init_args.l1_rpc_url.clone())?; let mut contracts_config = ContractsConfig::read(shell, ecosystem_config.config.join(CONTRACTS_FILE))?; contracts_config.l1.base_token_addr = chain_config.base_token.address; @@ -62,6 +64,7 @@ pub async fn init( init_args.forge_args.clone(), ecosystem_config, chain_config, + init_args.l1_rpc_url.clone(), ) .await?; spinner.finish(); @@ -73,6 +76,7 @@ pub async fn init( chain_config.get_wallets_config()?.governor_private_key(), contracts_config.l1.diamond_proxy_addr, &init_args.forge_args.clone(), + init_args.l1_rpc_url.clone(), ) .await?; spinner.finish(); @@ -86,23 +90,13 @@ pub async fn init( .await?; if init_args.deploy_paymaster { - deploy_paymaster::deploy_paymaster( - shell, - chain_config, - ecosystem_config, - init_args.forge_args.clone(), - ) - .await?; + deploy_paymaster::deploy_paymaster(shell, chain_config, init_args.forge_args.clone()) + .await?; } - genesis( - init_args.genesis_args.clone(), - shell, - chain_config, - ecosystem_config, - ) - .await - .context("Unable to perform genesis on the database")?; + genesis(init_args.genesis_args.clone(), shell, chain_config) + .await + .context("Unable to perform genesis on the database")?; Ok(()) } @@ -112,6 +106,7 @@ async fn register_chain( forge_args: ForgeScriptArgs, config: &EcosystemConfig, chain_config: &ChainConfig, + l1_rpc_url: String, ) -> anyhow::Result { let deploy_config_path = REGISTER_CHAIN.input(&config.link_to_code); @@ -124,7 +119,7 @@ async fn register_chain( let mut forge = Forge::new(&config.path_to_foundry()) .script(®ISTER_CHAIN.script(), forge_args.clone()) .with_ffi() - .with_rpc_url(config.l1_rpc_url.clone()) + .with_rpc_url(l1_rpc_url) .with_broadcast(); forge = fill_forge_private_key(forge, config.get_wallets()?.governor_private_key())?; diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/initialize_bridges.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/initialize_bridges.rs index 84635c6cd032..ebeacc1c15af 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/initialize_bridges.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/initialize_bridges.rs @@ -44,12 +44,13 @@ pub async fn initialize_bridges( build_l2_contracts(shell, &ecosystem_config.link_to_code)?; let input = InitializeBridgeInput::new(chain_config, ecosystem_config.era_chain_id)?; let foundry_contracts_path = chain_config.path_to_foundry(); + let secrets = chain_config.get_secrets_config()?; input.save(shell, INITIALIZE_BRIDGES.input(&chain_config.link_to_code))?; let mut forge = Forge::new(&foundry_contracts_path) .script(&INITIALIZE_BRIDGES.script(), forge_args.clone()) .with_ffi() - .with_rpc_url(ecosystem_config.l1_rpc_url.clone()) + .with_rpc_url(secrets.l1.l1_rpc_url.clone()) .with_broadcast(); forge = fill_forge_private_key( diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/create.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/create.rs index 6786b07d6776..259050bce049 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/create.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/create.rs @@ -5,11 +5,9 @@ use common::{slugify, Prompt, PromptConfirm, PromptSelect}; use serde::{Deserialize, Serialize}; use strum::IntoEnumIterator; use strum_macros::{Display, EnumIter}; -use url::Url; use crate::{ commands::chain::{args::create::ChainCreateArgs, ChainCreateArgsFinal}, - defaults::LOCAL_RPC_URL, types::L1Network, wallets::WalletCreation, }; @@ -20,8 +18,6 @@ pub struct EcosystemCreateArgs { pub ecosystem_name: Option, #[clap(long, help = "L1 Network", value_enum)] pub l1_network: Option, - #[clap(long, help = "L1 RPC URL")] - pub l1_rpc_url: Option, #[clap(long, help = "Code link")] pub link_to_code: Option, #[clap(flatten)] @@ -52,20 +48,6 @@ impl EcosystemCreateArgs { let l1_network = PromptSelect::new("Select the L1 network", L1Network::iter()).ask(); - let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { - let mut prompt = Prompt::new("What is the RPC URL of the L1 network?"); - if l1_network == L1Network::Localhost { - prompt = prompt.default(LOCAL_RPC_URL); - } - prompt - .validate_with(|val: &String| -> Result<(), String> { - Url::parse(val) - .map(|_| ()) - .map_err(|_| "Invalid RPC url".to_string()) - }) - .ask() - }); - // Make the only chain as a default one self.chain.set_as_default = Some(true); @@ -85,7 +67,6 @@ impl EcosystemCreateArgs { link_to_code, wallet_creation: chain.wallet_creation, wallet_path: chain.wallet_path.clone(), - l1_rpc_url, chain_args: chain, start_containers, } @@ -99,7 +80,6 @@ pub struct EcosystemCreateArgsFinal { pub link_to_code: String, pub wallet_creation: WalletCreation, pub wallet_path: Option, - pub l1_rpc_url: String, pub chain_args: ChainCreateArgsFinal, pub start_containers: bool, } diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/init.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/init.rs index 36a93594942b..e1bda4736ac8 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/init.rs @@ -1,10 +1,13 @@ use std::path::PathBuf; use clap::Parser; -use common::{forge::ForgeScriptArgs, PromptConfirm}; +use common::{forge::ForgeScriptArgs, Prompt, PromptConfirm}; use serde::{Deserialize, Serialize}; +use url::Url; use crate::commands::chain::args::genesis::GenesisArgs; +use crate::defaults::LOCAL_RPC_URL; +use crate::types::L1Network; #[derive(Debug, Clone, Serialize, Deserialize, Parser)] pub struct EcosystemArgs { @@ -14,19 +17,35 @@ pub struct EcosystemArgs { /// Path to ecosystem contracts #[clap(long)] pub ecosystem_contracts_path: Option, + #[clap(long, help = "L1 RPC URL")] + pub l1_rpc_url: Option, } impl EcosystemArgs { - pub fn fill_values_with_prompt(self) -> EcosystemArgsFinal { + pub fn fill_values_with_prompt(self, l1_network: L1Network) -> EcosystemArgsFinal { let deploy_ecosystem = self.deploy_ecosystem.unwrap_or_else(|| { PromptConfirm::new("Do you want to deploy ecosystem contracts? (Not needed if you already have an existing one)") .default(true) .ask() }); + let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { + let mut prompt = Prompt::new("What is the RPC URL of the L1 network?"); + if l1_network == L1Network::Localhost { + prompt = prompt.default(LOCAL_RPC_URL); + } + prompt + .validate_with(|val: &String| -> Result<(), String> { + Url::parse(val) + .map(|_| ()) + .map_err(|_| "Invalid RPC url".to_string()) + }) + .ask() + }); EcosystemArgsFinal { deploy_ecosystem, ecosystem_contracts_path: self.ecosystem_contracts_path, + l1_rpc_url, } } } @@ -35,6 +54,7 @@ impl EcosystemArgs { pub struct EcosystemArgsFinal { pub deploy_ecosystem: bool, pub ecosystem_contracts_path: Option, + pub l1_rpc_url: String, } #[derive(Debug, Clone, Serialize, Deserialize, Parser)] @@ -57,7 +77,7 @@ pub struct EcosystemInitArgs { } impl EcosystemInitArgs { - pub fn fill_values_with_prompt(self) -> EcosystemInitArgsFinal { + pub fn fill_values_with_prompt(self, l1_network: L1Network) -> EcosystemInitArgsFinal { let deploy_paymaster = self.deploy_paymaster.unwrap_or_else(|| { PromptConfirm::new("Do you want to deploy paymaster?") .default(true) @@ -68,7 +88,7 @@ impl EcosystemInitArgs { .default(true) .ask() }); - let ecosystem = self.ecosystem.fill_values_with_prompt(); + let ecosystem = self.ecosystem.fill_values_with_prompt(l1_network); EcosystemInitArgsFinal { deploy_paymaster, diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/create.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/create.rs index f1e6d98192d5..d3548a154607 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/create.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/create.rs @@ -69,7 +69,6 @@ fn create(args: EcosystemCreateArgs, shell: &Shell) -> anyhow::Result<()> { chains: chains_path.clone(), config: configs_path, default_chain: default_chain_name.clone(), - l1_rpc_url: args.l1_rpc_url, era_chain_id: ERA_CHAIN_ID, prover_version: chain_config.prover_version, wallet_creation: args.wallet_creation, diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs index 005c81736cff..0f4354c0394e 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs @@ -51,7 +51,7 @@ pub async fn run(args: EcosystemInitArgs, shell: &Shell) -> anyhow::Result<()> { }; let genesis_args = args.genesis_args.clone(); - let mut final_ecosystem_args = args.fill_values_with_prompt(); + let mut final_ecosystem_args = args.fill_values_with_prompt(ecosystem_config.l1_network); logger::info("Initializing ecosystem"); @@ -75,6 +75,7 @@ pub async fn run(args: EcosystemInitArgs, shell: &Shell) -> anyhow::Result<()> { &ecosystem_config, &contracts_config, final_ecosystem_args.forge_args.clone(), + final_ecosystem_args.ecosystem.l1_rpc_url.clone(), ) .await?; } @@ -96,9 +97,15 @@ pub async fn run(args: EcosystemInitArgs, shell: &Shell) -> anyhow::Result<()> { forge_args: final_ecosystem_args.forge_args.clone(), genesis_args: genesis_args.clone().fill_values_with_prompt(&chain_config), deploy_paymaster: final_ecosystem_args.deploy_paymaster, + l1_rpc_url: final_ecosystem_args.ecosystem.l1_rpc_url.clone(), }; - distribute_eth(&ecosystem_config, &chain_config).await?; + distribute_eth( + &ecosystem_config, + &chain_config, + final_ecosystem_args.ecosystem.l1_rpc_url.clone(), + ) + .await?; chain::init::init( &mut chain_init_args, @@ -121,6 +128,7 @@ pub async fn run(args: EcosystemInitArgs, shell: &Shell) -> anyhow::Result<()> { pub async fn distribute_eth( ecosystem_config: &EcosystemConfig, chain_config: &ChainConfig, + l1_rpc_url: String, ) -> anyhow::Result<()> { if chain_config.wallet_creation == WalletCreation::Localhost && ecosystem_config.l1_network == L1Network::Localhost @@ -139,7 +147,7 @@ pub async fn distribute_eth( common::ethereum::distribute_eth( wallets.operator, addresses, - ecosystem_config.l1_rpc_url.clone(), + l1_rpc_url, ecosystem_config.l1_network.chain_id(), AMOUNT_FOR_DISTRIBUTION_TO_WALLETS, ) @@ -179,6 +187,7 @@ async fn deploy_erc20( ecosystem_config: &EcosystemConfig, contracts_config: &ContractsConfig, forge_args: ForgeScriptArgs, + l1_rpc_url: String, ) -> anyhow::Result { let deploy_config_path = DEPLOY_ERC20.input(&ecosystem_config.link_to_code); DeployErc20Config::new(erc20_deployment_config, contracts_config) @@ -187,7 +196,7 @@ async fn deploy_erc20( let mut forge = Forge::new(&ecosystem_config.path_to_foundry()) .script(&DEPLOY_ERC20.script(), forge_args.clone()) .with_ffi() - .with_rpc_url(ecosystem_config.l1_rpc_url.clone()) + .with_rpc_url(l1_rpc_url) .with_broadcast(); forge = fill_forge_private_key( @@ -219,6 +228,7 @@ async fn deploy_ecosystem( forge_args, ecosystem_config, initial_deployment_config, + ecosystem.l1_rpc_url.clone(), ) .await; } @@ -264,6 +274,7 @@ async fn deploy_ecosystem_inner( forge_args: ForgeScriptArgs, config: &EcosystemConfig, initial_deployment_config: &InitialDeploymentConfig, + l1_rpc_url: String, ) -> anyhow::Result { let deploy_config_path = DEPLOY_ECOSYSTEM.input(&config.link_to_code); @@ -287,7 +298,7 @@ async fn deploy_ecosystem_inner( let mut forge = Forge::new(&config.path_to_foundry()) .script(&DEPLOY_ECOSYSTEM.script(), forge_args.clone()) .with_ffi() - .with_rpc_url(config.l1_rpc_url.clone()) + .with_rpc_url(l1_rpc_url.clone()) .with_broadcast(); if config.l1_network == L1Network::Localhost { @@ -312,6 +323,7 @@ async fn deploy_ecosystem_inner( config.get_wallets()?.governor_private_key(), contracts_config.ecosystem_contracts.bridgehub_proxy_addr, &forge_args, + l1_rpc_url.clone(), ) .await?; @@ -322,6 +334,7 @@ async fn deploy_ecosystem_inner( config.get_wallets()?.governor_private_key(), contracts_config.bridges.shared.l1_address, &forge_args, + l1_rpc_url.clone(), ) .await?; Ok(contracts_config) diff --git a/zk_toolbox/crates/zk_inception/src/configs/chain.rs b/zk_toolbox/crates/zk_inception/src/configs/chain.rs index aed1e7249861..49295a1e1e66 100644 --- a/zk_toolbox/crates/zk_inception/src/configs/chain.rs +++ b/zk_toolbox/crates/zk_inception/src/configs/chain.rs @@ -6,6 +6,8 @@ use std::{ use serde::{Deserialize, Serialize, Serializer}; use xshell::Shell; +use crate::configs::Secrets; +use crate::consts::SECRETS_FILE; use crate::{ configs::{ContractsConfig, GenesisConfig, ReadConfig, SaveConfig, WalletsConfig}, consts::{CONTRACTS_FILE, GENESIS_FILE, L1_CONTRACTS_FOUNDRY, WALLETS_FILE}, @@ -82,6 +84,10 @@ impl ChainConfig { ContractsConfig::read(self.get_shell(), self.configs.join(CONTRACTS_FILE)) } + pub fn get_secrets_config(&self) -> anyhow::Result { + Secrets::read(self.get_shell(), self.configs.join(SECRETS_FILE)) + } + pub fn path_to_foundry(&self) -> PathBuf { self.link_to_code.join(L1_CONTRACTS_FOUNDRY) } diff --git a/zk_toolbox/crates/zk_inception/src/configs/ecosystem.rs b/zk_toolbox/crates/zk_inception/src/configs/ecosystem.rs index b8b4da53262b..66e90f22f99b 100644 --- a/zk_toolbox/crates/zk_inception/src/configs/ecosystem.rs +++ b/zk_toolbox/crates/zk_inception/src/configs/ecosystem.rs @@ -29,7 +29,6 @@ struct EcosystemConfigInternal { pub chains: PathBuf, pub config: PathBuf, pub default_chain: String, - pub l1_rpc_url: String, pub era_chain_id: ChainId, pub prover_version: ProverMode, pub wallet_creation: WalletCreation, @@ -45,7 +44,6 @@ pub struct EcosystemConfig { pub chains: PathBuf, pub config: PathBuf, pub default_chain: String, - pub l1_rpc_url: String, pub era_chain_id: ChainId, pub prover_version: ProverMode, pub wallet_creation: WalletCreation, @@ -74,7 +72,6 @@ impl<'de> Deserialize<'de> for EcosystemConfig { chains: config.chains.clone(), config: config.config.clone(), default_chain: config.default_chain.clone(), - l1_rpc_url: config.l1_rpc_url.clone(), era_chain_id: config.era_chain_id, prover_version: config.prover_version, wallet_creation: config.wallet_creation, @@ -182,7 +179,6 @@ impl EcosystemConfig { chains: self.chains.clone(), config: self.config.clone(), default_chain: self.default_chain.clone(), - l1_rpc_url: self.l1_rpc_url.clone(), era_chain_id: self.era_chain_id, prover_version: self.prover_version, wallet_creation: self.wallet_creation, diff --git a/zk_toolbox/crates/zk_inception/src/configs/manipulations.rs b/zk_toolbox/crates/zk_inception/src/configs/manipulations.rs index 12423da97595..e8522a0446d9 100644 --- a/zk_toolbox/crates/zk_inception/src/configs/manipulations.rs +++ b/zk_toolbox/crates/zk_inception/src/configs/manipulations.rs @@ -10,8 +10,7 @@ use crate::{ initialize_bridges::output::InitializeBridgeOutput, paymaster::DeployPaymasterOutput, register_chain::output::RegisterChainOutput, }, - DatabasesConfig, EcosystemConfig, GeneralConfig, GenesisConfig, ReadConfig, SaveConfig, - Secrets, + DatabasesConfig, GeneralConfig, GenesisConfig, ReadConfig, SaveConfig, Secrets, }, consts::{ CONFIGS_PATH, CONTRACTS_FILE, GENERAL_FILE, GENESIS_FILE, SECRETS_FILE, WALLETS_FILE, @@ -49,24 +48,30 @@ pub(crate) fn update_genesis(shell: &Shell, config: &ChainConfig) -> anyhow::Res Ok(()) } -pub(crate) fn update_secrets( +pub(crate) fn update_database_secrets( shell: &Shell, config: &ChainConfig, db_config: &DatabasesConfig, - ecosystem_config: &EcosystemConfig, ) -> anyhow::Result<()> { let path = config.configs.join(SECRETS_FILE); let mut secrets = Secrets::read(shell, &path)?; secrets.database.server_url = db_config.server.full_url(); secrets.database.prover_url = db_config.prover.full_url(); - secrets - .l1 - .l1_rpc_url - .clone_from(&ecosystem_config.l1_rpc_url); secrets.save(shell, path)?; Ok(()) } +pub(crate) fn update_l1_rpc_url_secret( + shell: &Shell, + config: &ChainConfig, + l1_rpc_url: String, +) -> anyhow::Result<()> { + let path = config.configs.join(SECRETS_FILE); + let mut secrets = Secrets::read(shell, &path)?; + secrets.l1.l1_rpc_url = l1_rpc_url; + secrets.save(shell, path)?; + Ok(()) +} pub(crate) fn update_general_config(shell: &Shell, config: &ChainConfig) -> anyhow::Result<()> { let path = config.configs.join(GENERAL_FILE); let mut general = GeneralConfig::read(shell, &path)?;