Skip to content

Commit

Permalink
cloud_functions: add wormchainMonitor
Browse files Browse the repository at this point in the history
  • Loading branch information
panoel committed Oct 30, 2023
1 parent 7dab14d commit 2e34b36
Show file tree
Hide file tree
Showing 11 changed files with 633 additions and 26 deletions.
2 changes: 1 addition & 1 deletion cloud_functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "tsc",
"dev": "ts-node src/index.ts",
"start": "npx functions-framework --target=alarmMissingVaas [--signature-type=http]",
"start": "npx functions-framework --target=wormchainMonitor [--signature-type=http]",
"deploy": "bash scripts/deploy.sh",
"gcp-build": "npm i ./dist/src/wormhole-foundation-wormhole-monitor-common-0.0.1.tgz ./dist/src/wormhole-foundation-wormhole-monitor-database-0.0.1.tgz"
},
Expand Down
40 changes: 33 additions & 7 deletions cloud_functions/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,43 @@ if [ -z "$FIRESTORE_LATEST_TVLTVM_COLLECTION" ]; then
exit 1
fi

if [ -z "$SLACK_CHANNEL_ID" ]; then
echo "SLACK_CHANNEL_ID must be specified"
if [ -z "$MISSING_VAA_SLACK_CHANNEL_ID" ]; then
echo "MISSING_VAA_SLACK_CHANNEL_ID must be specified"
exit 1
fi

if [ -z "$SLACK_POST_URL" ]; then
echo "SLACK_POST_URL must be specified"
if [ -z "$MISSING_VAA_SLACK_POST_URL" ]; then
echo "MISSING_VAA_SLACK_POST_URL must be specified"
exit 1
fi

if [ -z "$SLACK_BOT_TOKEN" ]; then
echo "SLACK_BOT_TOKEN must be specified"
if [ -z "$MISSING_VAA_SLACK_BOT_TOKEN" ]; then
echo "MISSING_VAA_SLACK_BOT_TOKEN must be specified"
exit 1
fi

if [ -z "$WORMCHAIN_SLACK_CHANNEL_ID" ]; then
echo "WORMCHAIN_SLACK_CHANNEL_ID must be specified"
exit 1
fi

if [ -z "$WORMCHAIN_SLACK_POST_URL" ]; then
echo "WORMCHAIN_SLACK_POST_URL must be specified"
exit 1
fi

if [ -z "$WORMCHAIN_SLACK_BOT_TOKEN" ]; then
echo "WORMCHAIN_SLACK_BOT_TOKEN must be specified"
exit 1
fi

if [ -z "$WORMCHAIN_PAGERDUTY_ROUTING_KEY" ]; then
echo "WORMCHAIN_PAGERDUTY_ROUTING_KEY must be specified"
exit 1
fi

if [ -z "$WORMCHAIN_PAGERDUTY_URL" ]; then
echo "WORMCHAIN_PAGERDUTY_URL must be specified"
exit 1
fi

