From a239de12b8b7cb6879404643f168aa8e7b3b6a50 Mon Sep 17 00:00:00 2001 From: Paul Noel Date: Fri, 8 Sep 2023 13:11:28 -0500 Subject: [PATCH] cloud_functions/scripts: add processing --- cloud_functions/scripts/deploy.sh | 22 +++++++++++++++++++++- cloud_functions/src/alarmMissingVaas.ts | 14 ++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/cloud_functions/scripts/deploy.sh b/cloud_functions/scripts/deploy.sh index 25c8d76d..e41ddeda 100755 --- a/cloud_functions/scripts/deploy.sh +++ b/cloud_functions/scripts/deploy.sh @@ -109,6 +109,26 @@ if [ -z "$FIRESTORE_MESSAGE_COUNT_HISTORY_COLLECTION" ]; then exit 1 fi +if [ -z "$FIRESTORE_ALARM_MISSING_VAAS_COLLECTION" ]; then + echo "FIRESTORE_ALARM_MISSING_VAAS_COLLECTION must be specified" + exit 1 +fi + +if [ -z "$SLACK_CHANNEL_ID" ]; then + echo "SLACK_CHANNEL_ID must be specified" + exit 1 +fi + +if [ -z "$SLACK_POST_URL" ]; then + echo "SLACK_POST_URL must be specified" + exit 1 +fi + +if [ -z "$SLACK_BOT_TOKEN" ]; then + echo "SLACK_BOT_TOKEN must be specified" + exit 1 +fi + # Hack to make these packages available in the GCP build until they're published npm pack --silent --workspace @wormhole-foundation/wormhole-monitor-common --pack-destination ./dist/src npm pack --silent --workspace @wormhole-foundation/wormhole-monitor-database --pack-destination ./dist/src @@ -119,7 +139,7 @@ gcloud functions deploy compute-message-counts --entry-point computeMessageCount gcloud functions deploy latest-blocks --entry-point getLatestBlocks --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_COLLECTION=$FIRESTORE_LATEST_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 +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 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 diff --git a/cloud_functions/src/alarmMissingVaas.ts b/cloud_functions/src/alarmMissingVaas.ts index c9ca0c18..db93f82d 100644 --- a/cloud_functions/src/alarmMissingVaas.ts +++ b/cloud_functions/src/alarmMissingVaas.ts @@ -74,6 +74,10 @@ async function getAndProcessFirestore(): Promise> { assertEnvironmentVariable('FIRESTORE_ALARM_MISSING_VAAS_COLLECTION') ); let current = new Map(); + const now = new Date(); + const thePast = now; + thePast.setHours(now.getHours() - 2); + const twoHoursAgo = thePast.toISOString(); await collection .doc('VAAs') .get() @@ -81,8 +85,14 @@ async function getAndProcessFirestore(): Promise> { if (doc.exists) { const data = doc.data(); if (data) { - console.log('Document data:', data); - // TODO: Figure out how to process the VAAs and put into a map, if < 2 hours old + // if VAA < 2 hours old, leave in firestore + const vaas: FirestoreVAA[] = data.VAAs; + vaas.forEach((vaa) => { + if (vaa.noticedTS > twoHoursAgo) { + // console.log('keeping VAA in firestore', vaa.vaaKey); + current.set(vaa.vaaKey, vaa); + } + }); } } })