[xc-server] Reliability improvements (#875)
* [xc-server] Bugfix and improvements * Address review comments
This commit is contained in:
parent
91ccaee57c
commit
7dea578416
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
Loading…
Reference in New Issue