Skip to content

Commit

Permalink
refactor(agent): remove store module
Browse files Browse the repository at this point in the history
  • Loading branch information
Reisen committed Jun 5, 2024
1 parent 85fa35a commit 663a137
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 24 deletions.
1 change: 0 additions & 1 deletion src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ pub mod metrics;
pub mod pyth;
pub mod solana;
pub mod state;
pub mod store;

lazy_static! {
/// A static exit flag to indicate to running threads that we're shutting down. This is used to
Expand Down
7 changes: 2 additions & 5 deletions src/agent/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use {
local::PriceInfo,
State,
},
crate::agent::{
solana::oracle::PriceEntry,
store::PriceIdentifier,
},
crate::agent::solana::oracle::PriceEntry,
lazy_static::lazy_static,
prometheus_client::{
encoding::{
Expand Down Expand Up @@ -366,7 +363,7 @@ impl PriceLocalMetrics {
metrics
}

pub fn update(&self, price_id: &PriceIdentifier, price_info: &PriceInfo) {
pub fn update(&self, price_id: &pyth_sdk::Identifier, price_info: &PriceInfo) {
#[deny(unused_variables)]
let Self {
price,
Expand Down
7 changes: 3 additions & 4 deletions src/agent/solana/exporter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use {
self::transaction_monitor::TransactionMonitor,
super::{
super::store::PriceIdentifier,
key_store,
network::Network,
oracle::PricePublishingMetadata,
Expand Down Expand Up @@ -242,7 +241,7 @@ pub struct Exporter {
/// The last state published for each price identifier. Used to
/// rule out stale data and prevent repetitive publishing of
/// unchanged prices.
last_published_state: HashMap<PriceIdentifier, PriceInfo>,
last_published_state: HashMap<pyth_sdk::Identifier, PriceInfo>,

/// Watch receiver channel to access the current network state
network_state_rx: watch::Receiver<NetworkState>,
Expand Down Expand Up @@ -417,7 +416,7 @@ impl Exporter {
}
}

async fn get_permissioned_updates(&mut self) -> Result<Vec<(PriceIdentifier, PriceInfo)>> {
async fn get_permissioned_updates(&mut self) -> Result<Vec<(pyth_sdk::Identifier, PriceInfo)>> {
let local_store_contents = self.fetch_local_store_contents().await?;

let publish_keypair = self.get_publish_keypair().await?;
Expand Down Expand Up @@ -595,7 +594,7 @@ impl Exporter {
});
}

async fn fetch_local_store_contents(&self) -> Result<HashMap<PriceIdentifier, PriceInfo>> {
async fn fetch_local_store_contents(&self) -> Result<HashMap<pyth_sdk::Identifier, PriceInfo>> {
Ok(LocalStore::get_all_price_infos(&*self.state).await)
}

Expand Down
1 change: 0 additions & 1 deletion src/agent/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use {
NotifyPriceSched,
SubscriptionID,
},
store::PriceIdentifier,
},
serde::{
Deserialize,
Expand Down
5 changes: 2 additions & 3 deletions src/agent/state/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use {
network::Network,
oracle::PriceEntry,
},
store::PriceIdentifier,
},
global::{
AllAccountsData,
Expand Down Expand Up @@ -138,8 +137,8 @@ fn solana_price_account_to_pythd_api_price_account(
}
}

type PriceSubscriptions = HashMap<PriceIdentifier, Vec<NotifyPriceSubscription>>;
type PriceSchedSubscribtions = HashMap<PriceIdentifier, Vec<NotifyPriceSchedSubscription>>;
type PriceSubscriptions = HashMap<pyth_sdk::Identifier, Vec<NotifyPriceSubscription>>;
type PriceSchedSubscribtions = HashMap<pyth_sdk::Identifier, Vec<NotifyPriceSchedSubscription>>;

#[derive(Default)]
pub struct PricesState {
Expand Down
23 changes: 14 additions & 9 deletions src/agent/state/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
// is contributing to the network. The Exporters will then take this data and publish
// it to the networks.
use {
super::{
PriceIdentifier,
State,
},
super::State,
crate::agent::metrics::PriceLocalMetrics,
anyhow::{
anyhow,
Expand Down Expand Up @@ -45,7 +42,7 @@ impl PriceInfo {
}

pub struct Store {
prices: RwLock<HashMap<PriceIdentifier, PriceInfo>>,
prices: RwLock<HashMap<pyth_sdk::Identifier, PriceInfo>>,
metrics: PriceLocalMetrics,
logger: Logger,
}
Expand All @@ -62,8 +59,12 @@ impl Store {

#[async_trait::async_trait]
pub trait LocalStore {
async fn update(&self, price_identifier: PriceIdentifier, price_info: PriceInfo) -> Result<()>;
async fn get_all_price_infos(&self) -> HashMap<PriceIdentifier, PriceInfo>;
async fn update(
&self,
price_identifier: pyth_sdk::Identifier,
price_info: PriceInfo,
) -> Result<()>;
async fn get_all_price_infos(&self) -> HashMap<pyth_sdk::Identifier, PriceInfo>;
}

// Allow downcasting State into GlobalStore for functions that depend on the `GlobalStore` service.
Expand All @@ -79,7 +80,11 @@ where
for<'a> &'a T: Into<&'a Store>,
T: Sync,
{
async fn update(&self, price_identifier: PriceIdentifier, price_info: PriceInfo) -> Result<()> {
async fn update(
&self,
price_identifier: pyth_sdk::Identifier,
price_info: PriceInfo,
) -> Result<()> {
debug!(self.into().logger, "local store received price update"; "identifier" => bs58::encode(price_identifier.to_bytes()).into_string());

// Drop the update if it is older than the current one stored for the price
Expand All @@ -102,7 +107,7 @@ where
Ok(())
}

async fn get_all_price_infos(&self) -> HashMap<PriceIdentifier, PriceInfo> {
async fn get_all_price_infos(&self) -> HashMap<pyth_sdk::Identifier, PriceInfo> {
self.into().prices.read().await.clone()
}
}
1 change: 0 additions & 1 deletion src/agent/store.rs

This file was deleted.

0 comments on commit 663a137

Please sign in to comment.