[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",
|
||||
"version": "2.2.2",
|
||||
"version": "2.2.3",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@pythnetwork/pyth-price-service",
|
||||
"version": "2.2.2",
|
||||
"version": "2.2.3",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@certusone/wormhole-sdk": "^0.1.4",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@pythnetwork/pyth-price-service",
|
||||
"version": "2.2.2",
|
||||
"version": "2.2.3",
|
||||
"description": "Pyth Price Service",
|
||||
"main": "index.js",
|
||||
"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) {
|
||||
const { parse_vaa } = await importCoreWasm();
|
||||
|
||||
|
@ -184,55 +206,31 @@ export class Listener implements PriceStore {
|
|||
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) {
|
||||
const key = priceAttestation.priceId;
|
||||
|
||||
const lastAttestationTime =
|
||||
this.priceFeedVaaMap.get(key)?.attestationTime;
|
||||
const priceFeed = priceAttestationToPriceFeed(priceAttestation);
|
||||
const priceInfo = {
|
||||
seqNum: parsedVaa.sequence,
|
||||
vaa,
|
||||
publishTime: priceAttestation.publishTime,
|
||||
attestationTime: priceAttestation.attestationTime,
|
||||
priceFeed,
|
||||
emitterChainId: parsedVaa.emitter_chain,
|
||||
priceServiceReceiveTime: Math.floor(new Date().getTime() / 1000),
|
||||
};
|
||||
|
||||
if (
|
||||
lastAttestationTime === undefined ||
|
||||
lastAttestationTime < priceAttestation.attestationTime
|
||||
) {
|
||||
const priceFeed = priceAttestationToPriceFeed(priceAttestation);
|
||||
const priceInfo = {
|
||||
seqNum: parsedVaa.sequence,
|
||||
vaa,
|
||||
publishTime: priceAttestation.publishTime,
|
||||
attestationTime: priceAttestation.attestationTime,
|
||||
priceFeed,
|
||||
emitterChainId: parsedVaa.emitter_chain,
|
||||
priceServiceReceiveTime: Math.floor(new Date().getTime() / 1000),
|
||||
};
|
||||
const cachedPriceInfo = this.priceFeedVaaMap.get(key);
|
||||
|
||||
if (this.isNewPriceInfo(cachedPriceInfo, priceInfo)) {
|
||||
this.priceFeedVaaMap.set(key, priceInfo);
|
||||
|
||||
if (lastAttestationTime !== undefined) {
|
||||
if (cachedPriceInfo !== undefined) {
|
||||
this.promClient?.addPriceUpdatesAttestationTimeGap(
|
||||
priceAttestation.attestationTime - lastAttestationTime
|
||||
priceAttestation.attestationTime - cachedPriceInfo.attestationTime
|
||||
);
|
||||
}
|
||||
|
||||
const lastPublishTime = this.priceFeedVaaMap.get(key)?.publishTime;
|
||||
|
||||
if (lastPublishTime !== undefined) {
|
||||
this.promClient?.addPriceUpdatesPublishTimeGap(
|
||||
priceAttestation.publishTime - lastPublishTime
|
||||
priceAttestation.publishTime - cachedPriceInfo.publishTime
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue