@@ -157,13 +157,13 @@ export class Listener implements PriceStore {
157
157
this . promClient = promClient ;
158
158
this . spyServiceHost = config . spyServiceHost ;
159
159
this . loadFilters ( config . filtersRaw ) ;
160
- // Don't store any prices received from wormhole that are over 1 hour old.
161
- this . ignorePricesOlderThanSecs = 60 * 60 ;
160
+ // Don't store any prices received from wormhole that are over 5 minutes old.
161
+ this . ignorePricesOlderThanSecs = 5 * 60 ;
162
162
this . readinessConfig = config . readiness ;
163
163
this . updateCallbacks = [ ] ;
164
164
this . observedVaas = new LRUCache ( {
165
- max : 10000 , // At most 10000 items
166
- ttl : 60 * 1000 , // 60 seconds
165
+ max : 100000 , // At most 100000 items
166
+ ttl : 6 * 60 * 1000 , // 6 minutes which is longer than ignorePricesOlderThanSecs
167
167
} ) ;
168
168
this . vaasCache = new VaaCache (
169
169
config . cacheTtl ,
@@ -255,16 +255,6 @@ export class Listener implements PriceStore {
255
255
cachedInfo : PriceInfo | undefined ,
256
256
observedInfo : PriceInfo
257
257
) : boolean {
258
- // Sometimes we get old VAAs from wormhole (for unknown reasons). These VAAs can include price feeds that
259
- // were deleted and haven't been updated in a long time. This check filters out such feeds so they don't trigger
260
- // the stale feeds check.
261
- if (
262
- observedInfo . attestationTime <
263
- this . currentTimeInSeconds ( ) - this . ignorePricesOlderThanSecs
264
- ) {
265
- return false ;
266
- }
267
-
268
258
if ( cachedInfo === undefined ) {
269
259
return true ;
270
260
}
@@ -289,19 +279,17 @@ export class Listener implements PriceStore {
289
279
const vaaEmitterAddressHex = Buffer . from ( parsedVaa . emitterAddress ) . toString (
290
280
"hex"
291
281
) ;
282
+
292
283
const observedVaasKey : VaaKey = `${ parsedVaa . emitterChain } #${ vaaEmitterAddressHex } #${ parsedVaa . sequence } ` ;
293
284
294
285
if ( this . observedVaas . has ( observedVaasKey ) ) {
295
286
return ;
296
287
}
297
288
298
- this . observedVaas . set ( observedVaasKey , true ) ;
299
- this . promClient ?. incReceivedVaa ( ) ;
300
-
301
289
let batchAttestation ;
302
290
303
291
try {
304
- batchAttestation = await parseBatchPriceAttestation (
292
+ batchAttestation = parseBatchPriceAttestation (
305
293
Buffer . from ( parsedVaa . payload )
306
294
) ;
307
295
} catch ( e : any ) {
@@ -310,6 +298,29 @@ export class Listener implements PriceStore {
310
298
return ;
311
299
}
312
300
301
+ if ( batchAttestation . priceAttestations . length === 0 ) {
302
+ return ;
303
+ }
304
+
305
+ // Attestation time is the same in all feeds in the batch.
306
+ // Return early if an attestation is old to exclude it from
307
+ // the counter metric.
308
+ if (
309
+ batchAttestation . priceAttestations [ 0 ] . attestationTime <
310
+ this . currentTimeInSeconds ( ) - this . ignorePricesOlderThanSecs
311
+ ) {
312
+ return ;
313
+ }
314
+
315
+ // There is no `await` clause to release the current thread since the previous check
316
+ // but this is here to ensure this is correct as the code evolves.
317
+ if ( this . observedVaas . has ( observedVaasKey ) ) {
318
+ return ;
319
+ } else {
320
+ this . observedVaas . set ( observedVaasKey , true ) ;
321
+ this . promClient ?. incReceivedVaa ( ) ;
322
+ }
323
+
313
324
for ( const priceAttestation of batchAttestation . priceAttestations ) {
314
325
const key = priceAttestation . priceId ;
315
326
0 commit comments