Переглянути джерело

wormhole-attester: hotfix a bug on the `enable_healthcheck` option

This commit hardens the attester to actually use the attestation_cfg
defaults for the healthcheck settings. Additionally, we use the
constructor to assign healthcheck state from user-supplied
config. This provides better protection against missing assignments to
the struct.
Stan Drozd 2 роки тому
батько
коміт
83b975fdc2

+ 2 - 1
solana/pyth2wormhole/client/src/healthcheck.rs

@@ -1,4 +1,5 @@
 use {
+    crate::attestation_cfg,
     std::{
         collections::VecDeque,
         sync::Arc,
@@ -7,7 +8,7 @@ use {
 };
 
 lazy_static::lazy_static! {
-    pub static ref HEALTHCHECK_STATE: Arc<Mutex<HealthCheckState>> = Arc::new(Mutex::new(HealthCheckState::new(1, false)));
+    pub static ref HEALTHCHECK_STATE: Arc<Mutex<HealthCheckState>> = Arc::new(Mutex::new(HealthCheckState::new(attestation_cfg::default_healthcheck_window_size as usize, attestation_cfg::default_enable_healthcheck())));
 }
 
 /// Helper structure for deciding service health

+ 15 - 11
solana/pyth2wormhole/client/src/main.rs

@@ -41,6 +41,7 @@ use {
         gen_set_config_tx,
         gen_set_is_active_tx,
         get_config_account,
+        healthcheck::HealthCheckState,
         start_metrics_server,
         AttestationConfig,
         BatchState,
@@ -304,17 +305,20 @@ async fn handle_attest_daemon_mode(
     metrics_bind_addr: SocketAddr,
 ) -> Result<(), ErrBox> {
     // Update healthcheck window size from config
-    if attestation_cfg.enable_healthcheck {
-        if attestation_cfg.healthcheck_window_size == 0 {
-            return Err(format!(
-                "{} must be above 0",
-                stringify!(attestation_cfg.healthcheck_window_size)
-            )
-            .into());
-        }
-        let mut hc = HEALTHCHECK_STATE.lock().await;
-        hc.max_window_size = attestation_cfg.healthcheck_window_size as usize;
-    } else {
+    if attestation_cfg.healthcheck_window_size == 0 {
+        return Err(format!(
+            "{} must be above 0",
+            stringify!(attestation_cfg.healthcheck_window_size)
+        )
+        .into());
+    }
+    let mut hc = HEALTHCHECK_STATE.lock().await;
+    *hc = HealthCheckState::new(
+        attestation_cfg.healthcheck_window_size as usize,
+        attestation_cfg.enable_healthcheck,
+    );
+
+    if !attestation_cfg.enable_healthcheck {
         warn!("WARNING: Healthcheck is disabled");
     }