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

* [wormhole-attester] Fix rate_limit logic

* Address comments

* Trigger CI
This commit is contained in:
Ali Behjati 2023-03-28 18:06:00 +02:00 committed by GitHub
parent 272f11aac2
commit ce68b8e043
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 14 deletions

View File

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

View File

@ -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"

View File

@ -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;