Skip to content

Commit ce68b8e

Browse files
authored
[wormhole-attester] Fix rate_limit logic (#721)
* [wormhole-attester] Fix rate_limit logic * Address comments * Trigger CI
1 parent 272f11a commit ce68b8e

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

wormhole_attester/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wormhole_attester/program/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-wormhole-attester"
3-
version = "2.0.0"
3+
version = "2.0.1"
44
description = "Pyth-over-Wormhole Solana contract"
55
edition = "2018"
66

wormhole_attester/program/src/attest.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)