Skip to content

Commit

Permalink
fix: remove unnecessary fresh price filtering (#103)
Browse files Browse the repository at this point in the history
This change removes a check in the code that does not allow multiple
updates within the same timestamp to passthrough. `last_info.timestamp`
is always less than or equal to `info.timestamp`. So, this condition
`last_info.timestamp < info.timestamp` filters newer updates in the same
timestamp and essentially caps our publishing frequency to 1s. It was
intended to work for Solana but the publishing frequency itself takes
care of it. This change might result in increased Sol burn but the
actions to reduce it should be reducing the frequency. Please note that
in some filterings after, the same update prices are ignored so most of
the fee savings should remain there.
  • Loading branch information
ali-bahjati authored Dec 15, 2023
1 parent 04391be commit f08a52a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyth-agent"
version = "2.4.4"
version = "2.4.5"
edition = "2021"

[[bin]]
Expand Down
10 changes: 1 addition & 9 deletions src/agent/solana/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,6 @@ impl Exporter {
// and to ignore stale information.
let fresh_updates = local_store_contents
.into_iter()
.filter(|(identifier, info)| {
// Filter out timestamps older than what we already published
if let Some(last_info) = self.last_published_state.get(identifier) {
last_info.timestamp < info.timestamp
} else {
true // No prior data found, letting the price through
}
})
.filter(|(_identifier, info)| {
// Filter out timestamps that are old
(now - info.timestamp) < self.config.staleness_threshold.as_secs() as i64
Expand All @@ -452,7 +444,7 @@ impl Exporter {
// Filter out unchanged price data if the max delay wasn't reached

if let Some(last_info) = self.last_published_state.get(identifier) {
if (info.timestamp - last_info.timestamp)
if info.timestamp.saturating_sub(last_info.timestamp)
> self.config.unchanged_publish_threshold.as_secs() as i64
{
true // max delay since last published state reached, we publish anyway
Expand Down

0 comments on commit f08a52a

Please sign in to comment.