Use attestationTime instead of seqnum (#226)
SeqNum is not suitable for multiple sources, attestationTime is good but we should be careful of solana clock falling behind Also use this time for freshness metric because it's more useful.
This commit is contained in:
parent
a0d47178bf
commit
1a12005fbf
|
@ -40,7 +40,7 @@ function dummyPriceInfoPair(
|
||||||
id,
|
id,
|
||||||
{
|
{
|
||||||
priceFeed: dummyPriceFeed(id),
|
priceFeed: dummyPriceFeed(id),
|
||||||
receiveTime: 0,
|
attestationTime: 0,
|
||||||
seqNum,
|
seqNum,
|
||||||
vaaBytes: Buffer.from(vaa, "hex").toString("binary"),
|
vaaBytes: Buffer.from(vaa, "hex").toString("binary"),
|
||||||
},
|
},
|
||||||
|
|
|
@ -29,7 +29,7 @@ import { HexString, PriceFeed } from "@pythnetwork/pyth-sdk-js";
|
||||||
export type PriceInfo = {
|
export type PriceInfo = {
|
||||||
vaaBytes: string;
|
vaaBytes: string;
|
||||||
seqNum: number;
|
seqNum: number;
|
||||||
receiveTime: TimestampInSec;
|
attestationTime: TimestampInSec;
|
||||||
priceFeed: PriceFeed;
|
priceFeed: PriceFeed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -168,8 +168,8 @@ export class Listener implements PriceStore {
|
||||||
let isAnyPriceNew = batchAttestation.priceAttestations.some(
|
let isAnyPriceNew = batchAttestation.priceAttestations.some(
|
||||||
(priceAttestation) => {
|
(priceAttestation) => {
|
||||||
const key = priceAttestation.priceId;
|
const key = priceAttestation.priceId;
|
||||||
let lastSeqNum = this.priceFeedVaaMap.get(key)?.seqNum;
|
let lastAttestationTime = this.priceFeedVaaMap.get(key)?.attestationTime;
|
||||||
return lastSeqNum === undefined || lastSeqNum < parsedVAA.sequence;
|
return lastAttestationTime === undefined || lastAttestationTime < priceAttestation.attestationTime;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -180,13 +180,14 @@ export class Listener implements PriceStore {
|
||||||
for (let priceAttestation of batchAttestation.priceAttestations) {
|
for (let priceAttestation of batchAttestation.priceAttestations) {
|
||||||
const key = priceAttestation.priceId;
|
const key = priceAttestation.priceId;
|
||||||
|
|
||||||
let lastSeqNum = this.priceFeedVaaMap.get(key)?.seqNum;
|
let lastAttestationTime = this.priceFeedVaaMap.get(key)?.attestationTime;
|
||||||
if (lastSeqNum === undefined || lastSeqNum < parsedVAA.sequence) {
|
|
||||||
|
if (lastAttestationTime === undefined || lastAttestationTime < priceAttestation.attestationTime) {
|
||||||
const priceFeed = priceAttestationToPriceFeed(priceAttestation);
|
const priceFeed = priceAttestationToPriceFeed(priceAttestation);
|
||||||
this.priceFeedVaaMap.set(key, {
|
this.priceFeedVaaMap.set(key, {
|
||||||
seqNum: parsedVAA.sequence,
|
seqNum: parsedVAA.sequence,
|
||||||
vaaBytes: vaaBytes,
|
vaaBytes: vaaBytes,
|
||||||
receiveTime: new Date().getTime() / 1000,
|
attestationTime: priceAttestation.attestationTime,
|
||||||
priceFeed,
|
priceFeed,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ export class RestAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
const freshness: DurationInSec =
|
const freshness: DurationInSec =
|
||||||
new Date().getTime() / 1000 - latestPriceInfo.receiveTime;
|
new Date().getTime() / 1000 - latestPriceInfo.attestationTime;
|
||||||
this.promClient?.addApiRequestsPriceFreshness(
|
this.promClient?.addApiRequestsPriceFreshness(
|
||||||
req.path,
|
req.path,
|
||||||
id,
|
id,
|
||||||
|
@ -159,7 +159,7 @@ export class RestAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
const freshness: DurationInSec =
|
const freshness: DurationInSec =
|
||||||
new Date().getTime() / 1000 - latestPriceInfo.receiveTime;
|
new Date().getTime() / 1000 - latestPriceInfo.attestationTime;
|
||||||
this.promClient?.addApiRequestsPriceFreshness(
|
this.promClient?.addApiRequestsPriceFreshness(
|
||||||
req.path,
|
req.path,
|
||||||
id,
|
id,
|
||||||
|
|
Loading…
Reference in New Issue