From ff515cd6e292f5d1b5ae74d1ff7c52fb6e140cab Mon Sep 17 00:00:00 2001 From: Melisa Guevara Date: Tue, 10 Sep 2024 01:02:58 -0300 Subject: [PATCH] Improve logs for quorum mismatch or failures --- src/providers/retryProvider.ts | 40 ++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/providers/retryProvider.ts b/src/providers/retryProvider.ts index 436be844..3b7080dd 100644 --- a/src/providers/retryProvider.ts +++ b/src/providers/retryProvider.ts @@ -125,9 +125,15 @@ export class RetryProvider extends ethers.providers.StaticJsonRpcProvider { return values[0][1]; } - const throwQuorumError = () => { + const throwQuorumError = (fallbackValues?: [ethers.providers.StaticJsonRpcProvider, unknown][]) => { const errorTexts = errors.map(([provider, errorText]) => formatProviderError(provider, errorText)); const successfulProviderUrls = values.map(([provider]) => provider.connection.url); + const mismatchedProviders = Object.fromEntries( + [...values, ...(fallbackValues || [])] + .filter(([, result]) => !compareRpcResults(method, result, quorumResult)) + .map(([provider, result]) => [provider.connection.url, result]) + ); + this._logQuorumMismatchOrFailureDetails(method, params, successfulProviderUrls, mismatchedProviders, errors); throw new Error( "Not enough providers agreed to meet quorum.\n" + "Providers that errored:\n" + @@ -186,7 +192,7 @@ export class RetryProvider extends ethers.providers.StaticJsonRpcProvider { // If this count is less than we need for quorum, throw the quorum error. if (count < quorumThreshold) { - throwQuorumError(); + throwQuorumError(fallbackValues); } // If we've achieved quorum, then we should still log the providers that mismatched with the quorum result. @@ -199,21 +205,31 @@ export class RetryProvider extends ethers.providers.StaticJsonRpcProvider { .filter(([, result]) => compareRpcResults(method, result, quorumResult)) .map(([provider]) => provider.connection.url); if (Object.keys(mismatchedProviders).length > 0 || errors.length > 0) { - logger.warn({ - at: "ProviderUtils", - message: "Some providers mismatched with the quorum result or failed 🚸", - notificationPath: "across-warn", - method, - params, - quorumProviders, - mismatchedProviders, - erroringProviders: errors.map(([provider, errorText]) => formatProviderError(provider, errorText)), - }); + this._logQuorumMismatchOrFailureDetails(method, params, quorumProviders, mismatchedProviders, errors); } return quorumResult; } + _logQuorumMismatchOrFailureDetails( + method: string, + params: Array, + quorumProviders: string[], + mismatchedProviders: { [k: string]: unknown }, + errors: [ethers.providers.StaticJsonRpcProvider, string][] + ) { + logger.warn({ + at: "ProviderUtils", + message: "Some providers mismatched with the quorum result or failed 🚸", + notificationPath: "across-warn", + method, + params: JSON.stringify(params), + quorumProviders, + mismatchedProviders: JSON.stringify(mismatchedProviders), + erroringProviders: errors.map(([provider, errorText]) => formatProviderError(provider, errorText)), + }); + } + _validateResponse(method: string, _: Array, response: unknown): boolean { // Basic validation logic to start. // Note: eth_getTransactionReceipt is ignored here because null responses are expected in the case that ethers is