Skip to content

Commit 7fd896f

Browse files
committed
fix(contracts/pyth): allow same publish_time re-submissions
prevents oracle price staleness Signed-off-by: Artur Troian <troian@users.noreply.github.com>
1 parent 9df8eb2 commit 7fd896f

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
lines changed

Cargo.lock

Lines changed: 19 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ members = [
99
version = "0.0.1"
1010
authors = ["Artur Troian <troian.ap@gmail.com>"]
1111
edition = "2021"
12-
rust-version = "1.93.0"
12+
rust-version = "1.86.0"
1313

1414
[profile.release]
1515
opt-level = 3

contracts/pyth/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"
3-
version = "1.0.0"
3+
version = "1.0.1"
44
authors = ["Artur Troian <troian.ap@gmail.com"]
55
edition = "2021"
66
description = "Pyth price feed consumer contract for Akash Network"

contracts/pyth/src/contract.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,21 +247,26 @@ pub fn execute_update_price_feed(
247247
// Load existing price feed to get previous publish time
248248
let mut price_feed = PRICE_FEED.load(deps.storage)?;
249249

250-
// Ensure new price is not older than current price
251-
if publish_time <= price_feed.publish_time {
250+
// Reject truly older prices
251+
if publish_time < price_feed.publish_time {
252252
return Err(ContractError::InvalidPriceData {
253-
reason: "price data is not newer than current data".to_string(),
253+
reason: "price data is older than current data".to_string(),
254254
});
255255
}
256256

257-
// Update price feed in contract storage
258-
price_feed.prev_publish_time = price_feed.publish_time;
259-
price_feed.price = price;
260-
price_feed.conf = conf;
261-
price_feed.expo = expo;
262-
price_feed.publish_time = publish_time;
263-
264-
PRICE_FEED.save(deps.storage, &price_feed)?;
257+
// Update contract storage only if price is actually newer.
258+
// When publish_time == stored, skip the storage write but still
259+
// forward to x/oracle below to refresh the block height and
260+
// prevent the oracle price from going stale.
261+
if publish_time > price_feed.publish_time {
262+
price_feed.prev_publish_time = price_feed.publish_time;
263+
price_feed.price = price;
264+
price_feed.conf = conf;
265+
price_feed.expo = expo;
266+
price_feed.publish_time = publish_time;
267+
268+
PRICE_FEED.save(deps.storage, &price_feed)?;
269+
}
265270

266271
// Convert Pyth price to decimal string for x/oracle module
267272
let price_decimal = pyth_price_to_decimal(pyth_price.price, expo);

0 commit comments

Comments
 (0)