Skip to content

Commit

Permalink
add a test that continues from unsealed batch
Browse files Browse the repository at this point in the history
  • Loading branch information
itegulov committed Oct 9, 2024
1 parent 0e38efb commit 84aafa7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
4 changes: 2 additions & 2 deletions core/node/state_keeper/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct PendingBatchData {
pub(crate) pending_l2_blocks: Vec<L2BlockExecutionData>,
}

#[derive(Debug, Copy, Clone, Default)]
#[derive(Debug, Copy, Clone, Default, PartialEq)]
pub struct L2BlockParams {
/// The timestamp of the L2 block.
pub timestamp: u64,
Expand All @@ -58,7 +58,7 @@ pub struct L2BlockParams {
}

/// Parameters for a new L1 batch returned by [`StateKeeperIO::wait_for_new_batch_params()`].
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct L1BatchParams {
/// Protocol version for the new L1 batch.
pub protocol_version: ProtocolVersionId,
Expand Down
50 changes: 50 additions & 0 deletions core/node/state_keeper/src/io/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,3 +556,53 @@ async fn different_timestamp_for_l2_blocks_in_same_batch(commitment_mode: L1Batc
.expect("no new L2 block params");
assert!(l2_block_params.timestamp > current_timestamp);
}

#[test_casing(2, COMMITMENT_MODES)]
#[tokio::test]
async fn continue_unsealed_batch_on_restart(commitment_mode: L1BatchCommitmentMode) {
let connection_pool = ConnectionPool::<Core>::test_pool().await;
let tester = Tester::new(commitment_mode);
tester.genesis(&connection_pool).await;
let mut storage = connection_pool.connection().await.unwrap();

let (mut mempool, mut mempool_guard) =
tester.create_test_mempool_io(connection_pool.clone()).await;
let (cursor, _) = mempool.initialize().await.unwrap();

// Insert a transaction into the mempool in order to open a new batch.
let tx_filter = l2_tx_filter(
&tester.create_batch_fee_input_provider().await,
ProtocolVersionId::latest().into(),
)
.await
.unwrap();
let tx = tester.insert_tx(
&mut mempool_guard,
tx_filter.fee_per_gas,
tx_filter.gas_per_pubdata,
);
storage
.transactions_dal()
.insert_transaction_l2(&tx, TransactionExecutionMetrics::default())
.await
.unwrap();

let old_l1_batch_params = mempool
.wait_for_new_batch_params(&cursor, Duration::from_secs(10))
.await
.unwrap()
.expect("no batch params generated");

// Restart
drop((mempool, mempool_guard, cursor));
let (mut mempool, _) = tester.create_test_mempool_io(connection_pool.clone()).await;
let (cursor, _) = mempool.initialize().await.unwrap();

let new_l1_batch_params = mempool
.wait_for_new_batch_params(&cursor, Duration::from_secs(10))
.await
.unwrap()
.expect("no batch params generated");

assert_eq!(old_l1_batch_params, new_l1_batch_params);
}
20 changes: 15 additions & 5 deletions core/node/state_keeper/src/io/tests/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use std::{slice, sync::Arc, time::Duration};

use crate::{MempoolGuard, MempoolIO};
use zksync_base_token_adjuster::NoOpRatioProvider;
use zksync_config::{
configs::{chain::StateKeeperConfig, eth_sender::PubdataSendingMode, wallets::Wallets},
Expand All @@ -22,18 +23,17 @@ use zksync_node_genesis::create_genesis_l1_batch;
use zksync_node_test_utils::{
create_l1_batch, create_l2_block, create_l2_transaction, execute_l2_transaction,
};
use zksync_types::fee_model::FeeModelConfigV2;
use zksync_types::{
block::L2BlockHeader,
commitment::L1BatchCommitmentMode,
fee_model::{BatchFeeInput, FeeModelConfig, FeeModelConfigV1},
fee_model::{BatchFeeInput, FeeModelConfig},
l2::L2Tx,
protocol_version::{L1VerifierConfig, ProtocolSemanticVersion},
system_contracts::get_system_smart_contracts,
L2BlockNumber, L2ChainId, PriorityOpId, ProtocolVersionId, H256,
};

use crate::{MempoolGuard, MempoolIO};

#[derive(Debug)]
pub struct Tester {
base_system_contracts: BaseSystemContracts,
Expand Down Expand Up @@ -97,8 +97,13 @@ impl Tester {
MainNodeFeeInputProvider::new(
gas_adjuster,
Arc::new(NoOpRatioProvider::default()),
FeeModelConfig::V1(FeeModelConfigV1 {
FeeModelConfig::V2(FeeModelConfigV2 {
minimal_l2_gas_price: self.minimal_l2_gas_price(),
compute_overhead_part: 1.0,
pubdata_overhead_part: 1.0,
batch_overhead_l1_gas: 10,
max_gas_per_batch: 500_000_000_000,
max_pubdata_per_batch: 100_000_000_000,
}),
)
}
Expand All @@ -116,8 +121,13 @@ impl Tester {
let batch_fee_input_provider = MainNodeFeeInputProvider::new(
gas_adjuster,
Arc::new(NoOpRatioProvider::default()),
FeeModelConfig::V1(FeeModelConfigV1 {
FeeModelConfig::V2(FeeModelConfigV2 {
minimal_l2_gas_price: self.minimal_l2_gas_price(),
compute_overhead_part: 1.0,
pubdata_overhead_part: 1.0,
batch_overhead_l1_gas: 10,
max_gas_per_batch: 500_000_000_000,
max_pubdata_per_batch: 100_000_000_000,
}),
);

Expand Down

0 comments on commit 84aafa7

Please sign in to comment.