From 83cee3c3280bb2126a2ad34788dea3c4431f6218 Mon Sep 17 00:00:00 2001 From: Paul Noel Date: Tue, 17 Oct 2023 15:21:39 -0500 Subject: [PATCH] cloud_functions: remove globals --- cloud_functions/src/alarmMissingVaas.ts | 25 +++++++++++++------- cloud_functions/src/wormchainMonitor.ts | 31 ++++++++++++------------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/cloud_functions/src/alarmMissingVaas.ts b/cloud_functions/src/alarmMissingVaas.ts index df19cac6..40649466 100644 --- a/cloud_functions/src/alarmMissingVaas.ts +++ b/cloud_functions/src/alarmMissingVaas.ts @@ -31,14 +31,6 @@ interface GovernedVAA { txHash: string; } -const alarmSlackInfo: SlackInfo = { - channelId: assertEnvironmentVariable('MISSING_VAA_SLACK_CHANNEL_ID'), - postUrl: assertEnvironmentVariable('MISSING_VAA_SLACK_POST_URL'), - botToken: assertEnvironmentVariable('MISSING_VAA_SLACK_BOT_TOKEN'), - bannerTxt: 'Wormhole Missing VAA Alarm', - msg: '', -}; - // The key is the vaaKey type GovernedVAAMap = Map; @@ -52,6 +44,15 @@ export async function alarmMissingVaas(req: any, res: any) { res.status(204).send(''); return; } + + const alarmSlackInfo: SlackInfo = { + channelId: assertEnvironmentVariable('MISSING_VAA_SLACK_CHANNEL_ID'), + postUrl: assertEnvironmentVariable('MISSING_VAA_SLACK_POST_URL'), + botToken: assertEnvironmentVariable('MISSING_VAA_SLACK_BOT_TOKEN'), + bannerTxt: 'Wormhole Missing VAA Alarm', + msg: '', + }; + let firestoreVAAs: FirestoreVAA[] = []; try { // Get the current VAAs in the firestore holding area that we want to keep there. @@ -259,6 +260,14 @@ async function getLastBlockTimeFromFirestore(): Promise { } async function alarmOldBlockTimes(latestTimes: LatestTimeByChain): Promise { + const alarmSlackInfo: SlackInfo = { + channelId: assertEnvironmentVariable('MISSING_VAA_SLACK_CHANNEL_ID'), + postUrl: assertEnvironmentVariable('MISSING_VAA_SLACK_POST_URL'), + botToken: assertEnvironmentVariable('MISSING_VAA_SLACK_BOT_TOKEN'), + bannerTxt: 'Wormhole Missing VAA Alarm', + msg: '', + }; + let alarmsToStore: AlarmedChainTime[] = []; // Read in the already alarmed chains. const alarmedChains: Map = await getAlarmedChainsFromFirestore(); diff --git a/cloud_functions/src/wormchainMonitor.ts b/cloud_functions/src/wormchainMonitor.ts index 938ca2cc..7fc44cb8 100644 --- a/cloud_functions/src/wormchainMonitor.ts +++ b/cloud_functions/src/wormchainMonitor.ts @@ -1,5 +1,4 @@ import axios from 'axios'; -import * as fs from 'fs'; import { assertEnvironmentVariable, formatAndSendToSlack, sendToPagerDuty } from './utils'; import { PagerDutyInfo, SlackInfo } from './types'; import { evmosRPCs } from './data/evmosRPCs.json'; @@ -50,21 +49,6 @@ const chainInfos: ClientInfo[] = [ }, ]; -const wcSlackInfo: SlackInfo = { - channelId: assertEnvironmentVariable('WORMCHAIN_SLACK_CHANNEL_ID'), - postUrl: assertEnvironmentVariable('WORMCHAIN_SLACK_POST_URL'), - botToken: assertEnvironmentVariable('WORMCHAIN_SLACK_BOT_TOKEN'), - bannerTxt: 'Pending light client expiration', - msg: '', -}; - -const wcPagerDutyInfo: PagerDutyInfo = { - url: assertEnvironmentVariable('WORMCHAIN_PAGERDUTY_URL'), - routingKey: assertEnvironmentVariable('WORMCHAIN_PAGERDUTY_ROUTING_KEY'), - source: 'wormchainMonitor cloud function', - summary: '', -}; - export async function wormchainMonitor(req: any, res: any) { res.set('Access-Control-Allow-Origin', '*'); if (req.method === 'OPTIONS') { @@ -75,6 +59,21 @@ export async function wormchainMonitor(req: any, res: any) { res.status(204).send(''); return; } + + const wcSlackInfo: SlackInfo = { + channelId: assertEnvironmentVariable('WORMCHAIN_SLACK_CHANNEL_ID'), + postUrl: assertEnvironmentVariable('WORMCHAIN_SLACK_POST_URL'), + botToken: assertEnvironmentVariable('WORMCHAIN_SLACK_BOT_TOKEN'), + bannerTxt: 'Pending light client expiration', + msg: '', + }; + + const wcPagerDutyInfo: PagerDutyInfo = { + url: assertEnvironmentVariable('WORMCHAIN_PAGERDUTY_URL'), + routingKey: assertEnvironmentVariable('WORMCHAIN_PAGERDUTY_ROUTING_KEY'), + source: 'wormchainMonitor cloud function', + summary: '', + }; for (const info of chainInfos) { // Get wormchain info from wormchain let retrievedInfo: RetrievedInfo = await getClientInfo(WormchainRPCs, info.wormchainClientId);