Skip to content

Commit dd0225d

Browse files
authored
fix: hermes id handling (#162)
1 parent 3835e58 commit dd0225d

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

src/agent/services/lazer_exporter.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use {
44
Result,
55
anyhow,
66
},
7-
ed25519_dalek::SecretKey,
87
futures_util::{
98
SinkExt,
109
stream::{
@@ -54,14 +53,6 @@ pub struct Config {
5453
pub publish_interval_duration: Duration,
5554
}
5655

57-
#[derive(Clone, Deserialize)]
58-
struct PublisherSecretKey(SecretKey);
59-
impl std::fmt::Debug for PublisherSecretKey {
60-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61-
write!(f, "PublisherSecretKey(redacted)")
62-
}
63-
}
64-
6556
fn default_publish_interval() -> Duration {
6657
Duration::from_millis(200)
6758
}
@@ -129,16 +120,27 @@ async fn connect_to_relayers(
129120
#[derive(Deserialize)]
130121
struct SymbolResponse {
131122
pub pyth_lazer_id: u32,
123+
#[serde(rename = "name")]
132124
pub _name: String,
125+
#[serde(rename = "symbol")]
133126
pub _symbol: String,
127+
#[serde(rename = "description")]
134128
pub _description: String,
129+
#[serde(rename = "asset_type")]
135130
pub _asset_type: String,
131+
#[serde(rename = "exponent")]
136132
pub _exponent: i16,
133+
#[serde(rename = "cmc_id")]
137134
pub _cmc_id: Option<u32>,
135+
#[serde(rename = "interval")]
138136
pub _interval: Option<String>,
137+
#[serde(rename = "min_publishers")]
139138
pub _min_publishers: u16,
139+
#[serde(rename = "min_channel")]
140140
pub _min_channel: String,
141+
#[serde(rename = "state")]
141142
pub _state: String,
143+
#[serde(rename = "schedule")]
142144
pub _schedule: String,
143145
pub hermes_id: Option<String>,
144146
}
@@ -245,11 +247,20 @@ mod lazer_exporter {
245247
S: Send + Sync + 'static,
246248
{
247249
// TODO: Re-fetch on an interval?
248-
let lazer_symbols: HashMap<String, SymbolResponse> =
250+
let lazer_symbols: HashMap<pyth_sdk::Identifier, SymbolResponse> =
249251
match fetch_symbols(&config.history_url).await {
250252
Ok(symbols) => symbols
251253
.into_iter()
252-
.filter_map(|symbol| symbol.hermes_id.clone().map(|id| (id, symbol)))
254+
.filter_map(|symbol| {
255+
let hermes_id = symbol.hermes_id.clone()?;
256+
match pyth_sdk::Identifier::from_hex(hermes_id.clone()) {
257+
Ok(id) => Some((id, symbol)),
258+
Err(e) => {
259+
tracing::warn!("Failed to parse hermes_id {}: {e:?}", hermes_id);
260+
None
261+
}
262+
}
263+
})
253264
.collect(),
254265
Err(e) => {
255266
tracing::error!("Failed to fetch Lazer symbols: {e:?}");
@@ -296,7 +307,7 @@ mod lazer_exporter {
296307

297308
// TODO: This read locks and clones local::Store::prices, which may not meet performance needs.
298309
for (identifier, price_info) in state.get_all_price_infos().await {
299-
if let Some(symbol) = lazer_symbols.get(&identifier.to_string()) {
310+
if let Some(symbol) = lazer_symbols.get(&identifier) {
300311
let source_timestamp_micros = price_info.timestamp.and_utc().timestamp_micros();
301312
let source_timestamp = MessageField::some(Timestamp {
302313
seconds: source_timestamp_micros / 1_000_000,
@@ -353,7 +364,6 @@ mod lazer_exporter {
353364
tracing::error!("Error receiving message from at relayer {relayer_url}: {e:?}");
354365
}
355366
None => {
356-
// TODO: Probably still appropriate to return here, but retry in caller.
357367
tracing::error!("relayer connection closed");
358368
bail!("relayer connection closed");
359369
}

0 commit comments

Comments
 (0)