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

fix(zk_toolbox): Move l1 rpc to init stage #2074

Merged
merged 1 commit into from
May 28, 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
1 change: 0 additions & 1 deletion ZkStack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ link_to_code: .
chains: ./chains
config: ./configs/
default_chain: era
l1_rpc_url: http://localhost:8545
era_chain_id: 270
prover_version: NoProofs
wallet_creation: Localhost
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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==

[email protected]:
version "20.2.4"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.4.tgz#b42890f14566796f85ae8e3a25290d205f154a54"
Expand Down
6 changes: 4 additions & 2 deletions zk_toolbox/crates/zk_inception/src/accept_ownership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ pub async fn accept_admin(
governor: Option<H256>,
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(
Expand All @@ -47,12 +48,13 @@ pub async fn accept_owner(
governor: Option<H256>,
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(
Expand Down
22 changes: 22 additions & 0 deletions zk_toolbox/crates/zk_inception/src/commands/chain/args/init.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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<bool>,
#[clap(long, help = "L1 RPC URL")]
pub l1_rpc_url: Option<String>,
}

impl InitArgs {
Expand All @@ -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,
}
}
}
Expand All @@ -39,4 +60,5 @@ pub struct InitArgsFinal {
pub forge_args: ForgeScriptArgs,
pub genesis_args: GenesisArgsFinal,
pub deploy_paymaster: bool,
pub l1_rpc_url: String,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions zk_toolbox/crates/zk_inception/src/commands/chain/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand All @@ -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(())
Expand All @@ -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)?;
Expand All @@ -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:",
Expand Down
27 changes: 11 additions & 16 deletions zk_toolbox/crates/zk_inception/src/commands/chain/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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(())
}
Expand All @@ -112,6 +106,7 @@ async fn register_chain(
forge_args: ForgeScriptArgs,
config: &EcosystemConfig,
chain_config: &ChainConfig,
l1_rpc_url: String,
) -> anyhow::Result<ContractsConfig> {
let deploy_config_path = REGISTER_CHAIN.input(&config.link_to_code);

Expand All @@ -124,7 +119,7 @@ async fn register_chain(
let mut forge = Forge::new(&config.path_to_foundry())
.script(&REGISTER_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())?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -20,8 +18,6 @@ pub struct EcosystemCreateArgs {
pub ecosystem_name: Option<String>,
#[clap(long, help = "L1 Network", value_enum)]
pub l1_network: Option<L1Network>,
#[clap(long, help = "L1 RPC URL")]
pub l1_rpc_url: Option<String>,
#[clap(long, help = "Code link")]
pub link_to_code: Option<String>,
#[clap(flatten)]
Expand Down Expand Up @@ -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);

Expand All @@ -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,
}
Expand All @@ -99,7 +80,6 @@ pub struct EcosystemCreateArgsFinal {
pub link_to_code: String,
pub wallet_creation: WalletCreation,
pub wallet_path: Option<PathBuf>,
pub l1_rpc_url: String,
pub chain_args: ChainCreateArgsFinal,
pub start_containers: bool,
}
Expand Down
Loading
Loading