Skip to content

Commit

Permalink
cloud_functions: clean up alarmMissingVAAs.
Browse files Browse the repository at this point in the history
  • Loading branch information
panoel committed Jun 6, 2024
1 parent c1499ae commit b4a7fea
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions cloud_functions/src/alarmMissingVaas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChainId, Network } from '@wormhole-foundation/sdk-base';
import { ChainId, Network, toChainId } from '@wormhole-foundation/sdk-base';
import {
MISS_THRESHOLD_IN_MINS,
explorerBlock,
Expand Down Expand Up @@ -92,7 +92,7 @@ export async function alarmMissingVaas(req: any, res: any) {
thePast.setMinutes(now.getMinutes() - MISS_THRESHOLD_IN_MINS);
const missThreshold = thePast.toISOString();
for (const chain of Object.keys(messages)) {
const chainId = chain as unknown as ChainId;
const chainId: ChainId = toChainId(Number(chain));
const msgs = messages[chainId];
if (msgs && msgs.messages) {
for (let i = 0; i < msgs.messages.length; i++) {
Expand Down Expand Up @@ -154,7 +154,7 @@ export async function alarmMissingVaas(req: any, res: any) {
return;
}

// This function gets all the enqueued VAAs from he governorStatus collection.
// This function gets all the enqueued VAAs from the governorStatus collection.
async function getGovernedVaas(): Promise<GovernedVAAMap> {
const vaas: GovernedVAAMap = new Map<string, GovernedVAA>();
// Walk all the guardians and retrieve the enqueued VAAs
Expand Down Expand Up @@ -292,8 +292,8 @@ function convert(msg: ObservedMessage): FirestoreVAA {
function formatMessage(msg: ObservedMessage): string {
const cName: string = chainIdToName(msg.chain);
const vaaKeyUrl: string = `https://wormholescan.io/#/tx/${msg.chain}/${msg.emitter}/${msg.seq}`;
const txHashUrl: string = explorerTx(network, msg.chain as ChainId, msg.txHash);
const blockUrl: string = explorerBlock(network, msg.chain as ChainId, msg.block.toString());
const txHashUrl: string = explorerTx(network, toChainId(msg.chain), msg.txHash);
const blockUrl: string = explorerBlock(network, toChainId(msg.chain), msg.block.toString());
const formattedMsg = `*Chain:* ${cName}(${msg.chain})\n*TxHash:* <${txHashUrl}|${msg.txHash}>\n*VAA Key:* <${vaaKeyUrl}|${msg.chain}/${msg.emitter}/${msg.seq}> \n*Block:* <${blockUrl}|${msg.block}> \n*Timestamp:* ${msg.timestamp}`;
return formattedMsg;
}
Expand All @@ -310,7 +310,7 @@ async function getLastBlockTimeFromFirestore(): Promise<LatestTimeByChain> {
snapshot.docs
.sort((a, b) => Number(a.id) - Number(b.id))
.forEach((doc) => {
values[Number(doc.id) as ChainId] = { latestTime: doc.data().lastBlockKey.split('/')[1] };
values[toChainId(Number(doc.id))] = { latestTime: doc.data().lastBlockKey.split('/')[1] };
});
} catch (e) {
console.error(e);
Expand Down Expand Up @@ -338,7 +338,7 @@ async function alarmOldBlockTimes(latestTimes: LatestTimeByChain): Promise<void>
// Walk all chains and check the latest block time.
const now = new Date();
for (const chain of Object.keys(latestTimes)) {
const chainId: ChainId = chain as any as ChainId;
const chainId: ChainId = toChainId(Number(chain));
const latestTime: string | undefined = latestTimes[chainId]?.latestTime;
if (!latestTime) {
continue;
Expand Down

0 comments on commit b4a7fea

Please sign in to comment.