From 8d79323ff527250078eab54353473faddeec3550 Mon Sep 17 00:00:00 2001 From: bmzig <57361391+bmzig@users.noreply.github.com> Date: Fri, 6 Dec 2024 12:06:56 -0600 Subject: [PATCH 1/2] improve: only log relayer balances for tokens on supported chains (#1938) Signed-off-by: bennett --- src/monitor/Monitor.ts | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/monitor/Monitor.ts b/src/monitor/Monitor.ts index 0b488694e..7202af238 100644 --- a/src/monitor/Monitor.ts +++ b/src/monitor/Monitor.ts @@ -44,10 +44,10 @@ import { getWidestPossibleExpectedBlockRange, utils, } from "../utils"; - import { MonitorClients, updateMonitorClients } from "./MonitorClientHelper"; import { MonitorConfig } from "./MonitorConfig"; import { CombinedRefunds } from "../dataworker/DataworkerUtils"; +import { PUBLIC_NETWORKS } from "@across-protocol/constants"; // 60 minutes, which is the length of the challenge window, so if a rebalance takes longer than this to finalize, // then its finalizing after the subsequent challenge period has started, which is sub-optimal. @@ -306,20 +306,22 @@ export class Monitor { throw new Error(`No decimals found for ${tokenSymbol}`); } Object.entries(columns).forEach(([chainName, cell]) => { - Object.entries(cell).forEach(([balanceType, balance]) => { - this.logger.debug({ - at: "Monitor#reportRelayerBalances", - message: "Machine-readable single balance report", - relayer, - tokenSymbol, - decimals, - chainName, - balanceType, - balanceInWei: balance.toString(), - balance: Number(utils.formatUnits(balance, decimals)), - datadog: true, + if (this._tokenEnabledForNetwork(tokenSymbol, chainName)) { + Object.entries(cell).forEach(([balanceType, balance]) => { + this.logger.debug({ + at: "Monitor#reportRelayerBalances", + message: "Machine-readable single balance report", + relayer, + tokenSymbol, + decimals, + chainName, + balanceType, + balanceInWei: balance.toString(), + balance: Number(utils.formatUnits(balance, decimals)), + datadog: true, + }); }); - }); + } }); }); }); @@ -1289,4 +1291,13 @@ export class Monitor { }) ); } + + private _tokenEnabledForNetwork(tokenSymbol: string, networkName: string): boolean { + for (const [chainId, network] of Object.entries(PUBLIC_NETWORKS)) { + if (network.name === networkName) { + return isDefined(TOKEN_SYMBOLS_MAP[tokenSymbol]?.addresses[chainId]); + } + } + return false; + } } From e32d3de5b043f12188319661623d96fcd2c09710 Mon Sep 17 00:00:00 2001 From: Matt Rice Date: Fri, 6 Dec 2024 14:58:04 -0500 Subject: [PATCH 2/2] fix: remove excess reporter datadog logs (#1939) Signed-off-by: Matt Rice --- src/monitor/Monitor.ts | 55 +++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/monitor/Monitor.ts b/src/monitor/Monitor.ts index 7202af238..0182ef912 100644 --- a/src/monitor/Monitor.ts +++ b/src/monitor/Monitor.ts @@ -296,36 +296,37 @@ export class Monitor { message: `Balance report for ${relayer} 📖`, mrkdwn, }); - - // Note: types are here for clarity, not necessity. - - Object.entries(reports).forEach(([relayer, balanceTable]) => { - Object.entries(balanceTable).forEach(([tokenSymbol, columns]) => { - const decimals = allL1Tokens.find((token) => token.symbol === tokenSymbol)?.decimals; - if (!decimals) { - throw new Error(`No decimals found for ${tokenSymbol}`); - } - Object.entries(columns).forEach(([chainName, cell]) => { - if (this._tokenEnabledForNetwork(tokenSymbol, chainName)) { - Object.entries(cell).forEach(([balanceType, balance]) => { - this.logger.debug({ - at: "Monitor#reportRelayerBalances", - message: "Machine-readable single balance report", - relayer, - tokenSymbol, - decimals, - chainName, - balanceType, - balanceInWei: balance.toString(), - balance: Number(utils.formatUnits(balance, decimals)), - datadog: true, - }); + } + Object.entries(reports).forEach(([relayer, balanceTable]) => { + Object.entries(balanceTable).forEach(([tokenSymbol, columns]) => { + const decimals = allL1Tokens.find((token) => token.symbol === tokenSymbol)?.decimals; + if (!decimals) { + throw new Error(`No decimals found for ${tokenSymbol}`); + } + Object.entries(columns).forEach(([chainName, cell]) => { + if (this._tokenEnabledForNetwork(tokenSymbol, chainName)) { + Object.entries(cell).forEach(([balanceType, balance]) => { + // Don't log zero balances. + if (balance.isZero()) { + return; + } + this.logger.debug({ + at: "Monitor#reportRelayerBalances", + message: "Machine-readable single balance report", + relayer, + tokenSymbol, + decimals, + chainName, + balanceType, + balanceInWei: balance.toString(), + balance: Number(utils.formatUnits(balance, decimals)), + datadog: true, }); - } - }); + }); + } }); }); - } + }); } // Update current balances of all tokens on each supported chain for each relayer.