From 4e77da42cab6c4b3ea095da4f288bd318986a2d1 Mon Sep 17 00:00:00 2001 From: Denton X Date: Fri, 5 Apr 2024 19:45:05 +0000 Subject: [PATCH] fix: Run clippy --fix Signed-off-by: Denton X --- src/state_engine/engine.rs | 20 +++++++++++--------- src/state_engine/geyser.rs | 25 +++++++++++++++++-------- src/utils.rs | 1 + 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/state_engine/engine.rs b/src/state_engine/engine.rs index a74d0e4..e89bffe 100644 --- a/src/state_engine/engine.rs +++ b/src/state_engine/engine.rs @@ -1,7 +1,7 @@ use solana_account_decoder::UiAccountEncoding; use solana_account_decoder::UiDataSliceConfig; use solana_sdk::bs58; -use std::{str::FromStr, sync::Arc}; +use std::sync::Arc; use anchor_client::anchor_lang::AccountDeserialize; use anchor_client::anchor_lang::Discriminator; @@ -91,6 +91,7 @@ pub struct StateEngineConfig { pub signer_pubkey: Pubkey, } +#[allow(dead_code)] pub struct StateEngineService { nb_rpc_client: Arc, rpc_client: Arc, @@ -106,6 +107,7 @@ pub struct StateEngineService { update_tasks: Arc>>>>, } +#[allow(dead_code)] impl StateEngineService { pub async fn start(config: StateEngineConfig) -> anyhow::Result> { debug!("StateEngineService::start"); @@ -189,7 +191,7 @@ impl StateEngineService { .entry(*bank_address) .and_modify(|bank_entry| match bank_entry.try_write() { Ok(mut bank_wg) => { - bank_wg.bank = bank.clone(); + bank_wg.bank = *bank; } Err(e) => { error!("Failed to acquire write lock on bank: {}", e); @@ -198,7 +200,7 @@ impl StateEngineService { .or_insert_with(|| { Arc::new(RwLock::new(BankWrapper::new( *bank_address, - bank.clone(), + *bank, OracleWrapper::new( **oracle_address, OraclePriceFeedAdapter::try_from_bank_config( @@ -259,7 +261,7 @@ impl StateEngineService { .entry(*bank_address) .and_modify(|bank_entry| { if let Ok(mut bank_entry) = bank_entry.try_write() { - bank_entry.bank = bank.clone(); + bank_entry.bank = *bank; } else { warn!("Failed to acquire write lock on bank, bank update skipped"); } @@ -275,7 +277,7 @@ impl StateEngineService { Arc::new(RwLock::new(BankWrapper::new( *bank_address, - bank.clone(), + *bank, OracleWrapper::new( oracle_address, OraclePriceFeedAdapter::try_from_bank_config( @@ -305,7 +307,7 @@ impl StateEngineService { for mint in bank_mints.iter() { let ata = spl_associated_token_account::get_associated_token_address( &self.config.signer_pubkey, - &mint, + mint, ); token_account_addresses.push(ata); } @@ -486,7 +488,7 @@ impl StateEngineService { .entry(*marginfi_account_address) .and_modify(|marginfi_account_ref| { let marginfi_account_ref = Arc::clone(marginfi_account_ref); - let marginfi_account_updated = marginfi_account.clone(); + let marginfi_account_updated = *marginfi_account; tokio::spawn(async move { let mut marginfi_account_guard = marginfi_account_ref.write().await; marginfi_account_guard.account = marginfi_account_updated; @@ -495,7 +497,7 @@ impl StateEngineService { .or_insert_with(|| { Arc::new(RwLock::new(MarginfiAccountWrapper::new( *marginfi_account_address, - marginfi_account.clone(), + *marginfi_account, Vec::new(), ))) }); @@ -507,7 +509,7 @@ impl StateEngineService { let marginfi_accounts = self.marginfi_accounts.clone(); for account_ref in marginfi_accounts.iter() { let account = account_ref.value().read().await; - let marginfi_account = account.account.clone(); // clone the underlying data + let marginfi_account = account.account; // clone the underlying data let address = account.address; // get the address from the account let update_tasks = self.update_tasks.lock().await; diff --git a/src/state_engine/geyser.rs b/src/state_engine/geyser.rs index 380fea6..0ca1b6b 100644 --- a/src/state_engine/geyser.rs +++ b/src/state_engine/geyser.rs @@ -19,21 +19,25 @@ use crate::utils::account_update_to_account; use super::engine::StateEngineService; +#[allow(clippy::enum_variant_names)] #[derive(Debug, thiserror::Error)] pub enum GeyserServiceError { + #[allow(dead_code)] #[error("Generic error")] GenericError, #[error("Geyser client error: {0}")] - GeyserServiceError(#[from] GeyserGrpcClientError), + ServiceError(#[from] GeyserGrpcClientError), #[error("Error parsing account: {0}")] AnyhowError(#[from] anyhow::Error), } +#[allow(dead_code)] #[derive(Debug, Default)] struct GeyserRequestUpdate { accounts: Vec, } +#[allow(dead_code)] impl GeyserRequestUpdate { fn merge(&mut self, other: GeyserRequestUpdate) { self.accounts.extend(other.accounts); @@ -71,16 +75,21 @@ impl GeyserRequestUpdate { } } +#[allow(dead_code)] pub struct GeyserServiceConfig { pub endpoint: String, pub x_token: Option, } +#[allow(dead_code)] const MARGINFI_ACCOUNT_GROUP_PK_OFFSET: usize = 8; +#[allow(dead_code)] const BANK_GROUP_PK_OFFSET: usize = 8; +#[allow(dead_code)] pub struct GeyserService {} +#[allow(dead_code)] impl GeyserService { pub async fn connect( config: GeyserServiceConfig, @@ -119,7 +128,7 @@ impl GeyserService { let sub_req = Self::build_geyser_subscribe_request(&state_engine); let (mut subscribe_tx, mut subscribe_rx) = geyser_client.subscribe().await?; - subscribe_tx.send(sub_req); + let _ = subscribe_tx.send(sub_req).await; while let Some(msg) = subscribe_rx.next().await { let update = match msg { @@ -163,7 +172,7 @@ impl GeyserService { if let Ok(account_owner_pk) = Pubkey::try_from(account.owner.clone()) { if account_owner_pk == state_engine.get_marginfi_program_id() { let maybe_update = - Self::process_marginfi_account_update(state_engine, &account)?; + Self::process_marginfi_account_update(state_engine, account)?; if let Some(update) = maybe_update { geyser_update_request.merge(update); } @@ -173,12 +182,12 @@ impl GeyserService { if let Ok(address) = Pubkey::try_from(account.pubkey.clone()) { if state_engine.is_tracked_oracle(&address) { - Self::process_oracle_account_update(state_engine, &account)?; + Self::process_oracle_account_update(state_engine, account)?; processed = true; } if state_engine.is_tracked_token_account(&address) { - Self::process_token_account_update(state_engine, &account)?; + Self::process_token_account_update(state_engine, account)?; processed = true; } } @@ -248,12 +257,12 @@ impl GeyserService { error!("Error parsing oracle account: {:?}", e); GeyserServiceError::GenericError })?; - state_engine.update_oracle(&oracle_addres, oracle_account); + state_engine.update_oracle(&oracle_addres, oracle_account)?; Ok(()) } fn process_token_account_update( - state_engine: &Arc, - account_update: &SubscribeUpdateAccountInfo, + _state_engine: &Arc, + _account_update: &SubscribeUpdateAccountInfo, ) -> Result<(), GeyserServiceError> { Ok(()) } diff --git a/src/utils.rs b/src/utils.rs index 925dc88..5580d9c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -127,6 +127,7 @@ pub mod accessor { Pubkey::new_from_array(mint_bytes) } + #[allow(dead_code)] pub fn authority(bytes: &[u8]) -> Pubkey { let mut owner_bytes = [0u8; 32]; owner_bytes.copy_from_slice(&bytes[32..64]);