Skip to content

Commit 0a1d19b

Browse files
authored
fix: cargo update, zero price handling (#156)
1 parent c7fb686 commit 0a1d19b

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

.github/workflows/rustfmt.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ jobs:
1616
profile: minimal
1717
toolchain: nightly
1818
components: rustfmt
19-
- uses: pre-commit/action@v2.0.3
19+
- uses: pre-commit/action@v3.0.1

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/agent/services/lazer_exporter.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use {
22
crate::agent::state,
3-
anyhow::Result,
3+
anyhow::{
4+
anyhow,
5+
Result,
6+
},
47
futures_util::{
58
stream::{
69
SplitSink,
@@ -135,7 +138,7 @@ struct SymbolResponse {
135138

136139
async fn fetch_symbols(history_url: &Url) -> Result<Vec<SymbolResponse>> {
137140
let mut url = history_url.clone();
138-
url.set_scheme("http").unwrap();
141+
url.set_scheme("http").map_err(|_| anyhow!("invalid url"))?;
139142
url.set_path("/history/v1/symbols");
140143
let client = Client::new();
141144
let response = client.get(url).send().await?.error_for_status()?;
@@ -181,6 +184,7 @@ mod lazer_exporter {
181184
time::Duration,
182185
},
183186
tokio_stream::StreamMap,
187+
tracing::warn,
184188
};
185189

186190
pub async fn lazer_exporter<S>(config: Config, state: Arc<S>)
@@ -245,8 +249,14 @@ mod lazer_exporter {
245249
// TODO: This read locks and clones local::Store::prices, which may not meet performance needs.
246250
for (identifier, price_info) in state.get_all_price_infos().await {
247251
if let Some(symbol) = lazer_symbols.get(&identifier.to_string()) {
252+
let price = if let Ok(price) = NonZeroI64::try_from(price_info.price) {
253+
Some(Price(price))
254+
} else {
255+
warn!("Zero price in local state identifier: {identifier} price_info: {price_info:?}");
256+
continue;
257+
};
248258
if let Err(e) = relayer_sender.send_price_update(&PriceFeedDataV1 {
249-
price: Some(Price(NonZeroI64::try_from(price_info.price).unwrap())),
259+
price,
250260
best_ask_price: None,
251261
best_bid_price: None,
252262
price_feed_id: PriceFeedId(symbol.pyth_lazer_id),

0 commit comments

Comments
 (0)