[xc-server] Reliability improvements (#875)

* [xc-server] Bugfix and improvements

* Address review comments
This commit is contained in:
Ali Behjati 2023-06-11 14:58:36 +02:00 committed by GitHub
parent 91ccaee57c
commit 7dea578416
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 6 deletions

2
package-lock.json generated
View File

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

View File

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

View File

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

View File

@ -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");