Skip to content

Commit

Permalink
Move l1 rpc to init stage
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo committed May 28, 2024
1 parent be3ded9 commit 1ab3f43
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 73 deletions.
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
28 changes: 24 additions & 4 deletions zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/init.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -14,19 +17,35 @@ pub struct EcosystemArgs {
/// Path to ecosystem contracts
#[clap(long)]
pub ecosystem_contracts_path: Option<PathBuf>,
#[clap(long, help = "L1 RPC URL")]
pub l1_rpc_url: Option<String>,
}

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,
}
}
}
Expand All @@ -35,6 +54,7 @@ impl EcosystemArgs {
pub struct EcosystemArgsFinal {
pub deploy_ecosystem: bool,
pub ecosystem_contracts_path: Option<PathBuf>,
pub l1_rpc_url: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, Parser)]
Expand All @@ -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)
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 1ab3f43

Please sign in to comment.