From 93b4e08257802d11108870d867dd59fa35e52733 Mon Sep 17 00:00:00 2001 From: Danil Date: Thu, 12 Sep 2024 12:16:21 +0200 Subject: [PATCH] feat(zk_toolbox): deploy legacy bridge (#2837) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What ❔ Support legacy bridges in zk toolbox ## Why ❔ We still have some legacy bridges in production, so we have to have an opportunity to test it ## Checklist - [ ] 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`. --------- Signed-off-by: Danil --- .github/workflows/ci-core-reusable.yml | 36 +++++---- contracts | 2 +- prover/crates/lib/keystore/src/utils.rs | 1 + zk_toolbox/crates/common/src/server.rs | 8 +- zk_toolbox/crates/config/src/chain.rs | 4 + zk_toolbox/crates/config/src/ecosystem.rs | 1 + .../crates/config/src/forge_interface/mod.rs | 1 + .../src/forge_interface/script_params.rs | 6 ++ .../setup_legacy_bridge/mod.rs | 20 +++++ .../src/commands/args/run_server.rs | 4 +- .../src/commands/chain/args/create.rs | 4 + .../zk_inception/src/commands/chain/create.rs | 18 ++++- .../src/commands/chain/deploy_l2_contracts.rs | 14 +++- .../src/commands/chain/genesis.rs | 2 +- .../zk_inception/src/commands/chain/init.rs | 12 +++ .../zk_inception/src/commands/chain/mod.rs | 1 + .../src/commands/chain/setup_legacy_bridge.rs | 73 +++++++++++++++++++ .../zk_inception/src/commands/server.rs | 6 +- .../crates/zk_inception/src/messages.rs | 1 + .../src/commands/test/loadtest.rs | 52 +++++++++++++ .../zk_supervisor/src/commands/test/mod.rs | 10 ++- .../src/commands/test/recovery.rs | 2 +- .../crates/zk_supervisor/src/messages.rs | 2 + 23 files changed, 251 insertions(+), 29 deletions(-) create mode 100644 zk_toolbox/crates/config/src/forge_interface/setup_legacy_bridge/mod.rs create mode 100644 zk_toolbox/crates/zk_inception/src/commands/chain/setup_legacy_bridge.rs create mode 100644 zk_toolbox/crates/zk_supervisor/src/commands/test/loadtest.rs diff --git a/.github/workflows/ci-core-reusable.yml b/.github/workflows/ci-core-reusable.yml index 18cbc2c2afa3..a88a8fe3944e 100644 --- a/.github/workflows/ci-core-reusable.yml +++ b/.github/workflows/ci-core-reusable.yml @@ -71,7 +71,7 @@ jobs: strategy: fail-fast: false matrix: - vm_mode: [ "old", "new" ] + vm_mode: [ "OLD", "NEW" ] steps: - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 @@ -87,13 +87,12 @@ jobs: - name: Loadtest configuration run: | - echo EXPECTED_TX_COUNT=${{ matrix.vm_mode == 'new' && 21000 || 16000 }} >> .env + echo EXPECTED_TX_COUNT=${{ matrix.vm_mode == 'NEW' && 21000 || 16000 }} >> .env echo ACCOUNTS_AMOUNT="100" >> .env echo MAX_INFLIGHT_TXS="10" >> .env echo SYNC_API_REQUESTS_LIMIT="15" >> .env echo FAIL_FAST=true >> .env echo IN_DOCKER=1 >> .env - echo DATABASE_MERKLE_TREE_MODE=lightweight >> .env - name: Start services run: | @@ -107,23 +106,34 @@ jobs: ci_run git config --global --add safe.directory /usr/src/zksync/contracts/system-contracts ci_run git config --global --add safe.directory /usr/src/zksync/contracts - ci_run zk - ci_run zk init --local-legacy-bridge-testing + ci_run ./bin/zkt + ci_run zk_inception chain create \ + --chain-name legacy \ + --chain-id sequential \ + --prover-mode no-proofs \ + --wallet-creation localhost \ + --l1-batch-commit-data-generator-mode rollup \ + --base-token-address 0x0000000000000000000000000000000000000001 \ + --base-token-price-nominator 1 \ + --base-token-price-denominator 1 \ + --set-as-default false \ + --ignore-prerequisites \ + --legacy-bridge + + ci_run zk_inception ecosystem init --dev --verbose + ci_run zk_supervisor contracts --test-contracts # `sleep 60` because we need to wait until server added all the tokens - name: Run server run: | - EXPERIMENTAL_VM_STATE_KEEPER_FAST_VM_MODE=${{ matrix.vm_mode }} \ - CHAIN_MEMPOOL_DELAY_INTERVAL=50 \ - PASSED_ENV_VARS="EXPERIMENTAL_VM_STATE_KEEPER_FAST_VM_MODE,CHAIN_MEMPOOL_DELAY_INTERVAL" \ - ci_run zk server --uring --components api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads &>server.log & + ci_run sed -i -e 's/mode: FULL/mode: LIGHTWEIGHT/' chains/legacy/configs/general.yaml + ci_run sed -i -e 's/state_keeper_fast_vm_mode:.*/state_keeper_fast_vm_mode: ${{ matrix.vm_mode }}/' chains/legacy/configs/general.yaml + ci_run sed -i -e 's/delay_interval:.*/delay_interval: 50/' chains/legacy/configs/general.yaml + ci_run zk_inception server --uring --chain=legacy --components api,tree,eth,state_keeper,housekeeper,commitment_generator,vm_runner_protective_reads &>server.log & ci_run sleep 60 - - name: Deploy legacy era contracts - run: ci_run zk contract setup-legacy-bridge-era - - name: Perform loadtest - run: ci_run zk run loadtest + run: ci_run zk_supervisor t loadtest -v --chain=legacy - name: Show server.log logs if: always() diff --git a/contracts b/contracts index d3687694f71d..73b20c4b972f 160000 --- a/contracts +++ b/contracts @@ -1 +1 @@ -Subproject commit d3687694f71d83fa286b9c186b4c3ea173028f83 +Subproject commit 73b20c4b972f575613b4054d238332f93f2685cc diff --git a/prover/crates/lib/keystore/src/utils.rs b/prover/crates/lib/keystore/src/utils.rs index d9bb3b47dbb0..10504292d64f 100644 --- a/prover/crates/lib/keystore/src/utils.rs +++ b/prover/crates/lib/keystore/src/utils.rs @@ -115,6 +115,7 @@ pub fn calculate_snark_vk_hash(keystore: &Keystore) -> anyhow::Result { #[cfg(test)] mod tests { use std::str::FromStr; + use zksync_utils::env::Workspace; use super::*; diff --git a/zk_toolbox/crates/common/src/server.rs b/zk_toolbox/crates/common/src/server.rs index c65c8d4c13e2..40da1cf80325 100644 --- a/zk_toolbox/crates/common/src/server.rs +++ b/zk_toolbox/crates/common/src/server.rs @@ -9,6 +9,7 @@ use crate::cmd::Cmd; pub struct Server { components: Option>, code_path: PathBuf, + uring: bool, } /// Possible server modes. @@ -20,10 +21,11 @@ pub enum ServerMode { impl Server { /// Creates a new instance of the server. - pub fn new(components: Option>, code_path: PathBuf) -> Self { + pub fn new(components: Option>, code_path: PathBuf, uring: bool) -> Self { Self { components, code_path, + uring, } } @@ -52,10 +54,12 @@ impl Server { additional_args.push("--genesis".to_string()); } + let uring = self.uring.then_some("--features=rocksdb/io-uring"); + let mut cmd = Cmd::new( cmd!( shell, - "cargo run --release --bin zksync_server -- + "cargo run --release --bin zksync_server {uring...} -- --genesis-path {genesis_path} --wallets-path {wallets_path} --config-path {general_path} diff --git a/zk_toolbox/crates/config/src/chain.rs b/zk_toolbox/crates/config/src/chain.rs index 54ed1f7d3f35..affc8ccc770c 100644 --- a/zk_toolbox/crates/config/src/chain.rs +++ b/zk_toolbox/crates/config/src/chain.rs @@ -38,6 +38,8 @@ pub struct ChainConfigInternal { pub l1_batch_commit_data_generator_mode: L1BatchCommitmentMode, pub base_token: BaseToken, pub wallet_creation: WalletCreation, + #[serde(skip_serializing_if = "Option::is_none")] + pub legacy_bridge: Option, } /// Chain configuration file. This file is created in the chain @@ -58,6 +60,7 @@ pub struct ChainConfig { pub base_token: BaseToken, pub wallet_creation: WalletCreation, pub shell: OnceCell, + pub legacy_bridge: Option, } impl Serialize for ChainConfig { @@ -153,6 +156,7 @@ impl ChainConfig { l1_batch_commit_data_generator_mode: self.l1_batch_commit_data_generator_mode, base_token: self.base_token.clone(), wallet_creation: self.wallet_creation, + legacy_bridge: self.legacy_bridge, } } } diff --git a/zk_toolbox/crates/config/src/ecosystem.rs b/zk_toolbox/crates/config/src/ecosystem.rs index a0412fbc4733..7ff65d4612df 100644 --- a/zk_toolbox/crates/config/src/ecosystem.rs +++ b/zk_toolbox/crates/config/src/ecosystem.rs @@ -173,6 +173,7 @@ impl EcosystemConfig { artifacts: config .artifacts_path .unwrap_or_else(|| self.get_chain_artifacts_path(name)), + legacy_bridge: config.legacy_bridge, }) } diff --git a/zk_toolbox/crates/config/src/forge_interface/mod.rs b/zk_toolbox/crates/config/src/forge_interface/mod.rs index ea3d49c67ecb..c7033c45ed22 100644 --- a/zk_toolbox/crates/config/src/forge_interface/mod.rs +++ b/zk_toolbox/crates/config/src/forge_interface/mod.rs @@ -4,3 +4,4 @@ pub mod deploy_l2_contracts; pub mod paymaster; pub mod register_chain; pub mod script_params; +pub mod setup_legacy_bridge; diff --git a/zk_toolbox/crates/config/src/forge_interface/script_params.rs b/zk_toolbox/crates/config/src/forge_interface/script_params.rs index fb16aa97e6a8..e7e21ad132b8 100644 --- a/zk_toolbox/crates/config/src/forge_interface/script_params.rs +++ b/zk_toolbox/crates/config/src/forge_interface/script_params.rs @@ -61,3 +61,9 @@ pub const ACCEPT_GOVERNANCE_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams output: "script-out/output-accept-admin.toml", script_path: "deploy-scripts/AcceptAdmin.s.sol", }; + +pub const SETUP_LEGACY_BRIDGE: ForgeScriptParams = ForgeScriptParams { + input: "script-config/setup-legacy-bridge.toml", + output: "script-out/setup-legacy-bridge.toml", + script_path: "deploy-scripts/dev/SetupLegacyBridge.s.sol", +}; diff --git a/zk_toolbox/crates/config/src/forge_interface/setup_legacy_bridge/mod.rs b/zk_toolbox/crates/config/src/forge_interface/setup_legacy_bridge/mod.rs new file mode 100644 index 000000000000..e8189c521fb3 --- /dev/null +++ b/zk_toolbox/crates/config/src/forge_interface/setup_legacy_bridge/mod.rs @@ -0,0 +1,20 @@ +use serde::{Deserialize, Serialize}; +use zksync_basic_types::{Address, L2ChainId, H256}; + +use crate::traits::ZkToolboxConfig; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct SetupLegacyBridgeInput { + pub bridgehub: Address, + pub diamond_proxy: Address, + pub shared_bridge_proxy: Address, + pub transparent_proxy_admin: Address, + pub erc20bridge_proxy: Address, + pub token_weth_address: Address, + pub chain_id: L2ChainId, + pub l2shared_bridge_address: Address, + pub create2factory_salt: H256, + pub create2factory_addr: Address, +} + +impl ZkToolboxConfig for SetupLegacyBridgeInput {} diff --git a/zk_toolbox/crates/zk_inception/src/commands/args/run_server.rs b/zk_toolbox/crates/zk_inception/src/commands/args/run_server.rs index 1e373319ec73..ebe407d4822d 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/args/run_server.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/args/run_server.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::messages::{ MSG_SERVER_ADDITIONAL_ARGS_HELP, MSG_SERVER_BUILD_HELP, MSG_SERVER_COMPONENTS_HELP, - MSG_SERVER_GENESIS_HELP, + MSG_SERVER_GENESIS_HELP, MSG_SERVER_URING_HELP, }; #[derive(Debug, Serialize, Deserialize, Parser)] @@ -17,4 +17,6 @@ pub struct RunServerArgs { additional_args: Vec, #[clap(long, help = MSG_SERVER_BUILD_HELP)] pub build: bool, + #[clap(help=MSG_SERVER_URING_HELP, long, default_missing_value = "true", num_args = 0..=1)] + pub uring: bool, } diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/create.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/create.rs index 65f809287890..3ea15d10f8be 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/args/create.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/create.rs @@ -65,6 +65,8 @@ pub struct ChainCreateArgs { base_token_price_denominator: Option, #[clap(long, help = MSG_SET_AS_DEFAULT_HELP, default_missing_value = "true", num_args = 0..=1)] pub(crate) set_as_default: Option, + #[clap(long, default_value = "false")] + pub(crate) legacy_bridge: bool, } impl ChainCreateArgs { @@ -224,6 +226,7 @@ impl ChainCreateArgs { wallet_path, base_token, set_as_default, + legacy_bridge: self.legacy_bridge, }) } } @@ -238,6 +241,7 @@ pub struct ChainCreateArgsFinal { pub wallet_path: Option, pub base_token: BaseToken, pub set_as_default: bool, + pub legacy_bridge: bool, } #[derive(Debug, Clone, EnumIter, Display, PartialEq, Eq)] diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/create.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/create.rs index abdea482db4c..48a320ec27e0 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/create.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/create.rs @@ -59,15 +59,24 @@ pub(crate) fn create_chain_inner( ecosystem_config: &EcosystemConfig, shell: &Shell, ) -> anyhow::Result<()> { + if args.legacy_bridge { + logger::warn("WARNING!!! You are creating a chain with legacy bridge, use it only for testing compatibility") + } let default_chain_name = args.chain_name.clone(); let chain_path = ecosystem_config.chains.join(&default_chain_name); let chain_configs_path = create_local_configs_dir(shell, &chain_path)?; - let chain_id = ecosystem_config.list_of_chains().len() as u32; + let (chain_id, legacy_bridge) = if args.legacy_bridge { + // Legacy bridge is distinguished by using the same chain id as ecosystem + (ecosystem_config.era_chain_id, Some(true)) + } else { + (L2ChainId::from(args.chain_id), None) + }; + let internal_id = ecosystem_config.list_of_chains().len() as u32; let chain_config = ChainConfig { - id: chain_id, + id: internal_id, name: default_chain_name.clone(), - chain_id: L2ChainId::from(args.chain_id), + chain_id, prover_version: args.prover_version, l1_network: ecosystem_config.l1_network, link_to_code: ecosystem_config.link_to_code.clone(), @@ -79,13 +88,14 @@ pub(crate) fn create_chain_inner( base_token: args.base_token, wallet_creation: args.wallet_creation, shell: OnceCell::from(shell.clone()), + legacy_bridge, }; create_wallets( shell, &chain_config.configs, &ecosystem_config.link_to_code, - chain_id, + internal_id, args.wallet_creation, args.wallet_path, )?; diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_l2_contracts.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_l2_contracts.rs index 3625abfb15a9..7545ec2ec26f 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_l2_contracts.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_l2_contracts.rs @@ -125,12 +125,17 @@ pub async fn initialize_bridges( contracts_config: &mut ContractsConfig, forge_args: ForgeScriptArgs, ) -> anyhow::Result<()> { + let signature = if let Some(true) = chain_config.legacy_bridge { + Some("runDeployLegacySharedBridge") + } else { + Some("runDeploySharedBridge") + }; build_and_deploy( shell, chain_config, ecosystem_config, forge_args, - Some("runDeploySharedBridge"), + signature, |shell, out| { contracts_config.set_l2_shared_bridge(&InitializeBridgeOutput::read(shell, out)?) }, @@ -185,12 +190,17 @@ pub async fn deploy_l2_contracts( contracts_config: &mut ContractsConfig, forge_args: ForgeScriptArgs, ) -> anyhow::Result<()> { + let signature = if let Some(true) = chain_config.legacy_bridge { + Some("runWithLegacyBridge") + } else { + None + }; build_and_deploy( shell, chain_config, ecosystem_config, forge_args, - None, + signature, |shell, out| { contracts_config.set_l2_shared_bridge(&InitializeBridgeOutput::read(shell, out)?)?; contracts_config.set_default_l2_upgrade(&DefaultL2UpgradeOutput::read(shell, out)?)?; 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 0eb40d630ae9..bfa3f94916b8 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/genesis.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/genesis.rs @@ -168,7 +168,7 @@ async fn initialize_databases( } fn run_server_genesis(chain_config: &ChainConfig, shell: &Shell) -> anyhow::Result<()> { - let server = Server::new(None, chain_config.link_to_code.clone()); + let server = Server::new(None, chain_config.link_to_code.clone(), false); server .run( shell, 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 a5f57981d583..2b7dbf73f681 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs @@ -27,6 +27,7 @@ use crate::{ deploy_l2_contracts, deploy_paymaster, genesis::genesis, set_token_multiplier_setter::set_token_multiplier_setter, + setup_legacy_bridge::setup_legacy_bridge, }, portal::update_portal_config, }, @@ -142,6 +143,17 @@ pub async fn init( .await?; contracts_config.save_with_base_path(shell, &chain_config.configs)?; + if let Some(true) = chain_config.legacy_bridge { + setup_legacy_bridge( + shell, + chain_config, + ecosystem_config, + &contracts_config, + init_args.forge_args.clone(), + ) + .await?; + } + if init_args.deploy_paymaster { deploy_paymaster::deploy_paymaster( shell, diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs index afc92d2288bf..61a164c16553 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs @@ -16,6 +16,7 @@ pub mod deploy_paymaster; pub mod genesis; pub(crate) mod init; mod set_token_multiplier_setter; +mod setup_legacy_bridge; #[derive(Subcommand, Debug)] pub enum ChainCommands { diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/setup_legacy_bridge.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/setup_legacy_bridge.rs new file mode 100644 index 000000000000..925014fe4e61 --- /dev/null +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/setup_legacy_bridge.rs @@ -0,0 +1,73 @@ +use anyhow::Context; +use common::{ + forge::{Forge, ForgeScriptArgs}, + spinner::Spinner, +}; +use config::{ + forge_interface::{ + script_params::SETUP_LEGACY_BRIDGE, setup_legacy_bridge::SetupLegacyBridgeInput, + }, + traits::SaveConfig, + ChainConfig, ContractsConfig, EcosystemConfig, +}; +use xshell::Shell; + +use crate::{ + messages::{MSG_DEPLOYING_PAYMASTER, MSG_L1_SECRETS_MUST_BE_PRESENTED}, + utils::forge::{check_the_balance, fill_forge_private_key}, +}; + +pub async fn setup_legacy_bridge( + shell: &Shell, + chain_config: &ChainConfig, + ecosystem_config: &EcosystemConfig, + contracts_config: &ContractsConfig, + forge_args: ForgeScriptArgs, +) -> anyhow::Result<()> { + let input = SetupLegacyBridgeInput { + bridgehub: contracts_config.ecosystem_contracts.bridgehub_proxy_addr, + diamond_proxy: contracts_config.l1.diamond_proxy_addr, + shared_bridge_proxy: contracts_config.bridges.shared.l1_address, + transparent_proxy_admin: contracts_config + .ecosystem_contracts + .transparent_proxy_admin_addr, + erc20bridge_proxy: contracts_config.bridges.erc20.l1_address, + token_weth_address: Default::default(), + chain_id: chain_config.chain_id, + l2shared_bridge_address: contracts_config + .bridges + .shared + .l2_address + .expect("Not fully initialized"), + create2factory_salt: contracts_config.create2_factory_salt, + create2factory_addr: contracts_config.create2_factory_addr, + }; + let foundry_contracts_path = chain_config.path_to_foundry(); + input.save(shell, SETUP_LEGACY_BRIDGE.input(&chain_config.link_to_code))?; + let secrets = chain_config.get_secrets_config()?; + + let mut forge = Forge::new(&foundry_contracts_path) + .script(&SETUP_LEGACY_BRIDGE.script(), forge_args.clone()) + .with_ffi() + .with_rpc_url( + secrets + .l1 + .context(MSG_L1_SECRETS_MUST_BE_PRESENTED)? + .l1_rpc_url + .expose_str() + .to_string(), + ) + .with_broadcast(); + + forge = fill_forge_private_key( + forge, + ecosystem_config.get_wallets()?.governor_private_key(), + )?; + + let spinner = Spinner::new(MSG_DEPLOYING_PAYMASTER); + check_the_balance(&forge).await?; + forge.run(shell)?; + spinner.finish(); + + Ok(()) +} diff --git a/zk_toolbox/crates/zk_inception/src/commands/server.rs b/zk_toolbox/crates/zk_inception/src/commands/server.rs index b5a09ed04370..f96bc3aeebc9 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/server.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/server.rs @@ -35,7 +35,11 @@ fn run_server( chain_config: &ChainConfig, shell: &Shell, ) -> anyhow::Result<()> { - let server = Server::new(args.components.clone(), chain_config.link_to_code.clone()); + let server = Server::new( + args.components.clone(), + chain_config.link_to_code.clone(), + args.uring, + ); if args.build { server.build(shell)?; diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index 827aa03d7ba8..6fa1e293927b 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -224,6 +224,7 @@ pub(super) const MSG_SERVER_GENESIS_HELP: &str = "Run server in genesis mode"; pub(super) const MSG_SERVER_ADDITIONAL_ARGS_HELP: &str = "Additional arguments that can be passed through the CLI"; pub(super) const MSG_SERVER_BUILD_HELP: &str = "Build server but don't run it"; +pub(super) const MSG_SERVER_URING_HELP: &str = "Enables uring support for RocksDB"; /// Accept ownership related messages pub(super) const MSG_ACCEPTING_GOVERNANCE_SPINNER: &str = "Accepting governance..."; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/loadtest.rs b/zk_toolbox/crates/zk_supervisor/src/commands/test/loadtest.rs new file mode 100644 index 000000000000..5a2a87871b58 --- /dev/null +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/loadtest.rs @@ -0,0 +1,52 @@ +use anyhow::Context; +use common::{cmd::Cmd, config::global_config, logger}; +use config::EcosystemConfig; +use xshell::{cmd, Shell}; + +use crate::messages::MSG_CHAIN_NOT_FOUND_ERR; + +pub fn run(shell: &Shell) -> anyhow::Result<()> { + let ecosystem_config = EcosystemConfig::from_file(shell)?; + + let chain_config = ecosystem_config + .load_chain(global_config().chain_name.clone()) + .context(MSG_CHAIN_NOT_FOUND_ERR)?; + + let general_api = chain_config + .get_general_config()? + .api_config + .context("API config is not found")?; + + let mut command = cmd!(shell, "cargo run --release --bin loadnext") + .env( + "L2_CHAIN_ID", + chain_config + .get_genesis_config()? + .l2_chain_id + .as_u64() + .to_string(), + ) + .env( + "MAIN_TOKEN", + format!( + "{:?}", + ecosystem_config + .get_erc20_tokens() + .first() + .context("NO Erc20 tokens were deployed")? + .address + ), + ) + .env("L2_RPC_ADDRESS", general_api.web3_json_rpc.http_url) + .env("L2_WS_RPC_ADDRESS", general_api.web3_json_rpc.ws_url); + + if global_config().verbose { + command = command.env("RUST_LOG", "loadnext=info") + } + + Cmd::new(command).with_force_run().run()?; + + logger::outro("Loadtest success"); + + Ok(()) +} diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs index a536302afc15..712e2f75eefd 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/mod.rs @@ -6,15 +6,16 @@ use clap::Subcommand; use xshell::Shell; use crate::messages::{ - MSG_BUILD_ABOUT, MSG_INTEGRATION_TESTS_ABOUT, MSG_L1_CONTRACTS_ABOUT, MSG_PROVER_TEST_ABOUT, - MSG_RECOVERY_TEST_ABOUT, MSG_REVERT_TEST_ABOUT, MSG_RUST_TEST_ABOUT, MSG_TEST_WALLETS_INFO, - MSG_UPGRADE_TEST_ABOUT, + MSG_BUILD_ABOUT, MSG_INTEGRATION_TESTS_ABOUT, MSG_L1_CONTRACTS_ABOUT, MSG_LOADTEST_ABOUT, + MSG_PROVER_TEST_ABOUT, MSG_RECOVERY_TEST_ABOUT, MSG_REVERT_TEST_ABOUT, MSG_RUST_TEST_ABOUT, + MSG_TEST_WALLETS_INFO, MSG_UPGRADE_TEST_ABOUT, }; mod args; mod build; mod integration; mod l1_contracts; +mod loadtest; mod prover; mod recovery; mod revert; @@ -43,6 +44,8 @@ pub enum TestCommands { Prover, #[clap(about = MSG_TEST_WALLETS_INFO)] Wallet, + #[clap(about = MSG_LOADTEST_ABOUT)] + Loadtest, } pub async fn run(shell: &Shell, args: TestCommands) -> anyhow::Result<()> { @@ -56,5 +59,6 @@ pub async fn run(shell: &Shell, args: TestCommands) -> anyhow::Result<()> { TestCommands::L1Contracts => l1_contracts::run(shell), TestCommands::Prover => prover::run(shell), TestCommands::Wallet => wallet::run(shell), + TestCommands::Loadtest => loadtest::run(shell), } } diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/recovery.rs b/zk_toolbox/crates/zk_supervisor/src/commands/test/recovery.rs index 030d28966031..c69a9826d56c 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/recovery.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/recovery.rs @@ -21,7 +21,7 @@ pub async fn run(shell: &Shell, args: RecoveryArgs) -> anyhow::Result<()> { shell.change_dir(ecosystem_config.link_to_code.join(RECOVERY_TESTS_PATH)); logger::info(MSG_RECOVERY_TEST_RUN_INFO); - Server::new(None, ecosystem_config.link_to_code.clone()).build(shell)?; + Server::new(None, ecosystem_config.link_to_code.clone(), false).build(shell)?; if !args.no_deps { install_and_build_dependencies(shell, &ecosystem_config)?; diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index 89cf8c1d9b60..311a6e11c326 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -200,3 +200,5 @@ pub(super) const MSG_RUNNING_CONTRACTS_FMT_SPINNER: &str = "Running prettier for pub(super) const MSG_TEST_WALLETS_INFO: &str = "Print test wallets information"; pub(super) const MSG_DESERIALIZE_TEST_WALLETS_ERR: &str = "Impossible to deserialize test wallets"; pub(super) const MSG_WALLETS_TEST_SUCCESS: &str = "Wallets test success"; + +pub(super) const MSG_LOADTEST_ABOUT: &str = "Run loadtest";