Quellcode durchsuchen

[wormhole-attester] Fix rate_limit logic (#721)

* [wormhole-attester] Fix rate_limit logic

* Address comments

* Trigger CI
Ali Behjati vor 2 Jahren
Ursprung
Commit
ce68b8e043

+ 1 - 1
wormhole_attester/Cargo.lock

@@ -2693,7 +2693,7 @@ dependencies = [
 
 [[package]]
 name = "pyth-wormhole-attester"
-version = "2.0.0"
+version = "2.0.1"
 dependencies = [
  "borsh",
  "pyth-client",

+ 1 - 1
wormhole_attester/program/Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "pyth-wormhole-attester"
-version = "2.0.0"
+version = "2.0.1"
 description = "Pyth-over-Wormhole Solana contract"
 edition = "2018"
 

+ 16 - 12
wormhole_attester/program/src/attest.rs

@@ -255,21 +255,25 @@ pub fn attest(ctx: &ExecutionContext, accs: &mut Attest, data: AttestData) -> So
             price_struct,
         );
 
+        // Evaluate rate limit - should be smaller than duration from last attestation
+        let trading_publish_time_diff =
+            new_last_attested_trading_publish_time - state.0 .0.last_attested_trading_publish_time;
+        let attestation_time_diff = this_attestation_time - state.0 .0.last_attestation_time;
+
+        // We like to have the rate_limit for trading publish_time because that is the field that
+        // the users consume. Also, when the price is not trading and trading_publish_time is the
+        // same, we still want to send the prices (on a lower frequency).
+        if trading_publish_time_diff >= data.rate_limit_interval_secs as i64
+            || attestation_time_diff >= 2 * data.rate_limit_interval_secs as i64
+        {
+            over_rate_limit = false;
+        } else {
+            trace!("Price {:?}: over rate limit", price.key);
+        }
+
         // Save the new value for the next attestation of this symbol
         state.0 .0.last_attested_trading_publish_time = new_last_attested_trading_publish_time;
 
-        // don't re-evaluate if at least one symbol was found to be under limit
-        if over_rate_limit {
-            // Evaluate rate limit - should be smaller than duration from last attestation
-            if this_attestation_time - state.0 .0.last_attestation_time
-                >= data.rate_limit_interval_secs as i64
-            {
-                over_rate_limit = false;
-            } else {
-                trace!("Price {:?}: over rate limit", price.key);
-            }
-        }
-
         // Update last attestation time
         state.0 .0.last_attestation_time = this_attestation_time;