From 7265a40875f178b251ddd4603585fd7e01f9426f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20Bayindirli=20=F0=9F=A5=82?= <15343884+nbayindirli@users.noreply.github.com> Date: Wed, 17 Jul 2024 10:35:18 -0400 Subject: [PATCH] chore(sdk): add rpcUrl, chainId, and method(params) to smart provider logging (#4146) ### Description - adds rpcUrl, chainId, and method(params) to smart provider logging ### Drive-by changes - none ### Related issues - none ### Backward compatibility - yes ### Testing - manual --- .changeset/gold-seals-burn.md | 5 +++ typescript/cli/README.md | 5 ++- .../sdk/src/deploy/verify/ContractVerifier.ts | 31 ++++++++++++------- .../providers/SmartProvider/SmartProvider.ts | 30 +++++++++++++----- 4 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 .changeset/gold-seals-burn.md diff --git a/.changeset/gold-seals-burn.md b/.changeset/gold-seals-burn.md new file mode 100644 index 000000000..9b04c131e --- /dev/null +++ b/.changeset/gold-seals-burn.md @@ -0,0 +1,5 @@ +--- +'@hyperlane-xyz/sdk': patch +--- + +Add rpcUrl, chainId, and method(params) to smart provider logging. diff --git a/typescript/cli/README.md b/typescript/cli/README.md index 8493414cd..3dff0e17f 100644 --- a/typescript/cli/README.md +++ b/typescript/cli/README.md @@ -59,4 +59,7 @@ Send test message: `hyperlane send message` ## Logging The logging format can be toggled between human-readable vs JSON-structured logs using the `LOG_FORMAT` environment variable or the `--log ` flag. -The logging verbosity can be configured using the `LOG_LEVEL` environment variable or the `--verbosity ` flag. + +Note: If you are unable to see color output after setting `LOG_FORMAT`, you may set the `FORCE_COLOR=true` environment variable as a last resort. See https://force-color.org/ & https://github.com/chalk for more info. + +The logging verbosity can be configured using the `LOG_LEVEL` environment variable or the `--verbosity ` flag. diff --git a/typescript/sdk/src/deploy/verify/ContractVerifier.ts b/typescript/sdk/src/deploy/verify/ContractVerifier.ts index 023faf8a7..6e60016e6 100644 --- a/typescript/sdk/src/deploy/verify/ContractVerifier.ts +++ b/typescript/sdk/src/deploy/verify/ContractVerifier.ts @@ -102,7 +102,7 @@ export class ContractVerifier { url.searchParams.set('action', action); } - let response; + let response: Response; if (isGetRequest) { response = await fetch(url.toString(), { method: 'GET', @@ -123,20 +123,22 @@ export class ContractVerifier { switch (result.result) { case ExplorerApiErrors.VERIFICATION_PENDING: - await sleep(5000); // wait 5 seconds + await sleep(5000); + verificationLogger.trace( + { + result: result.result, + }, + 'Verification still pending', + ); return this.submitForm(chain, action, verificationLogger, options); case ExplorerApiErrors.ALREADY_VERIFIED: case ExplorerApiErrors.ALREADY_VERIFIED_ALT: - return; case ExplorerApiErrors.PROXY_FAILED: - errorMessage = 'Proxy verification failed, try manually?'; - break; case ExplorerApiErrors.BYTECODE_MISMATCH: - errorMessage = - 'Compiled bytecode does not match deployed bytecode, check constructor arguments?'; + errorMessage = `${result.message}: ${result.result}`; break; default: - errorMessage = `Verification failed. ${ + errorMessage = `Verification failed: ${ JSON.stringify(result.result) ?? response.statusText }`; break; @@ -181,7 +183,8 @@ export class ContractVerifier { return !!result[0]?.SourceCode; } catch (error) { verificationLogger.debug( - `Error checking if contract is already verified: ${error}`, + { error }, + 'Error checking if contract is already verified', ); return false; } @@ -215,11 +218,15 @@ export class ContractVerifier { input.address, ); verificationLogger.debug( - `✅ Successfully verified proxy ${addressUrl}#readProxyContract`, + { + url: `${addressUrl}#readProxyContract`, + }, + `✅ Successfully verified proxy`, ); } catch (error) { verificationLogger.debug( - `Verification of proxy at ${input.address} failed: ${error}`, + { error }, + `Verification of proxy at ${input.address} failed`, ); throw error; } @@ -339,7 +346,7 @@ export class ContractVerifier { verificationLogger.debug( `Contract already verified at ${addressUrl}#code`, ); - await sleep(200); // There is a rate limit of 5 requests per second + await sleep(200); // 5 calls/s (https://info.etherscan.com/api-return-errors/) return; } diff --git a/typescript/sdk/src/providers/SmartProvider/SmartProvider.ts b/typescript/sdk/src/providers/SmartProvider/SmartProvider.ts index 269ef158a..6cc8c3596 100644 --- a/typescript/sdk/src/providers/SmartProvider/SmartProvider.ts +++ b/typescript/sdk/src/providers/SmartProvider/SmartProvider.ts @@ -264,26 +264,40 @@ export class HyperlaneSmartProvider ); const result = await Promise.race([resultPromise, timeoutPromise]); + const providerMetadata = { + providerIndex: pIndex, + rpcUrl: provider.getBaseUrl(), + method: `${method}(${JSON.stringify(params)})`, + chainId: this.network.chainId, + }; + if (result.status === ProviderStatus.Success) { return result.value; } else if (result.status === ProviderStatus.Timeout) { - this.logger.trace( - `Slow response from provider #${pIndex}.${ - !isLastProvider ? ' Triggering next provider.' : '' - }`, + this.logger.debug( + { ...providerMetadata }, + `Slow response from provider:`, + isLastProvider ? '' : 'Triggering next provider.', ); providerResultPromises.push(resultPromise); pIndex += 1; } else if (result.status === ProviderStatus.Error) { this.logger.debug( - `Error from provider #${pIndex}: ${result.error} - ${ - !isLastProvider ? ' Triggering next provider.' : '' - }`, + { + error: result.error, + ...providerMetadata, + }, + `Error from provider.`, + isLastProvider ? '' : 'Triggering next provider.', ); providerResultErrors.push(result.error); pIndex += 1; } else { - throw new Error('Unexpected result from provider'); + throw new Error( + `Unexpected result from provider: ${JSON.stringify( + providerMetadata, + )}`, + ); } // All providers already triggered, wait for one to complete or all to fail/timeout