Skip to content

Commit

Permalink
fix: Run clippy --fix
Browse files Browse the repository at this point in the history
Signed-off-by: Denton X <[email protected]>
  • Loading branch information
exdx committed Apr 5, 2024
1 parent c456641 commit 4e77da4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
20 changes: 11 additions & 9 deletions src/state_engine/engine.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -91,6 +91,7 @@ pub struct StateEngineConfig {
pub signer_pubkey: Pubkey,
}

#[allow(dead_code)]
pub struct StateEngineService {
nb_rpc_client: Arc<solana_client::nonblocking::rpc_client::RpcClient>,
rpc_client: Arc<solana_client::rpc_client::RpcClient>,
Expand All @@ -106,6 +107,7 @@ pub struct StateEngineService {
update_tasks: Arc<Mutex<DashMap<Pubkey, tokio::task::JoinHandle<anyhow::Result<()>>>>>,
}

#[allow(dead_code)]
impl StateEngineService {
pub async fn start(config: StateEngineConfig) -> anyhow::Result<Arc<Self>> {
debug!("StateEngineService::start");
Expand Down Expand Up @@ -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);
Expand All @@ -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(
Expand Down Expand Up @@ -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");
}
Expand All @@ -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(
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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(),
)))
});
Expand All @@ -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;
Expand Down
25 changes: 17 additions & 8 deletions src/state_engine/geyser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pubkey>,
}

#[allow(dead_code)]
impl GeyserRequestUpdate {
fn merge(&mut self, other: GeyserRequestUpdate) {
self.accounts.extend(other.accounts);
Expand Down Expand Up @@ -71,16 +75,21 @@ impl GeyserRequestUpdate {
}
}

#[allow(dead_code)]
pub struct GeyserServiceConfig {
pub endpoint: String,
pub x_token: Option<String>,
}

#[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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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<StateEngineService>,
account_update: &SubscribeUpdateAccountInfo,
_state_engine: &Arc<StateEngineService>,
_account_update: &SubscribeUpdateAccountInfo,
) -> Result<(), GeyserServiceError> {
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 4e77da4

Please sign in to comment.