[price-service] Make gap metrics more accurate (#426)
* [price-service] Make gap metrics more accurate * Bump version to 2.2.3
This commit is contained in:
parent
f69a91d97c
commit
f45d6757e2
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@pythnetwork/pyth-price-service",
|
"name": "@pythnetwork/pyth-price-service",
|
||||||
"version": "2.2.2",
|
"version": "2.2.3",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@pythnetwork/pyth-price-service",
|
"name": "@pythnetwork/pyth-price-service",
|
||||||
"version": "2.2.2",
|
"version": "2.2.3",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@certusone/wormhole-sdk": "^0.1.4",
|
"@certusone/wormhole-sdk": "^0.1.4",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@pythnetwork/pyth-price-service",
|
"name": "@pythnetwork/pyth-price-service",
|
||||||
"version": "2.2.2",
|
"version": "2.2.3",
|
||||||
"description": "Pyth Price Service",
|
"description": "Pyth Price Service",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -155,6 +155,28 @@ export class Listener implements PriceStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isNewPriceInfo(
|
||||||
|
cachedInfo: PriceInfo | undefined,
|
||||||
|
observedInfo: PriceInfo
|
||||||
|
): boolean {
|
||||||
|
if (cachedInfo === undefined) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cachedInfo.attestationTime < observedInfo.attestationTime) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
cachedInfo.attestationTime === observedInfo.attestationTime &&
|
||||||
|
cachedInfo.seqNum < observedInfo.seqNum
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
async processVaa(vaa: Buffer) {
|
async processVaa(vaa: Buffer) {
|
||||||
const { parse_vaa } = await importCoreWasm();
|
const { parse_vaa } = await importCoreWasm();
|
||||||
|
|
||||||
|
@ -184,32 +206,9 @@ export class Listener implements PriceStore {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isAnyPriceNew = batchAttestation.priceAttestations.some(
|
|
||||||
(priceAttestation) => {
|
|
||||||
const key = priceAttestation.priceId;
|
|
||||||
const lastAttestationTime =
|
|
||||||
this.priceFeedVaaMap.get(key)?.attestationTime;
|
|
||||||
return (
|
|
||||||
lastAttestationTime === undefined ||
|
|
||||||
lastAttestationTime < priceAttestation.attestationTime
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!isAnyPriceNew) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const priceAttestation of batchAttestation.priceAttestations) {
|
for (const priceAttestation of batchAttestation.priceAttestations) {
|
||||||
const key = priceAttestation.priceId;
|
const key = priceAttestation.priceId;
|
||||||
|
|
||||||
const lastAttestationTime =
|
|
||||||
this.priceFeedVaaMap.get(key)?.attestationTime;
|
|
||||||
|
|
||||||
if (
|
|
||||||
lastAttestationTime === undefined ||
|
|
||||||
lastAttestationTime < priceAttestation.attestationTime
|
|
||||||
) {
|
|
||||||
const priceFeed = priceAttestationToPriceFeed(priceAttestation);
|
const priceFeed = priceAttestationToPriceFeed(priceAttestation);
|
||||||
const priceInfo = {
|
const priceInfo = {
|
||||||
seqNum: parsedVaa.sequence,
|
seqNum: parsedVaa.sequence,
|
||||||
|
@ -220,19 +219,18 @@ export class Listener implements PriceStore {
|
||||||
emitterChainId: parsedVaa.emitter_chain,
|
emitterChainId: parsedVaa.emitter_chain,
|
||||||
priceServiceReceiveTime: Math.floor(new Date().getTime() / 1000),
|
priceServiceReceiveTime: Math.floor(new Date().getTime() / 1000),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const cachedPriceInfo = this.priceFeedVaaMap.get(key);
|
||||||
|
|
||||||
|
if (this.isNewPriceInfo(cachedPriceInfo, priceInfo)) {
|
||||||
this.priceFeedVaaMap.set(key, priceInfo);
|
this.priceFeedVaaMap.set(key, priceInfo);
|
||||||
|
|
||||||
if (lastAttestationTime !== undefined) {
|
if (cachedPriceInfo !== undefined) {
|
||||||
this.promClient?.addPriceUpdatesAttestationTimeGap(
|
this.promClient?.addPriceUpdatesAttestationTimeGap(
|
||||||
priceAttestation.attestationTime - lastAttestationTime
|
priceAttestation.attestationTime - cachedPriceInfo.attestationTime
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
const lastPublishTime = this.priceFeedVaaMap.get(key)?.publishTime;
|
|
||||||
|
|
||||||
if (lastPublishTime !== undefined) {
|
|
||||||
this.promClient?.addPriceUpdatesPublishTimeGap(
|
this.promClient?.addPriceUpdatesPublishTimeGap(
|
||||||
priceAttestation.publishTime - lastPublishTime
|
priceAttestation.publishTime - cachedPriceInfo.publishTime
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue