Skip to content

Commit f6422cd

Browse files
authored
feat(state-keeper): mempool io opens batch if there is protocol upgrade tx (#3360)
## What ❔ Mempool io opens batch if there is protocol upgrade tx ## Why ❔ Currently if mempool is empty but there is protocol upgrade tx, then batch is not opened ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zkstack dev fmt` and `zkstack dev lint`.
1 parent 7ace594 commit f6422cd

File tree

3 files changed

+70
-6
lines changed

3 files changed

+70
-6
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/node/state_keeper/src/io/mempool.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,21 @@ impl StateKeeperIO for MempoolIO {
206206
.protocol_version_id_by_timestamp(timestamp)
207207
.await
208208
.context("Failed loading protocol version")?;
209+
let previous_protocol_version = storage
210+
.blocks_dal()
211+
.pending_protocol_version()
212+
.await
213+
.context("Failed loading previous protocol version")?;
214+
let batch_with_upgrade_tx = if previous_protocol_version != protocol_version {
215+
storage
216+
.protocol_versions_dal()
217+
.get_protocol_upgrade_tx(protocol_version)
218+
.await
219+
.context("Failed loading protocol upgrade tx")?
220+
.is_some()
221+
} else {
222+
false
223+
};
209224
drop(storage);
210225

211226
// We create a new filter each time, since parameters may change and a previously
@@ -217,7 +232,8 @@ impl StateKeeperIO for MempoolIO {
217232
.await
218233
.context("failed creating L2 transaction filter")?;
219234

220-
if !self.mempool.has_next(&self.filter) {
235+
// We do not populate mempool with upgrade tx so it should be checked separately.
236+
if !batch_with_upgrade_tx && !self.mempool.has_next(&self.filter) {
221237
tokio::time::sleep(self.delay_interval).await;
222238
continue;
223239
}

core/node/state_keeper/src/io/tests/mod.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use zksync_types::{
1818
commitment::{L1BatchCommitmentMode, PubdataParams},
1919
fee_model::{BatchFeeInput, PubdataIndependentBatchFeeModelInput},
2020
l2::L2Tx,
21+
protocol_upgrade::ProtocolUpgradeTx,
22+
protocol_version::ProtocolSemanticVersion,
2123
AccountTreeId, Address, L1BatchNumber, L2BlockNumber, L2ChainId, ProtocolVersion,
2224
ProtocolVersionId, StorageKey, TransactionTimeRangeConstraint, H256, U256,
2325
};
@@ -848,6 +850,52 @@ async fn test_mempool_with_timestamp_assertion() {
848850
);
849851
}
850852

853+
#[tokio::test]
854+
async fn test_batch_params_with_protocol_upgrade_tx() {
855+
let connection_pool = ConnectionPool::<Core>::constrained_test_pool(2).await;
856+
let tester = Tester::new(L1BatchCommitmentMode::Rollup);
857+
// Genesis is needed for proper mempool initialization.
858+
tester.genesis(&connection_pool).await;
859+
860+
let (mut mempool, _) = tester.create_test_mempool_io(connection_pool.clone()).await;
861+
let (cursor, _) = mempool.initialize().await.unwrap();
862+
863+
// Check that new batch params are not returned when there is no tx to process.
864+
let new_batch_params = mempool
865+
.wait_for_new_batch_params(&cursor, Duration::from_millis(100))
866+
.await
867+
.unwrap();
868+
assert!(new_batch_params.is_none());
869+
870+
// Insert protocol version with upgrade tx.
871+
let protocol_upgrade_tx = ProtocolUpgradeTx {
872+
execute: Default::default(),
873+
common_data: Default::default(),
874+
received_timestamp_ms: 0,
875+
};
876+
let version = ProtocolVersion {
877+
version: ProtocolSemanticVersion {
878+
minor: ProtocolVersionId::next(),
879+
patch: 0.into(),
880+
},
881+
tx: Some(protocol_upgrade_tx),
882+
..Default::default()
883+
};
884+
connection_pool
885+
.connection()
886+
.await
887+
.unwrap()
888+
.protocol_versions_dal()
889+
.save_protocol_version_with_tx(&version)
890+
.await
891+
.unwrap();
892+
let new_batch_params = mempool
893+
.wait_for_new_batch_params(&cursor, Duration::from_millis(100))
894+
.await
895+
.unwrap();
896+
assert!(new_batch_params.is_some());
897+
}
898+
851899
async fn insert_l2_transaction(storage: &mut Connection<'_, Core>, tx: &L2Tx) {
852900
storage
853901
.transactions_dal()

0 commit comments

Comments
 (0)