From 539152d9ece5e24718ac8d0d1366c63b47b46625 Mon Sep 17 00:00:00 2001 From: Paul Noel Date: Wed, 10 Jan 2024 07:45:34 -0600 Subject: [PATCH] cloud_functions: refactor for testnet --- cloud_functions/scripts/deploy.sh | 28 ++++++++++----------- cloud_functions/src/alarmMissingVaas.ts | 1 - cloud_functions/src/computeMessageCounts.ts | 5 +++- cloud_functions/src/computeMissingVaas.ts | 5 +++- cloud_functions/src/getMessageCounts.ts | 6 ++++- cloud_functions/src/getMissingVaas.ts | 6 ++++- 6 files changed, 32 insertions(+), 19 deletions(-) diff --git a/cloud_functions/scripts/deploy.sh b/cloud_functions/scripts/deploy.sh index 1bee5166..0b760c20 100755 --- a/cloud_functions/scripts/deploy.sh +++ b/cloud_functions/scripts/deploy.sh @@ -116,20 +116,20 @@ npm pack --silent --workspace @wormhole-foundation/wormhole-monitor-database --p # Context: Of all the cloud functions, there are some that only go into MAINNET and some that go into both MAINNET and TESTNET. # There are no cloud functions that only go into TESTNET. # First, deploy the functions that are common to both MAINNET and TESTNET -gcloud functions --project "$GCP_PROJECT" deploy alarm-missing-vaas --entry-point alarmMissingVaas --runtime nodejs18 --trigger-http --no-allow-unauthenticated --timeout 300 --memory 512MB --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 --project "$GCP_PROJECT" deploy compute-message-count-history --entry-point computeMessageCountHistory --runtime nodejs18 --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 --project "$GCP_PROJECT" deploy compute-message-counts --entry-point computeMessageCounts --runtime nodejs18 --trigger-http --allow-unauthenticated --timeout 300 --memory 4GB --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 --project "$GCP_PROJECT" deploy compute-missing-vaas --entry-point computeMissingVaas --runtime nodejs18 --trigger-http --allow-unauthenticated --timeout 300 --memory 4GB --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 --project "$GCP_PROJECT" deploy latest-blocks --entry-point getLatestBlocks --runtime nodejs18 --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_COLLECTION=$FIRESTORE_LATEST_COLLECTION -gcloud functions --project "$GCP_PROJECT" deploy latest-tvltvm --entry-point getLatestTvlTvm --runtime nodejs18 --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 --project "$GCP_PROJECT" deploy message-count-history --entry-point getMessageCountHistory --runtime nodejs18 --trigger-http --allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 --set-env-vars FIRESTORE_MESSAGE_COUNT_HISTORY_COLLECTION=$FIRESTORE_MESSAGE_COUNT_HISTORY_COLLECTION -gcloud functions --project "$GCP_PROJECT" deploy message-counts --entry-point getMessageCounts --runtime nodejs18 --trigger-http --allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 -gcloud functions --project "$GCP_PROJECT" deploy messages --entry-point getMessages --runtime nodejs18 --trigger-http --allow-unauthenticated --timeout 300 --memory 1GB --region europe-west3 --set-env-vars BIGTABLE_TABLE_ID=$BIGTABLE_TABLE_ID,BIGTABLE_INSTANCE_ID=$BIGTABLE_INSTANCE_ID,CLOUD_FUNCTIONS_NUM_ROWS=$CLOUD_FUNCTIONS_NUM_ROWS,CLOUD_FUNCTIONS_REFRESH_TIME_INTERVAL=$CLOUD_FUNCTIONS_REFRESH_TIME_INTERVAL,CLOUD_FUNCTIONS_BLOCK_INCREMENT=$CLOUD_FUNCTIONS_BLOCK_INCREMENT -gcloud functions --project "$GCP_PROJECT" deploy missing-vaas --entry-point getMissingVaas --runtime nodejs18 --trigger-http --allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 -gcloud functions --project "$GCP_PROJECT" deploy reobserve-vaas --entry-point getReobserveVaas --runtime nodejs18 --trigger-http --allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 --set-env-vars FIRESTORE_ALARM_MISSING_VAAS_COLLECTION=$FIRESTORE_ALARM_MISSING_VAAS_COLLECTION --set-secrets 'REOBSERVE_VAA_API_KEY=Reobs_VAA_API_key_xLabs:1' -gcloud functions --project "$GCP_PROJECT" deploy tvl --entry-point getTVL --runtime nodejs18 --trigger-http --allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 --set-env-vars FIRESTORE_TVL_COLLECTION=$FIRESTORE_TVL_COLLECTION -gcloud functions --project "$GCP_PROJECT" deploy tvl-history --entry-point getTVLHistory --runtime nodejs18 --trigger-http --allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 --set-env-vars FIRESTORE_TVL_HISTORY_COLLECTION=$FIRESTORE_TVL_HISTORY_COLLECTION -gcloud functions --project "$GCP_PROJECT" deploy vaas-by-tx-hash --entry-point getVaasByTxHash --runtime nodejs18 --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 --project "$GCP_PROJECT" deploy alarm-missing-vaas --entry-point alarmMissingVaas --runtime nodejs18 --trigger-http --no-allow-unauthenticated --timeout 300 --memory 512MB --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,NETWORK=$NETWORK +gcloud functions --project "$GCP_PROJECT" deploy compute-message-count-history --entry-point computeMessageCountHistory --runtime nodejs18 --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,NETWORK=$NETWORK +gcloud functions --project "$GCP_PROJECT" deploy compute-message-counts --entry-point computeMessageCounts --runtime nodejs18 --trigger-http --allow-unauthenticated --timeout 300 --memory 4GB --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,NETWORK=$NETWORK +gcloud functions --project "$GCP_PROJECT" deploy compute-missing-vaas --entry-point computeMissingVaas --runtime nodejs18 --trigger-http --allow-unauthenticated --timeout 300 --memory 4GB --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,NETWORK=$NETWORK +gcloud functions --project "$GCP_PROJECT" deploy latest-blocks --entry-point getLatestBlocks --runtime nodejs18 --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_COLLECTION=$FIRESTORE_LATEST_COLLECTION,NETWORK=$NETWORK +gcloud functions --project "$GCP_PROJECT" deploy latest-tvltvm --entry-point getLatestTvlTvm --runtime nodejs18 --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,NETWORK=$NETWORK +gcloud functions --project "$GCP_PROJECT" deploy message-count-history --entry-point getMessageCountHistory --runtime nodejs18 --trigger-http --allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 --set-env-vars FIRESTORE_MESSAGE_COUNT_HISTORY_COLLECTION=$FIRESTORE_MESSAGE_COUNT_HISTORY_COLLECTION,NETWORK=$NETWORK +gcloud functions --project "$GCP_PROJECT" deploy message-counts --entry-point getMessageCounts --runtime nodejs18 --trigger-http --allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 --set-env-vars NETWORK=$NETWORK +gcloud functions --project "$GCP_PROJECT" deploy messages --entry-point getMessages --runtime nodejs18 --trigger-http --allow-unauthenticated --timeout 300 --memory 1GB --region europe-west3 --set-env-vars BIGTABLE_TABLE_ID=$BIGTABLE_TABLE_ID,BIGTABLE_INSTANCE_ID=$BIGTABLE_INSTANCE_ID,CLOUD_FUNCTIONS_NUM_ROWS=$CLOUD_FUNCTIONS_NUM_ROWS,CLOUD_FUNCTIONS_REFRESH_TIME_INTERVAL=$CLOUD_FUNCTIONS_REFRESH_TIME_INTERVAL,CLOUD_FUNCTIONS_BLOCK_INCREMENT=$CLOUD_FUNCTIONS_BLOCK_INCREMENT,NETWORK=$NETWORK +gcloud functions --project "$GCP_PROJECT" deploy missing-vaas --entry-point getMissingVaas --runtime nodejs18 --trigger-http --allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 --set-env-vars NETWORK=$NETWORK +gcloud functions --project "$GCP_PROJECT" deploy reobserve-vaas --entry-point getReobserveVaas --runtime nodejs18 --trigger-http --allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 --set-env-vars FIRESTORE_ALARM_MISSING_VAAS_COLLECTION=$FIRESTORE_ALARM_MISSING_VAAS_COLLECTION,NETWORK=$NETWORK --set-secrets 'REOBSERVE_VAA_API_KEY=Reobs_VAA_API_key_xLabs:1' +gcloud functions --project "$GCP_PROJECT" deploy tvl --entry-point getTVL --runtime nodejs18 --trigger-http --allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 --set-env-vars FIRESTORE_TVL_COLLECTION=$FIRESTORE_TVL_COLLECTION,NETWORK=$NETWORK +gcloud functions --project "$GCP_PROJECT" deploy tvl-history --entry-point getTVLHistory --runtime nodejs18 --trigger-http --allow-unauthenticated --timeout 300 --memory 256MB --region europe-west3 --set-env-vars FIRESTORE_TVL_HISTORY_COLLECTION=$FIRESTORE_TVL_HISTORY_COLLECTION,NETWORK=$NETWORK +gcloud functions --project "$GCP_PROJECT" deploy vaas-by-tx-hash --entry-point getVaasByTxHash --runtime nodejs18 --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,NETWORK=$NETWORK # # Bail out if we are only deploying TESTNET functions diff --git a/cloud_functions/src/alarmMissingVaas.ts b/cloud_functions/src/alarmMissingVaas.ts index 9fec47c6..fcded1a5 100644 --- a/cloud_functions/src/alarmMissingVaas.ts +++ b/cloud_functions/src/alarmMissingVaas.ts @@ -4,7 +4,6 @@ import { assertEnvironmentVariable, formatAndSendToSlack, isVAASigned } from './ 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'; interface EnqueuedVAAResponse { sequence: string; diff --git a/cloud_functions/src/computeMessageCounts.ts b/cloud_functions/src/computeMessageCounts.ts index 6a1deb07..6d714823 100644 --- a/cloud_functions/src/computeMessageCounts.ts +++ b/cloud_functions/src/computeMessageCounts.ts @@ -6,7 +6,10 @@ import { Storage } from '@google-cloud/storage'; // Read/write with cloud storage const storage = new Storage(); // The ID of your GCS bucket -const bucketName = 'wormhole-observed-blocks-cache'; +let bucketName: string = 'wormhole-observed-blocks-cache'; +if (assertEnvironmentVariable('NETWORK') === 'TESTNET') { + bucketName = 'wormhole-observed-blocks-cache-testnet'; +} const cacheBucket = storage.bucket(bucketName); const cacheFileName = 'message-counts-cache.json'; const cloudStorageCache = cacheBucket.file(cacheFileName); diff --git a/cloud_functions/src/computeMissingVaas.ts b/cloud_functions/src/computeMissingVaas.ts index 68637775..fecfd76c 100644 --- a/cloud_functions/src/computeMissingVaas.ts +++ b/cloud_functions/src/computeMissingVaas.ts @@ -6,7 +6,10 @@ import { ObservedMessage } from './types'; // Read/write to cloud storage const storage = new Storage(); -const bucketName = 'wormhole-observed-blocks-cache'; +let bucketName: string = 'wormhole-observed-blocks-cache'; +if (assertEnvironmentVariable('NETWORK') === 'TESTNET') { + bucketName = 'wormhole-observed-blocks-cache-testnet'; +} const cacheBucket = storage.bucket(bucketName); const cacheFileName = 'missing-vaas-cache.json'; // The ID of your GCS bucket diff --git a/cloud_functions/src/getMessageCounts.ts b/cloud_functions/src/getMessageCounts.ts index 855cfbbb..44e156d7 100644 --- a/cloud_functions/src/getMessageCounts.ts +++ b/cloud_functions/src/getMessageCounts.ts @@ -1,5 +1,6 @@ import { ChainId } from '@certusone/wormhole-sdk/lib/cjs/utils/consts'; import { Storage } from '@google-cloud/storage'; +import { assertEnvironmentVariable } from './utils'; // Read from cloud storage const storage = new Storage(); @@ -27,7 +28,10 @@ export async function getMessageCounts(req: any, res: any) { let messages: CountsByChain = {}; try { // The ID of your GCS bucket - const bucketName = 'wormhole-observed-blocks-cache'; + let bucketName: string = 'wormhole-observed-blocks-cache'; + if (assertEnvironmentVariable('NETWORK') === 'TESTNET') { + bucketName = 'wormhole-observed-blocks-cache-testnet'; + } const cacheBucket = storage.bucket(bucketName); const cacheFileName = 'message-counts-cache.json'; const cloudStorageCache = cacheBucket.file(cacheFileName); diff --git a/cloud_functions/src/getMissingVaas.ts b/cloud_functions/src/getMissingVaas.ts index 4500d317..55e48f53 100644 --- a/cloud_functions/src/getMissingVaas.ts +++ b/cloud_functions/src/getMissingVaas.ts @@ -1,6 +1,7 @@ import { ChainId } from '@certusone/wormhole-sdk/lib/cjs/utils/consts'; import { Storage } from '@google-cloud/storage'; import { ObservedMessage } from './types'; +import { assertEnvironmentVariable } from './utils'; // Read from cloud storage const storage = new Storage(); @@ -15,7 +16,10 @@ export type MissingVaasByChain = { export async function commonGetMissingVaas(): Promise { // The ID of your GCS bucket - const bucketName = 'wormhole-observed-blocks-cache'; + let bucketName: string = 'wormhole-observed-blocks-cache'; + if (assertEnvironmentVariable('NETWORK') === 'TESTNET') { + bucketName = 'wormhole-observed-blocks-cache-testnet'; + } const cacheBucket = storage.bucket(bucketName); const cacheFileName = 'missing-vaas-cache.json'; const cloudStorageCache = cacheBucket.file(cacheFileName);