Skip to content

Commit 7dea578

Browse files
authored
[xc-server] Reliability improvements (#875)
* [xc-server] Bugfix and improvements * Address review comments
1 parent 91ccaee commit 7dea578

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

price_service/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/price-service-server",
3-
"version": "3.0.5",
3+
"version": "3.0.6",
44
"description": "Webservice for retrieving prices from the Pyth oracle.",
55
"private": "true",
66
"main": "index.js",

price_service/server/src/listen.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,12 @@ export class Listener implements PriceStore {
191191
this.spyServiceHost = config.spyServiceHost;
192192
this.loadFilters(config.filtersRaw);
193193
// Don't store any prices received from wormhole that are over 5 minutes old.
194-
this.ignorePricesOlderThanSecs = 5 * 60;
194+
this.ignorePricesOlderThanSecs = 60;
195195
this.readinessConfig = config.readiness;
196196
this.updateCallbacks = [];
197197
this.observedVaas = new LRUCache({
198-
max: 100000, // At most 100000 items
199-
ttl: 6 * 60 * 1000, // 6 minutes which is longer than ignorePricesOlderThanSecs
198+
max: 10000, // At most 10000 items
199+
ttl: 60 * 1000, // 1 minutes which is equal to ignorePricesOlderThanSecs
200200
});
201201
this.vaasCache = new VaaCache(
202202
config.cacheTtl,

price_service/server/src/rest.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,28 @@ export class RestAPI {
523523
endpoints.push("ready");
524524

525525
app.get("/live", (_, res: Response) => {
526-
res.sendStatus(StatusCodes.OK);
526+
const threshold = 60;
527+
const stalePriceTreshold = 10;
528+
529+
const currentTime: TimestampInSec = Math.floor(Date.now() / 1000);
530+
531+
const priceIds = [...this.priceFeedVaaInfo.getPriceIds()];
532+
let stalePriceCnt = 0;
533+
534+
for (const priceId of priceIds) {
535+
const latency =
536+
currentTime -
537+
this.priceFeedVaaInfo.getLatestPriceInfo(priceId)!.attestationTime;
538+
if (latency > threshold) {
539+
stalePriceCnt++;
540+
}
541+
}
542+
543+
if (stalePriceCnt > stalePriceTreshold) {
544+
res.sendStatus(StatusCodes.SERVICE_UNAVAILABLE);
545+
} else {
546+
res.sendStatus(StatusCodes.OK);
547+
}
527548
});
528549
endpoints.push("live");
529550

0 commit comments

Comments
 (0)