Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce verbosity of smartprovider logging #3084

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<any> {
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}`);

Original file line number Diff line number Diff line change
@@ -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<any> {
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);
}
25 changes: 13 additions & 12 deletions typescript/sdk/src/providers/SmartProvider/SmartProvider.ts
Original file line number Diff line number Diff line change
@@ -195,7 +195,6 @@ export class HyperlaneSmartProvider
// Trigger the next provider in line
if (pIndex < providers.length) {
const provider = providers[pIndex];
const providerUrl = provider.getBaseUrl();
const isLastProvider = pIndex === providers.length - 1;

// Skip the explorer provider if it's currently in a cooldown period
@@ -211,7 +210,7 @@ export class HyperlaneSmartProvider

const resultPromise = this.wrapProviderPerform(
provider,
providerUrl,
pIndex,
method,
params,
reqId,
@@ -225,15 +224,15 @@ export class HyperlaneSmartProvider
return result.value;
} else if (result.status === ProviderStatus.Timeout) {
this.logger(
`Slow response from provider using ${providerUrl}.${
`Slow response from provider #${pIndex}.${
!isLastProvider ? ' Triggering next provider.' : ''
}`,
);
providerResultPromises.push(resultPromise);
pIndex += 1;
} else if (result.status === ProviderStatus.Error) {
this.logger(
`Error from provider using ${providerUrl}.${
`Error from provider #${pIndex}.${
!isLastProvider ? ' Triggering next provider.' : ''
}`,
);
@@ -283,22 +282,24 @@ export class HyperlaneSmartProvider
// Warp for additional logging and error handling
protected async wrapProviderPerform(
provider: HyperlaneProvider,
providerUrl: string,
pIndex: number,
method: string,
params: any,
reqId: number,
): Promise<ProviderPerformResult> {
try {
this.logger(
`Provider using ${providerUrl} performing method ${method} for reqId ${reqId}`,
);
if (this.options?.debug)
this.logger(
`Provider #${pIndex} 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 #${pIndex} for reqId ${reqId}`,
error,
);
return { status: ProviderStatus.Error, error };
}
}
1 change: 1 addition & 0 deletions typescript/sdk/src/providers/SmartProvider/types.ts
Original file line number Diff line number Diff line change
@@ -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;
}