Skip to content

Commit 103a92c

Browse files
committed
use slot instead of publish_time for unique id
1 parent 4b42b93 commit 103a92c

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-stream"
3-
version = "0.1.5"
3+
version = "0.1.6"
44
edition = "2021"
55

66
[lib]

src/bin/pyth_reader.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct PriceInfo {
4343
conf: String,
4444
expo: i32,
4545
publish_time: i64,
46+
slot: u64, // Add this field
4647
}
4748

4849
// Add this struct to deserialize the configuration
@@ -149,12 +150,14 @@ async fn fetch_price_updates(jetstream: jetstream::Context, config: &AppConfig)
149150
conf: price_account.agg.conf.to_string(),
150151
expo: price_account.expo,
151152
publish_time: price_account.timestamp,
153+
slot: update.context.slot, // Add this field
152154
},
153155
ema_price: PriceInfo {
154156
price: price_account.ema_price.val.to_string(),
155157
conf: price_account.ema_conf.val.to_string(),
156158
expo: price_account.expo,
157159
publish_time: price_account.timestamp,
160+
slot: update.context.slot, // Add this field
158161
},
159162
},
160163
};
@@ -164,7 +167,7 @@ async fn fetch_price_updates(jetstream: jetstream::Context, config: &AppConfig)
164167
// Create a unique message ID
165168
let message_id = format!(
166169
"{}:{}",
167-
price_update.price_feed.id, price_update.price_feed.price.publish_time
170+
price_update.price_feed.id, price_update.price_feed.price.slot
168171
);
169172

170173
// Create headers with the Nats-Msg-Id

src/bin/websocket_server.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ struct PriceInfo {
263263
conf: String,
264264
expo: i32,
265265
publish_time: i64,
266+
slot: u64, // Add this field
266267
}
267268

268269
async fn handle_nats_messages(jetstream: jetstream::Context, clients: Clients) -> Result<()> {
@@ -309,7 +310,10 @@ async fn handle_nats_messages(jetstream: jetstream::Context, clients: Clients) -
309310
};
310311
price_update.price_feed.id = hex_id.clone();
311312

312-
debug!("Parsed price update for feed ID: {}", hex_id);
313+
debug!(
314+
"Parsed price update for feed ID: {} at slot: {}",
315+
hex_id, price_update.price_feed.price.slot
316+
);
313317

314318
let clients = clients.lock().await;
315319
debug!("Number of connected clients: {}", clients.len());
@@ -320,7 +324,10 @@ async fn handle_nats_messages(jetstream: jetstream::Context, clients: Clients) -
320324
if let Err(e) = sender.send(Message::Text(update_json)) {
321325
warn!(client_addr = %client_addr, error = %e, "Failed to send price update to client");
322326
} else {
323-
debug!("Successfully sent update to client: {}", client_addr);
327+
debug!(
328+
"Successfully sent update to client: {} for slot: {}",
329+
client_addr, price_update.price_feed.price.slot
330+
);
324331
}
325332
} else {
326333
debug!(

0 commit comments

Comments
 (0)