Skip to content

Commit 27b44d1

Browse files
authored
Fix crosschain staleness check (#56)
* Fix crosschain staleness check * Cleanup staleness * Drive-by poetry fix
1 parent 7c05112 commit 27b44d1

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ENV \
2727
POETRY_NO_INTERACTION=1
2828

2929
# Install Poetry - respects $POETRY_VERSION & $POETRY_HOME
30-
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python
30+
RUN curl -sSL https://install.python-poetry.org | python
3131
ENV PATH="$POETRY_HOME/bin:$PATH"
3232

3333
WORKDIR $APP_PATH

pyth_observer/check/price_feed.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ def run(self) -> bool:
198198
if not self.__state.crosschain_price["publish_time"]:
199199
return True
200200

201-
staleness = int(time.time()) - self.__state.crosschain_price["publish_time"]
201+
staleness = (
202+
self.__state.crosschain_price["snapshot_time"]
203+
- self.__state.crosschain_price["publish_time"]
204+
)
202205

203206
# Pass if current staleness is less than `max_staleness`
204207
if staleness < self.__max_staleness:

pyth_observer/crosschain.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import time
12
from typing import Dict, TypedDict
23

34
import requests
@@ -11,6 +12,7 @@ class CrosschainPrice(TypedDict):
1112
price: float
1213
conf: float
1314
publish_time: int # UNIX timestamp
15+
snapshot_time: int # UNIX timestamp
1416

1517

1618
class CrosschainPriceObserver:
@@ -51,6 +53,7 @@ async def get_crosschain_prices(self) -> Dict[str, CrosschainPrice]:
5153
"price": int(data["price"]["price"]) * 10 ** data["price"]["expo"],
5254
"conf": int(data["price"]["conf"]) * 10 ** data["price"]["expo"],
5355
"publish_time": data["price"]["publish_time"],
56+
"snapshot_time": int(time.time()),
5457
}
5558
for data in price_feeds
5659
}

tests/test_checks_price_feed.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ def test_price_feed_offline_check():
1616
confidence_interval_aggregate=10.0,
1717
coingecko_price=1005.0,
1818
coingecko_update=0,
19-
crosschain_price={"price": 1003.0, "conf": 10.0, "publish_time": 123},
19+
crosschain_price={
20+
"price": 1003.0,
21+
"conf": 10.0,
22+
"publish_time": 123,
23+
"snapshot_time": 123,
24+
},
2025
)
2126

2227
assert PriceFeedOfflineCheck(

0 commit comments

Comments
 (0)