From d26261d8e5bb3fb819e16a1fbe420ca6c7d4cc4a Mon Sep 17 00:00:00 2001 From: perekopskiy Date: Fri, 27 Sep 2024 13:26:31 +0300 Subject: [PATCH] fmt --- core/bin/external_node/src/config/mod.rs | 20 +---- core/bin/external_node/src/node_builder.rs | 13 +-- core/bin/zksync_server/src/node_builder.rs | 10 +-- core/lib/config/src/configs/contracts.rs | 4 - core/lib/config/src/testonly.rs | 2 - core/lib/dal/src/consensus/mod.rs | 49 ++++++------ core/lib/dal/src/consensus/proto/mod.proto | 2 +- core/lib/dal/src/consensus/tests.rs | 4 +- core/lib/dal/src/models/storage_sync.rs | 4 +- core/lib/env_config/src/contracts.rs | 5 -- core/lib/protobuf_config/src/contracts.rs | 18 ----- .../src/proto/config/contracts.proto | 4 +- core/lib/types/src/api/en.rs | 2 +- core/lib/types/src/api/mod.rs | 1 + core/lib/web3_decl/src/namespaces/zks.rs | 6 -- .../web3/backend_jsonrpsee/namespaces/zks.rs | 12 +-- .../api_server/src/web3/namespaces/zks.rs | 20 ++--- core/node/api_server/src/web3/state.rs | 5 +- core/node/consensus/src/storage/store.rs | 2 +- core/node/consensus/src/testonly.rs | 8 +- .../layers/state_keeper/output_handler.rs | 12 +-- core/node/node_sync/src/fetcher.rs | 2 +- core/node/node_sync/src/tests.rs | 9 +-- core/node/state_keeper/src/io/mempool.rs | 9 ++- core/node/state_keeper/src/io/persistence.rs | 80 ++++--------------- .../io/seal_logic/l2_block_seal_subtasks.rs | 13 ++- .../state_keeper/src/io/seal_logic/mod.rs | 6 +- core/node/state_keeper/src/io/tests/mod.rs | 17 +--- core/node/state_keeper/src/updates/mod.rs | 10 +-- 29 files changed, 98 insertions(+), 251 deletions(-) diff --git a/core/bin/external_node/src/config/mod.rs b/core/bin/external_node/src/config/mod.rs index 821df0a06de..dad2f3a87f6 100644 --- a/core/bin/external_node/src/config/mod.rs +++ b/core/bin/external_node/src/config/mod.rs @@ -111,7 +111,7 @@ pub(crate) struct RemoteENConfig { // a different name, with names adapted only for consistency. pub l1_shared_bridge_proxy_addr: Option
, pub l2_shared_bridge_addr: Option
, - pub l2_legacy_shared_bridge_addr: Option
, + pub l2_token_deployer_addr: Option
, pub l1_erc20_bridge_proxy_addr: Option
, pub l2_erc20_bridge_addr: Option
, pub l1_weth_bridge_addr: Option
, @@ -122,7 +122,6 @@ pub(crate) struct RemoteENConfig { pub dummy_verifier: bool, pub user_facing_bridgehub: Option
, - pub l2_native_token_vault_proxy_addr: Option
, } impl RemoteENConfig { @@ -135,14 +134,6 @@ impl RemoteENConfig { .get_testnet_paymaster() .rpc_context("get_testnet_paymaster") .await?; - let l2_native_token_vault_proxy_addr = client - .get_native_token_vault_proxy_addr() - .rpc_context("get_native_token_vault") - .await?; - let l2_legacy_shared_bridge_addr = client - .get_legacy_shared_bridge() - .rpc_context("get_legacy_shared_bridge") - .await?; let genesis = client.genesis_config().rpc_context("genesis").await.ok(); let ecosystem_contracts = client .get_ecosystem_contracts() @@ -208,7 +199,7 @@ impl RemoteENConfig { l2_erc20_bridge_addr: l2_erc20_default_bridge, l1_shared_bridge_proxy_addr: bridges.l1_shared_default_bridge, l2_shared_bridge_addr: l2_erc20_shared_bridge, - l2_legacy_shared_bridge_addr, + l2_token_deployer_addr: bridges.l2_token_deployer, l1_weth_bridge_addr: bridges.l1_weth_bridge, l2_weth_bridge_addr: bridges.l2_weth_bridge, base_token_addr, @@ -220,7 +211,6 @@ impl RemoteENConfig { .as_ref() .map(|a| a.dummy_verifier) .unwrap_or_default(), - l2_native_token_vault_proxy_addr, }) } @@ -240,10 +230,9 @@ impl RemoteENConfig { l1_shared_bridge_proxy_addr: Some(Address::repeat_byte(5)), l1_weth_bridge_addr: None, l2_shared_bridge_addr: Some(Address::repeat_byte(6)), - l2_legacy_shared_bridge_addr: Some(Address::repeat_byte(7)), + l2_token_deployer_addr: Some(Address::repeat_byte(6)), l1_batch_commit_data_generator_mode: L1BatchCommitmentMode::Rollup, dummy_verifier: true, - l2_native_token_vault_proxy_addr: Some(Address::repeat_byte(7)), } } } @@ -1417,6 +1406,7 @@ impl From<&ExternalNodeConfig> for InternalApiConfig { l2_shared_default_bridge: config.remote.l2_shared_bridge_addr, l1_weth_bridge: config.remote.l1_weth_bridge_addr, l2_weth_bridge: config.remote.l2_weth_bridge_addr, + l2_token_deployer: config.remote.l2_token_deployer_addr, }, bridgehub_proxy_addr: config.remote.bridgehub_proxy_addr, state_transition_proxy_addr: config.remote.state_transition_proxy_addr, @@ -1430,8 +1420,6 @@ impl From<&ExternalNodeConfig> for InternalApiConfig { filters_disabled: config.optional.filters_disabled, dummy_verifier: config.remote.dummy_verifier, l1_batch_commit_data_generator_mode: config.remote.l1_batch_commit_data_generator_mode, - l2_native_token_vault_proxy_addr: config.remote.l2_native_token_vault_proxy_addr, - l2_legacy_shared_bridge_addr: config.remote.l2_legacy_shared_bridge_addr, } } } diff --git a/core/bin/external_node/src/node_builder.rs b/core/bin/external_node/src/node_builder.rs index 70912552d93..4a5c143b275 100644 --- a/core/bin/external_node/src/node_builder.rs +++ b/core/bin/external_node/src/node_builder.rs @@ -192,18 +192,7 @@ impl ExternalNodeBuilder { const OPTIONAL_BYTECODE_COMPRESSION: bool = true; let persistence_layer = OutputHandlerLayer::new( - self.config - .remote - .l2_shared_bridge_addr - .expect("L2 shared bridge address is not set"), - self.config - .remote - .l2_native_token_vault_proxy_addr - .expect("L2 native token vault proxy address is not set"), - self.config - .remote - .l2_legacy_shared_bridge_addr - .expect("L2 legacy shared bridge address is not set"), + self.config.remote.l2_token_deployer_addr, self.config.optional.l2_block_seal_queue_capacity, ) .with_pre_insert_txs(true) // EN requires txs to be pre-inserted. diff --git a/core/bin/zksync_server/src/node_builder.rs b/core/bin/zksync_server/src/node_builder.rs index 763fd600e6f..01eea137b57 100644 --- a/core/bin/zksync_server/src/node_builder.rs +++ b/core/bin/zksync_server/src/node_builder.rs @@ -240,15 +240,7 @@ impl MainNodeBuilder { let wallets = self.wallets.clone(); let sk_config = try_load_config!(self.configs.state_keeper_config); let persistence_layer = OutputHandlerLayer::new( - self.contracts_config - .l2_shared_bridge_addr - .context("L2 shared bridge address")?, - self.contracts_config - .l2_native_token_vault_proxy_addr - .context("L2 native token vault proxy address")?, - self.contracts_config - .l2_legacy_shared_bridge_addr - .context("L2 legacy shared bridge address")?, + self.contracts_config.l2_shared_bridge_addr, sk_config.l2_block_seal_queue_capacity, ) .with_protective_reads_persistence_enabled(sk_config.protective_reads_persistence_enabled); diff --git a/core/lib/config/src/configs/contracts.rs b/core/lib/config/src/configs/contracts.rs index bf88c100cce..d96983c9719 100644 --- a/core/lib/config/src/configs/contracts.rs +++ b/core/lib/config/src/configs/contracts.rs @@ -30,7 +30,6 @@ pub struct ContractsConfig { pub validator_timelock_addr: Address, pub l1_shared_bridge_proxy_addr: Option
, pub l2_shared_bridge_addr: Option
, - pub l2_legacy_shared_bridge_addr: Option
, pub l1_erc20_bridge_proxy_addr: Option
, pub l2_erc20_bridge_addr: Option
, pub l1_weth_bridge_proxy_addr: Option
, @@ -44,7 +43,6 @@ pub struct ContractsConfig { // FIXME: maybe refactor pub user_facing_bridgehub_proxy_addr: Option
, pub user_facing_diamond_proxy_addr: Option
, - pub l2_native_token_vault_proxy_addr: Option
, pub l2_da_validator_addr: Option
, @@ -62,7 +60,6 @@ impl ContractsConfig { l2_erc20_bridge_addr: Some(Address::repeat_byte(0x0c)), l1_shared_bridge_proxy_addr: Some(Address::repeat_byte(0x0e)), l2_shared_bridge_addr: Some(Address::repeat_byte(0x0f)), - l2_legacy_shared_bridge_addr: Some(Address::repeat_byte(0x10)), l1_weth_bridge_proxy_addr: Some(Address::repeat_byte(0x0b)), l2_weth_bridge_addr: Some(Address::repeat_byte(0x0c)), l2_testnet_paymaster_addr: Some(Address::repeat_byte(0x11)), @@ -72,7 +69,6 @@ impl ContractsConfig { ecosystem_contracts: Some(EcosystemContracts::for_tests()), user_facing_bridgehub_proxy_addr: Some(Address::repeat_byte(0x15)), user_facing_diamond_proxy_addr: Some(Address::repeat_byte(0x16)), - l2_native_token_vault_proxy_addr: Some(Address::repeat_byte(0x0d)), chain_admin_addr: Some(Address::repeat_byte(0x18)), l2_da_validator_addr: Some(Address::repeat_byte(0x19)), } diff --git a/core/lib/config/src/testonly.rs b/core/lib/config/src/testonly.rs index f8a1105fe70..b8ad2bc8cd2 100644 --- a/core/lib/config/src/testonly.rs +++ b/core/lib/config/src/testonly.rs @@ -252,7 +252,6 @@ impl Distribution for EncodeDist { l2_erc20_bridge_addr: self.sample_opt(|| rng.gen()), l1_shared_bridge_proxy_addr: self.sample_opt(|| rng.gen()), l2_shared_bridge_addr: self.sample_opt(|| rng.gen()), - l2_legacy_shared_bridge_addr: self.sample_opt(|| rng.gen()), l1_weth_bridge_proxy_addr: self.sample_opt(|| rng.gen()), l2_weth_bridge_addr: self.sample_opt(|| rng.gen()), l2_testnet_paymaster_addr: self.sample_opt(|| rng.gen()), @@ -260,7 +259,6 @@ impl Distribution for EncodeDist { ecosystem_contracts: self.sample(rng), user_facing_bridgehub_proxy_addr: rng.gen(), user_facing_diamond_proxy_addr: rng.gen(), - l2_native_token_vault_proxy_addr: rng.gen(), l2_da_validator_addr: rng.gen(), base_token_addr: self.sample_opt(|| rng.gen()), chain_admin_addr: self.sample_opt(|| rng.gen()), diff --git a/core/lib/dal/src/consensus/mod.rs b/core/lib/dal/src/consensus/mod.rs index 763c13cc387..2a2df0adb45 100644 --- a/core/lib/dal/src/consensus/mod.rs +++ b/core/lib/dal/src/consensus/mod.rs @@ -142,7 +142,7 @@ pub struct Payload { pub fair_pubdata_price: Option, pub virtual_blocks: u32, pub operator_address: Address, - pub pubdata_params: PubdataParams, + pub pubdata_params: Option, pub transactions: Vec, pub last_in_batch: bool, } @@ -180,9 +180,19 @@ impl ProtoFmt for Payload { } } - let pubdata_params = required(&r.pubdata_params) - .context("pubdata_params")? - .clone(); + let pubdata_params = if let Some(pubdata_params) = &r.pubdata_params { + Some(PubdataParams { + l2_da_validator_address: required(&pubdata_params.l2_da_validator_address) + .and_then(|a| parse_h160(a)) + .context("operator_address")?, + pubdata_type: required(&pubdata_params.pubdata_type) + .and_then(|x| Ok(proto::L1BatchCommitDataGeneratorMode::try_from(*x)?)) + .context("l1_batch_commit_data_generator_mode")? + .parse(), + }) + } else { + None + }; Ok(Self { protocol_version, @@ -202,15 +212,7 @@ impl ProtoFmt for Payload { .context("operator_address")?, transactions, last_in_batch: *required(&r.last_in_batch).context("last_in_batch")?, - pubdata_params: PubdataParams { - l2_da_validator_address: required(&pubdata_params.l2_da_validator_address) - .and_then(|a| parse_h160(a)) - .context("operator_address")?, - pubdata_type: required(&pubdata_params.pubdata_type) - .and_then(|x| Ok(proto::L1BatchCommitDataGeneratorMode::try_from(*x)?)) - .context("l1_batch_commit_data_generator_mode")? - .parse(), - }, + pubdata_params, }) } @@ -229,17 +231,16 @@ impl ProtoFmt for Payload { transactions: vec![], transactions_v25: vec![], last_in_batch: Some(self.last_in_batch), - pubdata_params: Some(proto::PubdataParams { - l2_da_validator_address: Some( - self.pubdata_params - .l2_da_validator_address - .as_bytes() - .into(), - ), - pubdata_type: Some(proto::L1BatchCommitDataGeneratorMode::new( - &self.pubdata_params.pubdata_type, - ) as i32), - }), + pubdata_params: self + .pubdata_params + .map(|pubdata_params| proto::PubdataParams { + l2_da_validator_address: Some( + pubdata_params.l2_da_validator_address.as_bytes().into(), + ), + pubdata_type: Some(proto::L1BatchCommitDataGeneratorMode::new( + &pubdata_params.pubdata_type, + ) as i32), + }), }; match self.protocol_version { v if v >= ProtocolVersionId::Version25 => { diff --git a/core/lib/dal/src/consensus/proto/mod.proto b/core/lib/dal/src/consensus/proto/mod.proto index 24a8297031d..6083ad02910 100644 --- a/core/lib/dal/src/consensus/proto/mod.proto +++ b/core/lib/dal/src/consensus/proto/mod.proto @@ -27,7 +27,7 @@ message Payload { // Set for protocol_version >= 25. repeated TransactionV25 transactions_v25 = 12; optional bool last_in_batch = 10; // required - optional PubdataParams pubdata_params = 13; // required + optional PubdataParams pubdata_params = 13; // optional } message PubdataParams { diff --git a/core/lib/dal/src/consensus/tests.rs b/core/lib/dal/src/consensus/tests.rs index c99f8a37f7c..e50ff5b1cae 100644 --- a/core/lib/dal/src/consensus/tests.rs +++ b/core/lib/dal/src/consensus/tests.rs @@ -53,13 +53,13 @@ fn payload(rng: &mut impl Rng, protocol_version: ProtocolVersionId) -> Payload { }) .collect(), last_in_batch: rng.gen(), - pubdata_params: PubdataParams { + pubdata_params: Some(PubdataParams { pubdata_type: match rng.gen_range(0..2) { 0 => L1BatchCommitmentMode::Rollup, _ => L1BatchCommitmentMode::Validium, }, l2_da_validator_address: rng.gen(), - }, + }), } } diff --git a/core/lib/dal/src/models/storage_sync.rs b/core/lib/dal/src/models/storage_sync.rs index b9ef075f985..7bb3c228748 100644 --- a/core/lib/dal/src/models/storage_sync.rs +++ b/core/lib/dal/src/models/storage_sync.rs @@ -117,7 +117,7 @@ impl SyncBlock { virtual_blocks: Some(self.virtual_blocks), hash: Some(self.hash), protocol_version: self.protocol_version, - pubdata_params: self.pubdata_params, + pubdata_params: Some(self.pubdata_params), } } @@ -134,7 +134,7 @@ impl SyncBlock { operator_address: self.fee_account_address, transactions, last_in_batch: self.last_in_batch, - pubdata_params: self.pubdata_params, + pubdata_params: Some(self.pubdata_params), } } } diff --git a/core/lib/env_config/src/contracts.rs b/core/lib/env_config/src/contracts.rs index d1c6a252b02..01756fd2fd9 100644 --- a/core/lib/env_config/src/contracts.rs +++ b/core/lib/env_config/src/contracts.rs @@ -95,10 +95,6 @@ mod tests { user_facing_diamond_proxy_addr: Some(addr( "0xF00B988a98Ca742e7958DeF9F7823b5908715f4a", )), - l2_native_token_vault_proxy_addr: Some(addr( - "0xfc073319977e314f251eae6ae6be76b0b3baeecf", - )), - l2_legacy_shared_bridge_addr: Some(addr("0x8656770FA78c830456B00B4fFCeE6b1De0e1b888")), chain_admin_addr: Some(addr("0xdd6fa5c14e7550b4caf2aa2818d24c69cbc347ff")), l2_da_validator_addr: Some(addr("0xed6fa5c14e7550b4caf2aa2818d24c69cbc347ff")), } @@ -131,7 +127,6 @@ CONTRACTS_USER_FACING_DIAMOND_PROXY_ADDR="0xF00B988a98Ca742e7958DeF9F7823b590871 CONTRACTS_L2_NATIVE_TOKEN_VAULT_PROXY_ADDR="0xfc073319977e314f251eae6ae6be76b0b3baeecf" CONTRACTS_L2_DA_VALIDATOR_ADDR="0xed6fa5c14e7550b4caf2aa2818d24c69cbc347ff" CONTRACTS_CHAIN_ADMIN_ADDR="0xdd6fa5c14e7550b4caf2aa2818d24c69cbc347ff" -CONTRACTS_L2_LEGACY_SHARED_BRIDGE_ADDR="0x8656770FA78c830456B00B4fFCeE6b1De0e1b888" "#; lock.set_env(config); diff --git a/core/lib/protobuf_config/src/contracts.rs b/core/lib/protobuf_config/src/contracts.rs index a022c9aa1a1..616334b056c 100644 --- a/core/lib/protobuf_config/src/contracts.rs +++ b/core/lib/protobuf_config/src/contracts.rs @@ -76,12 +76,6 @@ impl ProtoRepr for proto::Contracts { .map(|x| parse_h160(x)) .transpose() .context("l2_shared_bridge_addr")?, - l2_legacy_shared_bridge_addr: l2 - .l2_legacy_shared_bridge_addr - .as_ref() - .map(|x| parse_h160(x)) - .transpose() - .context("l2_legacy_shared_bridge_addr")?, l1_weth_bridge_proxy_addr: weth_bridge .as_ref() .and_then(|bridge| bridge.l1_address.as_ref().map(|x| parse_h160(x))) @@ -119,12 +113,6 @@ impl ProtoRepr for proto::Contracts { .map(|x| parse_h160(x)) .transpose() .context("base_token_addr")?, - l2_native_token_vault_proxy_addr: l2 - .l2_native_token_vault_proxy_addr - .as_ref() - .map(|x| parse_h160(x)) - .transpose() - .context("l2_native_token_vault_proxy_addr")?, l2_da_validator_addr: l2 .l2_da_validator_addr .as_ref() @@ -172,13 +160,7 @@ impl ProtoRepr for proto::Contracts { }), l2: Some(proto::L2 { testnet_paymaster_addr: this.l2_testnet_paymaster_addr.map(|a| format!("{:?}", a)), - l2_native_token_vault_proxy_addr: this - .l2_native_token_vault_proxy_addr - .map(|a| format!("{:?}", a)), l2_da_validator_addr: this.l2_da_validator_addr.map(|a| format!("{:?}", a)), - l2_legacy_shared_bridge_addr: this - .l2_legacy_shared_bridge_addr - .map(|a| format!("{:?}", a)), }), bridges: Some(proto::Bridges { shared: Some(proto::Bridge { diff --git a/core/lib/protobuf_config/src/proto/config/contracts.proto b/core/lib/protobuf_config/src/proto/config/contracts.proto index 63e5eb1a3e9..655c67b003d 100644 --- a/core/lib/protobuf_config/src/proto/config/contracts.proto +++ b/core/lib/protobuf_config/src/proto/config/contracts.proto @@ -21,9 +21,7 @@ message L1 { message L2 { optional string testnet_paymaster_addr = 1; // optional; H160 - optional string l2_native_token_vault_proxy_addr = 2; // optional; H160 - optional string l2_da_validator_addr = 3; // optional; H160 - optional string l2_legacy_shared_bridge_addr = 4; // optional; H160 + optional string l2_da_validator_addr = 2; // optional; H160 } message Bridge { diff --git a/core/lib/types/src/api/en.rs b/core/lib/types/src/api/en.rs index 4a847b99e3d..52d66a29458 100644 --- a/core/lib/types/src/api/en.rs +++ b/core/lib/types/src/api/en.rs @@ -43,7 +43,7 @@ pub struct SyncBlock { /// Version of the protocol used for this block. pub protocol_version: ProtocolVersionId, /// Pubdata params used for this batch - pub pubdata_params: PubdataParams, + pub pubdata_params: Option, } /// Global configuration of the consensus served by the main node to the external nodes. diff --git a/core/lib/types/src/api/mod.rs b/core/lib/types/src/api/mod.rs index 65249f9bab6..75bcc6387aa 100644 --- a/core/lib/types/src/api/mod.rs +++ b/core/lib/types/src/api/mod.rs @@ -264,6 +264,7 @@ pub struct BridgeAddresses { pub l2_erc20_default_bridge: Option
, pub l1_weth_bridge: Option
, pub l2_weth_bridge: Option
, + pub l2_token_deployer: Option
, } #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] diff --git a/core/lib/web3_decl/src/namespaces/zks.rs b/core/lib/web3_decl/src/namespaces/zks.rs index b27bf262877..169d27aac1d 100644 --- a/core/lib/web3_decl/src/namespaces/zks.rs +++ b/core/lib/web3_decl/src/namespaces/zks.rs @@ -52,12 +52,6 @@ pub trait ZksNamespace { #[method(name = "getTestnetPaymaster")] async fn get_testnet_paymaster(&self) -> RpcResult>; - #[method(name = "getNativeTokenVault")] - async fn get_native_token_vault_proxy_addr(&self) -> RpcResult>; - - #[method(name = "getLegacySharedBridge")] - async fn get_legacy_shared_bridge(&self) -> RpcResult>; - #[method(name = "getBridgeContracts")] async fn get_bridge_contracts(&self) -> RpcResult; diff --git a/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/zks.rs b/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/zks.rs index c32a5e10ad0..14f3e6e7be4 100644 --- a/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/zks.rs +++ b/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/zks.rs @@ -54,16 +54,10 @@ impl ZksNamespaceServer for ZksNamespace { Ok(self.get_testnet_paymaster_impl()) } - async fn get_native_token_vault_proxy_addr(&self) -> RpcResult> { - Ok(self.get_native_token_vault_proxy_addr_impl()) - } - - async fn get_legacy_shared_bridge(&self) -> RpcResult> { - Ok(self.get_legacy_shared_bridge_impl()) - } - async fn get_bridge_contracts(&self) -> RpcResult { - Ok(self.get_bridge_contracts_impl()) + self.get_bridge_contracts_impl() + .await + .map_err(|err| self.current_method().map_err(err)) } async fn l1_chain_id(&self) -> RpcResult { diff --git a/core/node/api_server/src/web3/namespaces/zks.rs b/core/node/api_server/src/web3/namespaces/zks.rs index 09f1ead54a5..05ab8ddc271 100644 --- a/core/node/api_server/src/web3/namespaces/zks.rs +++ b/core/node/api_server/src/web3/namespaces/zks.rs @@ -7,7 +7,7 @@ use zksync_dal::{Connection, Core, CoreDal, DalError}; use zksync_metadata_calculator::api_server::TreeApiError; use zksync_mini_merkle_tree::MiniMerkleTree; use zksync_multivm::interface::VmExecutionResultAndLogs; -use zksync_system_constants::DEFAULT_L2_TX_GAS_PER_PUBDATA_BYTE; +use zksync_system_constants::{DEFAULT_L2_TX_GAS_PER_PUBDATA_BYTE, L2_ASSET_ROUTER_ADDRESS}; use zksync_types::{ api::{ state_override::StateOverride, BlockDetails, BridgeAddresses, ChainAggProof, GetLogsFilter, @@ -147,16 +147,18 @@ impl ZksNamespace { self.state.api_config.l2_testnet_paymaster_addr } - pub fn get_native_token_vault_proxy_addr_impl(&self) -> Option
{ - self.state.api_config.l2_native_token_vault_proxy_addr - } + pub async fn get_bridge_contracts_impl(&self) -> Result { + let mut bridge_contracts = self.state.api_config.bridge_addresses.clone(); + let mut storage = self.state.acquire_connection().await?; - pub fn get_legacy_shared_bridge_impl(&self) -> Option
{ - self.state.api_config.l2_legacy_shared_bridge_addr - } + // `L2_ASSET_ROUTER_ADDRESS` should be used as l2 bridge after gateway upgrade. + let pending_protocol_version = storage.blocks_dal().pending_protocol_version().await?; + if !pending_protocol_version.is_pre_gateway() { + bridge_contracts.l2_erc20_default_bridge = None; + bridge_contracts.l2_shared_default_bridge = Some(L2_ASSET_ROUTER_ADDRESS); + } - pub fn get_bridge_contracts_impl(&self) -> BridgeAddresses { - self.state.api_config.bridge_addresses.clone() + Ok(bridge_contracts) } pub fn l1_chain_id_impl(&self) -> U64 { diff --git a/core/node/api_server/src/web3/state.rs b/core/node/api_server/src/web3/state.rs index 203852346a9..c72380f2989 100644 --- a/core/node/api_server/src/web3/state.rs +++ b/core/node/api_server/src/web3/state.rs @@ -116,8 +116,6 @@ pub struct InternalApiConfig { pub dummy_verifier: bool, pub l1_batch_commit_data_generator_mode: L1BatchCommitmentMode, pub user_facing_bridgehub_addr: Option
, - pub l2_native_token_vault_proxy_addr: Option
, - pub l2_legacy_shared_bridge_addr: Option
, } impl InternalApiConfig { @@ -158,6 +156,7 @@ impl InternalApiConfig { .l1_weth_bridge_proxy_addr .unwrap_or_default(), ), + l2_token_deployer: contracts_config.l2_shared_bridge_addr, }, bridgehub_proxy_addr: contracts_config .ecosystem_contracts @@ -187,8 +186,6 @@ impl InternalApiConfig { .as_ref() .map(|a| a.bridgehub_proxy_addr), ), - l2_native_token_vault_proxy_addr: contracts_config.l2_native_token_vault_proxy_addr, - l2_legacy_shared_bridge_addr: contracts_config.l2_legacy_shared_bridge_addr, } } } diff --git a/core/node/consensus/src/storage/store.rs b/core/node/consensus/src/storage/store.rs index b3dd2bdac86..96a47f5abe7 100644 --- a/core/node/consensus/src/storage/store.rs +++ b/core/node/consensus/src/storage/store.rs @@ -35,7 +35,7 @@ fn to_fetched_block( l1_gas_price: payload.l1_gas_price, l2_fair_gas_price: payload.l2_fair_gas_price, fair_pubdata_price: payload.fair_pubdata_price, - pubdata_params: payload.pubdata_params, + pubdata_params: payload.pubdata_params.unwrap_or_default(), virtual_blocks: payload.virtual_blocks, operator_address: payload.operator_address, transactions: payload diff --git a/core/node/consensus/src/testonly.rs b/core/node/consensus/src/testonly.rs index 35802d14940..f91cde0544e 100644 --- a/core/node/consensus/src/testonly.rs +++ b/core/node/consensus/src/testonly.rs @@ -568,9 +568,7 @@ impl StateKeeperRunner { let (stop_send, stop_recv) = sync::watch::channel(false); let (persistence, l2_block_sealer) = StateKeeperPersistence::new( self.pool.0.clone(), - ethabi::Address::repeat_byte(11), - ethabi::Address::repeat_byte(12), - ethabi::Address::repeat_byte(13), + Some(ethabi::Address::repeat_byte(11)), 5, ); @@ -682,9 +680,7 @@ impl StateKeeperRunner { let (stop_send, stop_recv) = sync::watch::channel(false); let (persistence, l2_block_sealer) = StateKeeperPersistence::new( self.pool.0.clone(), - ethabi::Address::repeat_byte(11), - ethabi::Address::repeat_byte(12), - ethabi::Address::repeat_byte(13), + Some(ethabi::Address::repeat_byte(11)), 5, ); let tree_writes_persistence = TreeWritesPersistence::new(self.pool.0.clone()); diff --git a/core/node/node_framework/src/implementations/layers/state_keeper/output_handler.rs b/core/node/node_framework/src/implementations/layers/state_keeper/output_handler.rs index 21531a0eba3..3c1c276447e 100644 --- a/core/node/node_framework/src/implementations/layers/state_keeper/output_handler.rs +++ b/core/node/node_framework/src/implementations/layers/state_keeper/output_handler.rs @@ -35,10 +35,8 @@ use crate::{ /// - `L2BlockSealerTask` #[derive(Debug)] pub struct OutputHandlerLayer { - l2_shared_bridge_addr: Address, + l2_shared_bridge_addr: Option
, l2_block_seal_queue_capacity: usize, - l2_native_token_vault_proxy_addr: Address, - l2_legacy_shared_bridge_addr: Address, /// Whether transactions should be pre-inserted to DB. /// Should be set to `true` for EN's IO as EN doesn't store transactions in DB /// before they are included into L2 blocks. @@ -66,16 +64,12 @@ pub struct Output { impl OutputHandlerLayer { pub fn new( - l2_shared_bridge_addr: Address, - l2_native_token_vault_proxy_addr: Address, - l2_legacy_shared_bridge_addr: Address, + l2_shared_bridge_addr: Option
, l2_block_seal_queue_capacity: usize, ) -> Self { Self { l2_shared_bridge_addr, l2_block_seal_queue_capacity, - l2_native_token_vault_proxy_addr, - l2_legacy_shared_bridge_addr, pre_insert_txs: false, protective_reads_persistence_enabled: false, } @@ -115,8 +109,6 @@ impl WiringLayer for OutputHandlerLayer { let (mut persistence, l2_block_sealer) = StateKeeperPersistence::new( persistence_pool.clone(), self.l2_shared_bridge_addr, - self.l2_native_token_vault_proxy_addr, - self.l2_legacy_shared_bridge_addr, self.l2_block_seal_queue_capacity, ); if self.pre_insert_txs { diff --git a/core/node/node_sync/src/fetcher.rs b/core/node/node_sync/src/fetcher.rs index 6190a26d323..08e3d426243 100644 --- a/core/node/node_sync/src/fetcher.rs +++ b/core/node/node_sync/src/fetcher.rs @@ -94,7 +94,7 @@ impl TryFrom for FetchedBlock { .into_iter() .map(FetchedTransaction::new) .collect(), - pubdata_params: block.pubdata_params, + pubdata_params: block.pubdata_params.unwrap_or_default(), }) } } diff --git a/core/node/node_sync/src/tests.rs b/core/node/node_sync/src/tests.rs index 82d70dfa664..8582bbe9374 100644 --- a/core/node/node_sync/src/tests.rs +++ b/core/node/node_sync/src/tests.rs @@ -106,13 +106,8 @@ impl StateKeeperHandles { assert!(tx_hashes.iter().all(|tx_hashes| !tx_hashes.is_empty())); let sync_state = SyncState::default(); - let (persistence, l2_block_sealer) = StateKeeperPersistence::new( - pool.clone(), - Address::repeat_byte(1), - Address::default(), - Address::repeat_byte(13), - 5, - ); + let (persistence, l2_block_sealer) = + StateKeeperPersistence::new(pool.clone(), Some(Address::repeat_byte(1)), 5); let tree_writes_persistence = TreeWritesPersistence::new(pool.clone()); let output_handler = OutputHandler::new(Box::new(persistence.with_tx_insertion())) .with_handler(Box::new(tree_writes_persistence)) diff --git a/core/node/state_keeper/src/io/mempool.rs b/core/node/state_keeper/src/io/mempool.rs index ca20a2f6000..1a89cec9a40 100644 --- a/core/node/state_keeper/src/io/mempool.rs +++ b/core/node/state_keeper/src/io/mempool.rs @@ -195,6 +195,13 @@ impl StateKeeperIO for MempoolIO { continue; } + // Pubdata type should be `Rollup` for pre-gateway batches. + let pubdata_type = if protocol_version.is_pre_gateway() { + L1BatchCommitmentMode::Rollup + } else { + self.pubdata_type + }; + return Ok(Some(L1BatchParams { protocol_version, validation_computational_gas_limit: self.validation_computational_gas_limit, @@ -207,7 +214,7 @@ impl StateKeeperIO for MempoolIO { }, pubdata_params: PubdataParams { l2_da_validator_address: self.l2_da_validator_address, - pubdata_type: self.pubdata_type, + pubdata_type, }, })); } diff --git a/core/node/state_keeper/src/io/persistence.rs b/core/node/state_keeper/src/io/persistence.rs index cdca16b353f..e890cba41b4 100644 --- a/core/node/state_keeper/src/io/persistence.rs +++ b/core/node/state_keeper/src/io/persistence.rs @@ -29,9 +29,7 @@ struct Completable { #[derive(Debug)] pub struct StateKeeperPersistence { pool: ConnectionPool, - l2_shared_bridge_addr: Address, - l2_native_token_vault_proxy_addr: Address, - l2_legacy_shared_bridge_addr: Address, + l2_shared_bridge_addr: Option
, pre_insert_txs: bool, insert_protective_reads: bool, commands_sender: mpsc::Sender>, @@ -47,9 +45,7 @@ impl StateKeeperPersistence { /// `command_capacity` for unprocessed sealing commands. pub fn new( pool: ConnectionPool, - l2_shared_bridge_addr: Address, - l2_native_token_vault_proxy_addr: Address, - l2_legacy_shared_bridge_addr: Address, + l2_shared_bridge_addr: Option
, mut command_capacity: usize, ) -> (Self, L2BlockSealerTask) { let is_sync = command_capacity == 0; @@ -65,8 +61,6 @@ impl StateKeeperPersistence { let this = Self { pool, l2_shared_bridge_addr, - l2_native_token_vault_proxy_addr, - l2_legacy_shared_bridge_addr, pre_insert_txs: false, insert_protective_reads: true, commands_sender, @@ -163,12 +157,8 @@ impl StateKeeperOutputHandler for StateKeeperPersistence { } async fn handle_l2_block(&mut self, updates_manager: &UpdatesManager) -> anyhow::Result<()> { - let command = updates_manager.seal_l2_block_command( - self.l2_shared_bridge_addr, - self.l2_native_token_vault_proxy_addr, - self.l2_legacy_shared_bridge_addr, - self.pre_insert_txs, - ); + let command = + updates_manager.seal_l2_block_command(self.l2_shared_bridge_addr, self.pre_insert_txs); self.submit_l2_block(command).await; Ok(()) } @@ -185,8 +175,6 @@ impl StateKeeperOutputHandler for StateKeeperPersistence { .seal_l1_batch( self.pool.clone(), self.l2_shared_bridge_addr, - self.l2_native_token_vault_proxy_addr, - self.l2_legacy_shared_bridge_addr, self.insert_protective_reads, ) .await @@ -406,9 +394,7 @@ mod tests { let (persistence, l2_block_sealer) = StateKeeperPersistence::new( pool.clone(), - Address::default(), - Address::default(), - Address::default(), + Some(Address::default()), l2_block_sealer_capacity, ); let mut output_handler = OutputHandler::new(Box::new(persistence)) @@ -543,13 +529,8 @@ mod tests { .unwrap(); drop(storage); - let (mut persistence, l2_block_sealer) = StateKeeperPersistence::new( - pool.clone(), - Address::default(), - Address::default(), - Address::default(), - 1, - ); + let (mut persistence, l2_block_sealer) = + StateKeeperPersistence::new(pool.clone(), Some(Address::default()), 1); persistence = persistence.with_tx_insertion().without_protective_reads(); let mut output_handler = OutputHandler::new(Box::new(persistence)); tokio::spawn(l2_block_sealer.run()); @@ -587,22 +568,12 @@ mod tests { #[tokio::test] async fn l2_block_sealer_handle_blocking() { let pool = ConnectionPool::constrained_test_pool(1).await; - let (mut persistence, mut sealer) = StateKeeperPersistence::new( - pool, - Address::default(), - Address::default(), - Address::default(), - 1, - ); + let (mut persistence, mut sealer) = + StateKeeperPersistence::new(pool, Some(Address::default()), 1); // The first command should be successfully submitted immediately. let mut updates_manager = create_updates_manager(); - let seal_command = updates_manager.seal_l2_block_command( - Address::default(), - Address::default(), - Address::default(), - false, - ); + let seal_command = updates_manager.seal_l2_block_command(Some(Address::default()), false); persistence.submit_l2_block(seal_command).await; // The second command should lead to blocking @@ -610,12 +581,7 @@ mod tests { timestamp: 2, virtual_blocks: 1, }); - let seal_command = updates_manager.seal_l2_block_command( - Address::default(), - Address::default(), - Address::default(), - false, - ); + let seal_command = updates_manager.seal_l2_block_command(Some(Address::default()), false); { let submit_future = persistence.submit_l2_block(seal_command); futures::pin_mut!(submit_future); @@ -643,12 +609,7 @@ mod tests { timestamp: 3, virtual_blocks: 1, }); - let seal_command = updates_manager.seal_l2_block_command( - Address::default(), - Address::default(), - Address::default(), - false, - ); + let seal_command = updates_manager.seal_l2_block_command(Some(Address::default()), false); persistence.submit_l2_block(seal_command).await; let command = sealer.commands_receiver.recv().await.unwrap(); command.completion_sender.send(()).unwrap(); @@ -658,23 +619,14 @@ mod tests { #[tokio::test] async fn l2_block_sealer_handle_parallel_processing() { let pool = ConnectionPool::constrained_test_pool(1).await; - let (mut persistence, mut sealer) = StateKeeperPersistence::new( - pool, - Address::default(), - Address::default(), - Address::default(), - 5, - ); + let (mut persistence, mut sealer) = + StateKeeperPersistence::new(pool, Some(Address::default()), 5); // 5 L2 block sealing commands can be submitted without blocking. let mut updates_manager = create_updates_manager(); for i in 1..=5 { - let seal_command = updates_manager.seal_l2_block_command( - Address::default(), - Address::default(), - Address::default(), - false, - ); + let seal_command = + updates_manager.seal_l2_block_command(Some(Address::default()), false); updates_manager.push_l2_block(L2BlockParams { timestamp: i, virtual_blocks: 1, diff --git a/core/node/state_keeper/src/io/seal_logic/l2_block_seal_subtasks.rs b/core/node/state_keeper/src/io/seal_logic/l2_block_seal_subtasks.rs index 608e7f78f4b..bd283f23735 100644 --- a/core/node/state_keeper/src/io/seal_logic/l2_block_seal_subtasks.rs +++ b/core/node/state_keeper/src/io/seal_logic/l2_block_seal_subtasks.rs @@ -3,11 +3,11 @@ use async_trait::async_trait; use once_cell::sync::Lazy; use zksync_dal::{Connection, Core, CoreDal}; use zksync_multivm::interface::VmEvent; -use zksync_system_constants::CONTRACT_DEPLOYER_ADDRESS; +use zksync_system_constants::{CONTRACT_DEPLOYER_ADDRESS, L2_NATIVE_TOKEN_VAULT_ADDRESS}; use zksync_types::{ ethabi, tokens::{TokenInfo, TokenMetadata}, - Address, L2BlockNumber, H160, H256, + Address, L2BlockNumber, H256, }; use zksync_utils::h256_to_account_address; @@ -333,10 +333,9 @@ impl L2BlockSealSubtask for InsertTokensSubtask { connection: &mut Connection<'_, Core>, ) -> anyhow::Result<()> { let is_fictive = command.is_l2_block_fictive(); - let mut deployer_address = command.l2_native_token_vault_proxy_addr; - if command.l2_legacy_shared_bridge_addr != H160::zero() { - deployer_address = command.l2_legacy_shared_bridge_addr; - } + let deployer_address = command + .l2_shared_bridge_addr + .unwrap_or(L2_NATIVE_TOKEN_VAULT_ADDRESS); let progress = L2_BLOCK_METRICS.start(L2BlockSealStage::ExtractAddedTokens, is_fictive); let added_tokens = extract_added_tokens(deployer_address, &command.l2_block.events); @@ -559,8 +558,6 @@ mod tests { base_system_contracts_hashes: Default::default(), protocol_version: Some(ProtocolVersionId::latest()), l2_shared_bridge_addr: Default::default(), - l2_native_token_vault_proxy_addr: Default::default(), - l2_legacy_shared_bridge_addr: Default::default(), pre_insert_txs: false, }; diff --git a/core/node/state_keeper/src/io/seal_logic/mod.rs b/core/node/state_keeper/src/io/seal_logic/mod.rs index 0894ace7904..643042a927a 100644 --- a/core/node/state_keeper/src/io/seal_logic/mod.rs +++ b/core/node/state_keeper/src/io/seal_logic/mod.rs @@ -46,9 +46,7 @@ impl UpdatesManager { pub(super) async fn seal_l1_batch( &self, pool: ConnectionPool, - l2_shared_bridge_addr: Address, - l2_native_token_vault_proxy_addr: Address, - l2_legacy_shared_bridge_addr: Address, + l2_shared_bridge_addr: Option
, insert_protective_reads: bool, ) -> anyhow::Result<()> { let started_at = Instant::now(); @@ -62,8 +60,6 @@ impl UpdatesManager { // Seal fictive L2 block with last events and storage logs. let l2_block_command = self.seal_l2_block_command( l2_shared_bridge_addr, - l2_native_token_vault_proxy_addr, - l2_legacy_shared_bridge_addr, false, // fictive L2 blocks don't have txs, so it's fine to pass `false` here. ); diff --git a/core/node/state_keeper/src/io/tests/mod.rs b/core/node/state_keeper/src/io/tests/mod.rs index e487efe0615..5871148dcd3 100644 --- a/core/node/state_keeper/src/io/tests/mod.rs +++ b/core/node/state_keeper/src/io/tests/mod.rs @@ -285,9 +285,7 @@ async fn processing_storage_logs_when_sealing_l2_block() { pubdata_params: Default::default(), base_system_contracts_hashes: BaseSystemContractsHashes::default(), protocol_version: Some(ProtocolVersionId::latest()), - l2_shared_bridge_addr: Address::default(), - l2_native_token_vault_proxy_addr: Address::default(), - l2_legacy_shared_bridge_addr: Address::default(), + l2_shared_bridge_addr: Default::default(), pre_insert_txs: false, }; connection_pool @@ -377,9 +375,7 @@ async fn processing_events_when_sealing_l2_block() { base_fee_per_gas: 10, base_system_contracts_hashes: BaseSystemContractsHashes::default(), protocol_version: Some(ProtocolVersionId::latest()), - l2_shared_bridge_addr: Address::default(), - l2_native_token_vault_proxy_addr: Address::default(), - l2_legacy_shared_bridge_addr: Address::default(), + l2_shared_bridge_addr: Default::default(), pre_insert_txs: false, }; pool.connection() @@ -468,13 +464,8 @@ async fn l2_block_processing_after_snapshot_recovery(commitment_mode: L1BatchCom vec![], ); - let (mut persistence, l2_block_sealer) = StateKeeperPersistence::new( - connection_pool.clone(), - Address::default(), - Address::default(), - Address::default(), - 0, - ); + let (mut persistence, l2_block_sealer) = + StateKeeperPersistence::new(connection_pool.clone(), Some(Address::default()), 0); tokio::spawn(l2_block_sealer.run()); persistence.handle_l2_block(&updates).await.unwrap(); diff --git a/core/node/state_keeper/src/updates/mod.rs b/core/node/state_keeper/src/updates/mod.rs index b640bc8f66a..5d29061c70e 100644 --- a/core/node/state_keeper/src/updates/mod.rs +++ b/core/node/state_keeper/src/updates/mod.rs @@ -85,9 +85,7 @@ impl UpdatesManager { pub(crate) fn seal_l2_block_command( &self, - l2_shared_bridge_addr: Address, - l2_native_token_vault_proxy_addr: Address, - l2_legacy_shared_bridge_addr: Address, + l2_shared_bridge_addr: Option
, pre_insert_txs: bool, ) -> L2BlockSealCommand { L2BlockSealCommand { @@ -101,8 +99,6 @@ impl UpdatesManager { base_system_contracts_hashes: self.base_system_contract_hashes, protocol_version: Some(self.protocol_version), l2_shared_bridge_addr, - l2_native_token_vault_proxy_addr, - l2_legacy_shared_bridge_addr, pre_insert_txs, } } @@ -213,9 +209,7 @@ pub struct L2BlockSealCommand { pub base_fee_per_gas: u64, pub base_system_contracts_hashes: BaseSystemContractsHashes, pub protocol_version: Option, - pub l2_shared_bridge_addr: Address, - pub l2_native_token_vault_proxy_addr: Address, - pub l2_legacy_shared_bridge_addr: Address, + pub l2_shared_bridge_addr: Option
, pub pubdata_params: PubdataParams, /// Whether transactions should be pre-inserted to DB. /// Should be set to `true` for EN's IO as EN doesn't store transactions in DB