|
|
@@ -57,35 +57,6 @@ impl<'a> BatchState<'a> {
|
|
|
let sym_count = self.symbols.len();
|
|
|
let pubkeys: Vec<_> = self.symbols.iter().map(|s| s.price_addr).collect();
|
|
|
|
|
|
- // Always learn the current on-chain state for each symbol, use None values if lookup fails
|
|
|
- let mut new_symbol_states: Vec<Option<PriceAccount>> = match c
|
|
|
- .get_multiple_accounts(&pubkeys)
|
|
|
- .await
|
|
|
- {
|
|
|
- Ok(acc_opts) => {
|
|
|
- acc_opts
|
|
|
- .into_iter()
|
|
|
- .enumerate()
|
|
|
- .map(|(idx, opt)| {
|
|
|
- // Take each Some(acc), make it None and log on load_price_account() error
|
|
|
- opt.and_then(|acc| {
|
|
|
- pyth_sdk_solana::state::load_price_account(&acc.data)
|
|
|
- .cloned() // load_price_account() transmutes the data reference into another reference, and owning acc_opts is not enough
|
|
|
- .map_err(|e| {
|
|
|
- warn!("Could not parse symbol {}/{}: {}", idx, sym_count, e);
|
|
|
- e
|
|
|
- })
|
|
|
- .ok() // Err becomes None
|
|
|
- })
|
|
|
- })
|
|
|
- .collect()
|
|
|
- }
|
|
|
- Err(e) => {
|
|
|
- warn!("Could not look up any symbols on-chain: {}", e);
|
|
|
- vec![None; sym_count]
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
// min interval
|
|
|
if self.last_job_finished_at.elapsed()
|
|
|
> Duration::from_secs(self.conditions.min_interval_secs)
|
|
|
@@ -96,14 +67,47 @@ impl<'a> BatchState<'a> {
|
|
|
));
|
|
|
}
|
|
|
|
|
|
- for (idx, old_new_tup) in self
|
|
|
- .last_known_symbol_states
|
|
|
- .iter_mut() // Borrow mutably to make the update easier
|
|
|
- .zip(new_symbol_states.iter())
|
|
|
- .enumerate()
|
|
|
- {
|
|
|
- // Only evaluate this symbol if a triggering condition is not already met
|
|
|
- if ret.is_none() {
|
|
|
+ // Only lookup and compare symbols if the conditions require
|
|
|
+ if self.conditions.need_onchain_lookup() {
|
|
|
+ let mut new_symbol_states: Vec<Option<PriceAccount>> =
|
|
|
+ match c.get_multiple_accounts(&pubkeys).await {
|
|
|
+ Ok(acc_opts) => {
|
|
|
+ acc_opts
|
|
|
+ .into_iter()
|
|
|
+ .enumerate()
|
|
|
+ .map(|(idx, opt)| {
|
|
|
+ // Take each Some(acc), make it None and log on load_price_account() error
|
|
|
+ opt.and_then(|acc| {
|
|
|
+ pyth_sdk_solana::state::load_price_account(&acc.data)
|
|
|
+ .cloned() // load_price_account() transmutes the data reference into another reference, and owning acc_opts is not enough
|
|
|
+ .map_err(|e| {
|
|
|
+ warn!(
|
|
|
+ "Could not parse symbol {}/{}: {}",
|
|
|
+ idx, sym_count, e
|
|
|
+ );
|
|
|
+ e
|
|
|
+ })
|
|
|
+ .ok() // Err becomes None
|
|
|
+ })
|
|
|
+ })
|
|
|
+ .collect()
|
|
|
+ }
|
|
|
+ Err(e) => {
|
|
|
+ warn!("Could not look up any symbols on-chain: {}", e);
|
|
|
+ vec![None; sym_count]
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ for (idx, old_new_tup) in self
|
|
|
+ .last_known_symbol_states
|
|
|
+ .iter_mut() // Borrow mutably to make the update easier
|
|
|
+ .zip(new_symbol_states.iter())
|
|
|
+ .enumerate()
|
|
|
+ {
|
|
|
+ // Only evaluate this symbol if a triggering condition is not already met
|
|
|
+ if ret.is_some() {
|
|
|
+ break;
|
|
|
+ }
|
|
|
match old_new_tup {
|
|
|
(Some(old), Some(new)) => {
|
|
|
// publish_time_changed
|
|
|
@@ -143,19 +147,18 @@ impl<'a> BatchState<'a> {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- // Update with newer state only if a condition was met. We
|
|
|
- // don't want to shadow changes that may happen over a larger
|
|
|
- // period between state lookups.
|
|
|
- if ret.is_some() {
|
|
|
- for (old, new) in self
|
|
|
- .last_known_symbol_states
|
|
|
- .iter_mut()
|
|
|
- .zip(new_symbol_states.into_iter())
|
|
|
- {
|
|
|
- if new.is_some() {
|
|
|
- *old = new;
|
|
|
+ // Update with newer state only if a condition was met. We
|
|
|
+ // don't want to shadow changes that may happen over a larger
|
|
|
+ // period between state lookups.
|
|
|
+ if ret.is_some() {
|
|
|
+ for (old, new) in self
|
|
|
+ .last_known_symbol_states
|
|
|
+ .iter_mut()
|
|
|
+ .zip(new_symbol_states.into_iter())
|
|
|
+ {
|
|
|
+ if new.is_some() {
|
|
|
+ *old = new;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|