feat: Add smart provider log setter (#4007)

### Description
- Add logic to enable setting of log levels to the SmartProvider. 
- Add logic to set log level to `silent` in the beginning of
`deriveTokenType()`, and then resetting it after.

### Related issues
- Fixes #4006 

### Backward compatibility
Yes

### Testing
Manual
pull/4024/head
Lee 5 months ago committed by GitHub
parent 39f66df326
commit e38d31685e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/shiny-cups-help.md
  2. 1
      typescript/sdk/src/hook/EvmHookModule.hardhat-test.ts
  3. 8
      typescript/sdk/src/providers/SmartProvider/SmartProvider.ts
  4. 33
      typescript/sdk/src/token/EvmERC20WarpRouteReader.ts

@ -0,0 +1,5 @@
---
'@hyperlane-xyz/sdk': minor
---
Add logic to set smart provider log level to disable provider logs during Warp TokenType derive

@ -240,7 +240,6 @@ describe('EvmHookModule', async () => {
async function createHook(
config: HookConfig,
): Promise<{ hook: EvmHookModule; initialHookAddress: Address }> {
console.log('Creating hook with config: ', stringifyObject(config));
const hook = await EvmHookModule.create({
chain,
config,

@ -1,5 +1,5 @@
import { BigNumber, providers, utils } from 'ethers';
import { Logger } from 'pino';
import pino, { Logger } from 'pino';
import {
raceWithContext,
@ -97,6 +97,10 @@ export class HyperlaneSmartProvider
this.supportedMethods = [...supportedMethods.values()];
}
setLogLevel(level: pino.LevelWithSilentOrString) {
this.logger.level = level;
}
async getPriorityFee(): Promise<BigNumber> {
try {
return BigNumber.from(await this.perform('maxPriorityFeePerGas', {}));
@ -271,7 +275,7 @@ export class HyperlaneSmartProvider
providerResultPromises.push(resultPromise);
pIndex += 1;
} else if (result.status === ProviderStatus.Error) {
this.logger.warn(
this.logger.debug(
`Error from provider #${pIndex}: ${result.error} - ${
!isLastProvider ? ' Triggering next provider.' : ''
}`,

@ -10,7 +10,12 @@ import {
TokenRouterConfig,
TokenType,
} from '@hyperlane-xyz/sdk';
import { Address, eqAddress, rootLogger } from '@hyperlane-xyz/utils';
import {
Address,
eqAddress,
getLogLevel,
rootLogger,
} from '@hyperlane-xyz/utils';
import { DEFAULT_CONTRACT_READ_CONCURRENCY } from '../consts/concurrency.js';
import { EvmHookReader } from '../hook/EvmHookReader.js';
@ -90,12 +95,20 @@ export class EvmERC20WarpRouteReader {
},
};
// Temporarily turn off SmartProvider logging
// Provider errors are expected because deriving will call methods that may not exist in the Bytecode
this.setSmartProviderLogLevel('silent');
// First, try checking token specific methods
for (const [type, { factory, method }] of Object.entries(contractTypes)) {
for (const [tokenType, { factory, method }] of Object.entries(
contractTypes,
)) {
try {
const warpRoute = factory.connect(warpRouteAddress, this.provider);
await warpRoute[method]();
return type as TokenType;
this.setSmartProviderLogLevel(getLogLevel()); // returns to original level defined by rootLogger
return tokenType as TokenType;
} catch (e) {
continue;
}
@ -114,6 +127,8 @@ export class EvmERC20WarpRouteReader {
throw Error(
`Error accessing token specific method, implying this is not a supported token.`,
);
} finally {
this.setSmartProviderLogLevel(getLogLevel()); // returns to original level defined by rootLogger
}
}
@ -203,4 +218,16 @@ export class EvmERC20WarpRouteReader {
return { name, symbol, decimals, totalSupply: totalSupply.toString() };
}
/**
* Conditionally sets the log level for a smart provider.
*
* @param level - The log level to set, e.g. 'debug', 'info', 'warn', 'error'.
*/
protected setSmartProviderLogLevel(level: string) {
if ('setLogLevel' in this.provider) {
//@ts-ignore
this.provider.setLogLevel(level);
}
}
}

Loading…
Cancel
Save