From b4821e19ea7a4955544a85f2a898de234f56f54b Mon Sep 17 00:00:00 2001 From: Ivan Litteri <67517699+ilitteri@users.noreply.github.com> Date: Fri, 2 Feb 2024 12:23:07 -0300 Subject: [PATCH] feat: Rename Validium abstraction and implementors (#92) * Rename Validium pubdata abstraction and implementors * Rename struct fields and variables * feat: Abstract commit data generator initialization (#94) * Add L1BatchCommitDataGeneratorMode to StateKeeperConfig * Initialize L1BatchCommitter depending on the StateKeeperConfig * Fix bad merge --- core/bin/external_node/src/main.rs | 9 ++- core/lib/config/src/configs/chain.rs | 15 ++++ core/lib/env_config/src/chain.rs | 3 +- core/lib/types/src/aggregated_operations.rs | 7 +- ...r.rs => l1_batch_commit_data_generator.rs} | 10 +-- core/lib/types/src/lib.rs | 2 +- .../src/consistency_checker/mod.rs | 19 +++-- .../src/consistency_checker/tests/mod.rs | 79 ++++++++++++------- .../zksync_core/src/eth_sender/aggregator.rs | 26 +++--- .../src/eth_sender/publish_criterion.rs | 14 ++-- core/lib/zksync_core/src/eth_sender/tests.rs | 72 +++++++++-------- core/lib/zksync_core/src/lib.rs | 28 ++++--- etc/env/base/chain.toml | 2 + 13 files changed, 170 insertions(+), 116 deletions(-) rename core/lib/types/src/{l1_batch_committer.rs => l1_batch_commit_data_generator.rs} (93%) diff --git a/core/bin/external_node/src/main.rs b/core/bin/external_node/src/main.rs index 445e16a561d..3d5abde0a59 100644 --- a/core/bin/external_node/src/main.rs +++ b/core/bin/external_node/src/main.rs @@ -34,7 +34,7 @@ use zksync_dal::{healthcheck::ConnectionPoolHealthCheck, ConnectionPool}; use zksync_health_check::CheckHealth; use zksync_state::PostgresStorageCaches; use zksync_storage::RocksDB; -use zksync_types::l1_batch_committer::RollupModeL1BatchCommitter; +use zksync_types::l1_batch_commit_data_generator::RollupModeL1BatchCommitDataGenerator; use zksync_utils::wait_for_tasks::wait_for_tasks; mod config; @@ -229,10 +229,11 @@ async fn init_tasks( .context("failed to build a tree_pool")?; let tree_handle = task::spawn(metadata_calculator.run(tree_pool, tree_stop_receiver)); - let l1_batch_committer = Arc::new(RollupModeL1BatchCommitter {}); + let l1_batch_commit_data_generator = Arc::new(RollupModeL1BatchCommitDataGenerator {}); - let consistency_checker_handle = - tokio::spawn(consistency_checker.run(stop_receiver.clone(), l1_batch_committer)); + let consistency_checker_handle = tokio::spawn( + consistency_checker.run(stop_receiver.clone(), l1_batch_commit_data_generator), + ); let updater_handle = task::spawn(batch_status_updater.run(stop_receiver.clone())); let sk_handle = task::spawn(state_keeper.run()); diff --git a/core/lib/config/src/configs/chain.rs b/core/lib/config/src/configs/chain.rs index d35c6ed52b5..67845fcc2ae 100644 --- a/core/lib/config/src/configs/chain.rs +++ b/core/lib/config/src/configs/chain.rs @@ -45,6 +45,18 @@ impl Default for FeeModelVersion { } } +#[derive(Debug, Clone, Copy, Deserialize, PartialEq, Eq)] +pub enum L1BatchCommitDataGeneratorMode { + Rollup, + Validium, +} + +impl Default for L1BatchCommitDataGeneratorMode { + fn default() -> Self { + Self::Rollup + } +} + #[derive(Debug, Deserialize, Clone, PartialEq, Default)] pub struct StateKeeperConfig { /// The max number of slots for txs in a block before it should be sealed by the slots sealer. @@ -116,6 +128,8 @@ pub struct StateKeeperConfig { /// Number of keys that is processed by enum_index migration in State Keeper each L1 batch. pub enum_index_migration_chunk_size: Option, + + pub l1_batch_commit_data_generator_mode: L1BatchCommitDataGeneratorMode, } impl StateKeeperConfig { @@ -150,6 +164,7 @@ impl StateKeeperConfig { virtual_blocks_per_miniblock: 1, upload_witness_inputs_to_gcs: false, enum_index_migration_chunk_size: None, + l1_batch_commit_data_generator_mode: L1BatchCommitDataGeneratorMode::Rollup, } } diff --git a/core/lib/env_config/src/chain.rs b/core/lib/env_config/src/chain.rs index c258c5092e5..129b2b4adda 100644 --- a/core/lib/env_config/src/chain.rs +++ b/core/lib/env_config/src/chain.rs @@ -37,7 +37,7 @@ impl FromEnv for MempoolConfig { #[cfg(test)] mod tests { use zksync_basic_types::L2ChainId; - use zksync_config::configs::chain::FeeModelVersion; + use zksync_config::configs::chain::{FeeModelVersion, L1BatchCommitDataGeneratorMode}; use super::*; use crate::test_utils::{addr, EnvMutex}; @@ -94,6 +94,7 @@ mod tests { virtual_blocks_per_miniblock: 1, upload_witness_inputs_to_gcs: false, enum_index_migration_chunk_size: Some(2_000), + l1_batch_commit_data_generator_mode: L1BatchCommitDataGeneratorMode::Rollup, } } diff --git a/core/lib/types/src/aggregated_operations.rs b/core/lib/types/src/aggregated_operations.rs index fb06bfc7d3e..c4ef7a432dd 100644 --- a/core/lib/types/src/aggregated_operations.rs +++ b/core/lib/types/src/aggregated_operations.rs @@ -10,7 +10,8 @@ use zkevm_test_harness::{ use zksync_basic_types::{ethabi::Token, L1BatchNumber}; use crate::{ - commitment::L1BatchWithMetadata, l1_batch_committer::L1BatchCommitter, ProtocolVersionId, U256, + commitment::L1BatchWithMetadata, l1_batch_commit_data_generator::L1BatchCommitDataGenerator, + ProtocolVersionId, U256, }; fn l1_batch_range_from_batches( @@ -31,7 +32,7 @@ fn l1_batch_range_from_batches( pub struct L1BatchCommitOperation { pub last_committed_l1_batch: L1BatchWithMetadata, pub l1_batches: Vec, - pub l1_batch_committer: Arc, + pub l1_batch_commit_data_generator: Arc, } impl L1BatchCommitOperation { @@ -41,7 +42,7 @@ impl L1BatchCommitOperation { .l1_batches .iter() .map(|l1_batch_with_metadata| { - self.l1_batch_committer + self.l1_batch_commit_data_generator .l1_commit_data(l1_batch_with_metadata) }) .collect(); diff --git a/core/lib/types/src/l1_batch_committer.rs b/core/lib/types/src/l1_batch_commit_data_generator.rs similarity index 93% rename from core/lib/types/src/l1_batch_committer.rs rename to core/lib/types/src/l1_batch_commit_data_generator.rs index c93e12cd604..c4f5872ca82 100644 --- a/core/lib/types/src/l1_batch_committer.rs +++ b/core/lib/types/src/l1_batch_commit_data_generator.rs @@ -2,7 +2,7 @@ use zksync_basic_types::{ethabi::Token, U256}; use crate::{commitment::L1BatchWithMetadata, utils}; -pub trait L1BatchCommitter +pub trait L1BatchCommitDataGenerator where Self: std::fmt::Debug + Send + Sync, { @@ -16,12 +16,12 @@ where } #[derive(Debug, Clone)] -pub struct RollupModeL1BatchCommitter {} +pub struct RollupModeL1BatchCommitDataGenerator {} #[derive(Debug, Clone)] -pub struct ValidiumModeL1BatchCommitter {} +pub struct ValidiumModeL1BatchCommitDataGenerator {} -impl L1BatchCommitter for RollupModeL1BatchCommitter { +impl L1BatchCommitDataGenerator for RollupModeL1BatchCommitDataGenerator { fn l1_commit_data(&self, l1_batch_with_metadata: &L1BatchWithMetadata) -> Token { println!("RollupModeL1BatchCommitter"); let commit_data = if l1_batch_with_metadata @@ -38,7 +38,7 @@ impl L1BatchCommitter for RollupModeL1BatchCommitter { } } -impl L1BatchCommitter for ValidiumModeL1BatchCommitter { +impl L1BatchCommitDataGenerator for ValidiumModeL1BatchCommitDataGenerator { fn l1_commit_data(&self, l1_batch_with_metadata: &L1BatchWithMetadata) -> Token { println!("ValidiumModeL1BatchCommitter"); let commit_data = if l1_batch_with_metadata diff --git a/core/lib/types/src/lib.rs b/core/lib/types/src/lib.rs index dda9c767600..918be9d1081 100644 --- a/core/lib/types/src/lib.rs +++ b/core/lib/types/src/lib.rs @@ -63,7 +63,7 @@ pub mod utils; pub mod vk_transform; pub mod vm_version; -pub mod l1_batch_committer; +pub mod l1_batch_commit_data_generator; /// Denotes the first byte of the special zkSync's EIP-712-signed transaction. pub const EIP_712_TX_TYPE: u8 = 0x71; diff --git a/core/lib/zksync_core/src/consistency_checker/mod.rs b/core/lib/zksync_core/src/consistency_checker/mod.rs index c8cef1cc1ec..69e54b1141c 100644 --- a/core/lib/zksync_core/src/consistency_checker/mod.rs +++ b/core/lib/zksync_core/src/consistency_checker/mod.rs @@ -5,7 +5,9 @@ use tokio::sync::watch; use zksync_contracts::PRE_BOOJUM_COMMIT_FUNCTION; use zksync_dal::{ConnectionPool, StorageProcessor}; use zksync_eth_client::{clients::QueryClient, Error as L1ClientError, EthInterface}; -use zksync_types::{l1_batch_committer::L1BatchCommitter, web3::ethabi, L1BatchNumber, H256}; +use zksync_types::{ + l1_batch_commit_data_generator::L1BatchCommitDataGenerator, web3::ethabi, L1BatchNumber, H256, +}; use crate::{ metrics::{CheckerComponent, EN_METRICS}, @@ -66,7 +68,7 @@ impl LocalL1BatchCommitData { async fn new( storage: &mut StorageProcessor<'_>, batch_number: L1BatchNumber, - l1_batch_committer: Arc, + l1_batch_commit_data_generator: Arc, ) -> anyhow::Result> { let Some(storage_l1_batch) = storage .blocks_dal() @@ -114,7 +116,7 @@ impl LocalL1BatchCommitData { Ok(Some(Self { is_pre_boojum, - l1_commit_data: l1_batch_committer.l1_commit_data(&l1_batch), + l1_commit_data: l1_batch_commit_data_generator.l1_commit_data(&l1_batch), commit_tx_hash, })) } @@ -251,7 +253,7 @@ impl ConsistencyChecker { pub async fn run( mut self, mut stop_receiver: watch::Receiver, - l1_batch_committer: Arc, + l1_batch_commit_data_generator: Arc, ) -> anyhow::Result<()> { // It doesn't make sense to start the checker until we have at least one L1 batch with metadata. let earliest_l1_batch_number = @@ -290,9 +292,12 @@ impl ConsistencyChecker { // The batch might be already committed but not yet processed by the external node's tree // OR the batch might be processed by the external node's tree but not yet committed. // We need both. - let Some(local) = - LocalL1BatchCommitData::new(&mut storage, batch_number, l1_batch_committer.clone()) - .await? + let Some(local) = LocalL1BatchCommitData::new( + &mut storage, + batch_number, + l1_batch_commit_data_generator.clone(), + ) + .await? else { tokio::time::sleep(self.sleep_interval).await; continue; diff --git a/core/lib/zksync_core/src/consistency_checker/tests/mod.rs b/core/lib/zksync_core/src/consistency_checker/tests/mod.rs index 6a37db3de32..ca997d80931 100644 --- a/core/lib/zksync_core/src/consistency_checker/tests/mod.rs +++ b/core/lib/zksync_core/src/consistency_checker/tests/mod.rs @@ -9,8 +9,9 @@ use zksync_dal::StorageProcessor; use zksync_eth_client::clients::MockEthereum; use zksync_types::{ aggregated_operations::AggregatedActionType, block::BlockGasCount, - commitment::L1BatchWithMetadata, l1_batch_committer::RollupModeL1BatchCommitter, - web3::contract::Options, L2ChainId, ProtocolVersion, ProtocolVersionId, H256, + commitment::L1BatchWithMetadata, + l1_batch_commit_data_generator::RollupModeL1BatchCommitDataGenerator, web3::contract::Options, + L2ChainId, ProtocolVersion, ProtocolVersionId, H256, }; use super::*; @@ -44,11 +45,11 @@ fn create_pre_boojum_l1_batch_with_metadata(number: u32) -> L1BatchWithMetadata fn build_commit_tx_input_data( batches: &[L1BatchWithMetadata], - l1_batch_committer: Arc, + l1_batch_commit_data_generator: Arc, ) -> Vec { let commit_tokens = batches .iter() - .map(|batch| l1_batch_committer.l1_commit_data(batch)); + .map(|batch| l1_batch_commit_data_generator.l1_commit_data(batch)); let commit_tokens = ethabi::Token::Array(commit_tokens.collect()); let mut encoded = vec![]; @@ -88,9 +89,10 @@ fn build_commit_tx_input_data_is_correct() { create_l1_batch_with_metadata(1), create_l1_batch_with_metadata(2), ]; - let l1_batch_committer = Arc::new(RollupModeL1BatchCommitter {}); + let l1_batch_commit_data_generator = Arc::new(RollupModeL1BatchCommitDataGenerator {}); - let commit_tx_input_data = build_commit_tx_input_data(&batches, l1_batch_committer.clone()); + let commit_tx_input_data = + build_commit_tx_input_data(&batches, l1_batch_commit_data_generator.clone()); for batch in &batches { let commit_data = ConsistencyChecker::extract_commit_data( @@ -99,7 +101,10 @@ fn build_commit_tx_input_data_is_correct() { batch.header.number, ) .unwrap(); - assert_eq!(commit_data, l1_batch_committer.l1_commit_data(batch)); + assert_eq!( + commit_data, + l1_batch_commit_data_generator.l1_commit_data(batch) + ); } } @@ -304,9 +309,10 @@ async fn normal_checker_function( let mut commit_tx_hash_by_l1_batch = HashMap::with_capacity(l1_batches.len()); let client = MockEthereum::default(); - let l1_batch_committer = Arc::new(RollupModeL1BatchCommitter {}); + let l1_batch_commit_data_generator = Arc::new(RollupModeL1BatchCommitDataGenerator {}); for (i, l1_batches) in l1_batches.chunks(batches_per_transaction).enumerate() { - let input_data = build_commit_tx_input_data(l1_batches, l1_batch_committer.clone()); + let input_data = + build_commit_tx_input_data(l1_batches, l1_batch_commit_data_generator.clone()); let signed_tx = client.sign_prepared_tx( input_data.clone(), Options { @@ -332,7 +338,8 @@ async fn normal_checker_function( }; let (stop_sender, stop_receiver) = watch::channel(false); - let checker_task = tokio::spawn(checker.run(stop_receiver, l1_batch_committer.clone())); + let checker_task = + tokio::spawn(checker.run(stop_receiver, l1_batch_commit_data_generator.clone())); // Add new batches to the storage. for save_action in save_actions_mapper(&l1_batches) { @@ -383,10 +390,12 @@ async fn checker_processes_pre_boojum_batches( let mut commit_tx_hash_by_l1_batch = HashMap::with_capacity(l1_batches.len()); let client = MockEthereum::default(); - let l1_batch_committer = Arc::new(RollupModeL1BatchCommitter {}); + let l1_batch_commit_data_generator = Arc::new(RollupModeL1BatchCommitDataGenerator {}); for (i, l1_batch) in l1_batches.iter().enumerate() { - let input_data = - build_commit_tx_input_data(slice::from_ref(l1_batch), l1_batch_committer.clone()); + let input_data = build_commit_tx_input_data( + slice::from_ref(l1_batch), + l1_batch_commit_data_generator.clone(), + ); let signed_tx = client.sign_prepared_tx( input_data.clone(), Options { @@ -408,7 +417,7 @@ async fn checker_processes_pre_boojum_batches( }; let (stop_sender, stop_receiver) = watch::channel(false); - let checker_task = tokio::spawn(checker.run(stop_receiver, l1_batch_committer)); + let checker_task = tokio::spawn(checker.run(stop_receiver, l1_batch_commit_data_generator)); // Add new batches to the storage. for save_action in save_actions_mapper(&l1_batches) { @@ -443,10 +452,12 @@ async fn checker_functions_after_snapshot_recovery(delay_batch_insertion: bool) let l1_batch = create_l1_batch_with_metadata(99); - let l1_batch_committer = Arc::new(RollupModeL1BatchCommitter {}); + let l1_batch_commit_data_generator = Arc::new(RollupModeL1BatchCommitDataGenerator {}); - let commit_tx_input_data = - build_commit_tx_input_data(slice::from_ref(&l1_batch), l1_batch_committer.clone()); + let commit_tx_input_data = build_commit_tx_input_data( + slice::from_ref(&l1_batch), + l1_batch_commit_data_generator.clone(), + ); let client = MockEthereum::default(); let signed_tx = client.sign_prepared_tx( commit_tx_input_data.clone(), @@ -481,7 +492,7 @@ async fn checker_functions_after_snapshot_recovery(delay_batch_insertion: bool) ..create_mock_checker(client, pool.clone()) }; let (stop_sender, stop_receiver) = watch::channel(false); - let checker_task = tokio::spawn(checker.run(stop_receiver, l1_batch_committer)); + let checker_task = tokio::spawn(checker.run(stop_receiver, l1_batch_commit_data_generator)); if delay_batch_insertion { tokio::time::sleep(Duration::from_millis(10)).await; @@ -524,15 +535,17 @@ impl IncorrectDataKind { self, client: &MockEthereum, l1_batch: &L1BatchWithMetadata, - l1_batch_committer: Arc, + l1_batch_commit_data_generator: Arc, ) -> H256 { let (commit_tx_input_data, successful_status) = match self { Self::MissingStatus => { return H256::zero(); // Do not execute the transaction } Self::MismatchedStatus => { - let commit_tx_input_data = - build_commit_tx_input_data(slice::from_ref(l1_batch), l1_batch_committer); + let commit_tx_input_data = build_commit_tx_input_data( + slice::from_ref(l1_batch), + l1_batch_commit_data_generator, + ); (commit_tx_input_data, false) } Self::BogusCommitDataFormat => { @@ -544,21 +557,27 @@ impl IncorrectDataKind { Self::MismatchedCommitDataTimestamp => { let mut l1_batch = create_l1_batch_with_metadata(1); l1_batch.header.timestamp += 1; - let bogus_tx_input_data = - build_commit_tx_input_data(slice::from_ref(&l1_batch), l1_batch_committer); + let bogus_tx_input_data = build_commit_tx_input_data( + slice::from_ref(&l1_batch), + l1_batch_commit_data_generator, + ); (bogus_tx_input_data, true) } Self::CommitDataForAnotherBatch => { let l1_batch = create_l1_batch_with_metadata(100); - let bogus_tx_input_data = - build_commit_tx_input_data(slice::from_ref(&l1_batch), l1_batch_committer); + let bogus_tx_input_data = build_commit_tx_input_data( + slice::from_ref(&l1_batch), + l1_batch_commit_data_generator, + ); (bogus_tx_input_data, true) } Self::CommitDataForPreBoojum => { let mut l1_batch = create_l1_batch_with_metadata(1); l1_batch.header.protocol_version = Some(ProtocolVersionId::Version0); - let bogus_tx_input_data = - build_commit_tx_input_data(slice::from_ref(&l1_batch), l1_batch_committer); + let bogus_tx_input_data = build_commit_tx_input_data( + slice::from_ref(&l1_batch), + l1_batch_commit_data_generator, + ); (bogus_tx_input_data, true) } }; @@ -595,10 +614,10 @@ async fn checker_detects_incorrect_tx_data(kind: IncorrectDataKind, snapshot_rec } let l1_batch = create_l1_batch_with_metadata(if snapshot_recovery { 99 } else { 1 }); - let l1_batch_committer = Arc::new(RollupModeL1BatchCommitter {}); + let l1_batch_commit_data_generator = Arc::new(RollupModeL1BatchCommitDataGenerator {}); let client = MockEthereum::default(); let commit_tx_hash = kind - .apply(&client, &l1_batch, l1_batch_committer.clone()) + .apply(&client, &l1_batch, l1_batch_commit_data_generator.clone()) .await; let commit_tx_hash_by_l1_batch = HashMap::from([(l1_batch.header.number, commit_tx_hash)]); @@ -619,7 +638,7 @@ async fn checker_detects_incorrect_tx_data(kind: IncorrectDataKind, snapshot_rec // The checker must stop with an error. tokio::time::timeout( Duration::from_secs(30), - checker.run(stop_receiver, l1_batch_committer), + checker.run(stop_receiver, l1_batch_commit_data_generator), ) .await .expect("Timed out waiting for checker to stop") diff --git a/core/lib/zksync_core/src/eth_sender/aggregator.rs b/core/lib/zksync_core/src/eth_sender/aggregator.rs index e9e0f421c54..a6816384765 100644 --- a/core/lib/zksync_core/src/eth_sender/aggregator.rs +++ b/core/lib/zksync_core/src/eth_sender/aggregator.rs @@ -11,7 +11,7 @@ use zksync_types::{ }, commitment::L1BatchWithMetadata, helpers::unix_timestamp_ms, - l1_batch_committer::L1BatchCommitter, + l1_batch_commit_data_generator::L1BatchCommitDataGenerator, protocol_version::L1VerifierConfig, L1BatchNumber, ProtocolVersionId, }; @@ -28,14 +28,14 @@ pub struct Aggregator { execute_criteria: Vec>, config: SenderConfig, blob_store: Arc, - l1_batch_committer: Arc, + l1_batch_commit_data_generator: Arc, } impl Aggregator { pub fn new( config: SenderConfig, blob_store: Arc, - l1_batch_committer: Arc, + l1_batch_commit_data_generator: Arc, ) -> Self { Self { commit_criteria: vec![ @@ -92,7 +92,7 @@ impl Aggregator { ], config, blob_store, - l1_batch_committer, + l1_batch_commit_data_generator, } } @@ -164,7 +164,7 @@ impl Aggregator { &mut self.execute_criteria, ready_for_execute_batches, last_sealed_l1_batch, - self.l1_batch_committer.clone(), + self.l1_batch_commit_data_generator.clone(), ) .await; @@ -223,14 +223,14 @@ impl Aggregator { &mut self.commit_criteria, ready_for_commit_l1_batches, last_sealed_batch, - self.l1_batch_committer.clone(), + self.l1_batch_commit_data_generator.clone(), ) .await; batches.map(|batches| L1BatchCommitOperation { last_committed_l1_batch, l1_batches: batches, - l1_batch_committer: self.l1_batch_committer.clone(), + l1_batch_commit_data_generator: self.l1_batch_commit_data_generator.clone(), }) } @@ -320,14 +320,14 @@ impl Aggregator { storage: &mut StorageProcessor<'_>, ready_for_proof_l1_batches: Vec, last_sealed_l1_batch: L1BatchNumber, - l1_batch_committer: Arc, + l1_batch_commit_data_generator: Arc, ) -> Option { let batches = extract_ready_subrange( storage, &mut self.proof_criteria, ready_for_proof_l1_batches, last_sealed_l1_batch, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await?; @@ -374,7 +374,7 @@ impl Aggregator { storage, ready_for_proof_l1_batches, last_sealed_l1_batch, - self.l1_batch_committer.clone(), + self.l1_batch_commit_data_generator.clone(), ) .await } @@ -400,7 +400,7 @@ impl Aggregator { storage, ready_for_proof_batches, last_sealed_l1_batch, - self.l1_batch_committer.clone(), + self.l1_batch_commit_data_generator.clone(), ) .await } @@ -414,7 +414,7 @@ async fn extract_ready_subrange( publish_criteria: &mut [Box], unpublished_l1_batches: Vec, last_sealed_l1_batch: L1BatchNumber, - l1_batch_committer: Arc, + l1_batch_commit_data_generator: Arc, ) -> Option> { let mut last_l1_batch: Option = None; for criterion in publish_criteria { @@ -423,7 +423,7 @@ async fn extract_ready_subrange( storage, &unpublished_l1_batches, last_sealed_l1_batch, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; if let Some(l1_batch) = l1_batch_by_criterion { diff --git a/core/lib/zksync_core/src/eth_sender/publish_criterion.rs b/core/lib/zksync_core/src/eth_sender/publish_criterion.rs index d910cfa0c71..09909df4e68 100644 --- a/core/lib/zksync_core/src/eth_sender/publish_criterion.rs +++ b/core/lib/zksync_core/src/eth_sender/publish_criterion.rs @@ -5,7 +5,7 @@ use chrono::Utc; use zksync_dal::StorageProcessor; use zksync_types::{ aggregated_operations::AggregatedActionType, commitment::L1BatchWithMetadata, - l1_batch_committer::L1BatchCommitter, L1BatchNumber, + l1_batch_commit_data_generator::L1BatchCommitDataGenerator, L1BatchNumber, }; use super::metrics::METRICS; @@ -23,7 +23,7 @@ pub trait L1BatchPublishCriterion: fmt::Debug + Send + Sync { storage: &mut StorageProcessor<'_>, consecutive_l1_batches: &[L1BatchWithMetadata], last_sealed_l1_batch: L1BatchNumber, - _l1_batch_committer: Arc, + _l1_batch_commit_data_generator: Arc, ) -> Option; } @@ -45,7 +45,7 @@ impl L1BatchPublishCriterion for NumberCriterion { _storage: &mut StorageProcessor<'_>, consecutive_l1_batches: &[L1BatchWithMetadata], _last_sealed_l1_batch: L1BatchNumber, - _l1_batch_committer: Arc, + _l1_batch_commit_data_generator: Arc, ) -> Option { let mut batch_numbers = consecutive_l1_batches .iter() @@ -92,7 +92,7 @@ impl L1BatchPublishCriterion for TimestampDeadlineCriterion { _storage: &mut StorageProcessor<'_>, consecutive_l1_batches: &[L1BatchWithMetadata], last_sealed_l1_batch: L1BatchNumber, - _l1_batch_committer: Arc, + _l1_batch_commit_data_generator: Arc, ) -> Option { let first_l1_batch = consecutive_l1_batches.iter().next()?; let last_l1_batch_number = consecutive_l1_batches.iter().last()?.header.number.0; @@ -157,7 +157,7 @@ impl L1BatchPublishCriterion for GasCriterion { storage: &mut StorageProcessor<'_>, consecutive_l1_batches: &[L1BatchWithMetadata], _last_sealed_l1_batch: L1BatchNumber, - _l1_batch_committer: Arc, + _l1_batch_commit_data_generator: Arc, ) -> Option { let base_cost = agg_l1_batch_base_cost(self.op); assert!( @@ -215,13 +215,13 @@ impl L1BatchPublishCriterion for DataSizeCriterion { _storage: &mut StorageProcessor<'_>, consecutive_l1_batches: &[L1BatchWithMetadata], _last_sealed_l1_batch: L1BatchNumber, - l1_batch_committer: Arc, + l1_batch_commit_data_generator: Arc, ) -> Option { const STORED_BLOCK_INFO_SIZE: usize = 96; // size of `StoredBlockInfo` solidity struct let mut data_size_left = self.data_limit - STORED_BLOCK_INFO_SIZE; for (index, l1_batch) in consecutive_l1_batches.iter().enumerate() { - let l1_commit_data_size = l1_batch_committer.l1_commit_data_size(l1_batch); + let l1_commit_data_size = l1_batch_commit_data_generator.l1_commit_data_size(l1_batch); if data_size_left < l1_commit_data_size { if index == 0 { panic!( diff --git a/core/lib/zksync_core/src/eth_sender/tests.rs b/core/lib/zksync_core/src/eth_sender/tests.rs index 28a6102c61c..c9539dd230c 100644 --- a/core/lib/zksync_core/src/eth_sender/tests.rs +++ b/core/lib/zksync_core/src/eth_sender/tests.rs @@ -17,7 +17,9 @@ use zksync_types::{ commitment::{L1BatchMetaParameters, L1BatchMetadata, L1BatchWithMetadata}, ethabi::Token, helpers::unix_timestamp_ms, - l1_batch_committer::{L1BatchCommitter, RollupModeL1BatchCommitter}, + l1_batch_commit_data_generator::{ + L1BatchCommitDataGenerator, RollupModeL1BatchCommitDataGenerator, + }, web3::contract::Error, Address, L1BatchNumber, L1BlockNumber, ProtocolVersionId, H256, }; @@ -60,7 +62,7 @@ impl EthSenderTester { connection_pool: ConnectionPool, history: Vec, non_ordering_confirmations: bool, - l1_batch_committer: Arc, + l1_batch_commit_data_generator: Arc, ) -> Self { let eth_sender_config = ETHSenderConfig::for_tests(); let contracts_config = ContractsConfig::for_tests(); @@ -106,7 +108,7 @@ impl EthSenderTester { Aggregator::new( aggregator_config.clone(), store_factory.create_store().await, - l1_batch_committer, + l1_batch_commit_data_generator, ), gateway.clone(), // zkSync contract address @@ -145,12 +147,12 @@ impl EthSenderTester { #[tokio::test] async fn confirm_many() -> anyhow::Result<()> { let connection_pool = ConnectionPool::test_pool().await; - let l1_batch_committer = Arc::new(RollupModeL1BatchCommitter {}); + let l1_batch_commit_data_generator = Arc::new(RollupModeL1BatchCommitDataGenerator {}); let mut tester = EthSenderTester::new( connection_pool, vec![10; 100], false, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; @@ -228,12 +230,12 @@ async fn confirm_many() -> anyhow::Result<()> { #[tokio::test] async fn resend_each_block() -> anyhow::Result<()> { let connection_pool = ConnectionPool::test_pool().await; - let l1_batch_committer = Arc::new(RollupModeL1BatchCommitter {}); + let l1_batch_commit_data_generator = Arc::new(RollupModeL1BatchCommitDataGenerator {}); let mut tester = EthSenderTester::new( connection_pool, vec![7, 6, 5, 5, 5, 2, 1], false, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; @@ -346,12 +348,12 @@ async fn resend_each_block() -> anyhow::Result<()> { #[tokio::test] async fn dont_resend_already_mined() -> anyhow::Result<()> { let connection_pool = ConnectionPool::test_pool().await; - let l1_batch_committer = Arc::new(RollupModeL1BatchCommitter {}); + let l1_batch_commit_data_generator = Arc::new(RollupModeL1BatchCommitDataGenerator {}); let mut tester = EthSenderTester::new( connection_pool, vec![100; 100], false, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; let tx = tester @@ -424,12 +426,12 @@ async fn dont_resend_already_mined() -> anyhow::Result<()> { #[tokio::test] async fn three_scenarios() -> anyhow::Result<()> { let connection_pool = ConnectionPool::test_pool().await; - let l1_batch_committer = Arc::new(RollupModeL1BatchCommitter {}); + let l1_batch_commit_data_generator = Arc::new(RollupModeL1BatchCommitDataGenerator {}); let mut tester = EthSenderTester::new( connection_pool.clone(), vec![100; 100], false, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; let mut hashes = vec![]; @@ -503,12 +505,12 @@ async fn three_scenarios() -> anyhow::Result<()> { #[tokio::test] async fn failed_eth_tx() { let connection_pool = ConnectionPool::test_pool().await; - let l1_batch_committer = Arc::new(RollupModeL1BatchCommitter {}); + let l1_batch_commit_data_generator = Arc::new(RollupModeL1BatchCommitDataGenerator {}); let mut tester = EthSenderTester::new( connection_pool.clone(), vec![100; 100], false, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; @@ -582,12 +584,12 @@ fn l1_batch_with_metadata(header: L1BatchHeader) -> L1BatchWithMetadata { #[tokio::test] async fn correct_order_for_confirmations() -> anyhow::Result<()> { let connection_pool = ConnectionPool::test_pool().await; - let l1_batch_committer = Arc::new(RollupModeL1BatchCommitter {}); + let l1_batch_commit_data_generator = Arc::new(RollupModeL1BatchCommitDataGenerator {}); let mut tester = EthSenderTester::new( connection_pool, vec![100; 100], true, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; insert_genesis_protocol_version(&tester).await; @@ -600,7 +602,7 @@ async fn correct_order_for_confirmations() -> anyhow::Result<()> { genesis_l1_batch.clone(), first_l1_batch.clone(), true, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; prove_l1_batch( @@ -616,7 +618,7 @@ async fn correct_order_for_confirmations() -> anyhow::Result<()> { first_l1_batch.clone(), second_l1_batch.clone(), true, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; prove_l1_batch( @@ -652,12 +654,12 @@ async fn correct_order_for_confirmations() -> anyhow::Result<()> { #[tokio::test] async fn skipped_l1_batch_at_the_start() -> anyhow::Result<()> { let connection_pool = ConnectionPool::test_pool().await; - let l1_batch_committer = Arc::new(RollupModeL1BatchCommitter {}); + let l1_batch_commit_data_generator = Arc::new(RollupModeL1BatchCommitDataGenerator {}); let mut tester = EthSenderTester::new( connection_pool, vec![100; 100], true, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; insert_genesis_protocol_version(&tester).await; @@ -670,7 +672,7 @@ async fn skipped_l1_batch_at_the_start() -> anyhow::Result<()> { genesis_l1_batch.clone(), first_l1_batch.clone(), true, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; prove_l1_batch( @@ -686,7 +688,7 @@ async fn skipped_l1_batch_at_the_start() -> anyhow::Result<()> { first_l1_batch.clone(), second_l1_batch.clone(), true, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; prove_l1_batch( @@ -706,7 +708,7 @@ async fn skipped_l1_batch_at_the_start() -> anyhow::Result<()> { second_l1_batch.clone(), third_l1_batch.clone(), false, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; @@ -722,7 +724,7 @@ async fn skipped_l1_batch_at_the_start() -> anyhow::Result<()> { third_l1_batch.clone(), fourth_l1_batch.clone(), true, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; prove_l1_batch( @@ -756,12 +758,12 @@ async fn skipped_l1_batch_at_the_start() -> anyhow::Result<()> { #[tokio::test] async fn skipped_l1_batch_in_the_middle() -> anyhow::Result<()> { let connection_pool = ConnectionPool::test_pool().await; - let l1_batch_committer = Arc::new(RollupModeL1BatchCommitter {}); + let l1_batch_commit_data_generator = Arc::new(RollupModeL1BatchCommitDataGenerator {}); let mut tester = EthSenderTester::new( connection_pool, vec![100; 100], true, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; insert_genesis_protocol_version(&tester).await; @@ -773,7 +775,7 @@ async fn skipped_l1_batch_in_the_middle() -> anyhow::Result<()> { genesis_l1_batch.clone(), first_l1_batch.clone(), true, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; prove_l1_batch(&mut tester, genesis_l1_batch, first_l1_batch.clone(), true).await; @@ -783,7 +785,7 @@ async fn skipped_l1_batch_in_the_middle() -> anyhow::Result<()> { first_l1_batch.clone(), second_l1_batch.clone(), true, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; prove_l1_batch( @@ -802,7 +804,7 @@ async fn skipped_l1_batch_in_the_middle() -> anyhow::Result<()> { second_l1_batch.clone(), third_l1_batch.clone(), false, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; @@ -818,7 +820,7 @@ async fn skipped_l1_batch_in_the_middle() -> anyhow::Result<()> { third_l1_batch.clone(), fourth_l1_batch.clone(), true, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; prove_l1_batch( @@ -854,12 +856,12 @@ async fn skipped_l1_batch_in_the_middle() -> anyhow::Result<()> { #[tokio::test] async fn test_parse_multicall_data() { let connection_pool = ConnectionPool::test_pool().await; - let l1_batch_committer = Arc::new(RollupModeL1BatchCommitter {}); + let l1_batch_commit_data_generator = Arc::new(RollupModeL1BatchCommitDataGenerator {}); let tester = EthSenderTester::new( connection_pool, vec![100; 100], false, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; @@ -941,12 +943,12 @@ async fn test_parse_multicall_data() { #[tokio::test] async fn get_multicall_data() { let connection_pool = ConnectionPool::test_pool().await; - let l1_batch_committer = Arc::new(RollupModeL1BatchCommitter {}); + let l1_batch_commit_data_generator = Arc::new(RollupModeL1BatchCommitDataGenerator {}); let mut tester = EthSenderTester::new( connection_pool, vec![100; 100], false, - l1_batch_committer.clone(), + l1_batch_commit_data_generator.clone(), ) .await; let multicall_data = tester.aggregator.get_multicall_data().await; @@ -1019,12 +1021,12 @@ async fn commit_l1_batch( last_committed_l1_batch: L1BatchHeader, l1_batch: L1BatchHeader, confirm: bool, - l1_batch_committer: Arc, + l1_batch_commit_data_generator: Arc, ) -> H256 { let operation = AggregatedOperation::Commit(L1BatchCommitOperation { last_committed_l1_batch: l1_batch_with_metadata(last_committed_l1_batch), l1_batches: vec![l1_batch_with_metadata(l1_batch)], - l1_batch_committer, + l1_batch_commit_data_generator, }); send_operation(tester, operation, confirm).await } diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index 74825d23dfd..d7275519992 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -16,8 +16,8 @@ use zksync_config::{ configs::{ api::{MerkleTreeApiConfig, Web3JsonRpcConfig}, chain::{ - CircuitBreakerConfig, MempoolConfig, NetworkConfig, OperationsManagerConfig, - StateKeeperConfig, + CircuitBreakerConfig, L1BatchCommitDataGeneratorMode, MempoolConfig, NetworkConfig, + OperationsManagerConfig, StateKeeperConfig, }, contracts::ProverAtGenesis, database::{MerkleTreeConfig, MerkleTreeMode}, @@ -36,8 +36,9 @@ use zksync_queued_job_processor::JobProcessor; use zksync_state::PostgresStorageCaches; use zksync_types::{ fee_model::FeeModelConfig, - l1_batch_committer::{ - L1BatchCommitter, RollupModeL1BatchCommitter, ValidiumModeL1BatchCommitter, + l1_batch_commit_data_generator::{ + L1BatchCommitDataGenerator, RollupModeL1BatchCommitDataGenerator, + ValidiumModeL1BatchCommitDataGenerator, }, protocol_version::{L1VerifierConfig, VerifierParams}, system_contracts::get_system_smart_contracts, @@ -553,18 +554,25 @@ pub async fn initialize_components( let eth_client = PKSigningClient::from_config(ð_sender, &contracts_config, ð_client_config); let nonce = eth_client.pending_nonce("eth_sender").await.unwrap(); - let l1_batch_committer: Arc = - if std::env::var("VALIDIUM_MODE") == Ok("true".to_owned()) { - Arc::new(ValidiumModeL1BatchCommitter {}) - } else { - Arc::new(RollupModeL1BatchCommitter {}) + let state_keeper_config = configs + .state_keeper_config + .clone() + .context("state_keeper_config")?; + let l1_batch_commit_data_generator: Arc = + match state_keeper_config.l1_batch_commit_data_generator_mode { + L1BatchCommitDataGeneratorMode::Rollup => { + Arc::new(RollupModeL1BatchCommitDataGenerator {}) + } + L1BatchCommitDataGeneratorMode::Validium => { + Arc::new(ValidiumModeL1BatchCommitDataGenerator {}) + } }; let eth_tx_aggregator_actor = EthTxAggregator::new( eth_sender.sender.clone(), Aggregator::new( eth_sender.sender.clone(), store_factory.create_store().await, - l1_batch_committer, + l1_batch_commit_data_generator, ), Arc::new(eth_client), contracts_config.validator_timelock_addr, diff --git a/etc/env/base/chain.toml b/etc/env/base/chain.toml index 4a385be905a..a47c5c498d2 100644 --- a/etc/env/base/chain.toml +++ b/etc/env/base/chain.toml @@ -93,6 +93,8 @@ virtual_blocks_per_miniblock=1 # This variable should not be set to true in any customer facing environment. upload_witness_inputs_to_gcs=false +l1_batch_commit_data_generator_mode="Validium" + [chain.operations_manager] # Sleep time when there is no new input data delay_interval=100