Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion price_service/server/src/listen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export class Listener implements PriceStore {
private promClient: PromClient | undefined;
private spyServiceHost: string;
private filters: FilterEntry[] = [];
private ignorePricesOlderThanSecs: number;
private spyConnectionTime: TimestampInSec | undefined;
private readinessConfig: ListenerReadinessConfig;
private updateCallbacks: ((priceInfo: PriceInfo) => any)[];
Expand All @@ -156,6 +157,8 @@ export class Listener implements PriceStore {
this.promClient = promClient;
this.spyServiceHost = config.spyServiceHost;
this.loadFilters(config.filtersRaw);
// Don't store any prices received from wormhole that are over 1 hour old.
this.ignorePricesOlderThanSecs = 60 * 60;
this.readinessConfig = config.readiness;
this.updateCallbacks = [];
this.observedVaas = new LRUCache({
Expand Down Expand Up @@ -216,7 +219,7 @@ export class Listener implements PriceStore {
this.processVaa(vaaBytes);
});

this.spyConnectionTime = new Date().getTime() / 1000;
this.spyConnectionTime = this.currentTimeInSeconds();

let connected = true;
stream!.on("error", (err: any) => {
Expand Down Expand Up @@ -252,6 +255,16 @@ export class Listener implements PriceStore {
cachedInfo: PriceInfo | undefined,
observedInfo: PriceInfo
): boolean {
// Sometimes we get old VAAs from wormhole (for unknown reasons). These VAAs can include price feeds that
// were deleted and haven't been updated in a long time. This check filters out such feeds so they don't trigger
// the stale feeds check.
if (
observedInfo.attestationTime <
this.currentTimeInSeconds() - this.ignorePricesOlderThanSecs
) {
return false;
}

if (cachedInfo === undefined) {
return true;
}
Expand Down Expand Up @@ -379,4 +392,8 @@ export class Listener implements PriceStore {

return true;
}

private currentTimeInSeconds(): number {
return new Date().getTime() / 1000;
}
}