From 1e692e1de22d189b28b277b061ba0ffeec8b1b9a Mon Sep 17 00:00:00 2001 From: Pavel Strakhov Date: Tue, 12 Nov 2024 10:34:22 +0000 Subject: [PATCH] Deny clippy warnings in CI properly (#2109) * refactor(governance): fix clippy warnings * refactor(target_chains/cosmwasm): fix clippy warnings * refactor(apps/hermes): fix clippy warnings * refactor(apps/fortuna): fix clippy warnings * refactor(pythnet): fix clippy warnings * refactor(target_chains/solana): fix clippy warnings --- .pre-commit-config.yaml | 14 +++++++------- apps/fortuna/src/api/revelation.rs | 4 ---- apps/fortuna/src/chain/ethereum.rs | 2 +- apps/fortuna/src/chain/reader.rs | 12 ++++++------ apps/fortuna/src/command/run.rs | 2 +- apps/fortuna/src/keeper.rs | 10 +++++++--- apps/fortuna/src/state.rs | 3 +++ apps/hermes/server/src/network/wormhole.rs | 1 + .../src/tests/executor_simulator.rs | 2 +- .../remote-executor/src/tests/test_adversarial.rs | 12 ++++++------ .../src/tests/test_basic_instructions.rs | 8 +++----- .../programs/message_buffer/src/lib.rs | 3 +++ .../programs/mock-cpi-caller/src/lib.rs | 3 +++ .../programs/mock-cpi-caller/src/state/mod.rs | 5 ----- .../cosmwasm/contracts/pyth/src/contract.rs | 6 +++--- target_chains/cosmwasm/sdk/rust/src/testing.rs | 2 +- .../solana/programs/pyth-push-oracle/src/lib.rs | 3 +++ .../programs/pyth-solana-receiver/src/lib.rs | 4 ++++ .../programs/pyth-solana-receiver/src/sdk.rs | 1 + .../pyth_solana_receiver_sdk/src/cpi/accounts.rs | 2 ++ .../solana/pyth_solana_receiver_sdk/src/lib.rs | 3 +++ 21 files changed, 59 insertions(+), 43 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2b45f1ac78..cc41f00476 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -45,7 +45,7 @@ repos: - id: cargo-clippy-remote-executor name: Cargo clippy for remote executor language: "rust" - entry: cargo +1.66.1 clippy --manifest-path ./governance/remote_executor/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings + entry: cargo +1.66.1 clippy --manifest-path ./governance/remote_executor/Cargo.toml --tests -- --deny warnings pass_filenames: false files: governance/remote_executor # Hooks for cosmwasm contract @@ -58,7 +58,7 @@ repos: - id: cargo-clippy-cosmwasm name: Cargo clippy for cosmwasm contract language: "rust" - entry: cargo +1.82.0 clippy --manifest-path ./target_chains/cosmwasm/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings + entry: cargo +1.82.0 clippy --manifest-path ./target_chains/cosmwasm/Cargo.toml --tests -- --deny warnings pass_filenames: false files: target_chains/cosmwasm # Hooks for Hermes @@ -71,7 +71,7 @@ repos: - id: cargo-clippy-hermes name: Cargo clippy for Hermes language: "rust" - entry: cargo +1.82.0 clippy --manifest-path ./apps/hermes/server/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings + entry: cargo +1.82.0 clippy --manifest-path ./apps/hermes/server/Cargo.toml --tests -- --deny warnings pass_filenames: false files: apps/hermes # Hooks for Fortuna @@ -84,7 +84,7 @@ repos: - id: cargo-clippy-fortuna name: Cargo clippy for Fortuna language: "rust" - entry: cargo +1.82.0 clippy --manifest-path ./apps/fortuna/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings + entry: cargo +1.82.0 clippy --manifest-path ./apps/fortuna/Cargo.toml --tests -- --deny warnings pass_filenames: false files: apps/fortuna # Hooks for message buffer contract @@ -97,7 +97,7 @@ repos: - id: cargo-clippy-message-buffer name: Cargo clippy for message buffer contract language: "rust" - entry: cargo +1.66.1 clippy --manifest-path ./pythnet/message_buffer/Cargo.toml --tests --fix --allow-dirty --allow-staged --features test-bpf -- -D warnings + entry: cargo +1.66.1 clippy --manifest-path ./pythnet/message_buffer/Cargo.toml --tests -- --deny warnings pass_filenames: false files: pythnet/message_buffer # Hooks for pythnet_sdk @@ -110,7 +110,7 @@ repos: - id: cargo-clippy-pythnet-sdk name: Cargo clippy for pythnet SDK language: "rust" - entry: cargo +1.82.0 clippy --manifest-path ./pythnet/pythnet_sdk/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings + entry: cargo +1.82.0 clippy --manifest-path ./pythnet/pythnet_sdk/Cargo.toml --tests -- --deny warnings pass_filenames: false files: pythnet/pythnet_sdk # Hooks for solana receiver contract @@ -123,7 +123,7 @@ repos: - id: cargo-clippy-pyth-solana-receiver name: Cargo clippy for solana target chain contract language: "rust" - entry: cargo +1.73.0 clippy --manifest-path ./target_chains/solana/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings + entry: cargo +1.73.0 clippy --manifest-path ./target_chains/solana/Cargo.toml --tests -- --deny warnings pass_filenames: false files: target_chains/solana # For express relay python files diff --git a/apps/fortuna/src/api/revelation.rs b/apps/fortuna/src/api/revelation.rs index aca52985ee..152bd99132 100644 --- a/apps/fortuna/src/api/revelation.rs +++ b/apps/fortuna/src/api/revelation.rs @@ -40,10 +40,6 @@ pub async fn revelation( }) .inc(); - let sequence: u64 = sequence - .try_into() - .map_err(|_| RestError::InvalidSequenceNumber)?; - let state = state .chains .get(&chain_id) diff --git a/apps/fortuna/src/chain/ethereum.rs b/apps/fortuna/src/chain/ethereum.rs index 481c05517b..f4f97a07df 100644 --- a/apps/fortuna/src/chain/ethereum.rs +++ b/apps/fortuna/src/chain/ethereum.rs @@ -295,7 +295,7 @@ impl EntropyReader for PythRandom> { Ok(Some(reader::Request { provider: r.provider, sequence_number: r.sequence_number, - block_number: r.block_number.try_into()?, + block_number: r.block_number, use_blockhash: r.use_blockhash, })) } else { diff --git a/apps/fortuna/src/chain/reader.rs b/apps/fortuna/src/chain/reader.rs index 89956ee3ae..fde5fd48bc 100644 --- a/apps/fortuna/src/chain/reader.rs +++ b/apps/fortuna/src/chain/reader.rs @@ -157,7 +157,7 @@ pub mod mock { async fn get_block_number( &self, - confirmed_block_status: BlockStatus, + _confirmed_block_status: BlockStatus, ) -> Result { Ok(*self.block_number.read().unwrap()) } @@ -172,11 +172,11 @@ pub mod mock { async fn estimate_reveal_with_callback_gas( &self, - sender: Address, - provider: Address, - sequence_number: u64, - user_random_number: [u8; 32], - provider_revelation: [u8; 32], + _sender: Address, + _provider: Address, + _sequence_number: u64, + _user_random_number: [u8; 32], + _provider_revelation: [u8; 32], ) -> Result { Ok(U256::from(5)) } diff --git a/apps/fortuna/src/command/run.rs b/apps/fortuna/src/command/run.rs index adaa2e6930..3130a0c108 100644 --- a/apps/fortuna/src/command/run.rs +++ b/apps/fortuna/src/command/run.rs @@ -207,7 +207,7 @@ pub async fn run(opts: &RunOptions) -> Result<()> { async fn setup_chain_state( provider: &Address, - secret: &String, + secret: &str, chain_sample_interval: u64, chain_id: &ChainId, chain_config: &EthereumConfig, diff --git a/apps/fortuna/src/keeper.rs b/apps/fortuna/src/keeper.rs index cd1583bebd..b091d94fa8 100644 --- a/apps/fortuna/src/keeper.rs +++ b/apps/fortuna/src/keeper.rs @@ -351,8 +351,10 @@ pub async fn process_event_with_backoff( }) .inc(); tracing::info!("Started processing event"); - let mut backoff = ExponentialBackoff::default(); - backoff.max_elapsed_time = Some(Duration::from_secs(300)); // retry for 5 minutes + let backoff = ExponentialBackoff { + max_elapsed_time: Some(Duration::from_secs(300)), // retry for 5 minutes + ..Default::default() + }; match backoff::future::retry_notify( backoff, || async { @@ -704,7 +706,7 @@ pub async fn watch_blocks( loop { match stream_option { Some(ref mut stream) => { - if let None = stream.next().await { + if stream.next().await.is_none() { tracing::error!("Error blocks subscription stream ended"); return Err(anyhow!("Error blocks subscription stream ended")); } @@ -984,6 +986,7 @@ pub async fn send_and_confirm(contract_call: PythContractCall) -> Result<()> { } #[tracing::instrument(name = "adjust_fee", skip_all)] +#[allow(clippy::too_many_arguments)] pub async fn adjust_fee_wrapper( contract: Arc, provider_address: Address, @@ -1082,6 +1085,7 @@ pub async fn update_commitments_if_necessary( /// /// These conditions are intended to make sure that the keeper is profitable while also minimizing the number of fee /// update transactions. +#[allow(clippy::too_many_arguments)] pub async fn adjust_fee_if_necessary( contract: Arc, provider_address: Address, diff --git a/apps/fortuna/src/state.rs b/apps/fortuna/src/state.rs index 011a2199be..5460852744 100644 --- a/apps/fortuna/src/state.rs +++ b/apps/fortuna/src/state.rs @@ -83,6 +83,7 @@ impl PebbleHashChain { Ok(val) } + #[allow(clippy::len_without_is_empty)] pub fn len(&self) -> usize { self.length } @@ -140,6 +141,8 @@ mod test { let chain = PebbleHashChain::new(secret, length, sample_interval); let mut last_val = chain.reveal_ith(0).unwrap(); + + #[allow(clippy::needless_range_loop)] for i in 1..length { let cur_val = chain.reveal_ith(i).unwrap(); println!("{}", i); diff --git a/apps/hermes/server/src/network/wormhole.rs b/apps/hermes/server/src/network/wormhole.rs index ef53f5eccc..8e08395db6 100644 --- a/apps/hermes/server/src/network/wormhole.rs +++ b/apps/hermes/server/src/network/wormhole.rs @@ -75,6 +75,7 @@ pub struct GuardianSetData { /// /// The following module structure must match the protobuf definitions, so that the generated code /// can correctly reference modules from each other. +#[allow(clippy::enum_variant_names)] mod proto { pub mod node { pub mod v1 { diff --git a/governance/remote_executor/programs/remote-executor/src/tests/executor_simulator.rs b/governance/remote_executor/programs/remote-executor/src/tests/executor_simulator.rs index 9457c47d7f..b064f12cb5 100644 --- a/governance/remote_executor/programs/remote-executor/src/tests/executor_simulator.rs +++ b/governance/remote_executor/programs/remote-executor/src/tests/executor_simulator.rs @@ -123,7 +123,7 @@ impl ExecutorBench { pub fn add_vaa_account( &mut self, emitter: &Pubkey, - instructions: &Vec, + instructions: &[Instruction], validity: VaaAttack, ) -> Pubkey { let emitter_chain: u16 = match validity { diff --git a/governance/remote_executor/programs/remote-executor/src/tests/test_adversarial.rs b/governance/remote_executor/programs/remote-executor/src/tests/test_adversarial.rs index 7e92cc9142..618f33d25c 100644 --- a/governance/remote_executor/programs/remote-executor/src/tests/test_adversarial.rs +++ b/governance/remote_executor/programs/remote-executor/src/tests/test_adversarial.rs @@ -28,7 +28,7 @@ async fn test_adversarial() { // Setup VAAs let vaa_account_valid = bench.add_vaa_account( &emitter, - &vec![transfer( + &[transfer( &executor_key, &receiver, Rent::default().minimum_balance(0), @@ -37,7 +37,7 @@ async fn test_adversarial() { ); let vaa_account_wrong_data = bench.add_vaa_account( &emitter, - &vec![transfer( + &[transfer( &executor_key, &receiver, Rent::default().minimum_balance(0), @@ -46,7 +46,7 @@ async fn test_adversarial() { ); let vaa_account_wrong_owner = bench.add_vaa_account( &emitter, - &vec![transfer( + &[transfer( &executor_key, &receiver, Rent::default().minimum_balance(0), @@ -55,7 +55,7 @@ async fn test_adversarial() { ); let vaa_account_wrong_emitter_chain = bench.add_vaa_account( &emitter, - &vec![transfer( + &[transfer( &executor_key, &receiver, Rent::default().minimum_balance(0), @@ -65,7 +65,7 @@ async fn test_adversarial() { let vaa_account_wrong_vaa_magic = bench.add_vaa_account( &emitter, - &vec![transfer( + &[transfer( &executor_key, &receiver, Rent::default().minimum_balance(0), @@ -75,7 +75,7 @@ async fn test_adversarial() { // The goal of this account is creating a claim_record that the attacker is going to try to use to impersonate // the right claim_record - let vaa_account_valid_2 = bench.add_vaa_account(&emitter_2, &vec![], VaaAttack::None); + let vaa_account_valid_2 = bench.add_vaa_account(&emitter_2, &[], VaaAttack::None); let mut sim = bench.start().await; sim.airdrop(&executor_key, LAMPORTS_PER_SOL).await.unwrap(); diff --git a/governance/remote_executor/programs/remote-executor/src/tests/test_basic_instructions.rs b/governance/remote_executor/programs/remote-executor/src/tests/test_basic_instructions.rs index bbb76b46b6..2b98b196fa 100644 --- a/governance/remote_executor/programs/remote-executor/src/tests/test_basic_instructions.rs +++ b/governance/remote_executor/programs/remote-executor/src/tests/test_basic_instructions.rs @@ -57,11 +57,9 @@ async fn test_basic_instructions() { ); let vaa_account_create = - bench.add_vaa_account(&emitter, &vec![instruction1, instruction2], VaaAttack::None); - let vaa_account_transfer1 = - bench.add_vaa_account(&emitter, &vec![instruction3], VaaAttack::None); - let vaa_account_transfer2 = - bench.add_vaa_account(&emitter, &vec![instruction4], VaaAttack::None); + bench.add_vaa_account(&emitter, &[instruction1, instruction2], VaaAttack::None); + let vaa_account_transfer1 = bench.add_vaa_account(&emitter, &[instruction3], VaaAttack::None); + let vaa_account_transfer2 = bench.add_vaa_account(&emitter, &[instruction4], VaaAttack::None); let mut sim = bench.start().await; diff --git a/pythnet/message_buffer/programs/message_buffer/src/lib.rs b/pythnet/message_buffer/programs/message_buffer/src/lib.rs index 6f40ada507..b0b1bb7b5f 100644 --- a/pythnet/message_buffer/programs/message_buffer/src/lib.rs +++ b/pythnet/message_buffer/programs/message_buffer/src/lib.rs @@ -1,3 +1,6 @@ +// We can't do much about the size of `anchor_lang::error::Error`. +#![allow(clippy::result_large_err)] + pub mod instructions; mod state; diff --git a/pythnet/message_buffer/programs/mock-cpi-caller/src/lib.rs b/pythnet/message_buffer/programs/mock-cpi-caller/src/lib.rs index c0fa10ec75..b23975aa9b 100644 --- a/pythnet/message_buffer/programs/mock-cpi-caller/src/lib.rs +++ b/pythnet/message_buffer/programs/mock-cpi-caller/src/lib.rs @@ -1,3 +1,6 @@ +// We can't do much about the size of `anchor_lang::error::Error`. +#![allow(clippy::result_large_err)] + use {anchor_lang::prelude::*, instructions::*}; pub mod instructions; diff --git a/pythnet/message_buffer/programs/mock-cpi-caller/src/state/mod.rs b/pythnet/message_buffer/programs/mock-cpi-caller/src/state/mod.rs index 334624ce74..3e2c214e8d 100644 --- a/pythnet/message_buffer/programs/mock-cpi-caller/src/state/mod.rs +++ b/pythnet/message_buffer/programs/mock-cpi-caller/src/state/mod.rs @@ -18,8 +18,3 @@ pub enum PythAccountType { Test = 4, Permissions = 5, } -impl PythAccountType { - pub(crate) fn to_u32(&self) -> u32 { - *self as u32 - } -} diff --git a/target_chains/cosmwasm/contracts/pyth/src/contract.rs b/target_chains/cosmwasm/contracts/pyth/src/contract.rs index 2b8d49ba04..cc71b035ca 100644 --- a/target_chains/cosmwasm/contracts/pyth/src/contract.rs +++ b/target_chains/cosmwasm/contracts/pyth/src/contract.rs @@ -1097,7 +1097,7 @@ mod test { assert_eq!(ema_price.expo, feed_msg.exponent); assert_eq!(ema_price.publish_time, feed_msg.publish_time); } - _ => assert!(false, "invalid message type"), + _ => panic!("invalid message type"), }; } @@ -1228,8 +1228,8 @@ mod test { let info = mock_info("123", &[]); let result = update_price_feeds(deps.as_mut(), env, info, &[msg.into()]); assert!(result.is_ok()); - for i in 100..110 { - check_price_match(&deps, all_feeds[i]); + for msg in &all_feeds[100..110] { + check_price_match(&deps, msg); } } diff --git a/target_chains/cosmwasm/sdk/rust/src/testing.rs b/target_chains/cosmwasm/sdk/rust/src/testing.rs index 47ecdb0a70..285f7d94f0 100644 --- a/target_chains/cosmwasm/sdk/rust/src/testing.rs +++ b/target_chains/cosmwasm/sdk/rust/src/testing.rs @@ -4,7 +4,7 @@ use { from_binary, to_binary, Binary, Coin, ContractResult, QuerierResult, SystemError, SystemResult, }, - std::{collections::HashMap, time::Duration, u128}, + std::{collections::HashMap, time::Duration}, }; /// Mock version of Pyth for testing cosmwasm contracts. diff --git a/target_chains/solana/programs/pyth-push-oracle/src/lib.rs b/target_chains/solana/programs/pyth-push-oracle/src/lib.rs index b3af72bf89..2553914bac 100644 --- a/target_chains/solana/programs/pyth-push-oracle/src/lib.rs +++ b/target_chains/solana/programs/pyth-push-oracle/src/lib.rs @@ -1,3 +1,6 @@ +// We can't do much about the size of `anchor_lang::error::Error`. +#![allow(clippy::result_large_err)] + use { anchor_lang::prelude::*, pyth_solana_receiver_sdk::{ diff --git a/target_chains/solana/programs/pyth-solana-receiver/src/lib.rs b/target_chains/solana/programs/pyth-solana-receiver/src/lib.rs index 49eb3ff792..3c7822bf43 100644 --- a/target_chains/solana/programs/pyth-solana-receiver/src/lib.rs +++ b/target_chains/solana/programs/pyth-solana-receiver/src/lib.rs @@ -1,3 +1,6 @@ +// We can't do much about the size of `anchor_lang::error::Error`. +#![allow(clippy::result_large_err)] + pub use pythnet_sdk::wire::v1::MerklePriceUpdate; use { crate::error::ReceiverError, @@ -354,6 +357,7 @@ struct VaaComponents { emitter_chain: u16, } +#[allow(clippy::too_many_arguments)] fn post_price_update_from_vaa<'info>( config: &Account<'info, Config>, payer: &Signer<'info>, diff --git a/target_chains/solana/programs/pyth-solana-receiver/src/sdk.rs b/target_chains/solana/programs/pyth-solana-receiver/src/sdk.rs index d89268b6d1..3ccf7262b6 100644 --- a/target_chains/solana/programs/pyth-solana-receiver/src/sdk.rs +++ b/target_chains/solana/programs/pyth-solana-receiver/src/sdk.rs @@ -146,6 +146,7 @@ impl instruction::PostUpdate { } impl instruction::PostUpdateAtomic { + #[allow(clippy::too_many_arguments)] pub fn populate( payer: Pubkey, write_authority: Pubkey, diff --git a/target_chains/solana/pyth_solana_receiver_sdk/src/cpi/accounts.rs b/target_chains/solana/pyth_solana_receiver_sdk/src/cpi/accounts.rs index ffd3078c04..400c845e63 100644 --- a/target_chains/solana/pyth_solana_receiver_sdk/src/cpi/accounts.rs +++ b/target_chains/solana/pyth_solana_receiver_sdk/src/cpi/accounts.rs @@ -1,3 +1,5 @@ +#![allow(clippy::vec_init_then_push)] + // This file was populated with the expanded macros of programs/pyth-solana-receiver/src/lib.rs pub struct PostUpdateAtomic<'info> { diff --git a/target_chains/solana/pyth_solana_receiver_sdk/src/lib.rs b/target_chains/solana/pyth_solana_receiver_sdk/src/lib.rs index 31b4fe6e16..4e786d440d 100644 --- a/target_chains/solana/pyth_solana_receiver_sdk/src/lib.rs +++ b/target_chains/solana/pyth_solana_receiver_sdk/src/lib.rs @@ -1,3 +1,6 @@ +// We can't do much about the size of `anchor_lang::error::Error`. +#![allow(clippy::result_large_err)] + use { anchor_lang::{declare_id, prelude::*}, borsh::{BorshDeserialize, BorshSerialize},