diff --git a/package-lock.json b/package-lock.json index b71b1cdd..4b859021 100644 --- a/package-lock.json +++ b/package-lock.json @@ -57293,7 +57293,7 @@ }, "price_service/server": { "name": "@pythnetwork/price-service-server", - "version": "3.0.5", + "version": "3.0.6", "license": "Apache-2.0", "dependencies": { "@certusone/wormhole-sdk": "^0.9.9", diff --git a/price_service/server/package.json b/price_service/server/package.json index d9fcf978..60123392 100644 --- a/price_service/server/package.json +++ b/price_service/server/package.json @@ -1,6 +1,6 @@ { "name": "@pythnetwork/price-service-server", - "version": "3.0.5", + "version": "3.0.6", "description": "Webservice for retrieving prices from the Pyth oracle.", "private": "true", "main": "index.js", diff --git a/price_service/server/src/listen.ts b/price_service/server/src/listen.ts index c3a351a1..0c83110a 100644 --- a/price_service/server/src/listen.ts +++ b/price_service/server/src/listen.ts @@ -191,12 +191,12 @@ export class Listener implements PriceStore { this.spyServiceHost = config.spyServiceHost; this.loadFilters(config.filtersRaw); // Don't store any prices received from wormhole that are over 5 minutes old. - this.ignorePricesOlderThanSecs = 5 * 60; + this.ignorePricesOlderThanSecs = 60; this.readinessConfig = config.readiness; this.updateCallbacks = []; this.observedVaas = new LRUCache({ - max: 100000, // At most 100000 items - ttl: 6 * 60 * 1000, // 6 minutes which is longer than ignorePricesOlderThanSecs + max: 10000, // At most 10000 items + ttl: 60 * 1000, // 1 minutes which is equal to ignorePricesOlderThanSecs }); this.vaasCache = new VaaCache( config.cacheTtl, diff --git a/price_service/server/src/rest.ts b/price_service/server/src/rest.ts index 5ac4dcc7..3d70ca50 100644 --- a/price_service/server/src/rest.ts +++ b/price_service/server/src/rest.ts @@ -523,7 +523,28 @@ export class RestAPI { endpoints.push("ready"); app.get("/live", (_, res: Response) => { - res.sendStatus(StatusCodes.OK); + const threshold = 60; + const stalePriceTreshold = 10; + + const currentTime: TimestampInSec = Math.floor(Date.now() / 1000); + + const priceIds = [...this.priceFeedVaaInfo.getPriceIds()]; + let stalePriceCnt = 0; + + for (const priceId of priceIds) { + const latency = + currentTime - + this.priceFeedVaaInfo.getLatestPriceInfo(priceId)!.attestationTime; + if (latency > threshold) { + stalePriceCnt++; + } + } + + if (stalePriceCnt > stalePriceTreshold) { + res.sendStatus(StatusCodes.SERVICE_UNAVAILABLE); + } else { + res.sendStatus(StatusCodes.OK); + } }); endpoints.push("live");