diff --git a/Cargo.lock b/Cargo.lock index bb4399d1ae78..6e8b76c964c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -126,7 +126,7 @@ dependencies = [ "derive_more 1.0.0", "foldhash", "getrandom", - "hashbrown 0.15.0", + "hashbrown 0.15.2", "hex-literal", "indexmap 2.6.0", "itoa", @@ -3841,9 +3841,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.15.0" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" dependencies = [ "allocator-api2", "equivalent", @@ -4352,7 +4352,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.15.0", + "hashbrown 0.15.2", "serde", ] @@ -5180,7 +5180,7 @@ version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" dependencies = [ - "hashbrown 0.15.0", + "hashbrown 0.15.2", ] [[package]] diff --git a/core/node/state_keeper/src/io/mempool.rs b/core/node/state_keeper/src/io/mempool.rs index 991ecee699c3..cf354891236b 100644 --- a/core/node/state_keeper/src/io/mempool.rs +++ b/core/node/state_keeper/src/io/mempool.rs @@ -206,6 +206,21 @@ impl StateKeeperIO for MempoolIO { .protocol_version_id_by_timestamp(timestamp) .await .context("Failed loading protocol version")?; + let previous_protocol_version = storage + .blocks_dal() + .pending_protocol_version() + .await + .context("Failed loading previous protocol version")?; + let batch_with_upgrade_tx = if previous_protocol_version != protocol_version { + storage + .protocol_versions_dal() + .get_protocol_upgrade_tx(protocol_version) + .await + .context("Failed loading protocol upgrade tx")? + .is_some() + } else { + false + }; drop(storage); // We create a new filter each time, since parameters may change and a previously @@ -217,7 +232,8 @@ impl StateKeeperIO for MempoolIO { .await .context("failed creating L2 transaction filter")?; - if !self.mempool.has_next(&self.filter) { + // We do not populate mempool with upgrade tx so it should be checked separately. + if !batch_with_upgrade_tx && !self.mempool.has_next(&self.filter) { tokio::time::sleep(self.delay_interval).await; continue; } diff --git a/core/node/state_keeper/src/io/tests/mod.rs b/core/node/state_keeper/src/io/tests/mod.rs index 15164328b7a0..536efe82804a 100644 --- a/core/node/state_keeper/src/io/tests/mod.rs +++ b/core/node/state_keeper/src/io/tests/mod.rs @@ -18,6 +18,8 @@ use zksync_types::{ commitment::{L1BatchCommitmentMode, PubdataParams}, fee_model::{BatchFeeInput, PubdataIndependentBatchFeeModelInput}, l2::L2Tx, + protocol_upgrade::ProtocolUpgradeTx, + protocol_version::ProtocolSemanticVersion, AccountTreeId, Address, L1BatchNumber, L2BlockNumber, L2ChainId, ProtocolVersion, ProtocolVersionId, StorageKey, TransactionTimeRangeConstraint, H256, U256, }; @@ -848,6 +850,52 @@ async fn test_mempool_with_timestamp_assertion() { ); } +#[tokio::test] +async fn test_batch_params_with_protocol_upgrade_tx() { + let connection_pool = ConnectionPool::::constrained_test_pool(2).await; + let tester = Tester::new(L1BatchCommitmentMode::Rollup); + // Genesis is needed for proper mempool initialization. + tester.genesis(&connection_pool).await; + + let (mut mempool, _) = tester.create_test_mempool_io(connection_pool.clone()).await; + let (cursor, _) = mempool.initialize().await.unwrap(); + + // Check that new batch params are not returned when there is no tx to process. + let new_batch_params = mempool + .wait_for_new_batch_params(&cursor, Duration::from_millis(100)) + .await + .unwrap(); + assert!(new_batch_params.is_none()); + + // Insert protocol version with upgrade tx. + let protocol_upgrade_tx = ProtocolUpgradeTx { + execute: Default::default(), + common_data: Default::default(), + received_timestamp_ms: 0, + }; + let version = ProtocolVersion { + version: ProtocolSemanticVersion { + minor: ProtocolVersionId::next(), + patch: 0.into(), + }, + tx: Some(protocol_upgrade_tx), + ..Default::default() + }; + connection_pool + .connection() + .await + .unwrap() + .protocol_versions_dal() + .save_protocol_version_with_tx(&version) + .await + .unwrap(); + let new_batch_params = mempool + .wait_for_new_batch_params(&cursor, Duration::from_millis(100)) + .await + .unwrap(); + assert!(new_batch_params.is_some()); +} + async fn insert_l2_transaction(storage: &mut Connection<'_, Core>, tx: &L2Tx) { storage .transactions_dal()