Skip to content

Commit

Permalink
cloud_functions: remove globals
Browse files Browse the repository at this point in the history
  • Loading branch information
panoel committed Oct 17, 2023
1 parent df17896 commit 83cee3c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
25 changes: 17 additions & 8 deletions cloud_functions/src/alarmMissingVaas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, GovernedVAA>;

Expand All @@ -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.
Expand Down Expand Up @@ -259,6 +260,14 @@ async function getLastBlockTimeFromFirestore(): Promise<LatestTimeByChain> {
}

async function alarmOldBlockTimes(latestTimes: LatestTimeByChain): Promise<void> {
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<ChainId, AlarmedChainTime> = await getAlarmedChainsFromFirestore();
Expand Down
31 changes: 15 additions & 16 deletions cloud_functions/src/wormchainMonitor.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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') {
Expand All @@ -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);
Expand Down

0 comments on commit 83cee3c

Please sign in to comment.