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,
|
||||
{
|
||||
priceFeed: dummyPriceFeed(id),
|
||||
receiveTime: 0,
|
||||
attestationTime: 0,
|
||||
seqNum,
|
||||
vaaBytes: Buffer.from(vaa, "hex").toString("binary"),
|
||||
},
|
||||
|
|
|
@ -29,7 +29,7 @@ import { HexString, PriceFeed } from "@pythnetwork/pyth-sdk-js";
|
|||
export type PriceInfo = {
|
||||
vaaBytes: string;
|
||||
seqNum: number;
|
||||
receiveTime: TimestampInSec;
|
||||
attestationTime: TimestampInSec;
|
||||
priceFeed: PriceFeed;
|
||||
};
|
||||
|
||||
|
@ -168,8 +168,8 @@ export class Listener implements PriceStore {
|
|||
let isAnyPriceNew = batchAttestation.priceAttestations.some(
|
||||
(priceAttestation) => {
|
||||
const key = priceAttestation.priceId;
|
||||
let lastSeqNum = this.priceFeedVaaMap.get(key)?.seqNum;
|
||||
return lastSeqNum === undefined || lastSeqNum < parsedVAA.sequence;
|
||||
let lastAttestationTime = this.priceFeedVaaMap.get(key)?.attestationTime;
|
||||
return lastAttestationTime === undefined || lastAttestationTime < priceAttestation.attestationTime;
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -180,13 +180,14 @@ export class Listener implements PriceStore {
|
|||
for (let priceAttestation of batchAttestation.priceAttestations) {
|
||||
const key = priceAttestation.priceId;
|
||||
|
||||
let lastSeqNum = this.priceFeedVaaMap.get(key)?.seqNum;
|
||||
if (lastSeqNum === undefined || lastSeqNum < parsedVAA.sequence) {
|
||||
let lastAttestationTime = this.priceFeedVaaMap.get(key)?.attestationTime;
|
||||
|
||||
if (lastAttestationTime === undefined || lastAttestationTime < priceAttestation.attestationTime) {
|
||||
const priceFeed = priceAttestationToPriceFeed(priceAttestation);
|
||||
this.priceFeedVaaMap.set(key, {
|
||||
seqNum: parsedVAA.sequence,
|
||||
vaaBytes: vaaBytes,
|
||||
receiveTime: new Date().getTime() / 1000,
|
||||
attestationTime: priceAttestation.attestationTime,
|
||||
priceFeed,
|
||||
});
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ export class RestAPI {
|
|||
}
|
||||
|
||||
const freshness: DurationInSec =
|
||||
new Date().getTime() / 1000 - latestPriceInfo.receiveTime;
|
||||
new Date().getTime() / 1000 - latestPriceInfo.attestationTime;
|
||||
this.promClient?.addApiRequestsPriceFreshness(
|
||||
req.path,
|
||||
id,
|
||||
|
@ -159,7 +159,7 @@ export class RestAPI {
|
|||
}
|
||||
|
||||
const freshness: DurationInSec =
|
||||
new Date().getTime() / 1000 - latestPriceInfo.receiveTime;
|
||||
new Date().getTime() / 1000 - latestPriceInfo.attestationTime;
|
||||
this.promClient?.addApiRequestsPriceFreshness(
|
||||
req.path,
|
||||
id,
|
||||
|
|
Loading…
Reference in New Issue