7
7
getEnvironment ,
8
8
explorerBlock ,
9
9
explorerTx ,
10
+ MISS_THRESHOLD_IN_MINS ,
10
11
} from '@wormhole-foundation/wormhole-monitor-common' ;
11
12
import { Firestore } from 'firebase-admin/firestore' ;
12
13
@@ -88,22 +89,22 @@ export async function alarmMissingVaas(req: any, res: any) {
88
89
if ( messages ) {
89
90
const now = new Date ( ) ;
90
91
const thePast = now ;
91
- thePast . setHours ( now . getHours ( ) - 2 ) ;
92
- const twoHoursAgo = thePast . toISOString ( ) ;
92
+ thePast . setMinutes ( now . getMinutes ( ) - MISS_THRESHOLD_IN_MINS ) ;
93
+ const missThreshold = thePast . toISOString ( ) ;
93
94
for ( const chain of Object . keys ( messages ) ) {
94
95
const chainId = chain as unknown as ChainId ;
95
96
const msgs = messages [ chainId ] ;
96
97
if ( msgs && msgs . messages ) {
97
98
for ( let i = 0 ; i < msgs . messages . length ; i ++ ) {
98
- // Check the timestamp and only send messages that are older than 2 hours
99
+ // Check the timestamp and only send messages that are older than MISS_THRESHOLD_IN_MINS
99
100
const msg : ObservedMessage = msgs . messages [ i ] ;
100
101
// If there is a reference time for this chain, use it. Otherwise, use the current time.
101
- let timeToCheck = twoHoursAgo ;
102
+ let timeToCheck = missThreshold ;
102
103
if ( refTimes [ chainId ] ) {
103
104
let refTime = refTimes [ chainId ] ?. latestTime ;
104
105
if ( refTime ) {
105
106
const refDateTime = new Date ( refTime ) ;
106
- refDateTime . setHours ( refDateTime . getHours ( ) - 2 ) ;
107
+ refDateTime . setMinutes ( refDateTime . getMinutes ( ) - MISS_THRESHOLD_IN_MINS ) ;
107
108
timeToCheck = refDateTime . toISOString ( ) ;
108
109
}
109
110
}
@@ -196,7 +197,7 @@ async function getGovernedVaas(): Promise<GovernedVAAMap> {
196
197
}
197
198
198
199
// This function gets all the VAAs in the firestore table,
199
- // checks the timestamp (keeping any that are less than 2 hours old),
200
+ // checks the timestamp (keeping any that are less than MISS_THRESHOLD_IN_MINS old),
200
201
// and returns a map of those VAAs.
201
202
async function getAndProcessFirestore ( ) : Promise < Map < string , FirestoreVAA > > {
202
203
// Get VAAs in the firestore holding area.
@@ -207,19 +208,19 @@ async function getAndProcessFirestore(): Promise<Map<string, FirestoreVAA>> {
207
208
let current = new Map < string , FirestoreVAA > ( ) ;
208
209
const now = new Date ( ) ;
209
210
const thePast = now ;
210
- thePast . setHours ( now . getHours ( ) - 2 ) ;
211
- const twoHoursAgo = thePast . toISOString ( ) ;
211
+ thePast . setMinutes ( now . getMinutes ( ) - MISS_THRESHOLD_IN_MINS ) ;
212
+ const missThreshold = thePast . toISOString ( ) ;
212
213
await collection
213
214
. doc ( 'VAAs' )
214
215
. get ( )
215
216
. then ( ( doc ) => {
216
217
if ( doc . exists ) {
217
218
const data = doc . data ( ) ;
218
219
if ( data ) {
219
- // if VAA < 2 hours old, leave in firestore
220
+ // if VAA < MISS_THRESHOLD_IN_MINS old, leave in firestore
220
221
const vaas : FirestoreVAA [ ] = data . VAAs ;
221
222
vaas . forEach ( ( vaa ) => {
222
- if ( vaa . noticedTS > twoHoursAgo ) {
223
+ if ( vaa . noticedTS > missThreshold ) {
223
224
// console.log('keeping VAA in firestore', vaa.vaaKey);
224
225
current . set ( vaa . vaaKey , vaa ) ;
225
226
}
0 commit comments