Expand All @@ -145,7 +170,7 @@ gcloud functions deploy latest-blocks --entry-point getLatestBlocks --runtime no
gcloud functions deploy latest-tvltvm --entry-point getLatestTvlTvm --runtime nodejs16 --trigger-http --allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 --set-env-vars CLOUD_FUNCTIONS_REFRESH_TIME_INTERVAL=$CLOUD_FUNCTIONS_REFRESH_TIME_INTERVAL,FIRESTORE_LATEST_TVLTVM_COLLECTION=$FIRESTORE_LATEST_TVLTVM_COLLECTION
gcloud functions deploy compute-missing-vaas --entry-point computeMissingVaas --runtime nodejs16 --trigger-http --allow-unauthenticated --timeout 300 --memory 2GB --region europe-west3 --set-env-vars BIGTABLE_TABLE_ID=$BIGTABLE_TABLE_ID,BIGTABLE_INSTANCE_ID=$BIGTABLE_INSTANCE_ID,CLOUD_FUNCTIONS_REFRESH_TIME_INTERVAL=$CLOUD_FUNCTIONS_REFRESH_TIME_INTERVAL
gcloud functions deploy missing-vaas --entry-point getMissingVaas --runtime nodejs16 --trigger-http --allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3
gcloud functions deploy alarm-missing-vaas --entry-point alarmMissingVaas --runtime nodejs16 --trigger-http --no-allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 --set-env-vars SLACK_CHANNEL_ID=$SLACK_CHANNEL_ID,SLACK_POST_URL=$SLACK_POST_URL,SLACK_BOT_TOKEN=$SLACK_BOT_TOKEN,FIRESTORE_ALARM_MISSING_VAAS_COLLECTION=$FIRESTORE_ALARM_MISSING_VAAS_COLLECTION,FIRESTORE_GOVERNOR_STATUS_COLLECTION=$FIRESTORE_GOVERNOR_STATUS_COLLECTION,FIRESTORE_LATEST_COLLECTION=$FIRESTORE_LATEST_COLLECTION
gcloud functions deploy alarm-missing-vaas --entry-point alarmMissingVaas --runtime nodejs16 --trigger-http --no-allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 --set-env-vars MISSING_VAA_SLACK_CHANNEL_ID=$MISSING_VAA_SLACK_CHANNEL_ID,MISSING_VAA_SLACK_POST_URL=$MISSING_VAA_SLACK_POST_URL,MISSING_VAA_SLACK_BOT_TOKEN=$MISSING_VAA_SLACK_BOT_TOKEN,FIRESTORE_ALARM_MISSING_VAAS_COLLECTION=$FIRESTORE_ALARM_MISSING_VAAS_COLLECTION,FIRESTORE_GOVERNOR_STATUS_COLLECTION=$FIRESTORE_GOVERNOR_STATUS_COLLECTION,FIRESTORE_LATEST_COLLECTION=$FIRESTORE_LATEST_COLLECTION
gcloud functions deploy vaas-by-tx-hash --entry-point getVaasByTxHash --runtime nodejs16 --trigger-http --allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 --set-env-vars BIGTABLE_INSTANCE_ID=$BIGTABLE_INSTANCE_ID,BIGTABLE_SIGNED_VAAS_TABLE_ID=$BIGTABLE_SIGNED_VAAS_TABLE_ID,BIGTABLE_VAAS_BY_TX_HASH_TABLE_ID=$BIGTABLE_VAAS_BY_TX_HASH_TABLE_ID
gcloud functions deploy process-vaa --entry-point processVaa --runtime nodejs16 --timeout 300 --memory 256MB --region europe-west3 --trigger-topic $PUBSUB_SIGNED_VAA_TOPIC --set-env-vars BIGTABLE_INSTANCE_ID=$BIGTABLE_INSTANCE_ID,BIGTABLE_SIGNED_VAAS_TABLE_ID=$BIGTABLE_SIGNED_VAAS_TABLE_ID,BIGTABLE_VAAS_BY_TX_HASH_TABLE_ID=$BIGTABLE_VAAS_BY_TX_HASH_TABLE_ID,PG_USER=$PG_USER,PG_PASSWORD=$PG_PASSWORD,PG_DATABASE=$PG_DATABASE,PG_HOST=$PG_HOST,PG_TOKEN_TRANSFER_TABLE=$PG_TOKEN_TRANSFER_TABLE,PG_ATTEST_MESSAGE_TABLE=$PG_ATTEST_MESSAGE_TABLE,PG_TOKEN_METADATA_TABLE=$PG_TOKEN_METADATA_TABLE
gcloud functions deploy refresh-todays-token-prices --entry-point refreshTodaysTokenPrices --runtime nodejs16 --trigger-http --no-allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 --set-env-vars PG_USER=$PG_USER,PG_PASSWORD=$PG_PASSWORD,PG_DATABASE=$PG_DATABASE,PG_HOST=$PG_HOST,PG_TOKEN_METADATA_TABLE=$PG_TOKEN_METADATA_TABLE,PG_TOKEN_PRICE_HISTORY_TABLE=$PG_TOKEN_PRICE_HISTORY_TABLE
Expand All @@ -158,3 +183,4 @@ gcloud functions deploy message-count-history --entry-point getMessageCountHisto
gcloud functions deploy compute-message-count-history --entry-point computeMessageCountHistory --runtime nodejs16 --trigger-http --no-allow-unauthenticated --timeout 300 --memory 1GB --region europe-west3 --set-env-vars BIGTABLE_INSTANCE_ID=$BIGTABLE_INSTANCE_ID,BIGTABLE_SIGNED_VAAS_TABLE_ID=$BIGTABLE_SIGNED_VAAS_TABLE_ID,FIRESTORE_MESSAGE_COUNT_HISTORY_COLLECTION=$FIRESTORE_MESSAGE_COUNT_HISTORY_COLLECTION
gcloud functions deploy update-token-metadata --entry-point updateTokenMetadata --runtime nodejs16 --trigger-http --no-allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 --set-env-vars PG_USER=$PG_USER,PG_PASSWORD=$PG_PASSWORD,PG_DATABASE=$PG_DATABASE,PG_HOST=$PG_HOST,PG_TOKEN_METADATA_TABLE=$PG_TOKEN_METADATA_TABLE
gcloud functions deploy reobserve-vaas --entry-point getReobserveVaas --runtime nodejs16 --trigger-http --allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 --set-env-vars FIRESTORE_ALARM_MISSING_VAAS_COLLECTION=$FIRESTORE_ALARM_MISSING_VAAS_COLLECTION,REOBSERVE_VAA_API_KEY=$REOBSERVE_VAA_API_KEY
gcloud functions deploy wormchain-monitor --entry-point wormchainMonitor --runtime nodejs16 --trigger-http --no-allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 --set-env-vars WORMCHAIN_SLACK_CHANNEL_ID=$WORMCHAIN_SLACK_CHANNEL_ID,WORMCHAIN_SLACK_POST_URL=$WORMCHAIN_SLACK_POST_URL,WORMCHAIN_SLACK_BOT_TOKEN=$WORMCHAIN_SLACK_BOT_TOKEN,WORMCHAIN_PAGERDUTY_ROUTING_KEY=$WORMCHAIN_PAGERDUTY_ROUTING_KEY,WORMCHAIN_PAGERDUTY_URL=$WORMCHAIN_PAGERDUTY_URL
26 changes: 22 additions & 4 deletions cloud_functions/src/alarmMissingVaas.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CHAIN_ID_TO_NAME, ChainId, ChainName } from '@certusone/wormhole-sdk';
import { MissingVaasByChain, commonGetMissingVaas } from './getMissingVaas';
import { assertEnvironmentVariable, formatAndSendToSlack, isVAASigned } from './utils';
import { ObservedMessage, ReobserveInfo } from './types';
import { ObservedMessage, ReobserveInfo, SlackInfo } from './types';
import { explorerBlock, explorerTx } from '@wormhole-foundation/wormhole-monitor-common';
import { Firestore } from 'firebase-admin/firestore';
import axios from 'axios';
Expand Down Expand Up @@ -45,6 +45,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[] = [];
let reobsMap: Map<string, ReobserveInfo> = new Map<string, ReobserveInfo>();
try {
Expand Down Expand Up @@ -114,7 +123,8 @@ export async function alarmMissingVaas(req: any, res: any) {
txhash: msg.txHash,
vaaKey: vaaKey,
});
await formatAndSendToSlack(formatMessage(msg));
alarmSlackInfo.msg = formatMessage(msg);
await formatAndSendToSlack(alarmSlackInfo);
}
}
} else {
Expand Down Expand Up @@ -301,6 +311,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 All @@ -327,8 +345,8 @@ async function alarmOldBlockTimes(latestTimes: LatestTimeByChain): Promise<void>
const chainTime: Date = new Date(latestTime);
const cName: string = CHAIN_ID_TO_NAME[chainId] as ChainName;
const deltaTime: number = (now.getTime() - chainTime.getTime()) / (1000 * 60 * 60 * 24);
const formattedMsg = `*Chain:* ${cName}(${chainId})\nThe watcher is behind by ${deltaTime} days.`;
await formatAndSendToSlack(formattedMsg);
alarmSlackInfo.msg = `*Chain:* ${cName}(${chainId})\nThe watcher is behind by ${deltaTime} days.`;
await formatAndSendToSlack(alarmSlackInfo);
alarmsToStore.push({ chain: chainId, alarmTime: now.toISOString() });
}
}
Expand Down
104 changes: 104 additions & 0 deletions cloud_functions/src/data/evmosRPCs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"evmosRPCs": [
{
"address": "https://lcd-evmos.whispernode.com:443/",
"provider": "WhisperNode🤐"
},
{
"address": "https://rest.bd.evmos.org:1317/",
"provider": "Blockdaemon"
},
{
"address": "https://evmos-api.lavenderfive.com:443/",
"provider": "Lavender.Five Nodes 🐝"
},
{
"address": "https://api-evmos-ia.cosmosia.notional.ventures/",
"provider": "Notional"
},
{
"address": "https://api.evmos.interbloc.org/",
"provider": "Interbloc"
},
{
"address": "https://lcd.evmos.bh.rocks/",
"provider": "BlockHunters"
},
{
"address": "https://api-evmos.cosmos-spaces.cloud/",
"provider": "Cosmos Spaces"
},
{
"address": "https://api.evmos.nodestake.top/",
"provider": "NodeStake"
},
{
"address": "https://evmos-api.polkachu.com/",
"provider": "Polkachu"
},
{
"address": "https://api.evmos.silentvalidator.com/",
"provider": "silent"
},
{
"address": "https://rest.evmos.tcnetwork.io/",
"provider": "TC Network"
},
{
"address": "https://evmos.rest.stakin-nodes.com/",
"provider": "Stakin"
},
{
"address": "https://rest-evmos.architectnodes.com/",
"provider": "Architect Nodes"
},
{
"address": "https://evmos-api.validatrium.club/",
"provider": "Validatrium"
},
{
"address": "https://evmos-mainnet-lcd.autostake.com:443/",
"provider": "AutoStake 🛡️ Slash Protected"
},
{
"address": "https://evmos-api.stakeandrelax.net/",
"provider": "Stake&Relax Validator 🦥"
},
{
"address": "https://rest-evmos.ecostake.com/",
"provider": "ecostake"
},
{
"address": "https://evmos.rest.interchain.ivaldilabs.xyz/",
"provider": "ivaldilabs"
},
{
"address": "https://evmos-rest.publicnode.com/",
"provider": "Allnodes.com ⚡️ Nodes & Staking"
},
{
"address": "https://api-evmos-01.stakeflow.io/",
"provider": "Stakeflow"
},
{
"address": "https://evmos-api.theamsolutions.info/",
"provider": "AM Solutions"
},
{
"address": "https://lcd-evmos.validavia.me/",
"provider": "Validavia"
},
{
"address": "https://evmos-api.w3coins.io/",
"provider": "w3coins"
},
{
"address": "https://api-evmos.mms.team/",
"provider": "MMS"
},
{
"address": "https://evmos-api.stake-town.com:443/",
"provider": "StakeTown"
}
]
}
76 changes: 76 additions & 0 deletions cloud_functions/src/data/kujiraRPCs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"kujiraRPCs": [
{
"address": "https://lcd-kujira.whispernode.com:443/",
"provider": "WhisperNode🤐"
},
{
"address": "https://rest-kujira.goldenratiostaking.net/",
"provider": "Golden Ratio Staking"
},
{
"address": "https://lcd.kaiyo.kujira.setten.io/",
"provider": "setten.io"
},
{
"address": "https://kujira-api.lavenderfive.com:443/",
"provider": "Lavender.Five Nodes 🐝"
},
{
"address": "https://kujira-api.polkachu.com/",
"provider": "polkachu"
},
{
"address": "https://rest-kujira.ecostake.com/",
"provider": "ecostake"
},
{
"address": "https://api-kujira-ia.cosmosia.notional.ventures/",
"provider": "Notional"
},
{
"address": "https://kujira-lcd.wildsage.io/",
"provider": "WildSage Labs"
},
{
"address": "https://kujira-api.ibs.team/",
"provider": "Inter Blockchain Services"
},
{
"address": "https://api-kujira.starsquid.io/",
"provider": "Starsquid"
},
{
"address": "https://kujira.api.kjnodes.com/",
"provider": "kjnodes"
},
{
"address": "https://kuji-api.kleomedes.network/",
"provider": "Kleomedes"
},
{
"address": "https://kujira-mainnet-lcd.autostake.com:443/",
"provider": "AutoStake 🛡️ Slash Protected"
},
{
"address": "https://api.kujira.rektdao.club/",
"provider": "rektDAO"
},
{
"address": "https://kujira-api.theamsolutions.info/",
"provider": "AM Solutions"
},
{
"address": "https://kujira-api.w3coins.io/",
"provider": "w3coins"
},
{
"address": "https://api-kujira.mms.team/",
"provider": "MMS"
},
{
"address": "https://kujira-rest.publicnode.com/",
"provider": "Allnodes.com ⚡️ Nodes & Staking"
}
]
}
Loading

0 comments on commit 2e34b36

Please sign in to comment.