Skip to content

Commit

Permalink
Improve logs for quorum mismatch or failures
Browse files Browse the repository at this point in the history
  • Loading branch information
melisaguevara committed Sep 10, 2024
1 parent 9928cbc commit ff515cd
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions src/providers/retryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down Expand Up @@ -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.
Expand All @@ -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<unknown>,
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<unknown>, 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
Expand Down

0 comments on commit ff515cd

Please sign in to comment.