From 221fa91a870ef4a399f985c3b6f1093e54ef11a6 Mon Sep 17 00:00:00 2001 From: Nelson Taveras <4562733+nvtaveras@users.noreply.github.com> Date: Tue, 23 Jul 2024 02:03:45 -0400 Subject: [PATCH 01/14] WIP: health check --- src/health-check.fixture.json | 48 ++++++++++++++++++++++++ src/index.ts | 13 ++++++- src/parse-transaction-receipts.ts | 60 ++++++++++++++++++++---------- src/types.ts | 8 ++++ src/utils/is-health-check-event.ts | 21 +++++++++++ 5 files changed, 128 insertions(+), 22 deletions(-) create mode 100644 src/health-check.fixture.json create mode 100644 src/utils/is-health-check-event.ts diff --git a/src/health-check.fixture.json b/src/health-check.fixture.json new file mode 100644 index 0000000..031f030 --- /dev/null +++ b/src/health-check.fixture.json @@ -0,0 +1,48 @@ +[ + { + "blockHash": "0x3c3de1a0ae100d33d9a7863ddc59cdf6ec628c42bebf0854e18c462a7e2f6b90", + "blockNumber": "0x1990dc7", + "contractAddress": "", + "cumulativeGasUsed": "0x8e7542", + "effectiveGasPrice": "0x1bf08eb00", + "from": "0xfe9925e6ae9c4cd50ae471b90766aaef37ad307e", + "gasUsed": "0x4a836", + "logs": [ + { + "address": "0xefb84935239dacdecf7c5ba76d8de40b077b7b33", + "blockHash": "0x3c3de1a0ae100d33d9a7863ddc59cdf6ec628c42bebf0854e18c462a7e2f6b90", + "blockNumber": "0x1990dc7", + "data": "0x00000000000000000000000000000000000000000000000000000000669f37b9000000000000000000000000000000000000000000007ae21ecba8aa70ef8750", + "logIndex": "0xc5", + "removed": false, + "topics": [ + "0x7cebb17173a9ed273d2b7538f64395c0ebf352ff743f1cf8ce66b437a6144213", + "0x000000000000000000000000765de816845861e75a25fca122bb6898b8b1282a", + "0x000000000000000000000000fe9925e6ae9c4cd50ae471b90766aaef37ad307e" + ], + "transactionHash": "0x1091e1d6babb1711b30d6328f9d9755cc4e7d5004f9ef88c9526b1642f5f35e1", + "transactionIndex": "0x3" + }, + { + "address": "0xefb84935239dacdecf7c5ba76d8de40b077b7b33", + "blockHash": "0x3c3de1a0ae100d33d9a7863ddc59cdf6ec628c42bebf0854e18c462a7e2f6b90", + "blockNumber": "0x1990dc7", + "data": "0x000000000000000000000000000000000000000000007aef59d1fabdfb4cfc30", + "logIndex": "0xc6", + "removed": false, + "topics": [ + "0xa9981ebfc3b766a742486e898f54959b050a66006dbce1a4155c1f84a08bcf41", + "0x000000000000000000000000765de816845861e75a25fca122bb6898b8b1282a" + ], + "transactionHash": "0x1091e1d6babb1711b30d6328f9d9755cc4e7d5004f9ef88c9526b1642f5f35e1", + "transactionIndex": "0x3" + } + ], + "logsBloom": "0x00800000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000004000000000000000020000000000000000000000000400000008400000000100000000000000000000000000000000000000000401000000000000800000000000000000000000000000000000000800000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000", + "status": "0x1", + "to": "0xefb84935239dacdecf7c5ba76d8de40b077b7b33", + "transactionHash": "0x1091e1d6babb1711b30d6328f9d9755cc4e7d5004f9ef88c9526b1642f5f35e1", + "transactionIndex": "0x3", + "type": "0x0" + } +] diff --git a/src/index.ts b/src/index.ts index c6348a8..f76f985 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,8 +16,17 @@ export const watchdogNotifier: HttpFunction = async ( const parsedEvents = parseTransactionReceipts(req.body); for (const parsedEvent of parsedEvents) { - await sendDiscordNotification(parsedEvent.event, parsedEvent.txHash); - await sendTelegramNotification(parsedEvent.event, parsedEvent.txHash); + switch (parsedEvent.event.eventName) { + case "ProposalCreated": + await sendDiscordNotification(parsedEvent.event, parsedEvent.txHash); + await sendTelegramNotification(parsedEvent.event, parsedEvent.txHash); + break; + case "MedianUpdated": + console.info("[HealthCheck]: OK"); + break; + default: + console.warn("Unknown event type:", parsedEvent.event); + } } res.status(200).send("Event successfully processed"); diff --git a/src/parse-transaction-receipts.ts b/src/parse-transaction-receipts.ts index c5092de..0fa61a6 100644 --- a/src/parse-transaction-receipts.ts +++ b/src/parse-transaction-receipts.ts @@ -3,31 +3,36 @@ import { decodeEventLog } from "viem"; // Internal import GovernorABI from "./governor-abi.js"; -import { ProposalCreatedEvent } from "./types.js"; +import { HealthCheckEvent, ProposalCreatedEvent } from "./types.js"; import hasLogs from "./utils/has-logs.js"; import isProposalCreatedEvent from "./utils/is-proposal-created-event.js"; import isTransactionReceipt from "./utils/is-transaction-receipt.js"; // For debugging with SortedOracles: -// import SortedOraclesABI from "./sorted-oracles-abi.js"; +import SortedOraclesABI from "./sorted-oracles-abi.js"; +import isHealthCheckEvent from "./utils/is-health-check-event.js"; /** * Parse request body containing raw transaction receipts */ export default function parseTransactionReceipts( matchedTransactionReceipts: unknown, -): { event: ProposalCreatedEvent; txHash: string }[] { +): { event: ProposalCreatedEvent | HealthCheckEvent; txHash: string }[] { const result = []; if (!Array.isArray(matchedTransactionReceipts)) { throw new Error( - `Request body is not an array of transaction receipts but was: ${JSON.stringify(matchedTransactionReceipts)}`, + `Request body is not an array of transaction receipts but was: ${JSON.stringify( + matchedTransactionReceipts, + )}`, ); } for (const receipt of matchedTransactionReceipts) { if (!isTransactionReceipt(receipt)) { throw new Error( - `'receipt' is not of type 'TransactionReceipt': ${JSON.stringify(receipt)}`, + `'receipt' is not of type 'TransactionReceipt': ${JSON.stringify( + receipt, + )}`, ); } @@ -42,24 +47,39 @@ export default function parseTransactionReceipts( throw new Error("No topics found in log"); } - const event = decodeEventLog({ - // For debugging with SortedOracles: - // abi: SortedOraclesABI, - abi: GovernorABI, - data: log.data as `0x${string}`, - topics: log.topics as [ - signature: `0x${string}`, - ...args: `0x${string}`[], - ], - }); + try { + const event = decodeEventLog({ + abi: GovernorABI, + data: log.data as `0x${string}`, + topics: log.topics as [ + signature: `0x${string}`, + ...args: `0x${string}`[], + ], + }); - if (!isProposalCreatedEvent(event)) { - throw new Error( - `Event is not a ProposalCreatedEvent: ${JSON.stringify(event)}`, - ); + if (isProposalCreatedEvent(event)) { + result.push({ event, txHash: log.transactionHash }); + } + } catch (_) { + // TODO: think of how/if we should handle this error } - result.push({ event, txHash: log.transactionHash }); + try { + const event = decodeEventLog({ + abi: SortedOraclesABI, + data: log.data as `0x${string}`, + topics: log.topics as [ + signature: `0x${string}`, + ...args: `0x${string}`[], + ], + }); + + if (isHealthCheckEvent(event)) { + result.push({ event, txHash: log.transactionHash }); + } + } catch (_) { + // TODO: think of how/if we should handle this error + } } } diff --git a/src/types.ts b/src/types.ts index 2ca4fd0..1345625 100644 --- a/src/types.ts +++ b/src/types.ts @@ -41,3 +41,11 @@ export interface ProposalCreatedEvent { version: number; }; } + +export interface HealthCheckEvent { + eventName: "MedianUpdated"; + args: { + token: `0x${string}`; + value: bigint; + }; +} diff --git a/src/utils/is-health-check-event.ts b/src/utils/is-health-check-event.ts new file mode 100644 index 0000000..72b2883 --- /dev/null +++ b/src/utils/is-health-check-event.ts @@ -0,0 +1,21 @@ +import type { DecodeEventLogReturnType } from "viem"; +import type SortedOraclesABI from "../sorted-oracles-abi.js"; +import type { HealthCheckEvent } from "../types.js"; + +export default function isProposalCreatedEvent( + event: DecodeEventLogReturnType | null | undefined, +): event is HealthCheckEvent { + if ( + event === null || + event === undefined || + typeof event !== "object" || + !("args" in event) + ) { + return false; + } + return ( + event.eventName === "MedianUpdated" && + "token" in event.args && + "value" in event.args + ); +} From d96bda4e8232a7150d6637ffaa97821caaf5f8c8 Mon Sep 17 00:00:00 2001 From: Nelson Taveras <4562733+nvtaveras@users.noreply.github.com> Date: Tue, 23 Jul 2024 02:07:09 -0400 Subject: [PATCH 02/14] fix: wrong fn name --- src/utils/is-health-check-event.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/is-health-check-event.ts b/src/utils/is-health-check-event.ts index 72b2883..8431065 100644 --- a/src/utils/is-health-check-event.ts +++ b/src/utils/is-health-check-event.ts @@ -2,7 +2,7 @@ import type { DecodeEventLogReturnType } from "viem"; import type SortedOraclesABI from "../sorted-oracles-abi.js"; import type { HealthCheckEvent } from "../types.js"; -export default function isProposalCreatedEvent( +export default function isHealthCheckEvent( event: DecodeEventLogReturnType | null | undefined, ): event is HealthCheckEvent { if ( From e612fef38fe7dabe69fb4593cb940859ce21488c Mon Sep 17 00:00:00 2001 From: Nelson Taveras <4562733+nvtaveras@users.noreply.github.com> Date: Wed, 24 Jul 2024 23:39:46 -0400 Subject: [PATCH 03/14] feat: add health-check quicknode alert --- infra/quicknode.tf | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/infra/quicknode.tf b/infra/quicknode.tf index 97fcb6d..c82c9ad 100644 --- a/infra/quicknode.tf +++ b/infra/quicknode.tf @@ -20,6 +20,18 @@ resource "quicknode_notification" "notification" { enabled = true } +# Creates a new QuickAlert event listener for `MedianUpdated` events on our SortedOracles contract, +# which is used as a health check event to ensure quicknode alerts are firing. +resource "quicknode_notification" "healthcheck" { + name = "Healthcheck event" + network = "celo-mainnet" + + # Decoded version: `tx_logs_address == '0xefb84935239dacdecf7c5ba76d8de40b077b7b33' && tx_logs_topic0 == '0xa9981ebfc3b766a742486e898f54959b050a66006dbce1a4155c1f84a08bcf41' && tx_logs_topic1 == '0x000000000000000000000000765de816845861e75a25fca122bb6898b8b1282a'` + expression = "dHhfbG9nc19hZGRyZXNzID09ICcweGVmYjg0OTM1MjM5ZGFjZGVjZjdjNWJhNzZkOGRlNDBiMDc3YjdiMzMnICYmIHR4X2xvZ3NfdG9waWMwID09ICcweGE5OTgxZWJmYzNiNzY2YTc0MjQ4NmU4OThmNTQ5NTliMDUwYTY2MDA2ZGJjZTFhNDE1NWMxZjg0YTA4YmNmNDEnICYmIHR4X2xvZ3NfdG9waWMxID09ICcweDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDc2NWRlODE2ODQ1ODYxZTc1YTI1ZmNhMTIyYmI2ODk4YjhiMTI4MmEn" + destination_ids = [resource.quicknode_destination.destination.id] + enabled = true +} + # Creates a new QuickAlert destination that forwards all received `ProposalCreated` transaction receipts to our Cloud Function resource "quicknode_destination" "destination" { name = "Cloud Function" From 1906c47606a66cad3e5b7f954096aa1b72d2b99e Mon Sep 17 00:00:00 2001 From: Nelson Taveras <4562733+nvtaveras@users.noreply.github.com> Date: Wed, 24 Jul 2024 23:42:35 -0400 Subject: [PATCH 04/14] refactor: add block number to parsed events --- src/index.ts | 2 +- src/parse-transaction-receipts.ts | 18 +++++++++++++++--- src/types.ts | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index f76f985..6e7fcaf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,7 +22,7 @@ export const watchdogNotifier: HttpFunction = async ( await sendTelegramNotification(parsedEvent.event, parsedEvent.txHash); break; case "MedianUpdated": - console.info("[HealthCheck]: OK"); + console.info(`[HealthCheck]: Block ${parsedEvent.block}`); break; default: console.warn("Unknown event type:", parsedEvent.event); diff --git a/src/parse-transaction-receipts.ts b/src/parse-transaction-receipts.ts index 0fa61a6..186043a 100644 --- a/src/parse-transaction-receipts.ts +++ b/src/parse-transaction-receipts.ts @@ -17,7 +17,11 @@ import isHealthCheckEvent from "./utils/is-health-check-event.js"; */ export default function parseTransactionReceipts( matchedTransactionReceipts: unknown, -): { event: ProposalCreatedEvent | HealthCheckEvent; txHash: string }[] { +): { + block: number; + event: ProposalCreatedEvent | HealthCheckEvent; + txHash: string; +}[] { const result = []; if (!Array.isArray(matchedTransactionReceipts)) { throw new Error( @@ -58,7 +62,11 @@ export default function parseTransactionReceipts( }); if (isProposalCreatedEvent(event)) { - result.push({ event, txHash: log.transactionHash }); + result.push({ + block: Number(receipt.blockNumber), + event, + txHash: log.transactionHash, + }); } } catch (_) { // TODO: think of how/if we should handle this error @@ -75,7 +83,11 @@ export default function parseTransactionReceipts( }); if (isHealthCheckEvent(event)) { - result.push({ event, txHash: log.transactionHash }); + result.push({ + block: Number(receipt.blockNumber), + event, + txHash: log.transactionHash, + }); } } catch (_) { // TODO: think of how/if we should handle this error diff --git a/src/types.ts b/src/types.ts index 1345625..24ca96f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -44,6 +44,7 @@ export interface ProposalCreatedEvent { export interface HealthCheckEvent { eventName: "MedianUpdated"; + block: number; args: { token: `0x${string}`; value: bigint; From 7b56baf68b8c1d6db7b914848b420270b9e5a9b4 Mon Sep 17 00:00:00 2001 From: Nelson Taveras <4562733+nvtaveras@users.noreply.github.com> Date: Wed, 24 Jul 2024 23:44:38 -0400 Subject: [PATCH 05/14] test: add test-health-check cmd --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index c2a9538..e53688a 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "prestart": "tsc", "start": "NODE_ENV=development functions-framework --target=watchdogNotifier", "test": "curl -H \"Content-Type: application/json\" -d @src/proposal-created.fixture.json localhost:8080", + "test-health-check": "curl -H \"Content-Type: application/json\" -d @src/health-check.fixture.json localhost:8080", "test-in-prod": "./test-deployed-function.sh" }, "dependencies": { From fd4f51952f2a6f72cc9dffe337ed24d0081611be Mon Sep 17 00:00:00 2001 From: Nelson Taveras <4562733+nvtaveras@users.noreply.github.com> Date: Thu, 25 Jul 2024 00:27:14 -0400 Subject: [PATCH 06/14] chore: remove comment --- src/parse-transaction-receipts.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/parse-transaction-receipts.ts b/src/parse-transaction-receipts.ts index 186043a..6dc4c79 100644 --- a/src/parse-transaction-receipts.ts +++ b/src/parse-transaction-receipts.ts @@ -68,9 +68,7 @@ export default function parseTransactionReceipts( txHash: log.transactionHash, }); } - } catch (_) { - // TODO: think of how/if we should handle this error - } + } catch (_) {} try { const event = decodeEventLog({ @@ -89,9 +87,7 @@ export default function parseTransactionReceipts( txHash: log.transactionHash, }); } - } catch (_) { - // TODO: think of how/if we should handle this error - } + } catch (_) {} } } From 3fc2a159974bbcd7ac72a924ecc7dc963f3784c2 Mon Sep 17 00:00:00 2001 From: Nelson Taveras <4562733+nvtaveras@users.noreply.github.com> Date: Thu, 25 Jul 2024 00:29:47 -0400 Subject: [PATCH 07/14] chore: organize imports --- src/parse-transaction-receipts.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/parse-transaction-receipts.ts b/src/parse-transaction-receipts.ts index 6dc4c79..fd60d5d 100644 --- a/src/parse-transaction-receipts.ts +++ b/src/parse-transaction-receipts.ts @@ -5,12 +5,10 @@ import { decodeEventLog } from "viem"; import GovernorABI from "./governor-abi.js"; import { HealthCheckEvent, ProposalCreatedEvent } from "./types.js"; import hasLogs from "./utils/has-logs.js"; +import isHealthCheckEvent from "./utils/is-health-check-event.js"; import isProposalCreatedEvent from "./utils/is-proposal-created-event.js"; import isTransactionReceipt from "./utils/is-transaction-receipt.js"; - -// For debugging with SortedOracles: import SortedOraclesABI from "./sorted-oracles-abi.js"; -import isHealthCheckEvent from "./utils/is-health-check-event.js"; /** * Parse request body containing raw transaction receipts From b5b1d8c054438f56f9fc9486218043d0bdd5e5d6 Mon Sep 17 00:00:00 2001 From: Nelson Taveras <4562733+nvtaveras@users.noreply.github.com> Date: Thu, 25 Jul 2024 16:44:26 +0200 Subject: [PATCH 08/14] chore: rename to test:healthcheck Co-authored-by: chapati --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0a5eb7c..a7943a8 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "prestart": "tsc", "start": "NODE_ENV=development functions-framework --target=watchdogNotifier", "test": "curl -H \"Content-Type: application/json\" -d @src/proposal-created.fixture.json localhost:8080", - "test-health-check": "curl -H \"Content-Type: application/json\" -d @src/health-check.fixture.json localhost:8080", + "test:healthcheck": "curl -H \"Content-Type: application/json\" -d @src/health-check.fixture.json localhost:8080", "test-in-prod": "./test-deployed-function.sh" }, "dependencies": { From 56b553c87b01341b9bd98ee305452387336e1bb0 Mon Sep 17 00:00:00 2001 From: Nelson Taveras <4562733+nvtaveras@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:44:50 -0400 Subject: [PATCH 09/14] chore: comment --- src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.ts b/src/index.ts index 6e7fcaf..cb3605c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,6 +22,7 @@ export const watchdogNotifier: HttpFunction = async ( await sendTelegramNotification(parsedEvent.event, parsedEvent.txHash); break; case "MedianUpdated": + // Acts a health check/heartbeat for the service, as it's a frequently emitted event console.info(`[HealthCheck]: Block ${parsedEvent.block}`); break; default: From a5b59284461316d887971b512835700a81575423 Mon Sep 17 00:00:00 2001 From: Nelson Taveras <4562733+nvtaveras@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:45:13 -0400 Subject: [PATCH 10/14] chore: remove sorted oracles fixture --- src/sorted-oracle-report.fixture.json | 35 --------------------------- 1 file changed, 35 deletions(-) delete mode 100644 src/sorted-oracle-report.fixture.json diff --git a/src/sorted-oracle-report.fixture.json b/src/sorted-oracle-report.fixture.json deleted file mode 100644 index 16b296b..0000000 --- a/src/sorted-oracle-report.fixture.json +++ /dev/null @@ -1,35 +0,0 @@ -[ - { - "blockHash": "0xacfb9a345bf578e4ed4f6a1aa213e041165afb7c9b65554233f4bd430c9d5cd7", - "blockNumber": "0x100fd41", - "contractAddress": "", - "cumulativeGasUsed": "0x16098f", - "effectiveGasPrice": "0x5c2c1d4c1", - "from": "0xECcd1e9439094D025Ac7D08d16B0BFE0DA3BEA53", - - "gasUsed": "0x159947", - "logs": [ - { - "address": "0xefB84935239dAcdecF7c5bA76d8dE40b077B7b33", - "blockHash": "0x4ba208f58db5fbbd65ce8dbfc5e65d42aa40444bfb7467a8c902d35ac79a152f", - "blockNumber": "0x100fd41", - "data": "0x000000000000000000000000000000000000000000000000000000006687ba8b00000000000000000000000000000000000000000000c396ea22e327bc7f1ff0", - "logIndex": "0x0", - "removed": false, - "topics": [ - "0x7cebb17173a9ed273d2b7538f64395c0ebf352ff743f1cf8ce66b437a6144213", - "0x000000000000000000000000206b25ea01e188ee243131afde526ba6e131a016", - "0x00000000000000000000000055de75fd0c2b37987757172fef7ba2ea935d284d" - ], - "transactionHash": "0x8dbe52bd851440b5d08bafbcfdce1890a9cb6015c45f07ab4f479e522f617975", - "transactionIndex": "0x1" - } - ], - "logsBloom": "0x002400080001000004200000802000000006010000000014000004004000004080000100000000420000000000001000028000080800000000010500010040008000004004000002000000080004002001000000002000021000010100000000000200000000280000800000000000000080002000000008000000100200000000000000000000008002000000000200100000004000002800008040000000001002000010000000000000100000000000080000800000000000000000000000010000020000000000000000000000040000000000000090000000000040000000012000000000a0000004008000080200020000000040000000600000004000", - "status": "0x1", - "to": "0xefB84935239dAcdecF7c5bA76d8dE40b077B7b33", - "transactionHash": "0x8dbe52bd851440b5d08bafbcfdce1890a9cb6015c45f07ab4f479e522f617975", - "transactionIndex": "0x1", - "type": "0x2" - } -] From 48613517ad271e7e8ee336ebe92a480fcbe0e99a Mon Sep 17 00:00:00 2001 From: Nelson Taveras <4562733+nvtaveras@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:55:11 -0400 Subject: [PATCH 11/14] chore: linter --- src/index.ts | 2 +- src/parse-transaction-receipts.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index cb3605c..2a9eb18 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,7 +23,7 @@ export const watchdogNotifier: HttpFunction = async ( break; case "MedianUpdated": // Acts a health check/heartbeat for the service, as it's a frequently emitted event - console.info(`[HealthCheck]: Block ${parsedEvent.block}`); + console.info("[HealthCheck]: Block " + parsedEvent.block); break; default: console.warn("Unknown event type:", parsedEvent.event); diff --git a/src/parse-transaction-receipts.ts b/src/parse-transaction-receipts.ts index fd60d5d..0720977 100644 --- a/src/parse-transaction-receipts.ts +++ b/src/parse-transaction-receipts.ts @@ -66,7 +66,7 @@ export default function parseTransactionReceipts( txHash: log.transactionHash, }); } - } catch (_) {} + } catch {} try { const event = decodeEventLog({ @@ -85,7 +85,7 @@ export default function parseTransactionReceipts( txHash: log.transactionHash, }); } - } catch (_) {} + } catch {} } } From 66c80b86660fb4d1f80af488a2f589b1917cc7aa Mon Sep 17 00:00:00 2001 From: Nelson Taveras <4562733+nvtaveras@users.noreply.github.com> Date: Thu, 25 Jul 2024 11:28:05 -0400 Subject: [PATCH 12/14] chore: ci linter --- package.json | 4 ++-- src/index.ts | 2 +- src/parse-transaction-receipts.ts | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index a7943a8..8b630af 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,8 @@ "prestart": "tsc", "start": "NODE_ENV=development functions-framework --target=watchdogNotifier", "test": "curl -H \"Content-Type: application/json\" -d @src/proposal-created.fixture.json localhost:8080", - "test:healthcheck": "curl -H \"Content-Type: application/json\" -d @src/health-check.fixture.json localhost:8080", - "test-in-prod": "./test-deployed-function.sh" + "test-in-prod": "./test-deployed-function.sh", + "test:healthcheck": "curl -H \"Content-Type: application/json\" -d @src/health-check.fixture.json localhost:8080" }, "dependencies": { "@google-cloud/functions-framework": "^3.4.0", diff --git a/src/index.ts b/src/index.ts index 2a9eb18..563d44c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,7 +23,7 @@ export const watchdogNotifier: HttpFunction = async ( break; case "MedianUpdated": // Acts a health check/heartbeat for the service, as it's a frequently emitted event - console.info("[HealthCheck]: Block " + parsedEvent.block); + console.info("[HealthCheck]: Block", parsedEvent.block); break; default: console.warn("Unknown event type:", parsedEvent.event); diff --git a/src/parse-transaction-receipts.ts b/src/parse-transaction-receipts.ts index 0720977..c9e32b0 100644 --- a/src/parse-transaction-receipts.ts +++ b/src/parse-transaction-receipts.ts @@ -66,6 +66,7 @@ export default function parseTransactionReceipts( txHash: log.transactionHash, }); } + // eslint-disable-next-line no-empty } catch {} try { @@ -85,6 +86,7 @@ export default function parseTransactionReceipts( txHash: log.transactionHash, }); } + // eslint-disable-next-line no-empty } catch {} } } From df37ebf71f239477ce22e2be56b8f30714307e69 Mon Sep 17 00:00:00 2001 From: Nelson Taveras <4562733+nvtaveras@users.noreply.github.com> Date: Fri, 26 Jul 2024 10:42:25 -0400 Subject: [PATCH 13/14] fix: make block number optional --- src/parse-transaction-receipts.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/parse-transaction-receipts.ts b/src/parse-transaction-receipts.ts index c9e32b0..57125fa 100644 --- a/src/parse-transaction-receipts.ts +++ b/src/parse-transaction-receipts.ts @@ -16,7 +16,7 @@ import SortedOraclesABI from "./sorted-oracles-abi.js"; export default function parseTransactionReceipts( matchedTransactionReceipts: unknown, ): { - block: number; + block?: number; event: ProposalCreatedEvent | HealthCheckEvent; txHash: string; }[] { @@ -61,7 +61,6 @@ export default function parseTransactionReceipts( if (isProposalCreatedEvent(event)) { result.push({ - block: Number(receipt.blockNumber), event, txHash: log.transactionHash, }); From 8d46fb87796a7cbcffe08734782bfd2c4380c80e Mon Sep 17 00:00:00 2001 From: Nelson Taveras <4562733+nvtaveras@users.noreply.github.com> Date: Fri, 26 Jul 2024 10:52:01 -0400 Subject: [PATCH 14/14] chore: make default event throw --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 563d44c..0b198a9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,7 +26,7 @@ export const watchdogNotifier: HttpFunction = async ( console.info("[HealthCheck]: Block", parsedEvent.block); break; default: - console.warn("Unknown event type:", parsedEvent.event); + throw new Error("Unknown event type", parsedEvent.event); } }