Skip to content

Commit af5b937

Browse files
committed
cloud_functions: use getNetwork()
1 parent 53a55a7 commit af5b937

File tree

5 files changed

+46
-24
lines changed

5 files changed

+46
-24
lines changed

cloud_functions/src/alarmMissingVaas.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ async function getAndProcessFirestore(): Promise<Map<string, FirestoreVAA>> {
214214
const vaas: FirestoreVAA[] = data.VAAs;
215215
vaas.forEach((vaa) => {
216216
// vaa.chain is guaranteed to be a string representation of a number e.g. "34"
217-
if (vaa.noticedTS > getMissThreshold(now, toChainId(Number(vaa.chain)))) {
217+
if (vaa.noticedTS > getMissThreshold(now, vaa.chain)) {
218218
// console.log('keeping VAA in firestore', vaa.vaaKey);
219219
current.set(vaa.vaaKey, vaa);
220220
}

cloud_functions/src/getMissingVaas.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Storage } from '@google-cloud/storage';
22
import { ObservedMessage } from './types';
3-
import { assertEnvironmentVariable } from './utils';
43
import { ChainId } from '@wormhole-foundation/sdk-base';
4+
import { getNetwork } from '@wormhole-foundation/wormhole-monitor-common';
55

66
// Read from cloud storage
77
const storage = new Storage();
@@ -17,7 +17,7 @@ export type MissingVaasByChain = {
1717
export async function commonGetMissingVaas(): Promise<MissingVaasByChain> {
1818
// The ID of your GCS bucket
1919
let bucketName: string = 'wormhole-observed-blocks-cache';
20-
if (assertEnvironmentVariable('NETWORK') === 'TESTNET') {
20+
if (getNetwork() === 'Testnet') {
2121
bucketName = 'wormhole-observed-blocks-cache-testnet';
2222
}
2323
const cacheBucket = storage.bucket(bucketName);

common/src/consts.ts

+27-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { Chain, ChainId, Network, chainToChainId, toChain, toChainId } from '@wormhole-foundation/sdk-base';
1+
import {
2+
Chain,
3+
ChainId,
4+
Network,
5+
chainToChainId,
6+
toChain,
7+
toChainId,
8+
} from '@wormhole-foundation/sdk-base';
29

310
export type Mode = 'vaa' | 'ntt';
411

@@ -98,14 +105,29 @@ export const INITIAL_NTT_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN: {
98105
['Devnet']: {},
99106
};
100107

101-
export function getMissThreshold(date: Date, chainId: ChainId): string {
102-
const missThresholdInMins = chainId === toChainId("Scroll") ? 120 : MISS_THRESHOLD_IN_MINS_DEFAULT;
103-
const missDate = new Date(date);
108+
export function getMissThreshold(date: Date, chainish: number | string | Chain | ChainId): string {
109+
// We would like chainish to really be a ChainId.
110+
let missThresholdInMins: number;
111+
try {
112+
let chainId: ChainId;
113+
if (typeof chainish === 'string' && !Number.isNaN(Number(chainish))) {
114+
// e.g. Handle '1'
115+
chainId = toChainId(Number(chainish));
116+
} else {
117+
// At this point we either have a number, a non-number string, a Chain, or a ChainId
118+
chainId = toChainId(chainish);
119+
}
120+
missThresholdInMins = chainId === toChainId('Scroll') ? 120 : MISS_THRESHOLD_IN_MINS_DEFAULT;
121+
} catch (e) {
122+
// If we can't get the chainId, we'll use the default value.
123+
missThresholdInMins = MISS_THRESHOLD_IN_MINS_DEFAULT;
124+
}
125+
const missDate = date;
104126
missDate.setMinutes(missDate.getMinutes() - missThresholdInMins);
105127
return missDate.toISOString();
106128
}
107129

108-
export const TOKEN_BRIDGE_EMITTERS: { [key in Chain]?: string } = {
130+
export const TOKEN_BRIDGE_EMITTERS: { [key in Chain]?: string } = {
109131
Solana: 'ec7372995d5cc8732397fb0ad35c0121e0eaa90d26f828a534cab54391b3a4f5',
110132
Ethereum: '0000000000000000000000003ee18b2214aff97000d974cf647e7c347e8fa585',
111133
Terra: '0000000000000000000000007cf7b764e38a0a5e967972c1df77d432510564e2',

dashboard/src/components/Monitor.tsx

+14-14
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import {
1616
Tooltip,
1717
Typography,
1818
} from '@mui/material';
19-
import { chainIdToChain, toChainId } from '@wormhole-foundation/sdk-base';
19+
import { ChainId, chainIdToChain } from '@wormhole-foundation/sdk-base';
2020
import {
2121
MISS_THRESHOLD_LABEL,
2222
explorerBlock,
2323
explorerTx,
2424
explorerVaa,
25-
getMissThreshold
25+
getMissThreshold,
2626
} from '@wormhole-foundation/wormhole-monitor-common';
2727
import axios from 'axios';
2828
import { useCallback, useEffect, useMemo, useState } from 'react';
@@ -78,7 +78,7 @@ function BlockDetail({ chain, message }: { chain: string; message: ObservedMessa
7878
gutterBottom
7979
>
8080
<IconButton
81-
href={explorerTx(network, toChainId(Number(chain)), message.txHash)}
81+
href={explorerTx(network, Number(chain) as ChainId, message.txHash)}
8282
target="_blank"
8383
size="small"
8484
sx={inlineIconButtonSx}
@@ -106,7 +106,7 @@ function BlockDetail({ chain, message }: { chain: string; message: ObservedMessa
106106
<Typography gutterBottom>
107107
Block {message.block}{' '}
108108
<IconButton
109-
href={explorerBlock(network, toChainId(Number(chain)), message.block.toString())}
109+
href={explorerBlock(network, Number(chain) as ChainId, message.block.toString())}
110110
target="_blank"
111111
size="small"
112112
sx={inlineIconButtonSx}
@@ -240,7 +240,7 @@ function ReobserveCodeContent({ misses }: { misses: MissesByChain }) {
240240
.map(([chain, info]) => {
241241
const filteredMisses = showAllMisses
242242
? info.messages
243-
: info.messages.filter((message) => message.timestamp < getMissThreshold(now, toChainId(Number(chain))));
243+
: info.messages.filter((message) => message.timestamp < getMissThreshold(now, chain));
244244
return filteredMisses.length === 0
245245
? null
246246
: filteredMisses
@@ -295,7 +295,7 @@ function Misses({
295295
const filteredMisses = showAllMisses
296296
? info.messages
297297
: info.messages
298-
.filter((message) => message.timestamp < getMissThreshold(now, toChainId(Number(chain))))
298+
.filter((message) => message.timestamp < getMissThreshold(now, chain))
299299
.filter(
300300
(message) =>
301301
!governorInfo?.enqueuedVAAs.some(
@@ -309,7 +309,7 @@ function Misses({
309309
<CollapsibleSection
310310
key={chain}
311311
defaultExpanded={false}
312-
header={`${chainIdToChain.get(toChainId(Number(chain)))} (${chain}) - ${
312+
header={`${chainIdToChain.get(Number(chain) as ChainId)} (${chain}) - ${
313313
filteredMisses.length
314314
}`}
315315
>
@@ -385,7 +385,7 @@ function Monitor({ governorInfo }: { governorInfo?: CloudGovernorInfo | null })
385385
const filteredMisses = showAllMisses
386386
? info.messages
387387
: info.messages
388-
.filter((message) => message.timestamp < getMissThreshold(now, toChainId(Number(chain))))
388+
.filter((message) => message.timestamp < getMissThreshold(now, chain))
389389
.filter(
390390
(message) =>
391391
!governorInfo?.enqueuedVAAs.some(
@@ -397,7 +397,7 @@ function Monitor({ governorInfo }: { governorInfo?: CloudGovernorInfo | null })
397397
);
398398
return filteredMisses.length === 0
399399
? counts
400-
: { ...counts, [toChainId(Number(chain))]: filteredMisses.length };
400+
: { ...counts, [Number(chain) as ChainId]: filteredMisses.length };
401401
}, {})
402402
: {};
403403
}, [governorInfo?.enqueuedVAAs, misses, showAllMisses]);
@@ -499,14 +499,14 @@ function Monitor({ governorInfo }: { governorInfo?: CloudGovernorInfo | null })
499499
header={
500500
<div>
501501
<Typography variant="h5" sx={{ mb: 0.5 }}>
502-
{chainIdToChain.get(toChainId(Number(chain)))} ({chain})
502+
{chainIdToChain.get(Number(chain) as ChainId)} ({chain})
503503
</Typography>
504504
<Typography variant="body2" sx={{ mb: 0.5 }}>
505505
Last Indexed Block - {lastBlock.split('/')[0]}
506506
{' - '}
507507
{new Date(lastBlock.split('/')[1]).toLocaleString()}
508508
</Typography>
509-
{messageCounts?.[toChainId(Number(chain))] ? (
509+
{messageCounts?.[Number(chain) as ChainId] ? (
510510
<Typography
511511
component="div"
512512
sx={{
@@ -516,12 +516,12 @@ function Monitor({ governorInfo }: { governorInfo?: CloudGovernorInfo | null })
516516
>
517517
<Box sx={missingBlockSx} />
518518
&nbsp;={' '}
519-
{messageCounts?.[toChainId(Number(chain))]?.numMessagesWithoutVaas}
519+
{messageCounts?.[Number(chain) as ChainId]?.numMessagesWithoutVaas}
520520
&nbsp;&nbsp;
521521
<Box sx={doneBlockSx} />
522522
&nbsp;={' '}
523-
{(messageCounts?.[toChainId(Number(chain))]?.numTotalMessages || 0) -
524-
(messageCounts?.[toChainId(Number(chain))]?.numMessagesWithoutVaas ||
523+
{(messageCounts?.[Number(chain) as ChainId]?.numTotalMessages || 0) -
524+
(messageCounts?.[Number(chain) as ChainId]?.numMessagesWithoutVaas ||
525525
0)}
526526
</Typography>
527527
) : null}

watcher/scripts/solanaMissedMessageAccounts.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import {
1010
normalizeCompileInstruction,
1111
} from '@wormhole-foundation/wormhole-monitor-common/src/solana';
1212
import { getMissThreshold } from '@wormhole-foundation/wormhole-monitor-common';
13-
import { contracts, toChainId } from '@wormhole-foundation/sdk-base';
13+
import { contracts } from '@wormhole-foundation/sdk-base';
1414

1515
// This script finds the message accounts which correspond to solana misses
1616

1717
(async () => {
1818
const now = new Date();
19-
const missThreshold = getMissThreshold(now, toChainId('Solana'))
19+
const missThreshold = getMissThreshold(now, 'Solana');
2020
let log = ora('Fetching Solana misses').start();
2121
try {
2222
const response = await axios.get(

0 commit comments

Comments
 (0)