Skip to content

Commit

Permalink
Fix clippy (#2298)
Browse files Browse the repository at this point in the history
* Do not process the same tx twice

Signed-off-by: Danil Lugovskoi <[email protected]>

* Fix clippy

Signed-off-by: Danil Lugovskoi <[email protected]>

* Update rust

Signed-off-by: Danil Lugovskoi <[email protected]>

Signed-off-by: Danil Lugovskoi <[email protected]>
  • Loading branch information
Deniallugo authored Sep 15, 2022
1 parent ef1852b commit 5bbb939
Show file tree
Hide file tree
Showing 42 changed files with 104 additions and 55 deletions.
2 changes: 1 addition & 1 deletion core/bin/block_revert/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ async fn main() -> anyhow::Result<()> {
let key_without_prefix = opt
.operator_private_key
.strip_prefix("0x")
.unwrap_or_else(|| opt.operator_private_key.as_str());
.unwrap_or(opt.operator_private_key.as_str());

let contracts = ContractsConfig::from_env();
let eth_client_config = ETHClientConfig::from_env();
Expand Down
1 change: 1 addition & 0 deletions core/bin/data_restore/src/inmemory_storage_interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl InMemoryStorageInteractor {
_withdrawals: &[WithdrawalEvent],
_pending_withdrawals: &[WithdrawalPendingEvent],
) {
// We don't use it for testing right now
}

pub(crate) fn load_committed_events_state(&self) -> Vec<BlockEvent> {
Expand Down
4 changes: 2 additions & 2 deletions core/bin/prover/src/plonk_step_by_step_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ impl PlonkStepByStepProver {
self.precomputed_sample_proofs
.single_proofs
.iter()
.cloned()
.take(proofs_to_pad),
.take(proofs_to_pad)
.cloned(),
)
.collect();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ impl OperationNotifier {
let updated_accounts: Vec<AccountId> = block
.block_transactions
.iter()
.map(|exec_op| exec_op.get_updated_account_ids())
.flatten()
.flat_map(|exec_op| exec_op.get_updated_account_ids())
.collect();

for id in updated_accounts {
Expand Down
4 changes: 2 additions & 2 deletions core/bin/zksync_api/src/api_server/rest/v01/api_decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ impl ApiV01 {
eth_tx_hash: H256,
) -> Result<Option<PriorityOp>, anyhow::Error> {
let mut storage = self.connection_pool.access_storage().await?;
Ok(storage
storage
.chain()
.mempool_schema()
.get_pending_operation_by_hash(eth_tx_hash)
.await?)
.await
}
}
1 change: 1 addition & 0 deletions core/bin/zksync_api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![recursion_limit = "256"]
#![allow(clippy::derive_partial_eq_without_eq, clippy::needless_question_mark)]

pub mod api_server;
pub mod eth_checker;
Expand Down
4 changes: 2 additions & 2 deletions core/bin/zksync_core/src/committer/aggregated_committer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ fn create_new_commit_operation(
) -> Option<BlocksCommitOperation> {
let new_blocks = new_blocks
.iter()
.cloned()
.take(max_blocks_to_commit)
.cloned()
.collect::<Vec<_>>();
let any_block_commit_deadline_triggered = {
let block_commit_deadline_seconds = block_commit_deadline.as_secs() as i64;
Expand Down Expand Up @@ -157,8 +157,8 @@ fn create_execute_blocks_operation(
) -> Option<BlocksExecuteOperation> {
let proven_non_executed_block = proven_non_executed_block
.iter()
.cloned()
.take(max_blocks_to_execute)
.cloned()
.collect::<Vec<_>>();
let any_block_execute_deadline_triggered = {
let block_execute_deadline_seconds = block_execute_deadline.as_secs() as i64;
Expand Down
1 change: 1 addition & 0 deletions core/bin/zksync_eth_sender/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! occurring in `ZKSync` with the Ethereum blockchain by creating
//! transactions from the operations, sending them and ensuring that
//! every transaction is executed successfully and confirmed.
#![allow(clippy::derive_partial_eq_without_eq)]

// Built-in deps
use std::collections::VecDeque;
Expand Down
10 changes: 5 additions & 5 deletions core/bin/zksync_eth_sender/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ async fn operation_commitment_workflow() {
.ethereum
.get_mock()
.unwrap()
.assert_sent(&expected_tx.used_tx_hashes[0].as_bytes().to_vec())
.assert_sent(expected_tx.used_tx_hashes[0].as_bytes())
.await;

// Increment block, make the transaction look successfully executed, and process the
Expand Down Expand Up @@ -391,7 +391,7 @@ async fn stuck_transaction() {
.ethereum
.get_mut_mock()
.unwrap()
.assert_sent(&expected_sent_tx.hash.as_bytes().to_vec())
.assert_sent(expected_sent_tx.hash.as_bytes())
.await;

// Increment block, make the transaction look successfully executed, and process the
Expand Down Expand Up @@ -525,7 +525,7 @@ async fn operations_order() {
.ethereum
.get_mock()
.unwrap()
.assert_sent(&current_tx_hash.as_bytes().to_vec())
.assert_sent(current_tx_hash.as_bytes())
.await;

// Mark the tx as successfully
Expand Down Expand Up @@ -802,7 +802,7 @@ async fn confirmations_independence() {
.ethereum
.get_mut_mock()
.unwrap()
.assert_sent(&next_tx.hash.as_bytes().to_vec())
.assert_sent(next_tx.hash.as_bytes())
.await;

// Add a confirmation for a *stuck* transaction.
Expand Down Expand Up @@ -946,7 +946,7 @@ async fn concurrent_operations_order() {
.ethereum
.get_mock()
.unwrap()
.assert_sent(&current_tx_hash.as_bytes().to_vec())
.assert_sent(current_tx_hash.as_bytes())
.await;

// Mark the tx as successfully
Expand Down
1 change: 1 addition & 0 deletions core/bin/zksync_event_listener/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl Handler<RemoveSubscriber> for ServerMonitor {
impl Handler<NewEvents> for ServerMonitor {
type Result = ();

#[allow(clippy::unnecessary_to_owned)]
fn handle(&mut self, msg: NewEvents, ctx: &mut Self::Context) {
if msg.0.as_ref().is_empty() {
vlog::info!("Server monitor received empty array of events");
Expand Down
1 change: 1 addition & 0 deletions core/lib/api_client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#![allow(clippy::derive_partial_eq_without_eq)]
pub mod rest;
1 change: 1 addition & 0 deletions core/lib/api_types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::derive_partial_eq_without_eq)]
pub use either::Either;
use serde::{Deserialize, Serialize};
use zksync_types::{
Expand Down
5 changes: 5 additions & 0 deletions core/lib/circuit/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#![allow(
clippy::map_flatten,
clippy::unnecessary_to_owned,
clippy::derive_partial_eq_without_eq
)]
pub mod account;
pub mod allocated_structures;
pub mod circuit;
Expand Down
1 change: 1 addition & 0 deletions core/lib/config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::derive_partial_eq_without_eq)]
pub use crate::configs::{
ApiConfig, ChainConfig, ContractsConfig, DBConfig, DevLiquidityTokenWatcherConfig,
ETHClientConfig, ETHSenderConfig, ETHWatchConfig, EventListenerConfig,
Expand Down
1 change: 1 addition & 0 deletions core/lib/crypto/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::derive_partial_eq_without_eq)]
//! `zksync_crypto` is a crate containing essential zkSync cryptographic primitives, such as private keys and hashers.
use crate::franklin_crypto::{
Expand Down
2 changes: 1 addition & 1 deletion core/lib/eth_client/src/clients/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ impl<S: EthereumSigner> ETHDirectClient<S> {
};
#[cfg(feature = "with-metrics")]
metrics::histogram!("eth_client.direct.get_tx_status", start.elapsed());
Ok(res?)
res
}

pub async fn logs(&self, filter: Filter) -> anyhow::Result<Vec<Log>> {
Expand Down
1 change: 1 addition & 0 deletions core/lib/eth_client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::derive_partial_eq_without_eq)]
pub mod clients;
pub mod ethereum_gateway;
pub use clients::http_client::ETHDirectClient;
Expand Down
2 changes: 2 additions & 0 deletions core/lib/eth_signer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::derive_partial_eq_without_eq)]

#[macro_use]
extern crate serde_derive;

Expand Down
1 change: 1 addition & 0 deletions core/lib/state/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::derive_partial_eq_without_eq)]
pub mod handler;
pub mod state;

Expand Down
36 changes: 36 additions & 0 deletions core/lib/storage/sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -2393,6 +2393,24 @@
},
"query": "INSERT INTO committed_nonce (account_id, nonce, block_number) VALUES ($1, $2, $3) \n ON CONFLICT (account_id) \n DO UPDATE \n SET nonce = $2, block_number = $3\n "
},
"3c7addfbdf988190fe3d6c4fe01569599e4fe7e55ed24f83e9309cbbcb0ba46c": {
"describe": {
"columns": [
{
"name": "count",
"ordinal": 0,
"type_info": "Int8"
}
],
"nullable": [
null
],
"parameters": {
"Left": []
}
},
"query": "SELECT COUNT(*) FROM withdrawals WHERE withdrawal_tx_hash IS NULL"
},
"3e63555f8c8d341b2536bec02e1c60755888686fab50cad8dde060c3aca96f9b": {
"describe": {
"columns": [
Expand Down Expand Up @@ -2682,6 +2700,24 @@
},
"query": "\n DELETE FROM pending_block WHERE number = $1\n "
},
"45835bd8baba982b410df9a81970dfb547dd9660f6a768a1eb588ce1ee33f36f": {
"describe": {
"columns": [
{
"name": "max",
"ordinal": 0,
"type_info": "Int8"
}
],
"nullable": [
null
],
"parameters": {
"Left": []
}
},
"query": "SELECT MAX(withdrawal_tx_block) FROM withdrawals"
},
"45dc23ee9e4fd0bf52e2a82f3ed83210ec3a49c01b70a82bd6fac566da1a0f3b": {
"describe": {
"columns": [
Expand Down
1 change: 1 addition & 0 deletions core/lib/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
// `sqlx` macros result in these warning being triggered.
#![allow(clippy::toplevel_ref_arg, clippy::suspicious_else_formatting)]
#![allow(clippy::derive_partial_eq_without_eq, clippy::map_flatten)]

// Built-in deps
use std::env;
Expand Down
4 changes: 2 additions & 2 deletions core/lib/token_db_cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ impl TokenDBCache {
token: TokenId,
market: TokenMarketVolume,
) -> anyhow::Result<()> {
Ok(storage
storage
.tokens_schema()
.update_token_market_volume(token, market)
.await?)
.await
}
}
2 changes: 1 addition & 1 deletion core/lib/types/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl ExecutedOperations {
/// Unlike public data, some operations may not have a witness.
pub fn get_eth_witness_bytes(&self) -> Option<Vec<u8>> {
self.get_executed_op()
.map(|op| op.eth_witness().unwrap_or_else(Vec::new))
.map(|op| op.eth_witness().unwrap_or_default())
}

/// Returns the list of accounts affected by the operation.
Expand Down
1 change: 1 addition & 0 deletions core/lib/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
//!
//! [`Block`]: ./block/struct.Block.html
//! [`Account`]: ./account/struct.Account.html
#![allow(clippy::derive_partial_eq_without_eq)]

pub mod account;
pub mod aggregated_operations;
Expand Down
2 changes: 1 addition & 1 deletion core/lib/types/src/tx/primitives/packed_public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl PackedPublicKey {
return Err(DeserializeError::IncorrectPublicKeyLength);
}
Ok(PackedPublicKey(PublicKey::<Engine>(
edwards::Point::read(&*bytes, &JUBJUB_PARAMS as &AltJubjubBn256)
edwards::Point::read(bytes, &JUBJUB_PARAMS as &AltJubjubBn256)
.map_err(DeserializeError::RestoreCurvePoint)?,
)))
}
Expand Down
2 changes: 1 addition & 1 deletion core/lib/types/src/withdrawals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub struct WithdrawalEvent {
}

#[derive(Debug, Error)]
#[clippy::allow(large-enum-variant)]
#[allow(clippy::large_enum_variant)]
pub enum WithdrawalPendingParseError {
#[error("Cannot parse log for Withdrawal Pending Event {0:?}")]
ParseError(Log),
Expand Down
2 changes: 1 addition & 1 deletion core/lib/utils/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mod tests {
#[tokio::test]
async fn retries_given_fut() {
let mut counter = 0;
let _ = retry_opt! {
retry_opt! {
CondRespond {
respond: counter == 10
}.await,
Expand Down
2 changes: 1 addition & 1 deletion core/tests/loadnext/src/account/tx_command_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl AccountLifespan {
.amount
.clone()
.try_into()
.unwrap_or_else(|_| u128::max_value())
.unwrap_or(u128::MAX)
.into();
let eth_tx_hash = match ethereum
.deposit(self.main_token.id, amount, self.wallet.address())
Expand Down
6 changes: 3 additions & 3 deletions core/tests/loadnext/src/command/tx_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{

/// Type of transaction. It doesn't copy the zkSync operation list, because
/// it divides some transactions in subcategories (e.g. to new account / to existing account; to self / to other; etc)/
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum TxType {
Deposit,
TransferToNew,
Expand Down Expand Up @@ -92,7 +92,7 @@ impl TxType {
/// Modifier to be applied to the transaction in order to make it incorrect.
/// Incorrect transactions are a significant part of loadtest, because we want to ensure
/// that server is resilient for all the possible kinds of user input.
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum IncorrectnessModifier {
ZeroFee,
IncorrectZkSyncSignature,
Expand Down Expand Up @@ -163,7 +163,7 @@ impl IncorrectnessModifier {
/// Expected outcome of transaction:
/// Since we may create erroneous transactions on purpose,
/// we may expect different outcomes for each transaction.
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum ExpectedOutcome {
/// Transactions was successfully executed.
TxSucceed,
Expand Down
1 change: 1 addition & 0 deletions core/tests/loadnext/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::derive_partial_eq_without_eq)]
pub mod account;
pub mod account_pool;
pub mod all;
Expand Down
1 change: 0 additions & 1 deletion core/tests/loadnext/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! In order to launch it, you must provide required environmental variables, for details see `README.md`.
//! Without required variables provided, test is launched in the localhost/development mode with some hard-coded
//! values to check the local zkSync deployment.
use loadnext::{config::LoadtestConfig, executor::Executor, report_collector::LoadtestResult};

#[tokio::main]
Expand Down
Loading

0 comments on commit 5bbb939

Please sign in to comment.