Skip to content

Commit

Permalink
watcher: change miss to 30 mins
Browse files Browse the repository at this point in the history
  • Loading branch information
panoel committed Mar 28, 2024
1 parent 1e79184 commit c2ead9a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
21 changes: 11 additions & 10 deletions cloud_functions/src/alarmMissingVaas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getEnvironment,
explorerBlock,
explorerTx,
MISS_THRESHOLD_IN_MINS,
} from '@wormhole-foundation/wormhole-monitor-common';
import { Firestore } from 'firebase-admin/firestore';

Expand Down Expand Up @@ -88,22 +89,22 @@ export async function alarmMissingVaas(req: any, res: any) {
if (messages) {
const now = new Date();
const thePast = now;
thePast.setHours(now.getHours() - 2);
const twoHoursAgo = thePast.toISOString();
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 msgs = messages[chainId];
if (msgs && msgs.messages) {
for (let i = 0; i < msgs.messages.length; i++) {
// Check the timestamp and only send messages that are older than 2 hours
// Check the timestamp and only send messages that are older than MISS_THRESHOLD_IN_MINS
const msg: ObservedMessage = msgs.messages[i];
// If there is a reference time for this chain, use it. Otherwise, use the current time.
let timeToCheck = twoHoursAgo;
let timeToCheck = missThreshold;
if (refTimes[chainId]) {
let refTime = refTimes[chainId]?.latestTime;
if (refTime) {
const refDateTime = new Date(refTime);
refDateTime.setHours(refDateTime.getHours() - 2);
refDateTime.setMinutes(refDateTime.getMinutes() - MISS_THRESHOLD_IN_MINS);
timeToCheck = refDateTime.toISOString();
}
}
Expand Down Expand Up @@ -196,7 +197,7 @@ async function getGovernedVaas(): Promise<GovernedVAAMap> {
}

// This function gets all the VAAs in the firestore table,
// checks the timestamp (keeping any that are less than 2 hours old),
// checks the timestamp (keeping any that are less than MISS_THRESHOLD_IN_MINS old),
// and returns a map of those VAAs.
async function getAndProcessFirestore(): Promise<Map<string, FirestoreVAA>> {
// Get VAAs in the firestore holding area.
Expand All @@ -207,19 +208,19 @@ async function getAndProcessFirestore(): Promise<Map<string, FirestoreVAA>> {
let current = new Map<string, FirestoreVAA>();
const now = new Date();
const thePast = now;
thePast.setHours(now.getHours() - 2);
const twoHoursAgo = thePast.toISOString();
thePast.setMinutes(now.getMinutes() - MISS_THRESHOLD_IN_MINS);
const missThreshold = thePast.toISOString();
await collection
.doc('VAAs')
.get()
.then((doc) => {
if (doc.exists) {
const data = doc.data();
if (data) {
// if VAA < 2 hours old, leave in firestore
// if VAA < MISS_THRESHOLD_IN_MINS old, leave in firestore
const vaas: FirestoreVAA[] = data.VAAs;
vaas.forEach((vaa) => {
if (vaa.noticedTS > twoHoursAgo) {
if (vaa.noticedTS > missThreshold) {
// console.log('keeping VAA in firestore', vaa.vaaKey);
current.set(vaa.vaaKey, vaa);
}
Expand Down
3 changes: 3 additions & 0 deletions common/src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export type Network = {
};
export type Mode = 'vaa' | 'ntt';

export const MISS_THRESHOLD_IN_MINS = 30;
export const MISS_THRESHOLD_LABEL = '30 minutes';

export const INITIAL_DEPLOYMENT_BLOCK_BY_NETWORK_AND_CHAIN: {
[key in Environment]: { [key in ChainName]?: string };
} = {
Expand Down
18 changes: 11 additions & 7 deletions dashboard/src/components/Monitor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
explorerBlock,
explorerTx,
explorerVaa,
MISS_THRESHOLD_IN_MINS,
MISS_THRESHOLD_LABEL,
} from '@wormhole-foundation/wormhole-monitor-common';
import { Environment, useCurrentEnvironment, useNetworkContext } from '../contexts/NetworkContext';
import { CloudGovernorInfo } from '../hooks/useCloudGovernorInfo';
Expand Down Expand Up @@ -248,16 +250,16 @@ function DetailBlocks({ chain }: { chain: string }) {

function ReobserveCodeContent({ misses }: { misses: MissesByChain }) {
const now = new Date();
now.setHours(now.getHours() - 2);
const twoHoursAgo = now.toISOString();
now.setMinutes(now.getMinutes() - MISS_THRESHOLD_IN_MINS);
const missThreshold = now.toISOString();
const { showAllMisses } = useSettings();
return (
<pre>
{Object.entries(misses)
.map(([chain, info]) => {
const filteredMisses = showAllMisses
? info.messages
: info.messages.filter((message) => message.timestamp < twoHoursAgo);
: info.messages.filter((message) => message.timestamp < missThreshold);
return filteredMisses.length === 0
? null
: filteredMisses
Expand Down Expand Up @@ -323,15 +325,15 @@ function Misses({ governorInfo }: { governorInfo?: CloudGovernorInfo | null }) {
};
}, [currentNetwork]);
const now = new Date();
now.setHours(now.getHours() - 2);
const twoHoursAgo = now.toISOString();
now.setMinutes(now.getMinutes() - MISS_THRESHOLD_IN_MINS);
const missThreshold = now.toISOString();
const missesElements = misses
? Object.entries(misses)
.map(([chain, info]) => {
const filteredMisses = showAllMisses
? info.messages
: info.messages
.filter((message) => message.timestamp < twoHoursAgo)
.filter((message) => message.timestamp < missThreshold)
.filter(
(message) =>
!governorInfo?.enqueuedVAAs.some(
Expand Down Expand Up @@ -396,7 +398,9 @@ function Misses({ governorInfo }: { governorInfo?: CloudGovernorInfo | null }) {
) : missesElements.length ? (
missesElements
) : (
<Typography pl={0.5}>No misses{showAllMisses ? '' : ' > 2 Hours'}!</Typography>
<Typography pl={0.5}>
No misses{showAllMisses ? '' : ` > ${MISS_THRESHOLD_LABEL}`}!
</Typography>
)}
</>
);
Expand Down
7 changes: 4 additions & 3 deletions watcher/scripts/solanaMissedMessageAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ import {
isLegacyMessage,
normalizeCompileInstruction,
} from '@wormhole-foundation/wormhole-monitor-common/src/solana';
import { MISS_THRESHOLD_IN_MINS } from '@wormhole-foundation/wormhole-monitor-common';

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

(async () => {
const now = new Date();
now.setHours(now.getHours() - 2);
const twoHoursAgo = now.toISOString();
now.setMinutes(now.getMinutes() - MISS_THRESHOLD_IN_MINS);
const missThreshold = now.toISOString();
let log = ora('Fetching Solana misses').start();
try {
const response = await axios.get(
'https://europe-west3-wormhole-message-db-mainnet.cloudfunctions.net/missing-vaas'
);
const solanaTxHashes = response.data[1].messages
.filter((m: any) => m.timestamp < twoHoursAgo)
.filter((m: any) => m.timestamp < missThreshold)
.map((m: any) => m.txHash);
log.succeed();
log = ora('Fetching message accounts').start();
Expand Down

0 comments on commit c2ead9a

Please sign in to comment.