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