Skip to content

Commit

Permalink
First round of clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless committed Dec 7, 2021
1 parent 54a4088 commit 7f70cca
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 128 deletions.
4 changes: 1 addition & 3 deletions core/bin/prover/src/dummy_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ impl ProverConfig for DummyProverConfig {

#[derive(Debug)]
pub struct DummyProver {
config: DummyProverConfig,
precomputed_proofs: PrecomputedSampleProofs,
}

impl ProverImpl for DummyProver {
type Config = DummyProverConfig;

fn create_from_config(config: Self::Config) -> Self {
fn create_from_config(_config: Self::Config) -> Self {
Self {
config,
precomputed_proofs: load_precomputed_proofs()
.expect("Failed to load precomputed proofs"),
}
Expand Down
2 changes: 1 addition & 1 deletion core/bin/prover/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn test_data_for_prover() -> JobRequestData {
account_id: empty_account_id,
};

let deposit_witness = DepositWitness::apply_tx(&mut witness_accum.account_tree, &deposit_op);
let deposit_witness = DepositWitness::apply_tx(witness_accum.account_tree, &deposit_op);
let deposit_operations = deposit_witness.calculate_operations(());
let pub_data_from_witness = deposit_witness.get_pubdata();
let offset_commitment = deposit_witness.get_offset_commitment_data();
Expand Down
12 changes: 6 additions & 6 deletions core/bin/zksync_api/src/api_server/rest/v02/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ impl TestServerConfig {
if *block_number <= VERIFIED_BLOCKS_COUNT {
// Add jobs to `job_prover_queue`.
let job_data = serde_json::Value::default();
ProverSchema(&mut storage)
ProverSchema(storage)
.add_prover_job_to_job_queue(
block_number,
block_number,
Expand All @@ -512,7 +512,7 @@ impl TestServerConfig {
ProverJobType::SingleProof,
)
.await?;
ProverSchema(&mut storage)
ProverSchema(storage)
.add_prover_job_to_job_queue(
block_number,
block_number,
Expand All @@ -523,12 +523,12 @@ impl TestServerConfig {
.await?;

// Get job id.
let stored_job_id = ProverSchema(&mut storage)
let stored_job_id = ProverSchema(storage)
.get_idle_prover_job_from_job_queue()
.await?
.unwrap()
.job_id;
let stored_aggregated_job_id = ProverSchema(&mut storage)
let stored_aggregated_job_id = ProverSchema(storage)
.get_idle_prover_job_from_job_queue()
.await?
.unwrap()
Expand All @@ -537,10 +537,10 @@ impl TestServerConfig {
// Store proofs.
let proof = get_sample_single_proof();
let aggregated_proof = get_sample_aggregated_proof();
ProverSchema(&mut storage)
ProverSchema(storage)
.store_proof(stored_job_id, block_number, &proof)
.await?;
ProverSchema(&mut storage)
ProverSchema(storage)
.store_aggregated_proof(
stored_aggregated_job_id,
block_number,
Expand Down
7 changes: 0 additions & 7 deletions core/bin/zksync_api/src/api_server/rpc_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ use super::tx_sender::TxSender;

#[derive(Clone)]
pub struct RpcApp {
runtime_handle: tokio::runtime::Handle,

cache_of_executed_priority_operations: AsyncLruCache<u32, StoredExecutedPriorityOperation>,
cache_of_transaction_receipts: AsyncLruCache<Vec<u8>, TxReceiptResponse>,
cache_of_complete_withdrawal_tx_hashes: AsyncLruCache<TxHash, String>,
Expand All @@ -61,9 +59,6 @@ impl RpcApp {
private_url: String,
confirmations_for_eth_event: u64,
) -> Self {
let runtime_handle = tokio::runtime::Handle::try_current()
.expect("RpcApp must be created from the context of Tokio Runtime");

let api_requests_caches_size = config.caches_size;

let tx_sender = TxSender::new(
Expand All @@ -75,8 +70,6 @@ impl RpcApp {
);

RpcApp {
runtime_handle,

cache_of_executed_priority_operations: AsyncLruCache::new(api_requests_caches_size),
cache_of_transaction_receipts: AsyncLruCache::new(api_requests_caches_size),
cache_of_complete_withdrawal_tx_hashes: AsyncLruCache::new(api_requests_caches_size),
Expand Down
4 changes: 0 additions & 4 deletions core/bin/zksync_api/src/api_server/web3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub const NFT_FACTORY_ADDRESS: &str = "2000000000000000000000000000000000000000"

#[derive(Clone)]
pub struct Web3RpcApp {
runtime_handle: tokio::runtime::Handle,
connection_pool: ConnectionPool,
logs_helper: LogsHelper,
calls_helper: CallsHelper,
Expand All @@ -37,10 +36,7 @@ pub struct Web3RpcApp {

impl Web3RpcApp {
pub fn new(connection_pool: ConnectionPool, config: &Web3Config) -> Self {
let runtime_handle = tokio::runtime::Handle::try_current()
.expect("Web3RpcApp must be created from the context of Tokio Runtime");
Web3RpcApp {
runtime_handle,
connection_pool,
logs_helper: LogsHelper::new(),
calls_helper: CallsHelper::new(),
Expand Down
16 changes: 6 additions & 10 deletions core/bin/zksync_api/src/fee_ticker/ticker_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,11 @@ pub trait FeeTickerAPI {
#[derive(Debug, Clone)]
pub(crate) struct TokenCacheEntry {
price: TokenPrice,
creation_time: Instant,
}

impl TokenCacheEntry {
fn new(price: TokenPrice, creation_time: Instant) -> Self {
Self {
price,
creation_time,
}
fn new(price: TokenPrice) -> Self {
Self { price }
}

fn is_cache_entry_expired(&self) -> bool {
Expand Down Expand Up @@ -135,10 +131,10 @@ impl<T: TokenPriceAPI> TickerApi<T> {
}

async fn update_stored_value(&self, token_id: TokenId, price: TokenPrice) {
self.price_cache.lock().await.insert(
token_id,
TokenCacheEntry::new(price.clone(), Instant::now()),
);
self.price_cache
.lock()
.await
.insert(token_id, TokenCacheEntry::new(price.clone()));
self._update_stored_value(token_id, price)
.await
.map_err(|e| vlog::warn!("Failed to update historical ticker price: {}", e))
Expand Down
24 changes: 12 additions & 12 deletions core/lib/circuit/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> {
fn execute_op<CS: ConstraintSystem<E>>(
&self,
mut cs: CS,
mut cur: &mut AllocatedOperationBranch<E>,
cur: &mut AllocatedOperationBranch<E>,
lhs: &AllocatedOperationBranch<E>,
rhs: &AllocatedOperationBranch<E>,
op: &Operation<E>,
Expand Down Expand Up @@ -1026,7 +1026,7 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> {
let op_flags = vec![
self.deposit(
cs.namespace(|| "deposit"),
&mut cur,
cur,
global_variables,
is_account_empty,
&op_data,
Expand All @@ -1035,7 +1035,7 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> {
)?,
self.transfer(
cs.namespace(|| "transfer"),
&mut cur,
cur,
lhs,
rhs,
global_variables,
Expand All @@ -1053,7 +1053,7 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> {
)?,
self.transfer_to_new(
cs.namespace(|| "transfer_to_new"),
&mut cur,
cur,
lhs,
rhs,
global_variables,
Expand All @@ -1071,7 +1071,7 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> {
)?,
self.withdraw(
cs.namespace(|| "withdraw"),
&mut cur,
cur,
global_variables,
&is_a_geq_b,
&op_data,
Expand All @@ -1087,7 +1087,7 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> {
// Close disable.
// self.close_account(
// cs.namespace(|| "close_account"),
// &mut cur,
// cur,
// &chunk_data,
// &ext_pubdata_chunk,
// &op_data,
Expand All @@ -1098,7 +1098,7 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> {
// )?,
self.full_exit(
cs.namespace(|| "full_exit"),
&mut cur,
cur,
global_variables,
&op_data,
ext_pubdata_chunk,
Expand All @@ -1111,7 +1111,7 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> {
self.change_pubkey_offchain(
cs.namespace(|| "change_pubkey_offchain"),
lhs,
&mut cur,
cur,
global_variables,
&op_data,
ext_pubdata_chunk,
Expand All @@ -1133,7 +1133,7 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> {
)?,
self.forced_exit(
cs.namespace(|| "forced_exit"),
&mut cur,
cur,
lhs,
rhs,
global_variables,
Expand All @@ -1151,7 +1151,7 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> {
)?,
self.mint_nft(
cs.namespace(|| "mint_nft"),
&mut cur,
cur,
global_variables,
&is_a_geq_b,
is_account_empty,
Expand All @@ -1166,7 +1166,7 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> {
)?,
self.withdraw_nft(
cs.namespace(|| "withdraw_nft"),
&mut cur,
cur,
global_variables,
&is_a_geq_b,
&op_data,
Expand All @@ -1181,7 +1181,7 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> {
)?,
self.swap(
cs.namespace(|| "swap"),
&mut cur,
cur,
global_variables,
&is_a_geq_b,
is_account_empty,
Expand Down
8 changes: 3 additions & 5 deletions core/lib/circuit/src/playground/plonk_playground.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn test_transpile_deposit_franklin_existing_account() {

plasma_state.apply_deposit_op(&deposit_op);

let deposit_witness = DepositWitness::apply_tx(&mut witness_accum.account_tree, &deposit_op);
let deposit_witness = DepositWitness::apply_tx(witness_accum.account_tree, &deposit_op);
let deposit_operations = deposit_witness.calculate_operations(());
let pub_data_from_witness = deposit_witness.get_pubdata();

Expand Down Expand Up @@ -225,8 +225,7 @@ fn test_new_transpile_deposit_franklin_existing_account() {

for _ in 0..NUM_DEPOSITS {
plasma_state.apply_deposit_op(&deposit_op);
let deposit_witness =
DepositWitness::apply_tx(&mut witness_accum.account_tree, &deposit_op);
let deposit_witness = DepositWitness::apply_tx(witness_accum.account_tree, &deposit_op);
let deposit_operations = deposit_witness.calculate_operations(());
let pub_data_from_witness = deposit_witness.get_pubdata();

Expand Down Expand Up @@ -400,8 +399,7 @@ fn test_fma_transpile_deposit_franklin_existing_account() {

for _ in 0..NUM_DEPOSITS {
plasma_state.apply_deposit_op(&deposit_op);
let deposit_witness =
DepositWitness::apply_tx(&mut witness_accum.account_tree, &deposit_op);
let deposit_witness = DepositWitness::apply_tx(witness_accum.account_tree, &deposit_op);
let deposit_operations = deposit_witness.calculate_operations(());
let pub_data_from_witness = deposit_witness.get_pubdata();

Expand Down
4 changes: 2 additions & 2 deletions core/lib/circuit/src/witness/tests/full_exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn apply_nft_mint_and_full_exit_nft_operations() -> ZkSyncCircuit<'static, Bn256
.unwrap();
fees.push(fee);

let witness = MintNFTWitness::apply_tx(&mut witness_accum.account_tree, &mint_nft_op);
let witness = MintNFTWitness::apply_tx(witness_accum.account_tree, &mint_nft_op);
let circuit_operations = witness.calculate_operations(mint_nft_input);
let pub_data_from_witness = witness.get_pubdata();
let offset_commitment = witness.get_offset_commitment_data();
Expand All @@ -142,7 +142,7 @@ fn apply_nft_mint_and_full_exit_nft_operations() -> ZkSyncCircuit<'static, Bn256
.expect("Operation failed");

let witness = FullExitWitness::apply_tx(
&mut witness_accum.account_tree,
witness_accum.account_tree,
&(full_exit_op, full_exit_sucess),
);
let circuit_operations = witness.calculate_operations(());
Expand Down
15 changes: 7 additions & 8 deletions core/lib/circuit/src/witness/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ fn apply_many_ops() -> ZkSyncCircuit<'static, Bn256> {
<ZkSyncState as TxHandler<Deposit>>::apply_op(&mut plasma_state, &deposit_op)
.expect("Deposit failed");

let witness = DepositWitness::apply_tx(&mut witness_accum.account_tree, &deposit_op);
let witness = DepositWitness::apply_tx(witness_accum.account_tree, &deposit_op);
let circuit_operations = witness.calculate_operations(());
let pub_data_from_witness = witness.get_pubdata();
let offset_commitment = witness.get_offset_commitment_data();
Expand All @@ -253,7 +253,7 @@ fn apply_many_ops() -> ZkSyncCircuit<'static, Bn256> {
.unwrap();
fees.push(fee);

let witness = TransferWitness::apply_tx(&mut witness_accum.account_tree, &transfer_op);
let witness = TransferWitness::apply_tx(witness_accum.account_tree, &transfer_op);
let circuit_operations = witness.calculate_operations(transfer_input);
let pub_data_from_witness = witness.get_pubdata();
let offset_commitment = witness.get_offset_commitment_data();
Expand All @@ -272,8 +272,7 @@ fn apply_many_ops() -> ZkSyncCircuit<'static, Bn256> {
.unwrap();
fees.push(fee);

let witness =
TransferToNewWitness::apply_tx(&mut witness_accum.account_tree, &transfer_to_new_op);
let witness = TransferToNewWitness::apply_tx(witness_accum.account_tree, &transfer_to_new_op);
let circuit_operations = witness.calculate_operations(transfer_to_new_input);
let pub_data_from_witness = witness.get_pubdata();
let offset_commitment = witness.get_offset_commitment_data();
Expand All @@ -291,7 +290,7 @@ fn apply_many_ops() -> ZkSyncCircuit<'static, Bn256> {
.unwrap();
fees.push(fee);

let witness = WithdrawWitness::apply_tx(&mut witness_accum.account_tree, &withdraw_op);
let witness = WithdrawWitness::apply_tx(witness_accum.account_tree, &withdraw_op);
let circuit_operations = witness.calculate_operations(withdraw_input);
let pub_data_from_witness = witness.get_pubdata();
let offset_commitment = witness.get_offset_commitment_data();
Expand All @@ -308,7 +307,7 @@ fn apply_many_ops() -> ZkSyncCircuit<'static, Bn256> {
.expect("Operation failed");

let witness = FullExitWitness::apply_tx(
&mut witness_accum.account_tree,
witness_accum.account_tree,
&(full_exit_op, full_exit_success),
);
let circuit_operations = witness.calculate_operations(());
Expand All @@ -328,7 +327,7 @@ fn apply_many_ops() -> ZkSyncCircuit<'static, Bn256> {
.unwrap();
fees.push(fee);

let witness = MintNFTWitness::apply_tx(&mut witness_accum.account_tree, &mint_nft_op);
let witness = MintNFTWitness::apply_tx(witness_accum.account_tree, &mint_nft_op);
let circuit_operations = witness.calculate_operations(mint_nft_input);
let pub_data_from_witness = witness.get_pubdata();
let offset_commitment = witness.get_offset_commitment_data();
Expand All @@ -347,7 +346,7 @@ fn apply_many_ops() -> ZkSyncCircuit<'static, Bn256> {
.unwrap();
fees.push(fee);

let witness = WithdrawNFTWitness::apply_tx(&mut witness_accum.account_tree, &withdraw_nft_op);
let witness = WithdrawNFTWitness::apply_tx(witness_accum.account_tree, &withdraw_nft_op);
let circuit_operations = witness.calculate_operations(withdraw_nft_input);
let pub_data_from_witness = witness.get_pubdata();
let offset_commitment = witness.get_offset_commitment_data();
Expand Down
6 changes: 3 additions & 3 deletions core/lib/circuit/src/witness/tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub fn generic_test_scenario<W, F>(
plasma_state.collect_fee(&fees, FEE_ACCOUNT_ID);

// Apply op on circuit
let witness = W::apply_tx(&mut witness_accum.account_tree, &op);
let witness = W::apply_tx(witness_accum.account_tree, &op);
let circuit_operations = witness.calculate_operations(input);
let pub_data_from_witness = witness.get_pubdata();
let offset_commitment = witness.get_offset_commitment_data();
Expand Down Expand Up @@ -225,7 +225,7 @@ pub fn corrupted_input_test_scenario<W, F, B>(
plasma_state.collect_fee(&fees, FEE_ACCOUNT_ID);

// Apply op on circuit
let witness = W::apply_tx(&mut witness_accum.account_tree, &op);
let witness = W::apply_tx(witness_accum.account_tree, &op);
let circuit_operations = witness.calculate_operations(input.clone());
let pub_data_from_witness = witness.get_pubdata();
let offset_commitment = witness.get_offset_commitment_data();
Expand Down Expand Up @@ -292,7 +292,7 @@ pub fn incorrect_op_test_scenario<W, F, B>(
let fees = collect_fees();

// Apply op on circuit
let witness = W::apply_tx(&mut witness_accum.account_tree, &op);
let witness = W::apply_tx(witness_accum.account_tree, &op);
let circuit_operations = witness.calculate_operations(input.clone());
let pub_data_from_witness = witness.get_pubdata();
let offset_commitment = witness.get_offset_commitment_data();
Expand Down
Loading

0 comments on commit 7f70cca

Please sign in to comment.