Skip to content

Commit c127ff1

Browse files
authored
fix(zk_toolbox): Move l1 rpc to init stage (matter-labs#2074)
## What ❔ <!-- What are the changes this PR brings about? --> <!-- Example: This PR adds a PR template to the repo. --> <!-- (For bigger PRs adding more context is appreciated) --> ## Why ❔ <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zk fmt` and `zk lint`. - [ ] Spellcheck has been run via `zk spellcheck`. Signed-off-by: Danil <[email protected]>
1 parent 97c6d5c commit c127ff1

File tree

15 files changed

+112
-76
lines changed

15 files changed

+112
-76
lines changed

ZkStack.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ link_to_code: .
44
chains: ./chains
55
config: ./configs/
66
default_chain: era
7-
l1_rpc_url: http://localhost:8545
87
era_chain_id: 270
98
prover_version: NoProofs
109
wallet_creation: Localhost

yarn.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -2805,11 +2805,6 @@
28052805
expect "^29.0.0"
28062806
pretty-format "^29.0.0"
28072807

2808-
"@types/js-yaml@^4.0.9":
2809-
version "4.0.9"
2810-
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.9.tgz#cd82382c4f902fed9691a2ed79ec68c5898af4c2"
2811-
integrity sha512-k4MGaQl5TGo/iipqb2UDG2UwjXziSWkh0uysQelTlJpX1qGlpUZYm8PnO4DxG1qBomtJUdYJ6qR6xdIah10JLg==
2812-
28132808
"@types/json-schema@^7.0.12":
28142809
version "7.0.15"
28152810
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841"
@@ -10949,6 +10944,11 @@ yaml@^2.4.1:
1094910944
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.4.1.tgz#2e57e0b5e995292c25c75d2658f0664765210eed"
1095010945
integrity sha512-pIXzoImaqmfOrL7teGUBt/T7ZDnyeGBWyXQBvOVhLkWLN37GXv8NMLK406UY6dS51JfcQHsmcW5cJ441bHg6Lg==
1095110946

10947+
yaml@^2.4.2:
10948+
version "2.4.2"
10949+
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.4.2.tgz#7a2b30f2243a5fc299e1f14ca58d475ed4bc5362"
10950+
integrity sha512-B3VqDZ+JAg1nZpaEmWtTXUlBneoGx6CPM9b0TENK6aoSu5t73dItudwdgmi6tHlIZZId4dZ9skcAQ2UbcyAeVA==
10951+
1095210952
1095310953
version "20.2.4"
1095410954
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.4.tgz#b42890f14566796f85ae8e3a25290d205f154a54"

zk_toolbox/crates/zk_inception/src/accept_ownership.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ pub async fn accept_admin(
2121
governor: Option<H256>,
2222
target_address: Address,
2323
forge_args: &ForgeScriptArgs,
24+
l1_rpc_url: String,
2425
) -> anyhow::Result<()> {
2526
let foundry_contracts_path = ecosystem_config.path_to_foundry();
2627
let forge = Forge::new(&foundry_contracts_path)
2728
.script(&ACCEPT_GOVERNANCE.script(), forge_args.clone())
2829
.with_ffi()
29-
.with_rpc_url(ecosystem_config.l1_rpc_url.clone())
30+
.with_rpc_url(l1_rpc_url)
3031
.with_broadcast()
3132
.with_signature("acceptAdmin()");
3233
accept_ownership(
@@ -47,12 +48,13 @@ pub async fn accept_owner(
4748
governor: Option<H256>,
4849
target_address: Address,
4950
forge_args: &ForgeScriptArgs,
51+
l1_rpc_url: String,
5052
) -> anyhow::Result<()> {
5153
let foundry_contracts_path = ecosystem_config.path_to_foundry();
5254
let forge = Forge::new(&foundry_contracts_path)
5355
.script(&ACCEPT_GOVERNANCE.script(), forge_args.clone())
5456
.with_ffi()
55-
.with_rpc_url(ecosystem_config.l1_rpc_url.clone())
57+
.with_rpc_url(l1_rpc_url)
5658
.with_broadcast()
5759
.with_signature("acceptOwner()");
5860
accept_ownership(

zk_toolbox/crates/zk_inception/src/commands/chain/args/init.rs

+22
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
use clap::Parser;
22
use common::forge::ForgeScriptArgs;
3+
use common::Prompt;
34
use serde::{Deserialize, Serialize};
5+
use url::Url;
46

57
use super::genesis::GenesisArgsFinal;
8+
use crate::defaults::LOCAL_RPC_URL;
9+
use crate::types::L1Network;
610
use crate::{commands::chain::args::genesis::GenesisArgs, configs::ChainConfig};
711

812
#[derive(Debug, Clone, Serialize, Deserialize, Parser)]
@@ -16,6 +20,8 @@ pub struct InitArgs {
1620
pub genesis_args: GenesisArgs,
1721
#[clap(long, default_missing_value = "true", num_args = 0..=1)]
1822
pub deploy_paymaster: Option<bool>,
23+
#[clap(long, help = "L1 RPC URL")]
24+
pub l1_rpc_url: Option<String>,
1925
}
2026

2127
impl InitArgs {
@@ -26,10 +32,25 @@ impl InitArgs {
2632
.ask()
2733
});
2834

35+
let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| {
36+
let mut prompt = Prompt::new("What is the RPC URL of the L1 network?");
37+
if config.l1_network == L1Network::Localhost {
38+
prompt = prompt.default(LOCAL_RPC_URL);
39+
}
40+
prompt
41+
.validate_with(|val: &String| -> Result<(), String> {
42+
Url::parse(val)
43+
.map(|_| ())
44+
.map_err(|_| "Invalid RPC url".to_string())
45+
})
46+
.ask()
47+
});
48+
2949
InitArgsFinal {
3050
forge_args: self.forge_args,
3151
genesis_args: self.genesis_args.fill_values_with_prompt(config),
3252
deploy_paymaster,
53+
l1_rpc_url,
3354
}
3455
}
3556
}
@@ -39,4 +60,5 @@ pub struct InitArgsFinal {
3960
pub forge_args: ForgeScriptArgs,
4061
pub genesis_args: GenesisArgsFinal,
4162
pub deploy_paymaster: bool,
63+
pub l1_rpc_url: String,
4264
}

zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {
2222
let chain_config = ecosystem_config
2323
.load_chain(chain_name)
2424
.context("Chain not initialized. Please create a chain first")?;
25-
deploy_paymaster(shell, &chain_config, &ecosystem_config, args).await
25+
deploy_paymaster(shell, &chain_config, args).await
2626
}
2727

2828
pub async fn deploy_paymaster(
2929
shell: &Shell,
3030
chain_config: &ChainConfig,
31-
ecosystem_config: &EcosystemConfig,
3231
forge_args: ForgeScriptArgs,
3332
) -> anyhow::Result<()> {
3433
let input = DeployPaymasterInput::new(chain_config)?;
3534
let foundry_contracts_path = chain_config.path_to_foundry();
3635
input.save(shell, DEPLOY_PAYMASTER.input(&chain_config.link_to_code))?;
36+
let secrets = chain_config.get_secrets_config()?;
3737

3838
let mut forge = Forge::new(&foundry_contracts_path)
3939
.script(&DEPLOY_PAYMASTER.script(), forge_args.clone())
4040
.with_ffi()
41-
.with_rpc_url(ecosystem_config.l1_rpc_url.clone())
41+
.with_rpc_url(secrets.l1.l1_rpc_url.clone())
4242
.with_broadcast();
4343

4444
forge = fill_forge_private_key(

zk_toolbox/crates/zk_inception/src/commands/chain/genesis.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use super::args::genesis::GenesisArgsFinal;
1313
use crate::{
1414
commands::chain::args::genesis::GenesisArgs,
1515
configs::{
16-
update_general_config, update_secrets, ChainConfig, DatabasesConfig, EcosystemConfig,
16+
update_database_secrets, update_general_config, ChainConfig, DatabasesConfig,
17+
EcosystemConfig,
1718
},
1819
server::{RunServer, ServerMode},
1920
};
@@ -29,7 +30,7 @@ pub async fn run(args: GenesisArgs, shell: &Shell) -> anyhow::Result<()> {
2930
.context("Chain not initialized. Please create a chain first")?;
3031
let args = args.fill_values_with_prompt(&chain_config);
3132

32-
genesis(args, shell, &chain_config, &ecosystem_config).await?;
33+
genesis(args, shell, &chain_config).await?;
3334
logger::outro("Genesis completed successfully");
3435

3536
Ok(())
@@ -39,7 +40,6 @@ pub async fn genesis(
3940
args: GenesisArgsFinal,
4041
shell: &Shell,
4142
config: &ChainConfig,
42-
ecosystem_config: &EcosystemConfig,
4343
) -> anyhow::Result<()> {
4444
// Clean the rocksdb
4545
shell.remove_path(&config.rocks_db_path)?;
@@ -49,7 +49,7 @@ pub async fn genesis(
4949
.databases_config()
5050
.context("Database config was not fully generated")?;
5151
update_general_config(shell, config)?;
52-
update_secrets(shell, config, &db_config, ecosystem_config)?;
52+
update_database_secrets(shell, config, &db_config)?;
5353

5454
logger::note(
5555
"Selected config:",

zk_toolbox/crates/zk_inception/src/commands/chain/init.rs

+11-16
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use common::{
88
use xshell::Shell;
99

1010
use super::args::init::InitArgsFinal;
11+
use crate::configs::update_l1_rpc_url_secret;
1112
use crate::forge_utils::check_the_balance;
1213
use crate::{
1314
accept_ownership::accept_admin,
@@ -50,6 +51,7 @@ pub async fn init(
5051
copy_configs(shell, &ecosystem_config.link_to_code, &chain_config.configs)?;
5152

5253
update_genesis(shell, chain_config)?;
54+
update_l1_rpc_url_secret(shell, chain_config, init_args.l1_rpc_url.clone())?;
5355
let mut contracts_config =
5456
ContractsConfig::read(shell, ecosystem_config.config.join(CONTRACTS_FILE))?;
5557
contracts_config.l1.base_token_addr = chain_config.base_token.address;
@@ -62,6 +64,7 @@ pub async fn init(
6264
init_args.forge_args.clone(),
6365
ecosystem_config,
6466
chain_config,
67+
init_args.l1_rpc_url.clone(),
6568
)
6669
.await?;
6770
spinner.finish();
@@ -73,6 +76,7 @@ pub async fn init(
7376
chain_config.get_wallets_config()?.governor_private_key(),
7477
contracts_config.l1.diamond_proxy_addr,
7578
&init_args.forge_args.clone(),
79+
init_args.l1_rpc_url.clone(),
7680
)
7781
.await?;
7882
spinner.finish();
@@ -86,23 +90,13 @@ pub async fn init(
8690
.await?;
8791

8892
if init_args.deploy_paymaster {
89-
deploy_paymaster::deploy_paymaster(
90-
shell,
91-
chain_config,
92-
ecosystem_config,
93-
init_args.forge_args.clone(),
94-
)
95-
.await?;
93+
deploy_paymaster::deploy_paymaster(shell, chain_config, init_args.forge_args.clone())
94+
.await?;
9695
}
9796

98-
genesis(
99-
init_args.genesis_args.clone(),
100-
shell,
101-
chain_config,
102-
ecosystem_config,
103-
)
104-
.await
105-
.context("Unable to perform genesis on the database")?;
97+
genesis(init_args.genesis_args.clone(), shell, chain_config)
98+
.await
99+
.context("Unable to perform genesis on the database")?;
106100

107101
Ok(())
108102
}
@@ -112,6 +106,7 @@ async fn register_chain(
112106
forge_args: ForgeScriptArgs,
113107
config: &EcosystemConfig,
114108
chain_config: &ChainConfig,
109+
l1_rpc_url: String,
115110
) -> anyhow::Result<ContractsConfig> {
116111
let deploy_config_path = REGISTER_CHAIN.input(&config.link_to_code);
117112

@@ -124,7 +119,7 @@ async fn register_chain(
124119
let mut forge = Forge::new(&config.path_to_foundry())
125120
.script(&REGISTER_CHAIN.script(), forge_args.clone())
126121
.with_ffi()
127-
.with_rpc_url(config.l1_rpc_url.clone())
122+
.with_rpc_url(l1_rpc_url)
128123
.with_broadcast();
129124

130125
forge = fill_forge_private_key(forge, config.get_wallets()?.governor_private_key())?;

zk_toolbox/crates/zk_inception/src/commands/chain/initialize_bridges.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ pub async fn initialize_bridges(
4444
build_l2_contracts(shell, &ecosystem_config.link_to_code)?;
4545
let input = InitializeBridgeInput::new(chain_config, ecosystem_config.era_chain_id)?;
4646
let foundry_contracts_path = chain_config.path_to_foundry();
47+
let secrets = chain_config.get_secrets_config()?;
4748
input.save(shell, INITIALIZE_BRIDGES.input(&chain_config.link_to_code))?;
4849

4950
let mut forge = Forge::new(&foundry_contracts_path)
5051
.script(&INITIALIZE_BRIDGES.script(), forge_args.clone())
5152
.with_ffi()
52-
.with_rpc_url(ecosystem_config.l1_rpc_url.clone())
53+
.with_rpc_url(secrets.l1.l1_rpc_url.clone())
5354
.with_broadcast();
5455

5556
forge = fill_forge_private_key(

zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/create.rs

-20
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ use common::{slugify, Prompt, PromptConfirm, PromptSelect};
55
use serde::{Deserialize, Serialize};
66
use strum::IntoEnumIterator;
77
use strum_macros::{Display, EnumIter};
8-
use url::Url;
98

109
use crate::{
1110
commands::chain::{args::create::ChainCreateArgs, ChainCreateArgsFinal},
12-
defaults::LOCAL_RPC_URL,
1311
types::L1Network,
1412
wallets::WalletCreation,
1513
};
@@ -20,8 +18,6 @@ pub struct EcosystemCreateArgs {
2018
pub ecosystem_name: Option<String>,
2119
#[clap(long, help = "L1 Network", value_enum)]
2220
pub l1_network: Option<L1Network>,
23-
#[clap(long, help = "L1 RPC URL")]
24-
pub l1_rpc_url: Option<String>,
2521
#[clap(long, help = "Code link")]
2622
pub link_to_code: Option<String>,
2723
#[clap(flatten)]
@@ -52,20 +48,6 @@ impl EcosystemCreateArgs {
5248

5349
let l1_network = PromptSelect::new("Select the L1 network", L1Network::iter()).ask();
5450

55-
let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| {
56-
let mut prompt = Prompt::new("What is the RPC URL of the L1 network?");
57-
if l1_network == L1Network::Localhost {
58-
prompt = prompt.default(LOCAL_RPC_URL);
59-
}
60-
prompt
61-
.validate_with(|val: &String| -> Result<(), String> {
62-
Url::parse(val)
63-
.map(|_| ())
64-
.map_err(|_| "Invalid RPC url".to_string())
65-
})
66-
.ask()
67-
});
68-
6951
// Make the only chain as a default one
7052
self.chain.set_as_default = Some(true);
7153

@@ -85,7 +67,6 @@ impl EcosystemCreateArgs {
8567
link_to_code,
8668
wallet_creation: chain.wallet_creation,
8769
wallet_path: chain.wallet_path.clone(),
88-
l1_rpc_url,
8970
chain_args: chain,
9071
start_containers,
9172
}
@@ -99,7 +80,6 @@ pub struct EcosystemCreateArgsFinal {
9980
pub link_to_code: String,
10081
pub wallet_creation: WalletCreation,
10182
pub wallet_path: Option<PathBuf>,
102-
pub l1_rpc_url: String,
10383
pub chain_args: ChainCreateArgsFinal,
10484
pub start_containers: bool,
10585
}

0 commit comments

Comments
 (0)