Skip to content

Commit

Permalink
Fix remaining issues
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc committed Jan 21, 2021
1 parent ce854ea commit 7935aeb
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 266 deletions.
33 changes: 18 additions & 15 deletions core/bin/prover/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Built-in deps
use std::collections::HashMap;
use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;
// External deps
Expand All @@ -12,8 +11,8 @@ use zksync_circuit::{
serialization::ProverData,
witness::{deposit::DepositWitness, utils::WitnessBuilder, Witness},
};
use zksync_config::configs::ChainConfig;
use zksync_config::{ConfigurationOptions, ProverOptions};
use zksync_config::configs::{ChainConfig, ProverConfig};
// use zksync_config::{ConfigurationOptions, ProverOptions};
use zksync_crypto::{
circuit::{account::CircuitAccount, CircuitAccountTree},
pairing::ff::PrimeField,
Expand All @@ -36,7 +35,7 @@ use zksync_types::{
struct MockProverConfigs {
plonk_config: PlonkStepByStepProverConfig,
dummy_config: DummyProverConfig,
prover_options: ProverOptions,
prover_options: ProverConfig,
shutdown_request: ShutdownRequest,
prover_name: String,
}
Expand All @@ -52,16 +51,20 @@ impl Default for MockProverConfigs {
let dummy_config = DummyProverConfig {
block_sizes: vec![6, 30],
};
let prover_options = ProverOptions {
secret_auth: "".to_string(),
prepare_data_interval: Duration::from_secs(5),
heartbeat_interval: Duration::from_secs(0),
cycle_wait: Duration::from_millis(500),
prover_server_address: "0.0.0.0:8088"
.parse::<SocketAddr>()
.expect("Can't get address from port"),
witness_generators: 2,
idle_provers: 1,
let prover_options = ProverConfig {
prover: zksync_config::configs::prover::Prover {
heartbeat_interval: 1000,
cycle_wait: 500,
request_timeout: 1,
},
core: zksync_config::configs::prover::Core {
gone_timeout: 2,
idle_provers: 1,
},
witness_generator: zksync_config::configs::prover::WitnessGenerator {
prepare_data_interval: 5000,
witness_generators: 2,
},
};

Self {
Expand Down Expand Up @@ -155,7 +158,7 @@ async fn test_shutdown_request() {
&prover_name,
)
.fuse();
let timeout = tokio::time::delay_for(prover_options.cycle_wait).fuse();
let timeout = tokio::time::delay_for(prover_options.prover.cycle_wait()).fuse();

pin_mut!(prover_work_cycle, timeout);

Expand Down
21 changes: 9 additions & 12 deletions core/bin/zksync_core/src/state_keeper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,18 +696,15 @@ impl ZkSyncStateKeeper {
tx: ZkSyncTx,
block_timestamp: u64,
) -> Result<(), anyhow::Error> {
match tx {
ZkSyncTx::Transfer(tx) => {
let valid_from = u64::from(tx.valid_from.unwrap_or(0));
let valid_until = u64::from(tx.valid_until.unwrap_or(u32::MAX));
ensure!(
valid_from <= block_timestamp && block_timestamp <= valid_until,
"The transaction can't be executed in the block because of an invalid timestamp"
);
}
_ => {
// There are no timestamps in other transactions
}
if let ZkSyncTx::Transfer(tx) = tx {
let valid_from = u64::from(tx.valid_from.unwrap_or(0));
let valid_until = u64::from(tx.valid_until.unwrap_or(u32::MAX));
ensure!(
valid_from <= block_timestamp && block_timestamp <= valid_until,
"The transaction can't be executed in the block because of an invalid timestamp"
);
} else {
// There are no timestamps in other transactions
}
Ok(())
}
Expand Down
17 changes: 9 additions & 8 deletions core/bin/zksync_core/src/state_keeper/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ fn create_account_and_fast_withdrawal<B: Into<BigUint>>(
)
}

#[allow(clippy::clippy::too_many_arguments)]
fn create_account_and_withdrawal_impl<B: Into<BigUint>>(
tester: &mut StateKeeperTester,
token_id: TokenId,
Expand Down Expand Up @@ -358,7 +359,7 @@ mod apply_tx {
/// small number of chunks left in the block
#[test]
fn not_enough_chunks() {
let mut tester = StateKeeperTester::new(1, 1, 1, 1);
let mut tester = StateKeeperTester::new(1, 1, 1);
let withdraw =
create_account_and_withdrawal(&mut tester, 0, 1, 200u32, 145u32, 0, u32::MAX);
let result = tester.state_keeper.apply_tx(&withdraw);
Expand Down Expand Up @@ -396,7 +397,7 @@ mod apply_tx {
/// with 1 priority_op, 1 succeeded tx, 1 failed tx
#[tokio::test]
async fn seal_pending_block() {
let mut tester = StateKeeperTester::new(20, 3, 3, 2);
let mut tester = StateKeeperTester::new(20, 3, 3);
let good_withdraw =
create_account_and_withdrawal(&mut tester, 0, 1, 200u32, 145u32, 0, u32::MAX);
let bad_withdraw =
Expand Down Expand Up @@ -448,7 +449,7 @@ async fn seal_pending_block() {
/// with 1 priority_op, 1 succeeded tx, 1 failed tx
#[tokio::test]
async fn store_pending_block() {
let mut tester = StateKeeperTester::new(20, 3, 3, 2);
let mut tester = StateKeeperTester::new(20, 3, 3);
let good_withdraw =
create_account_and_withdrawal(&mut tester, 0, 1, 200u32, 145u32, 0, u32::MAX);
let bad_withdraw =
Expand Down Expand Up @@ -608,7 +609,7 @@ mod execute_proposed_block {
/// Checks if executing a small proposed_block is done correctly
#[tokio::test]
async fn small() {
let mut tester = StateKeeperTester::new(20, 3, 3, 2);
let mut tester = StateKeeperTester::new(20, 3, 3);
let good_withdraw =
create_account_and_withdrawal(&mut tester, 0, 1, 200u32, 145u32, 0, u32::MAX);
let bad_withdraw =
Expand Down Expand Up @@ -641,7 +642,7 @@ mod execute_proposed_block {
/// so 1 block should get sealed in the process
#[tokio::test]
async fn few_chunks() {
let mut tester = StateKeeperTester::new(12, 3, 3, 2);
let mut tester = StateKeeperTester::new(12, 3, 3);
let good_withdraw =
create_account_and_withdrawal(&mut tester, 0, 1, 200u32, 145u32, 0, u32::MAX);
let bad_withdraw =
Expand Down Expand Up @@ -672,7 +673,7 @@ mod execute_proposed_block {
/// max_iterations == 0, so the block should get sealed, not stored
#[tokio::test]
async fn few_iterations() {
let mut tester = StateKeeperTester::new(20, 0, 0, 2);
let mut tester = StateKeeperTester::new(20, 0, 0);
let good_withdraw =
create_account_and_withdrawal(&mut tester, 0, 1, 200u32, 145u32, 0, u32::MAX);
let bad_withdraw =
Expand Down Expand Up @@ -701,7 +702,7 @@ mod execute_proposed_block {
const MAX_ITERATIONS: usize = 100;
const FAST_ITERATIONS: usize = 0; // Seal block right after fast withdrawal.

let mut tester = StateKeeperTester::new(6, MAX_ITERATIONS, FAST_ITERATIONS, 2);
let mut tester = StateKeeperTester::new(6, MAX_ITERATIONS, FAST_ITERATIONS);
let withdraw =
create_account_and_fast_withdrawal(&mut tester, 0, 1, 200u32, 145u32, 0, u32::MAX);

Expand Down Expand Up @@ -926,7 +927,7 @@ mod execute_proposed_block {
/// and transaction with an invalid timestamp failed.
#[tokio::test]
async fn transfers_with_different_timestamps() {
let mut tester = StateKeeperTester::new(20, 5, 5, 4);
let mut tester = StateKeeperTester::new(20, 5, 5);

let token_id: TokenId = 0;
let account_from_id: AccountId = 1;
Expand Down
63 changes: 31 additions & 32 deletions core/bin/zksync_eth_sender/src/tx_queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use zksync_types::aggregated_operations::{AggregatedActionType, AggregatedOperat

mod counter_queue;
mod sparse_queue;
mod withdrawals_counter_queue;

pub type RawTxData = Vec<u8>;

Expand Down Expand Up @@ -190,37 +189,37 @@ mod tests {
use super::*;
use zksync_types::{block::Block, Action};

fn get_tx_data(
operation_type: OperationType,
block_number: BlockNumber,
raw: RawTxData,
) -> TxData {
let block = Block::new_from_available_block_sizes(
block_number,
Default::default(),
0,
vec![],
(0, 0),
&[0],
1_000_000.into(),
1_500_000.into(),
);

let action = match operation_type {
OperationType::Commit => Action::Commit,
_ => Action::Verify {
proof: Default::default(),
},
};

let operation = Operation {
id: None,
action,
block,
};

TxData::from_operation(operation_type, operation, raw)
}
// fn get_tx_data(
// operation_type: OperationType,
// block_number: BlockNumber,
// raw: RawTxData,
// ) -> TxData {
// let block = Block::new_from_available_block_sizes(
// block_number,
// Default::default(),
// 0,
// vec![],
// (0, 0),
// &[0],
// 1_000_000.into(),
// 1_500_000.into(),
// );

// let action = match operation_type {
// OperationType::Commit => Action::Commit,
// _ => Action::Verify {
// proof: Default::default(),
// },
// };

// let operation = Operation {
// id: None,
// action,
// block,
// };

// TxData::from_operation(operation_type, operation, raw)
// }

/// Checks the basic workflow of the queue including adding several operations
/// and retrieving them later.
Expand Down
Loading

0 comments on commit 7935aeb

Please sign in to comment.