瀏覽代碼

feat: add hermes_base_url to run options and remove from config

Daniel Chew 8 月之前
父節點
當前提交
1c6637d939

+ 6 - 0
apps/argus/src/command/run.rs

@@ -97,6 +97,7 @@ pub async fn run_keeper(
     private_key: String,
     metrics_registry: Arc<RwLock<Registry>>,
     rpc_metrics: Arc<RpcMetrics>,
+    hermes_base_url: String,
 ) -> Result<()> {
     let mut handles = Vec::new();
     let keeper_metrics: Arc<KeeperMetrics> = Arc::new({
@@ -119,6 +120,7 @@ pub async fn run_keeper(
             chain_config.clone(),
             keeper_metrics.clone(),
             rpc_metrics.clone(),
+            hermes_base_url.clone(),
         )));
     }
 
@@ -131,6 +133,9 @@ pub async fn run(opts: &RunOptions) -> Result<()> {
     let metrics_registry = Arc::new(RwLock::new(Registry::default()));
     let rpc_metrics = Arc::new(RpcMetrics::new(metrics_registry.clone()).await);
 
+    // Store the hermes base URL from the command-line argument
+    let hermes_base_url = opts.hermes_base_url.clone();
+
     let mut tasks = Vec::new();
     for (chain_id, chain_config) in config.chains.clone() {
         let rpc_metrics = rpc_metrics.clone();
@@ -184,6 +189,7 @@ pub async fn run(opts: &RunOptions) -> Result<()> {
             keeper_private_key,
             metrics_registry.clone(),
             rpc_metrics.clone(),
+            hermes_base_url.clone(),
         ));
     } else {
         tracing::info!("Not starting keeper service: no keeper private key specified. Please add one to the config if you would like to run the keeper service.")

+ 2 - 23
apps/argus/src/config.rs

@@ -26,6 +26,7 @@ mod withdraw_fees;
 
 const DEFAULT_RPC_ADDR: &str = "127.0.0.1:34000";
 const DEFAULT_HTTP_ADDR: &str = "http://127.0.0.1:34000";
+const DEFAULT_HERMES_BASE_URL: &str = "https://hermes.pyth.network";
 
 #[derive(Parser, Debug)]
 #[command(name = crate_name!())]
@@ -66,7 +67,7 @@ pub enum Options {
 pub struct ConfigOptions {
     /// Path to a configuration file containing the list of supported blockchains
     #[arg(long = "config")]
-    #[arg(env = "FORTUNA_CONFIG")]
+    #[arg(env = "ARGUS_CONFIG")]
     #[arg(default_value = "config.yaml")]
     pub config: String,
 }
@@ -76,8 +77,6 @@ pub struct Config {
     pub chains: HashMap<ChainId, EthereumConfig>,
     pub provider: ProviderConfig,
     pub keeper: KeeperConfig,
-    #[serde(default)]
-    pub hermes: HermesConfig,
 }
 
 impl Config {
@@ -356,23 +355,3 @@ impl SecretString {
         Ok(None)
     }
 }
-
-/// Configuration for the Hermes API integration
-#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
-pub struct HermesConfig {
-    /// Base URL for the Hermes API
-    #[serde(default = "default_hermes_base_url")]
-    pub base_url: String,
-}
-
-impl Default for HermesConfig {
-    fn default() -> Self {
-        Self {
-            base_url: default_hermes_base_url(),
-        }
-    }
-}
-
-fn default_hermes_base_url() -> String {
-    "https://hermes.pyth.network".to_string()
-}

+ 6 - 0
apps/argus/src/config/run.rs

@@ -11,4 +11,10 @@ pub struct RunOptions {
     #[arg(default_value = super::DEFAULT_RPC_ADDR)]
     #[arg(env = "RPC_ADDR")]
     pub addr: SocketAddr,
+
+    /// Base URL for the Hermes API
+    #[arg(long = "hermes-base-url")]
+    #[arg(default_value = super::DEFAULT_HERMES_BASE_URL)]
+    #[arg(env = "HERMES_BASE_URL")]
+    pub hermes_base_url: String,
 }

+ 4 - 0
apps/argus/src/keeper.rs

@@ -59,6 +59,7 @@ pub async fn run_keeper_threads(
     chain_state: BlockchainState,
     metrics: Arc<KeeperMetrics>,
     rpc_metrics: Arc<RpcMetrics>,
+    hermes_base_url: String,
 ) {
     tracing::info!("starting keeper");
     let latest_safe_block = get_latest_safe_block(&chain_state).in_current_span().await;
@@ -89,6 +90,7 @@ pub async fn run_keeper_threads(
             chain_state.clone(),
             metrics.clone(),
             fulfilled_requests_cache.clone(),
+            hermes_base_url.clone(),
         )
         .in_current_span(),
     );
@@ -99,6 +101,7 @@ pub async fn run_keeper_threads(
     let request_check_metrics = metrics.clone();
     let request_check_escalation_policy = chain_eth_config.escalation_policy.to_policy();
     let request_check_fulfilled_requests_cache = fulfilled_requests_cache.clone();
+    let request_check_hermes_base_url = hermes_base_url.clone();
 
     // Spawn a thread to periodically check for active requests
     spawn(
@@ -114,6 +117,7 @@ pub async fn run_keeper_threads(
                     request_check_chain_state.clone(),
                     request_check_metrics.clone(),
                     request_check_fulfilled_requests_cache.clone(),
+                    request_check_hermes_base_url.clone(),
                 )
                 .in_current_span()
                 .await;

+ 9 - 18
apps/argus/src/keeper/hermes.rs

@@ -36,13 +36,12 @@ use {
     ethers::types::Bytes,
     reqwest::Client,
     serde::{Deserialize, Serialize},
-    std::{env, time::Duration},
+    std::time::Duration,
     tracing,
 };
 
-const HERMES_BASE_URL: &str = "https://hermes.pyth.network";
-const HERMES_ENV_VAR: &str = "HERMES_BASE_URL";
 const HERMES_TIMEOUT: Duration = Duration::from_secs(10);
+const DEFAULT_HERMES_BASE_URL: &str = "https://hermes.pyth.network";
 
 /// Binary data response from Hermes API
 #[derive(Debug, Serialize, Deserialize)]
@@ -72,20 +71,10 @@ pub struct HermesClient {
 }
 
 impl HermesClient {
-    /// Create a new Hermes client with the base URL from environment variable or default
+    /// Create a new Hermes client with default configuration
     pub fn new() -> Self {
-        // Create a default config with the default base URL
-        let default_config = crate::config::HermesConfig {
-            base_url: HERMES_BASE_URL.to_string(),
-        };
-        Self::from_config(&default_config)
-    }
-
-    /// Create a new Hermes client with the base URL from the config
-    pub fn from_config(config: &crate::config::HermesConfig) -> Self {
-        // Environment variable takes precedence over config
-        let base_url = env::var(HERMES_ENV_VAR).unwrap_or_else(|_| config.base_url.clone());
-        Self::with_base_url(base_url)
+        // Use the default base URL
+        Self::with_base_url(DEFAULT_HERMES_BASE_URL.to_string())
     }
 
     /// Create a new Hermes client with a custom base URL
@@ -173,12 +162,14 @@ impl Default for HermesClient {
 pub async fn fetch_price_updates_from_hermes(
     publish_time: u64,
     price_ids: &[[u8; 32]],
+    hermes_base_url: String,
 ) -> Result<Vec<Bytes>> {
     const MAX_RETRIES: usize = 3;
     const RETRY_DELAY: std::time::Duration = std::time::Duration::from_millis(500);
 
-    // Use HermesClient::new() which will read from environment variables if available
-    let hermes_client = HermesClient::new();
+    // Create a client with the provided base URL
+    let hermes_client = HermesClient::with_base_url(hermes_base_url);
+
     let mut last_error = None;
 
     for retry in 0..MAX_RETRIES {

+ 8 - 1
apps/argus/src/keeper/request.rs

@@ -51,6 +51,7 @@ pub async fn process_active_requests(
     chain_state: api::BlockchainState,
     metrics: Arc<KeeperMetrics>,
     fulfilled_requests_cache: Arc<RwLock<HashSet<u64>>>,
+    hermes_base_url: String,
 ) {
     tracing::info!("Processing active requests from contract storage");
 
@@ -77,6 +78,7 @@ pub async fn process_active_requests(
                                 gas_limit,
                                 escalation_policy.clone(),
                                 metrics.clone(),
+                                hermes_base_url.clone(),
                             )
                             .in_current_span(),
                         );
@@ -109,6 +111,7 @@ pub async fn process_request_with_backoff(
     gas_limit: U256,
     escalation_policy: EscalationPolicy,
     metrics: Arc<KeeperMetrics>,
+    hermes_base_url: String,
 ) -> Result<()> {
     // We process all price update requests for our provider
     let account_label = AccountLabel {
@@ -129,7 +132,11 @@ pub async fn process_request_with_backoff(
     };
 
     // Fetch price update data from Hermes for the requested price IDs
-    let update_data = fetch_price_updates_from_hermes(request_details.publish_time.as_u64(), &request.price_ids).await?;
+    let update_data = fetch_price_updates_from_hermes(
+        request_details.publish_time.as_u64(),
+        &request.price_ids,
+        hermes_base_url,
+    ).await?;
 
     let contract_call = contract.execute_callback(
         request.sequence_number,