From 1f1eab092267522164f7485afe84d752bf19e446 Mon Sep 17 00:00:00 2001 From: J M Rossy Date: Tue, 19 Dec 2023 13:08:50 -0500 Subject: [PATCH] Reduce verbosity of smartprovider logging --- .../SmartProvider/HyperlaneEtherscanProvider.ts | 15 +++++++++------ .../SmartProvider/HyperlaneJsonRpcProvider.ts | 8 +++++--- .../src/providers/SmartProvider/SmartProvider.ts | 16 +++++++++------- .../sdk/src/providers/SmartProvider/types.ts | 1 + 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/typescript/sdk/src/providers/SmartProvider/HyperlaneEtherscanProvider.ts b/typescript/sdk/src/providers/SmartProvider/HyperlaneEtherscanProvider.ts index 7177cf229f..25acd5344b 100644 --- a/typescript/sdk/src/providers/SmartProvider/HyperlaneEtherscanProvider.ts +++ b/typescript/sdk/src/providers/SmartProvider/HyperlaneEtherscanProvider.ts @@ -30,6 +30,7 @@ export class HyperlaneEtherscanProvider constructor( public readonly explorerConfig: BlockExplorer, network: providers.Networkish, + public readonly options?: { debug?: boolean }, ) { super(network, explorerConfig.apiKey); if (!explorerConfig.apiKey) { @@ -80,9 +81,10 @@ export class HyperlaneEtherscanProvider const hostname = this.getHostname(); let waitTime = this.getQueryWaitTime(); while (waitTime > 0) { - this.logger( - `HyperlaneEtherscanProvider waiting ${waitTime}ms to avoid rate limit`, - ); + if (this.options?.debug) + this.logger( + `HyperlaneEtherscanProvider waiting ${waitTime}ms to avoid rate limit`, + ); await sleep(waitTime); waitTime = this.getQueryWaitTime(); } @@ -92,9 +94,10 @@ export class HyperlaneEtherscanProvider } async perform(method: string, params: any, reqId?: number): Promise { - this.logger( - `HyperlaneEtherscanProvider performing method ${method} for reqId ${reqId}`, - ); + if (this.options?.debug) + this.logger( + `HyperlaneEtherscanProvider performing method ${method} for reqId ${reqId}`, + ); if (!this.supportedMethods.includes(method as ProviderMethod)) throw new Error(`Unsupported method ${method}`); diff --git a/typescript/sdk/src/providers/SmartProvider/HyperlaneJsonRpcProvider.ts b/typescript/sdk/src/providers/SmartProvider/HyperlaneJsonRpcProvider.ts index 15220ef3a1..1a3ffbe6b5 100644 --- a/typescript/sdk/src/providers/SmartProvider/HyperlaneJsonRpcProvider.ts +++ b/typescript/sdk/src/providers/SmartProvider/HyperlaneJsonRpcProvider.ts @@ -23,14 +23,16 @@ export class HyperlaneJsonRpcProvider constructor( public readonly rpcConfig: RpcConfigWithConnectionInfo, network: providers.Networkish, + public readonly options?: { debug?: boolean }, ) { super(rpcConfig.connection ?? rpcConfig.http, network); } async perform(method: string, params: any, reqId?: number): Promise { - this.logger( - `HyperlaneJsonRpcProvider performing method ${method} for reqId ${reqId}`, - ); + if (this.options?.debug) + this.logger( + `HyperlaneJsonRpcProvider performing method ${method} for reqId ${reqId}`, + ); if (method === ProviderMethod.GetLogs) { return this.performGetLogs(params); } diff --git a/typescript/sdk/src/providers/SmartProvider/SmartProvider.ts b/typescript/sdk/src/providers/SmartProvider/SmartProvider.ts index 49dbda1c54..c0a78dfef0 100644 --- a/typescript/sdk/src/providers/SmartProvider/SmartProvider.ts +++ b/typescript/sdk/src/providers/SmartProvider/SmartProvider.ts @@ -289,16 +289,18 @@ export class HyperlaneSmartProvider reqId: number, ): Promise { try { - this.logger( - `Provider using ${providerUrl} performing method ${method} for reqId ${reqId}`, - ); + if (this.options?.debug) + this.logger( + `Provider using ${providerUrl} performing method ${method} for reqId ${reqId}`, + ); const result = await provider.perform(method, params, reqId); return { status: ProviderStatus.Success, value: result }; } catch (error) { - this.logger( - `Error performing ${method} on provider ${providerUrl} for reqId ${reqId}`, - error, - ); + if (this.options?.debug) + this.logger( + `Error performing ${method} on provider ${providerUrl} for reqId ${reqId}`, + error, + ); return { status: ProviderStatus.Error, error }; } } diff --git a/typescript/sdk/src/providers/SmartProvider/types.ts b/typescript/sdk/src/providers/SmartProvider/types.ts index 99ab306234..487d378934 100644 --- a/typescript/sdk/src/providers/SmartProvider/types.ts +++ b/typescript/sdk/src/providers/SmartProvider/types.ts @@ -50,4 +50,5 @@ export interface ProviderRetryOptions { export interface SmartProviderOptions extends ProviderRetryOptions { // The time to wait before attempting the next provider fallbackStaggerMs?: number; + debug?: boolean; }