Skip to content

Commit eb65f9b

Browse files
authored
Hermes: Add support for multiple quorum listeners (#2820)
1 parent 84c6a40 commit eb65f9b

File tree

4 files changed

+26
-23
lines changed

4 files changed

+26
-23
lines changed

apps/hermes/server/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.

apps/hermes/server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hermes"
3-
version = "0.10.1-alpha"
3+
version = "0.10.2-alpha"
44
description = "Hermes is an agent that provides Verified Prices from the Pythnet Pyth Oracle."
55
edition = "2021"
66

apps/hermes/server/src/config/pythnet.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ pub struct Options {
2525
/// Address of a PythNet quorum websocket RPC endpoint.
2626
#[arg(long = "pythnet-quorum-ws-addr")]
2727
#[arg(env = "PYTHNET_QUORUM_WS_ADDR")]
28-
pub quorum_ws_addr: Option<String>,
28+
#[arg(value_delimiter = ',')]
29+
pub quorum_ws_addrs: Option<Vec<String>>,
2930
}

apps/hermes/server/src/network/pythnet.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -436,27 +436,29 @@ where
436436
})
437437
};
438438

439-
let task_quorum_listener = match opts.pythnet.quorum_ws_addr {
440-
Some(pythnet_quorum_ws_addr) => {
441-
let store = state.clone();
442-
let mut exit = crate::EXIT.subscribe();
443-
tokio::spawn(async move {
444-
loop {
445-
let current_time = Instant::now();
446-
tokio::select! {
447-
_ = exit.changed() => break,
448-
Err(err) = run_quorom_listener(store.clone(), pythnet_quorum_ws_addr.clone()) => {
449-
tracing::error!(error = ?err, "Error in Pythnet quorum network listener.");
450-
if current_time.elapsed() < Duration::from_secs(30) {
451-
tracing::error!("Pythnet quorum listener restarting too quickly. Sleep 1s.");
452-
tokio::time::sleep(Duration::from_secs(1)).await;
439+
let task_quorum_listeners = match opts.pythnet.quorum_ws_addrs {
440+
Some(pythnet_quorum_ws_addrs) => tokio::spawn(async move {
441+
pythnet_quorum_ws_addrs.into_iter().for_each(|pythnet_quorum_ws_addr| {
442+
let store = state.clone();
443+
let mut exit = crate::EXIT.subscribe();
444+
tokio::spawn(async move {
445+
loop {
446+
let current_time = Instant::now();
447+
tokio::select! {
448+
_ = exit.changed() => break,
449+
Err(err) = run_quorom_listener(store.clone(), pythnet_quorum_ws_addr.clone()) => {
450+
tracing::error!(ws_addr = ?pythnet_quorum_ws_addr, error = ?err, "Error in Pythnet quorum network listener.");
451+
if current_time.elapsed() < Duration::from_secs(30) {
452+
tracing::error!("Pythnet quorum listener restarting too quickly. Sleep 1s.");
453+
tokio::time::sleep(Duration::from_secs(1)).await;
454+
}
455+
}
453456
}
454457
}
455-
}
456-
}
457-
tracing::info!("Shutting down Pythnet quorum listener...");
458-
})
459-
}
458+
tracing::info!("Shutting down Pythnet quorum listener...");
459+
});
460+
});
461+
}),
460462
None => tokio::spawn(async {
461463
tracing::warn!(
462464
"Pythnet quorum websocket address not provided, skipping quorum listener."
@@ -468,7 +470,7 @@ where
468470
task_listener,
469471
task_guardian_watcher,
470472
task_price_feeds_metadata_updater,
471-
task_quorum_listener,
473+
task_quorum_listeners,
472474
);
473475
Ok(())
474476
}

0 commit comments

Comments
 (0)