diff --git a/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs b/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs index 0ea8a627b654..528daa34caca 100644 --- a/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs +++ b/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs @@ -51,7 +51,7 @@ impl<'a> Tokenizable for CommitBatchInfoRollup<'a> { Token::Tuple(encode_l1_commit( &self.l1_batch_with_metadata.header, &self.l1_batch_with_metadata.metadata, - Some(&self.l1_batch_with_metadata), + Some(self.l1_batch_with_metadata), )) } } diff --git a/core/lib/types/src/commitment/mod.rs b/core/lib/types/src/commitment/mod.rs index 65280b4991d1..a65faca0e50c 100644 --- a/core/lib/types/src/commitment/mod.rs +++ b/core/lib/types/src/commitment/mod.rs @@ -99,31 +99,6 @@ impl L1BatchMetadata { } } -impl Default for L1BatchMetadata { - fn default() -> Self { - L1BatchMetadata { - root_hash: Default::default(), - rollup_last_leaf_index: 0, - merkle_root_hash: Default::default(), - initial_writes_compressed: Some(vec![]), - repeated_writes_compressed: Some(vec![]), - commitment: Default::default(), - l2_l1_merkle_root: Default::default(), - block_meta_params: L1BatchMetaParameters { - zkporter_is_available: false, - bootloader_code_hash: Default::default(), - default_aa_code_hash: Default::default(), - }, - aux_data_hash: Default::default(), - meta_parameters_hash: Default::default(), - pass_through_data_hash: Default::default(), - events_queue_commitment: Some(H256::zero()), - bootloader_initial_content_commitment: Some(H256::zero()), - state_diffs_compressed: vec![], - } - } -} - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct L1BatchWithMetadata { pub header: L1BatchHeader, @@ -471,7 +446,7 @@ impl L1BatchAuxiliaryOutput { } /// Meta parameters for an L1 batch. They are the same for each L1 batch per run. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct L1BatchMetaParameters { pub zkporter_is_available: bool, pub bootloader_code_hash: H256, diff --git a/core/lib/zksync_core/src/api_server/web3/tests/mod.rs b/core/lib/zksync_core/src/api_server/web3/tests/mod.rs index 3d75ef167555..4477d3e29c89 100644 --- a/core/lib/zksync_core/src/api_server/web3/tests/mod.rs +++ b/core/lib/zksync_core/src/api_server/web3/tests/mod.rs @@ -5,19 +5,9 @@ use async_trait::async_trait; use jsonrpsee::core::ClientError; use multivm::zk_evm_latest::ethereum_types::U256; use tokio::sync::watch; -use zksync_config::{ - configs::{ - api::Web3JsonRpcConfig, - chain::{NetworkConfig, StateKeeperConfig}, - eth_sender::{ProofSendingMode, SenderConfig}, - ContractsConfig, - }, - ETHSenderConfig, GasAdjusterConfig, -}; +use zksync_config::configs::{api::Web3JsonRpcConfig, chain::NetworkConfig, ContractsConfig}; use zksync_dal::{transactions_dal::L2TxSubmissionResult, ConnectionPool, StorageProcessor}; -use zksync_eth_client::{clients::MockEthereum, EthInterface}; use zksync_health_check::CheckHealth; -use zksync_object_store::ObjectStoreFactory; use zksync_types::{ api, block::{L1BatchHeader, MiniblockHeader}, @@ -33,8 +23,8 @@ use zksync_types::{ TransactionExecutionResult, }, utils::{storage_key_for_eth_balance, storage_key_for_standard_token_balance}, - AccountTreeId, Address, Bytes, L1BatchNumber, L1BlockNumber, Nonce, StorageKey, StorageLog, - VmEvent, H256, U64, + AccountTreeId, Address, Bytes, L1BatchNumber, Nonce, StorageKey, StorageLog, VmEvent, H256, + U64, }; use zksync_utils::u256_to_h256; use zksync_web3_decl::{ @@ -48,15 +38,7 @@ use crate::{ execution_sandbox::testonly::MockTransactionExecutor, tx_sender::tests::create_test_tx_sender, }, - eth_sender::{ - aggregated_operations::AggregatedOperation, - l1_batch_commit_data_generator::{ - RollupModeL1BatchCommitDataGenerator, ValidiumModeL1BatchCommitDataGenerator, - }, - Aggregator, EthTxAggregator, EthTxManager, - }, genesis::{ensure_genesis_state, GenesisParams}, - l1_gas_price::GasAdjuster, utils::testonly::{ create_l1_batch, create_l1_batch_metadata, create_l2_transaction, create_miniblock, l1_batch_metadata_to_commitment_artifacts, prepare_recovery_snapshot, @@ -955,83 +937,45 @@ async fn getting_all_account_balances() { struct GetPubdataTest; impl GetPubdataTest { - const WAIT_CONFIRMATIONS: u64 = 10; - const MAX_BASE_FEE_SAMPLES: usize = 3; - - fn l1_batch_with_metadata(header: L1BatchHeader) -> L1BatchWithMetadata { - let mut metadata = L1BatchMetadata::default(); - metadata.state_diffs_compressed = Self::build_state_diffs_compressed(); - L1BatchWithMetadata { - header, - metadata: metadata, - raw_published_factory_deps: Self::build_raw_published_factory_deps(), - } - } - - async fn insert_l1_batch( + async fn insert_l1_batch_with_metadata( storage: &mut StorageProcessor<'_>, - number: L1BatchNumber, + l1_batch_header: L1BatchHeader, + l1_batch_metadata: L1BatchMetadata, ) -> L1BatchHeader { - let mut header = create_l1_batch(number.0); - header.l2_to_l1_logs = Self::build_l2_to_l1_logs(); - header.l2_to_l1_messages = Self::build_l2_to_l1_messages(); // Save L1 batch to the database storage .blocks_dal() - .insert_mock_l1_batch(&header) + .insert_mock_l1_batch(&l1_batch_header) .await .unwrap(); - let metadata = L1BatchMetadata::default(); storage .blocks_dal() - .save_l1_batch_tree_data(header.number, &metadata.tree_data()) + .save_l1_batch_tree_data(l1_batch_header.number, &l1_batch_metadata.tree_data()) .await .unwrap(); storage .blocks_dal() .save_l1_batch_commitment_artifacts( - header.number, - &l1_batch_metadata_to_commitment_artifacts(&metadata), + l1_batch_header.number, + &l1_batch_metadata_to_commitment_artifacts(&l1_batch_metadata), ) .await .unwrap(); - header - } - async fn send_operation( - aggregator: &EthTxAggregator, - manager: &mut EthTxManager, - storage: &mut StorageProcessor<'_>, - aggregated_operation: AggregatedOperation, - current_block: L1BlockNumber, - ) -> H256 { - let tx = aggregator - .save_eth_tx(storage, &aggregated_operation, true) + storage + .blocks_dal() + .insert_miniblock(&create_miniblock(l1_batch_header.number.0)) .await .unwrap(); - let hash = manager - .send_eth_tx(storage, &tx, 0, current_block) + storage + .blocks_dal() + .mark_miniblocks_as_executed_in_l1_batch(l1_batch_header.number) .await .unwrap(); - hash - } - - async fn commit_l1_batch( - aggregator: &EthTxAggregator, - manager: &mut EthTxManager, - storage: &mut StorageProcessor<'_>, - last_committed_l1_batch: L1BatchHeader, - l1_batch: L1BatchHeader, - current_block: L1BlockNumber, - ) -> H256 { - let operation = AggregatedOperation::Commit( - Self::l1_batch_with_metadata(last_committed_l1_batch), - vec![Self::l1_batch_with_metadata(l1_batch)], - ); - Self::send_operation(aggregator, manager, storage, operation, current_block).await + l1_batch_header } fn build_l2_to_l1_logs() -> Vec { @@ -1047,136 +991,41 @@ impl GetPubdataTest { vec![user_l2_to_l1_log] } - - fn build_l2_to_l1_messages() -> Vec> { - vec![vec![1, 2, 3]] - } - - fn build_raw_published_factory_deps() -> Vec> { - vec![vec![1, 2, 3]] - } - - fn build_state_diffs_compressed() -> Vec { - vec![1, 2, 3] - } - - // fn build_expected_pubdata(l1_batch_with_metadata: L1BatchWithMetadata) -> Vec { - // let l2_to_l1_logs = Self::build_l2_to_l1_logs(); - // let l2_to_l1_messages = Self::build_l2_to_l1_messages(); - // let raw_published_factory_deps = Self::build_raw_published_factory_deps(); - // let state_diffs_compressed = Self::build_state_diffs_compressed(); - - // let mut expected_pubdata = vec![]; - // expected_pubdata.extend((l2_to_l1_logs.len() as u32).to_be_bytes()); - // for l2_to_l1_log in &l2_to_l1_logs { - // expected_pubdata.extend(l2_to_l1_log.0.to_bytes()); - // } - // //dbg!(&expected_pubdata.len()); - // expected_pubdata.extend((l2_to_l1_messages.len() as u32).to_be_bytes()); - // for msg in &l2_to_l1_messages { - // expected_pubdata.extend((msg.len() as u32).to_be_bytes()); - // expected_pubdata.extend(msg); - // } - // //dbg!(&expected_pubdata.len()); - - // expected_pubdata.extend((raw_published_factory_deps.len() as u32).to_be_bytes()); - // for bytecode in &raw_published_factory_deps { - // expected_pubdata.extend((bytecode.len() as u32).to_be_bytes()); - // expected_pubdata.extend(bytecode); - // } - // //dbg!(&expected_pubdata.len()); - // expected_pubdata.extend(&state_diffs_compressed); - - // //dbg!(&expected_pubdata.len()); - - // expected_pubdata - // } } #[async_trait] impl HttpTest for GetPubdataTest { async fn test(&self, client: &HttpClient, pool: &ConnectionPool) -> anyhow::Result<()> { - let pubdata = client.get_batch_pubdata(L1BatchNumber(1)).await?; + let l1_batch_number = L1BatchNumber(1); + // Assert pubdata is None if L1BatchWithMetadata is not found + let pubdata = client.get_batch_pubdata(l1_batch_number).await?; assert_eq!(pubdata, None); - let eth_sender_config = ETHSenderConfig::for_tests(); - let aggregator_config = SenderConfig { - aggregated_proof_sizes: vec![1], - ..eth_sender_config.sender.clone() - }; - let contracts_config = ContractsConfig::for_tests(); - let store_factory = ObjectStoreFactory::mock(); - let gateway = Arc::new( - MockEthereum::default() - .with_fee_history( - std::iter::repeat(0) - .take(Self::WAIT_CONFIRMATIONS as usize) - .chain(vec![10; 100]) - .collect(), - ) - .with_non_ordering_confirmation(false) - .with_multicall_address(contracts_config.l1_multicall3_addr), - ); - gateway.advance_block_number(Self::WAIT_CONFIRMATIONS); - - let gas_adjuster = Arc::new( - GasAdjuster::new( - gateway.clone(), - GasAdjusterConfig { - max_base_fee_samples: Self::MAX_BASE_FEE_SAMPLES, - pricing_formula_parameter_a: 3.0, - pricing_formula_parameter_b: 2.0, - ..eth_sender_config.gas_adjuster - }, - ) - .await - .unwrap(), - ); - let aggregator = EthTxAggregator::new( - SenderConfig { - proof_sending_mode: ProofSendingMode::SkipEveryProof, - ..eth_sender_config.sender.clone() - }, - // Aggregator - unused - Aggregator::new( - aggregator_config.clone(), - store_factory.create_store().await, - Arc::new(RollupModeL1BatchCommitDataGenerator {}), - ), - gateway.clone(), - // zkSync contract address - Address::random(), - contracts_config.l1_multicall3_addr, - Address::random(), - Default::default(), - Arc::new(RollupModeL1BatchCommitDataGenerator {}), - ) - .await; + // Assert pubdata is expected if L1BatchWithMetadata is found + // Create L1 batch header and add pubdata (l2_to_l1_logs, l2_to_l1_messages) + let mut l1_batch_header: L1BatchHeader = create_l1_batch(l1_batch_number.0); + l1_batch_header.l2_to_l1_logs = Self::build_l2_to_l1_logs(); + l1_batch_header.l2_to_l1_messages = vec![vec![1, 2, 3]]; - let mut manager = EthTxManager::new( - eth_sender_config.sender, - gas_adjuster.clone(), - gateway.clone(), - ); - let mut storage = pool.access_storage().await?; + // Create metadata + let l1_batch_metadata: L1BatchMetadata = create_l1_batch_metadata(l1_batch_number.0); - let genesis_l1_batch = create_l1_batch(0); - let first_l1_batch = Self::insert_l1_batch(&mut storage, L1BatchNumber(1)).await; - - Self::commit_l1_batch( - &aggregator, - &mut manager, - &mut storage, - genesis_l1_batch.clone(), - first_l1_batch.clone(), - L1BlockNumber(gateway.block_number("").await.unwrap().as_u32()), - ) - .await; + // Build L1BatchWithMetadata + let l1_batch_with_metadata = L1BatchWithMetadata { + header: l1_batch_header.clone(), + metadata: l1_batch_metadata.clone(), + raw_published_factory_deps: vec![], + }; - let l1_batch_with_metadata = Self::l1_batch_with_metadata(first_l1_batch); let expected_pubdata: Bytes = l1_batch_with_metadata.construct_pubdata().into(); - let pubdata = client.get_batch_pubdata(L1BatchNumber(1)).await?; + let mut storage = pool.access_storage().await?; + Self::insert_l1_batch_with_metadata(&mut storage, l1_batch_header, l1_batch_metadata).await; + + // Call the endpoint + let pubdata = client.get_batch_pubdata(l1_batch_number).await?; + + // Assert pubdata is equal to expected pubdata assert_eq!(pubdata, Some(expected_pubdata)); Ok(()) diff --git a/core/lib/zksync_core/src/api_server/web3/tests/vm.rs b/core/lib/zksync_core/src/api_server/web3/tests/vm.rs index 22760c37feb1..f91c95081f84 100644 --- a/core/lib/zksync_core/src/api_server/web3/tests/vm.rs +++ b/core/lib/zksync_core/src/api_server/web3/tests/vm.rs @@ -3,6 +3,7 @@ use std::sync::atomic::{AtomicU32, Ordering}; use multivm::interface::{ExecutionResult, VmRevertReason}; +use zksync_config::configs::chain::StateKeeperConfig; use zksync_types::{ get_intrinsic_constants, transaction_request::CallRequest, L2ChainId, PackedEthSignature, U256, }; diff --git a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs index 6f655bc5550a..fa9bce07321e 100644 --- a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs +++ b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs @@ -461,7 +461,7 @@ impl EthTxAggregator { } } - pub(crate) async fn save_eth_tx( + pub(super) async fn save_eth_tx( &self, storage: &mut StorageProcessor<'_>, aggregated_op: &AggregatedOperation, diff --git a/core/lib/zksync_core/src/eth_sender/mod.rs b/core/lib/zksync_core/src/eth_sender/mod.rs index 845b6b7e3a60..109624e5a4e8 100644 --- a/core/lib/zksync_core/src/eth_sender/mod.rs +++ b/core/lib/zksync_core/src/eth_sender/mod.rs @@ -1,4 +1,4 @@ -pub mod aggregated_operations; +mod aggregated_operations; mod aggregator; mod error; mod eth_tx_aggregator; diff --git a/core/lib/zksync_core/src/eth_sender/tests_helpers.rs b/core/lib/zksync_core/src/eth_sender/tests_helpers.rs index 107816658e7b..3a0e73c46398 100644 --- a/core/lib/zksync_core/src/eth_sender/tests_helpers.rs +++ b/core/lib/zksync_core/src/eth_sender/tests_helpers.rs @@ -12,7 +12,7 @@ use zksync_l1_contract_interface::i_executor::methods::{ExecuteBatches, ProveBat use zksync_object_store::ObjectStoreFactory; use zksync_types::{ block::L1BatchHeader, - commitment::{L1BatchMetadata, L1BatchWithMetadata}, + commitment::{L1BatchMetaParameters, L1BatchMetadata, L1BatchWithMetadata}, ethabi::Token, helpers::unix_timestamp_ms, web3::contract::Error, @@ -36,7 +36,7 @@ static DUMMY_OPERATION: Lazy = Lazy::new(|| { AggregatedOperation::Execute(ExecuteBatches { l1_batches: vec![L1BatchWithMetadata { header: create_l1_batch(1), - metadata: L1BatchMetadata::default(), + metadata: default_l1_batch_metadata(), raw_published_factory_deps: Vec::new(), }], }) @@ -149,11 +149,34 @@ impl EthSenderTester { fn l1_batch_with_metadata(header: L1BatchHeader) -> L1BatchWithMetadata { L1BatchWithMetadata { header, - metadata: L1BatchMetadata::default(), + metadata: default_l1_batch_metadata(), raw_published_factory_deps: vec![], } } +fn default_l1_batch_metadata() -> L1BatchMetadata { + L1BatchMetadata { + root_hash: Default::default(), + rollup_last_leaf_index: 0, + merkle_root_hash: Default::default(), + initial_writes_compressed: Some(vec![]), + repeated_writes_compressed: Some(vec![]), + commitment: Default::default(), + l2_l1_merkle_root: Default::default(), + block_meta_params: L1BatchMetaParameters { + zkporter_is_available: false, + bootloader_code_hash: Default::default(), + default_aa_code_hash: Default::default(), + }, + aux_data_hash: Default::default(), + meta_parameters_hash: Default::default(), + pass_through_data_hash: Default::default(), + events_queue_commitment: Some(H256::zero()), + bootloader_initial_content_commitment: Some(H256::zero()), + state_diffs_compressed: vec![], + } +} + pub(crate) async fn confirm_many(tester: &mut EthSenderTester) -> anyhow::Result<()> { let mut hashes = vec![]; @@ -594,8 +617,7 @@ async fn insert_l1_batch(tester: &EthSenderTester, number: L1BatchNumber) -> L1B .insert_mock_l1_batch(&header) .await .unwrap(); - let metadata = L1BatchMetadata::default(); - + let metadata = default_l1_batch_metadata(); tester .storage() .await