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