diff --git a/packages/relay/src/lib/clients/cache/localLRUCache.ts b/packages/relay/src/lib/clients/cache/localLRUCache.ts index ab314f6cdf..dc9caa6594 100644 --- a/packages/relay/src/lib/clients/cache/localLRUCache.ts +++ b/packages/relay/src/lib/clients/cache/localLRUCache.ts @@ -127,9 +127,7 @@ export class LocalLRUCache implements ICacheClient { public async getRemainingTtl(key: string, callingMethod: string): Promise { const cache = this.getCacheInstance(key); const remainingTtl = cache.getRemainingTTL(key); // in milliseconds - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`returning remaining TTL ${key}:${remainingTtl} on ${callingMethod} call`); - } + this.logger.trace('returning remaining TTL %s:%s on %s call', key, remainingTtl, callingMethod); return remainingTtl; } @@ -195,9 +193,7 @@ export class LocalLRUCache implements ICacheClient { * @param callingMethod - The name of the method calling the cache. */ public async delete(key: string, callingMethod: string): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`delete cache for ${key} on ${callingMethod} call`); - } + this.logger.trace('delete cache for %s on %s call', key, callingMethod); const cache = this.getCacheInstance(key); cache.delete(key); } @@ -254,9 +250,7 @@ export class LocalLRUCache implements ICacheClient { const matchingKeys = keys.filter((key) => regex.test(key)); - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`retrieving keys matching ${pattern} on ${callingMethod} call`); - } + this.logger.trace('retrieving keys matching %s on %s call', pattern, callingMethod); return matchingKeys; } diff --git a/packages/relay/src/lib/clients/cache/redisCache.ts b/packages/relay/src/lib/clients/cache/redisCache.ts index 80c5f3ebfa..15b73672d8 100644 --- a/packages/relay/src/lib/clients/cache/redisCache.ts +++ b/packages/relay/src/lib/clients/cache/redisCache.ts @@ -149,9 +149,7 @@ export class RedisCache implements IRedisCacheClient { const message = `Caching ${censoredKey}:${censoredValue} on ${callingMethod} for ${ resolvedTtl > 0 ? `${resolvedTtl} ms` : 'indefinite time' }`; - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`${message}`); - } + this.logger.trace('%s', message); // TODO: add metrics } diff --git a/packages/relay/src/lib/clients/mirrorNodeClient.ts b/packages/relay/src/lib/clients/mirrorNodeClient.ts index f5396af534..ba2ec9ad64 100644 --- a/packages/relay/src/lib/clients/mirrorNodeClient.ts +++ b/packages/relay/src/lib/clients/mirrorNodeClient.ts @@ -148,7 +148,7 @@ export class MirrorNodeClient { */ private readonly cacheService: CacheService; - static readonly EVM_ADDRESS_REGEX: RegExp = /\/accounts\/([\d\.]+)/; + static readonly EVM_ADDRESS_REGEX: RegExp = /\/accounts\/([\d.]+)/; public static readonly mirrorNodeContractResultsPageMax = ConfigService.get('MIRROR_NODE_CONTRACT_RESULTS_PG_MAX'); public static readonly mirrorNodeContractResultsLogsPageMax = ConfigService.get( @@ -224,9 +224,7 @@ export class MirrorNodeClient { retries: mirrorNodeRetries, retryDelay: (retryCount, error) => { const delay = mirrorNodeRetryDelay * retryCount; - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`Retry delay ${delay} ms on '${error?.request?.path}'`); - } + this.logger.trace("Retry delay %s ms on '%s'", delay, error?.request?.path); return delay; }, retryCondition: (error) => { @@ -451,11 +449,12 @@ export class MirrorNodeClient { const acceptedErrorResponses = MirrorNodeClient.acceptedErrorStatusesResponsePerRequestPathMap.get(pathLabel); if (error.response && acceptedErrorResponses?.includes(effectiveStatusCode)) { - if (this.logger.isLevelEnabled('debug')) { - this.logger.debug( - `An accepted error occurred while communicating with the mirror node server: method=${method}, path=${path}, status=${effectiveStatusCode}`, - ); - } + this.logger.debug( + 'An accepted error occurred while communicating with the mirror node server: method=%s, path=%s, status=%s', + method, + path, + effectiveStatusCode, + ); return null; } @@ -496,9 +495,7 @@ export class MirrorNodeClient { if (page === pageMax) { // max page reached - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`Max page reached ${pageMax} with ${results.length} results`); - } + this.logger.trace('Max page reached %s with %s results', pageMax, results.length); throw predefined.PAGINATION_MAX(pageMax); } @@ -1539,11 +1536,11 @@ export class MirrorNodeClient { operatorAccountId: string, requestDetails: RequestDetails, ): Promise { - if (this.logger.isLevelEnabled('debug')) { - this.logger.debug( - `Get transaction record via mirror node: transactionId=${transactionId}, txConstructorName=${txConstructorName}`, - ); - } + this.logger.debug( + 'Get transaction record via mirror node: transactionId=%s, txConstructorName=%s', + transactionId, + txConstructorName, + ); // Create a modified copy of requestDetails const modifiedRequestDetails = new RequestDetails({ diff --git a/packages/relay/src/lib/clients/sdkClient.ts b/packages/relay/src/lib/clients/sdkClient.ts index bffab5ce30..b35fdaee5e 100644 --- a/packages/relay/src/lib/clients/sdkClient.ts +++ b/packages/relay/src/lib/clients/sdkClient.ts @@ -557,11 +557,11 @@ export class SDKClient { let transactionFee: number = 0; let txRecordChargeAmount: number = 0; try { - if (this.logger.isLevelEnabled('debug')) { - this.logger.debug( - `Get transaction record via consensus node: transactionId=${transactionId}, txConstructorName=${txConstructorName}`, - ); - } + this.logger.debug( + 'Get transaction record via consensus node: transactionId=%s, txConstructorName=%s', + transactionId, + txConstructorName, + ); const transactionRecord = await new TransactionRecordQuery() .setTransactionId(transactionId) diff --git a/packages/relay/src/lib/config/hbarSpendingPlanConfigService.ts b/packages/relay/src/lib/config/hbarSpendingPlanConfigService.ts index ca471d22c5..6fe37318e9 100644 --- a/packages/relay/src/lib/config/hbarSpendingPlanConfigService.ts +++ b/packages/relay/src/lib/config/hbarSpendingPlanConfigService.ts @@ -112,9 +112,7 @@ export class HbarSpendingPlanConfigService { const spendingPlanConfig = ConfigService.get('HBAR_SPENDING_PLANS_CONFIG'); if (!spendingPlanConfig) { - if (logger.isLevelEnabled('trace')) { - logger.trace('HBAR_SPENDING_PLANS_CONFIG is undefined'); - } + logger.trace('HBAR_SPENDING_PLANS_CONFIG is undefined'); return []; } @@ -123,22 +121,17 @@ export class HbarSpendingPlanConfigService { return JSON.parse(spendingPlanConfig) as SpendingPlanConfig[]; } catch (jsonParseError: any) { // If parsing as JSON fails, treat it as a file path - if (logger.isLevelEnabled('trace')) { - logger.trace( - `Failed to parse HBAR_SPENDING_PLAN as JSON: ${jsonParseError.message}, now treating it as a file path...`, - ); - } + logger.trace( + 'Failed to parse HBAR_SPENDING_PLAN as JSON: %s, now treating it as a file path...', + jsonParseError.message, + ); try { const configFilePath = findConfig(spendingPlanConfig); if (configFilePath && fs.existsSync(configFilePath)) { const fileContent = fs.readFileSync(configFilePath, 'utf-8'); return JSON.parse(fileContent) as SpendingPlanConfig[]; } else { - if (logger.isLevelEnabled('trace')) { - logger.trace( - `HBAR Spending Configuration file not found at path "${configFilePath ?? spendingPlanConfig}"`, - ); - } + logger.trace('HBAR Spending Configuration file not found at path "%s"', configFilePath ?? spendingPlanConfig); return []; } } catch (fileError: any) { @@ -217,11 +210,11 @@ export class HbarSpendingPlanConfigService { */ private async updatePlanAssociations(spendingPlanConfigs: SpendingPlanConfig[]): Promise { for (const planConfig of spendingPlanConfigs) { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace( - `Updating associations for HBAR spending plan '${planConfig.name}' with ID ${planConfig.id}...`, - ); - } + this.logger.trace( + "Updating associations for HBAR spending plan '%s' with ID %s...", + planConfig.name, + planConfig.id, + ); await this.deleteObsoleteEvmAddressAssociations(planConfig); await this.deleteObsoleteIpAddressAssociations(planConfig); await this.updateEvmAddressAssociations(planConfig); diff --git a/packages/relay/src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository.ts b/packages/relay/src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository.ts index 5fee2d106d..9359c645d2 100644 --- a/packages/relay/src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository.ts +++ b/packages/relay/src/lib/db/repositories/hbarLimiter/evmAddressHbarSpendingPlanRepository.ts @@ -69,9 +69,7 @@ export class EvmAddressHbarSpendingPlanRepository { for (const key of keys) { const addressPlan = await this.cache.getAsync(key, callingMethod); if (addressPlan?.planId === planId) { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`Removing EVM address ${addressPlan.evmAddress} from HbarSpendingPlan with ID ${planId}`); - } + this.logger.trace('Removing EVM address %s from HbarSpendingPlan with ID %s', addressPlan.evmAddress, planId); await this.cache.delete(key, callingMethod); } } @@ -89,11 +87,11 @@ export class EvmAddressHbarSpendingPlanRepository { if (!addressPlan) { throw new EvmAddressHbarSpendingPlanNotFoundError(evmAddress); } - if (this.logger.isLevelEnabled('debug')) { - this.logger.debug( - `Retrieved link between EVM address ${evmAddress} and HbarSpendingPlan with ID ${addressPlan.planId}`, - ); - } + this.logger.debug( + 'Retrieved link between EVM address %s and HbarSpendingPlan with ID %s', + evmAddress, + addressPlan.planId, + ); return new EvmAddressHbarSpendingPlan(addressPlan); } @@ -107,11 +105,11 @@ export class EvmAddressHbarSpendingPlanRepository { async save(addressPlan: IEvmAddressHbarSpendingPlan, ttl: number): Promise { const key = this.getKey(addressPlan.evmAddress); await this.cache.set(key, addressPlan, 'save', ttl); - if (this.logger.isLevelEnabled('debug')) { - this.logger.debug( - `Linked EVM address ${addressPlan.evmAddress} to HbarSpendingPlan with ID ${addressPlan.planId}`, - ); - } + this.logger.debug( + 'Linked EVM address %s to HbarSpendingPlan with ID %s', + addressPlan.evmAddress, + addressPlan.planId, + ); } /** @@ -127,9 +125,7 @@ export class EvmAddressHbarSpendingPlanRepository { const errorMessage = evmAddressPlan ? `Removed EVM address ${evmAddress} from HbarSpendingPlan with ID ${evmAddressPlan.planId}` : `Trying to remove EVM address ${evmAddress}, which is not linked to a spending plan`; - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`${errorMessage}`); - } + this.logger.trace('%s', errorMessage); } /** diff --git a/packages/relay/src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository.ts b/packages/relay/src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository.ts index ed12b49ef1..f0db4af577 100644 --- a/packages/relay/src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository.ts +++ b/packages/relay/src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository.ts @@ -42,9 +42,7 @@ export class HbarSpendingPlanRepository { if (!plan) { throw new HbarSpendingPlanNotFoundError(id); } - if (this.logger.isLevelEnabled('debug')) { - this.logger.debug(`Retrieved subscription with ID ${id}`); - } + this.logger.debug('Retrieved subscription with ID %s', id); return { ...plan, createdAt: new Date(plan.createdAt), @@ -81,18 +79,14 @@ export class HbarSpendingPlanRepository { spendingHistory: [], amountSpent: 0, }; - if (this.logger.isLevelEnabled('debug')) { - this.logger.debug(`Creating HbarSpendingPlan with ID ${plan.id}...`); - } + this.logger.debug('Creating HbarSpendingPlan with ID %s...', plan.id); const key = this.getKey(plan.id); await this.cache.set(key, plan, 'create', ttl); return new HbarSpendingPlan(plan); } async delete(id: string): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`Deleting HbarSpendingPlan with ID ${id}...`); - } + this.logger.trace('Deleting HbarSpendingPlan with ID %s...', id); const key = this.getKey(id); await this.cache.delete(key, 'delete'); } @@ -117,9 +111,7 @@ export class HbarSpendingPlanRepository { async getSpendingHistory(id: string): Promise { await this.checkExistsAndActive(id); - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`Retrieving spending history for HbarSpendingPlan with ID ${id}...`); - } + this.logger.trace('Retrieving spending history for HbarSpendingPlan with ID %s...', id); const key = this.getSpendingHistoryKey(id); const spendingHistory = await this.cache.lRange(key, 0, -1, 'getSpendingHistory'); return spendingHistory.map((entry) => new HbarSpendingRecord(entry)); @@ -134,9 +126,7 @@ export class HbarSpendingPlanRepository { async addAmountToSpendingHistory(id: string, amount: number): Promise { await this.checkExistsAndActive(id); - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`Adding ${amount} to spending history for HbarSpendingPlan with ID ${id}...`); - } + this.logger.trace('Adding %s to spending history for HbarSpendingPlan with ID %s...', amount, id); const key = this.getSpendingHistoryKey(id); const entry: IHbarSpendingRecord = { amount, timestamp: new Date() }; return this.cache.rPush(key, entry, 'addAmountToSpendingHistory'); @@ -150,9 +140,7 @@ export class HbarSpendingPlanRepository { async getAmountSpent(id: string): Promise { await this.checkExistsAndActive(id); - if (this.logger.isLevelEnabled('debug')) { - this.logger.debug(`Retrieving amountSpent for HbarSpendingPlan with ID ${id}...`); - } + this.logger.debug('Retrieving amountSpent for HbarSpendingPlan with ID %s...', id); const key = this.getAmountSpentKey(id); return this.cache.getAsync(key, 'getAmountSpent').then((amountSpent) => parseInt(amountSpent ?? '0')); } @@ -162,15 +150,11 @@ export class HbarSpendingPlanRepository { * @returns - A promise that resolves when the operation is complete. */ async resetAmountSpentOfAllPlans(): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`Resetting the \`amountSpent\` entries for all HbarSpendingPlans...`); - } + this.logger.trace('Resetting the `amountSpent` entries for all HbarSpendingPlans...'); const callerMethod = this.resetAmountSpentOfAllPlans.name; const keys = await this.cache.keys(this.getAmountSpentKey('*'), callerMethod); await Promise.all(keys.map((key) => this.cache.delete(key, callerMethod))); - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`Successfully reset ${keys.length} "amountSpent" entries for HbarSpendingPlans.`); - } + this.logger.trace('Successfully reset %s "amountSpent" entries for HbarSpendingPlans.', keys.length); } /** @@ -185,14 +169,10 @@ export class HbarSpendingPlanRepository { const key = this.getAmountSpentKey(id); if (!(await this.cache.getAsync(key, 'addToAmountSpent'))) { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`No spending yet for HbarSpendingPlan with ID ${id}, setting amountSpent to ${amount}...`); - } + this.logger.trace('No spending yet for HbarSpendingPlan with ID %s, setting amountSpent to %s...', id, amount); await this.cache.set(key, amount, 'addToAmountSpent', ttl); } else { - if (this.logger.isLevelEnabled('debug')) { - this.logger.debug(`Adding ${amount} to amountSpent for HbarSpendingPlan with ID ${id}...`); - } + this.logger.debug('Adding %s to amountSpent for HbarSpendingPlan with ID %s...', amount, id); await this.cache.incrBy(key, amount, 'addToAmountSpent'); } } diff --git a/packages/relay/src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository.ts b/packages/relay/src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository.ts index f1b973a908..f946de0328 100644 --- a/packages/relay/src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository.ts +++ b/packages/relay/src/lib/db/repositories/hbarLimiter/ipAddressHbarSpendingPlanRepository.ts @@ -69,9 +69,7 @@ export class IPAddressHbarSpendingPlanRepository { for (const key of keys) { const addressPlan = await this.cache.getAsync(key, callingMethod); if (addressPlan?.planId === planId) { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`Removing IP address from HbarSpendingPlan with ID ${planId}`); - } + this.logger.trace('Removing IP address from HbarSpendingPlan with ID %s', planId); await this.cache.delete(key, callingMethod); } } @@ -89,9 +87,7 @@ export class IPAddressHbarSpendingPlanRepository { if (!addressPlan) { throw new IPAddressHbarSpendingPlanNotFoundError(ipAddress); } - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`Retrieved link between IP address and HbarSpendingPlan with ID ${addressPlan.planId}`); - } + this.logger.trace('Retrieved link between IP address and HbarSpendingPlan with ID %s', addressPlan.planId); return new IPAddressHbarSpendingPlan(addressPlan); } @@ -121,9 +117,7 @@ export class IPAddressHbarSpendingPlanRepository { const errorMessage = ipAddressSpendingPlan ? `Removed IP address from HbarSpendingPlan with ID ${ipAddressSpendingPlan.planId}` : `Trying to remove an IP address, which is not linked to a spending plan`; - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`${errorMessage}`); - } + this.logger.trace('%s', errorMessage); } /** diff --git a/packages/relay/src/lib/debug.ts b/packages/relay/src/lib/debug.ts index 098331a410..7e3197a2ca 100644 --- a/packages/relay/src/lib/debug.ts +++ b/packages/relay/src/lib/debug.ts @@ -115,10 +115,6 @@ export class DebugImpl implements Debug { tracerObject: TransactionTracerConfig, requestDetails: RequestDetails, ): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`traceTransaction(${transactionIdOrHash})`); - } - //we use a wrapper since we accept a transaction where a second param with tracer/tracerConfig may not be provided //and we will still default to opcodeLogger const tracer = tracerObject?.tracer ?? TracerType.OpcodeLogger; diff --git a/packages/relay/src/lib/dispatcher/rpcMethodDispatcher.ts b/packages/relay/src/lib/dispatcher/rpcMethodDispatcher.ts index 514be8d028..2dc0c3ae06 100644 --- a/packages/relay/src/lib/dispatcher/rpcMethodDispatcher.ts +++ b/packages/relay/src/lib/dispatcher/rpcMethodDispatcher.ts @@ -79,9 +79,7 @@ export class RpcMethodDispatcher { const operationHandler = this.methodRegistry.get(rpcMethodName); if (!operationHandler) { - if (this.logger.isLevelEnabled('debug')) { - this.logger.debug(`RPC method not found in registry: rpcMethodName=${rpcMethodName}`); - } + this.logger.debug('RPC method not found in registry: rpcMethodName=%s', rpcMethodName); throw this.throwUnregisteredRpcMethods(rpcMethodName); } @@ -90,11 +88,11 @@ export class RpcMethodDispatcher { const methodParamSchemas = operationHandler[RPC_PARAM_VALIDATION_RULES_KEY]; if (methodParamSchemas) { - if (this.logger.isLevelEnabled('info')) { - this.logger.info( - `Validating method parameters for ${rpcMethodName}, params: ${JSON.stringify(rpcMethodParams)}`, - ); - } + this.logger.info( + 'Validating method parameters for %s, params: %s', + rpcMethodName, + JSON.stringify(rpcMethodParams), + ); validateParams(rpcMethodParams, methodParamSchemas); } diff --git a/packages/relay/src/lib/eth.ts b/packages/relay/src/lib/eth.ts index 2c75057a26..94435329fb 100644 --- a/packages/relay/src/lib/eth.ts +++ b/packages/relay/src/lib/eth.ts @@ -205,9 +205,6 @@ export class EthImpl implements Eth { @rpcMethod @rpcParamLayoutConfig(RPC_LAYOUT.REQUEST_DETAILS_ONLY) async blockNumber(requestDetails: RequestDetails): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`blockNumber()`); - } return await this.common.getLatestBlockNumber(requestDetails); } @@ -224,9 +221,6 @@ export class EthImpl implements Eth { @rpcMethod @rpcParamLayoutConfig(RPC_LAYOUT.REQUEST_DETAILS_ONLY) chainId(): string { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`chainId()`); - } return this.chain; } @@ -297,9 +291,6 @@ export class EthImpl implements Eth { @rpcMethod @rpcParamLayoutConfig(RPC_LAYOUT.REQUEST_DETAILS_ONLY) async mining(): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace('mining()'); - } return false; } @@ -340,9 +331,6 @@ export class EthImpl implements Eth { 0: { type: 'hex', required: true }, }) async getFilterLogs(filterId: string, requestDetails: RequestDetails): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`getFilterLogs(${filterId})`); - } return this.filterService.getFilterLogs(filterId, requestDetails); } @@ -361,9 +349,6 @@ export class EthImpl implements Eth { 0: { type: 'hex', required: true }, }) async getFilterChanges(filterId: string, requestDetails: RequestDetails): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`getFilterChanges(${filterId})`); - } return this.filterService.getFilterChanges(filterId, requestDetails); } @@ -379,9 +364,6 @@ export class EthImpl implements Eth { @rpcMethod @rpcParamLayoutConfig(RPC_LAYOUT.REQUEST_DETAILS_ONLY) async newBlockFilter(requestDetails: RequestDetails): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace('newBlockFilter()'); - } return this.filterService.newBlockFilter(requestDetails); } @@ -399,9 +381,6 @@ export class EthImpl implements Eth { 0: { type: 'hex', required: true }, }) async uninstallFilter(filterId: string): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`uninstallFilter(${filterId})`); - } return this.filterService.uninstallFilter(filterId); } @@ -417,9 +396,6 @@ export class EthImpl implements Eth { @rpcMethod @rpcParamLayoutConfig(RPC_LAYOUT.REQUEST_DETAILS_ONLY) newPendingTransactionFilter(): JsonRpcError { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace('newPendingTransactionFilter()'); - } return predefined.UNSUPPORTED_METHOD; } @@ -429,9 +405,6 @@ export class EthImpl implements Eth { @rpcMethod @rpcParamLayoutConfig(RPC_LAYOUT.REQUEST_DETAILS_ONLY) async submitWork(): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace('submitWork()'); - } return false; } @@ -441,9 +414,6 @@ export class EthImpl implements Eth { @rpcMethod @rpcParamLayoutConfig(RPC_LAYOUT.REQUEST_DETAILS_ONLY) async syncing(): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace('syncing()'); - } return false; } @@ -525,9 +495,6 @@ export class EthImpl implements Eth { @rpcMethod @rpcParamLayoutConfig(RPC_LAYOUT.REQUEST_DETAILS_ONLY) async hashrate(): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace('hashrate()'); - } return constants.ZERO_HEX; } @@ -542,9 +509,6 @@ export class EthImpl implements Eth { @rpcMethod @rpcParamLayoutConfig(RPC_LAYOUT.REQUEST_DETAILS_ONLY) getWork(): JsonRpcError { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace('getWork()'); - } return predefined.UNSUPPORTED_METHOD; } @@ -559,9 +523,6 @@ export class EthImpl implements Eth { @rpcMethod @rpcParamLayoutConfig(RPC_LAYOUT.REQUEST_DETAILS_ONLY) submitHashrate(): JsonRpcError { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace('submitHashrate()'); - } return predefined.UNSUPPORTED_METHOD; } @@ -618,9 +579,6 @@ export class EthImpl implements Eth { @rpcMethod @rpcParamLayoutConfig(RPC_LAYOUT.REQUEST_DETAILS_ONLY) protocolVersion(): JsonRpcError { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace('protocolVersion()'); - } return predefined.UNSUPPORTED_METHOD; } @@ -635,9 +593,6 @@ export class EthImpl implements Eth { @rpcMethod @rpcParamLayoutConfig(RPC_LAYOUT.REQUEST_DETAILS_ONLY) coinbase(): JsonRpcError { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace('coinbase()'); - } return predefined.UNSUPPORTED_METHOD; } @@ -652,9 +607,6 @@ export class EthImpl implements Eth { @rpcMethod @rpcParamLayoutConfig(RPC_LAYOUT.REQUEST_DETAILS_ONLY) simulateV1(): JsonRpcError { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace('simulateV1()'); - } return predefined.UNSUPPORTED_METHOD; } @@ -669,9 +621,6 @@ export class EthImpl implements Eth { @rpcMethod @rpcParamLayoutConfig(RPC_LAYOUT.REQUEST_DETAILS_ONLY) blobBaseFee(): JsonRpcError { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace('blobBaseFee()'); - } return predefined.UNSUPPORTED_METHOD; } @@ -983,10 +932,6 @@ export class EthImpl implements Eth { `call({to=${call.to}, from=${call.from}, data=${callData}, gas=${call.gas}, gasPrice=${call.gasPrice} blockParam=${blockParam}, estimate=${call.estimate})`, ); // log request info and increment metrics counter - const callDataSize = callData ? callData.length : 0; - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`call data size: ${callDataSize}`); - } this.eventEmitter.emit('eth_execution', { method: constants.ETH_CALL, @@ -1093,9 +1038,6 @@ export class EthImpl implements Eth { @rpcMethod @rpcParamLayoutConfig(RPC_LAYOUT.REQUEST_DETAILS_ONLY) async maxPriorityFeePerGas(): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace('maxPriorityFeePerGas()'); - } return constants.ZERO_HEX; } @@ -1134,9 +1076,6 @@ export class EthImpl implements Eth { @rpcMethod @rpcParamLayoutConfig(RPC_LAYOUT.REQUEST_DETAILS_ONLY) getProof(): JsonRpcError { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace('getProof()'); - } return predefined.UNSUPPORTED_METHOD; } @@ -1152,9 +1091,6 @@ export class EthImpl implements Eth { @rpcMethod @rpcParamLayoutConfig(RPC_LAYOUT.REQUEST_DETAILS_ONLY) createAccessList(): JsonRpcError { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace('createAccessList()'); - } return predefined.UNSUPPORTED_METHOD; } } diff --git a/packages/relay/src/lib/precheck.ts b/packages/relay/src/lib/precheck.ts index 1da6a082a8..4bec3f2576 100644 --- a/packages/relay/src/lib/precheck.ts +++ b/packages/relay/src/lib/precheck.ts @@ -108,11 +108,11 @@ export class Precheck { * @param accountInfoNonce - The nonce of the account. */ nonce(tx: Transaction, accountInfoNonce: number): void { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace( - `Nonce precheck for sendRawTransaction(tx.nonce=${tx.nonce}, accountInfoNonce=${accountInfoNonce})`, - ); - } + this.logger.trace( + 'Nonce precheck for sendRawTransaction(tx.nonce=%s, accountInfoNonce=%s)', + tx.nonce, + accountInfoNonce, + ); if (accountInfoNonce > tx.nonce) { throw predefined.NONCE_TOO_LOW(tx.nonce, accountInfoNonce); diff --git a/packages/relay/src/lib/services/ethService/accountService/AccountService.ts b/packages/relay/src/lib/services/ethService/accountService/AccountService.ts index 95970ad779..45bf165ea4 100644 --- a/packages/relay/src/lib/services/ethService/accountService/AccountService.ts +++ b/packages/relay/src/lib/services/ethService/accountService/AccountService.ts @@ -99,9 +99,7 @@ export class AccountService implements IAccountService { blockNumberOrTagOrHash: string, requestDetails: RequestDetails, ): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`getBalance(account=${account}, blockNumberOrTag=${blockNumberOrTagOrHash})`); - } + this.logger.trace('getBalance(account=%s, blockNumberOrTag=%s)', account, blockNumberOrTagOrHash); let latestBlock: LatestBlockNumberTimestamp | null | undefined; // this check is required, because some tools like Metamask pass for parameter latest block, with a number (ex 0x30ea) diff --git a/packages/relay/src/lib/services/ethService/blockService/BlockService.ts b/packages/relay/src/lib/services/ethService/blockService/BlockService.ts index 109a74515c..6607a39bb5 100644 --- a/packages/relay/src/lib/services/ethService/blockService/BlockService.ts +++ b/packages/relay/src/lib/services/ethService/blockService/BlockService.ts @@ -155,11 +155,11 @@ export class BlockService implements IBlockService { const receiptPromises = contractResults.map(async (contractResult) => { if (Utils.isRevertedDueToHederaSpecificValidation(contractResult)) { - if (this.logger.isLevelEnabled('debug')) { - this.logger.debug( - `Transaction with hash ${contractResult.hash} is skipped due to hedera-specific validation failure (${contractResult.result})`, - ); - } + this.logger.debug( + 'Transaction with hash %s is skipped due to hedera-specific validation failure (%s)', + contractResult.hash, + contractResult.result, + ); return null; } diff --git a/packages/relay/src/lib/services/ethService/contractService/ContractService.ts b/packages/relay/src/lib/services/ethService/contractService/ContractService.ts index 64a610cc54..897008e587 100644 --- a/packages/relay/src/lib/services/ethService/contractService/ContractService.ts +++ b/packages/relay/src/lib/services/ethService/contractService/ContractService.ts @@ -100,9 +100,7 @@ export class ContractService implements IContractService { * @returns An empty array of addresses */ public accounts(): [] { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`accounts()`); - } + this.logger.trace('accounts()'); return []; } diff --git a/packages/relay/src/lib/services/ethService/ethCommonService/CommonService.ts b/packages/relay/src/lib/services/ethService/ethCommonService/CommonService.ts index 5419ba2d13..7368f79be9 100644 --- a/packages/relay/src/lib/services/ethService/ethCommonService/CommonService.ts +++ b/packages/relay/src/lib/services/ethService/ethCommonService/CommonService.ts @@ -225,20 +225,19 @@ export class CommonService implements ICommonService { returnLatest: boolean = true, ): Promise { if (!returnLatest && this.blockTagIsLatestOrPending(blockNumberOrTagOrHash)) { - if (this.logger.isLevelEnabled('debug')) { - this.logger.debug( - `Detected a contradiction between blockNumberOrTagOrHash and returnLatest. The request does not target the latest block, yet blockNumberOrTagOrHash representing latest or pending: returnLatest=${returnLatest}, blockNumberOrTagOrHash=${blockNumberOrTagOrHash}`, - ); - } + this.logger.debug( + 'Detected a contradiction between blockNumberOrTagOrHash and returnLatest. The request does not target the latest block, yet blockNumberOrTagOrHash representing latest or pending: returnLatest=%s, blockNumberOrTagOrHash=%s', + returnLatest, + blockNumberOrTagOrHash, + ); return null; } if (blockNumberOrTagOrHash === constants.EMPTY_HEX) { - if (this.logger.isLevelEnabled('debug')) { - this.logger.debug( - `Invalid input detected in getHistoricalBlockResponse(): blockNumberOrTagOrHash=${blockNumberOrTagOrHash}.`, - ); - } + this.logger.debug( + 'Invalid input detected in getHistoricalBlockResponse(): blockNumberOrTagOrHash=%s.', + blockNumberOrTagOrHash, + ); return null; } @@ -469,9 +468,7 @@ export class CommonService implements ICommonService { * @param requestDetails */ public async gasPrice(requestDetails: RequestDetails): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`eth_gasPrice`); - } + this.logger.trace('eth_gasPrice'); try { const gasPrice = Utils.addPercentageBufferToGasPrice(await this.getGasPriceInWeibars(requestDetails)); diff --git a/packages/relay/src/lib/services/ethService/feeService/FeeService.ts b/packages/relay/src/lib/services/ethService/feeService/FeeService.ts index b626fe2742..1fc8c60052 100644 --- a/packages/relay/src/lib/services/ethService/feeService/FeeService.ts +++ b/packages/relay/src/lib/services/ethService/feeService/FeeService.ts @@ -139,9 +139,7 @@ export class FeeService implements IFeeService { * @param requestDetails */ public async maxPriorityFeePerGas(): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace('maxPriorityFeePerGas()'); - } + this.logger.trace('maxPriorityFeePerGas()'); return constants.ZERO_HEX; } diff --git a/packages/relay/src/lib/services/ethService/transactionService/TransactionService.ts b/packages/relay/src/lib/services/ethService/transactionService/TransactionService.ts index 6a1b80816f..3439a241bc 100644 --- a/packages/relay/src/lib/services/ethService/transactionService/TransactionService.ts +++ b/packages/relay/src/lib/services/ethService/transactionService/TransactionService.ts @@ -106,9 +106,7 @@ export class TransactionService implements ITransactionService { transactionIndex: string, requestDetails: RequestDetails, ): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`getTransactionByBlockHashAndIndex(hash=${blockHash}, index=${transactionIndex})`); - } + this.logger.trace('getTransactionByBlockHashAndIndex(hash=%s, index=%s)', blockHash, transactionIndex); try { return await this.getTransactionByBlockHashOrBlockNumAndIndex( diff --git a/packages/relay/src/lib/services/hbarLimitService/index.ts b/packages/relay/src/lib/services/hbarLimitService/index.ts index 40f708a9fa..1cab823ace 100644 --- a/packages/relay/src/lib/services/hbarLimitService/index.ts +++ b/packages/relay/src/lib/services/hbarLimitService/index.ts @@ -174,9 +174,7 @@ export class HbarLimitService implements IHbarLimitService { * @returns {Promise} - A promise that resolves when the operation is complete. */ async resetLimiter(requestDetails: RequestDetails): Promise { - if (this.logger.isLevelEnabled('trace')) { - this.logger.trace(`Resetting HBAR rate limiter...`); - } + this.logger.trace('Resetting HBAR rate limiter...'); await this.hbarSpendingPlanRepository.resetAmountSpentOfAllPlans(); const remainingBudget = await this.getRemainingBudget(requestDetails); this.hbarLimitRemainingGauge.set(remainingBudget.toTinybars().toNumber()); @@ -218,9 +216,7 @@ export class HbarLimitService implements IHbarLimitService { return false; } const signer = `signerAddress=${evmAddress}`; - if (this.logger.isLevelEnabled('debug')) { - this.logger.debug(`Checking if signer account should be limited: ${signer}`); - } + this.logger.debug('Checking if signer account should be limited: %s', signer); let spendingPlan = await this.getSpendingPlan(evmAddress, requestDetails); if (!spendingPlan) { // Create a basic spending plan if none exists for the evm address @@ -434,9 +430,7 @@ export class HbarLimitService implements IHbarLimitService { try { return await this.getSpendingPlanByEvmAddress(evmAddress); } catch (error) { - if (this.logger.isLevelEnabled('debug')) { - this.logger.debug(`Spending plan not found: evmAddress='${evmAddress}'`); - } + this.logger.debug('Spending plan not found: evmAddress=%s', evmAddress); } } @@ -444,9 +438,7 @@ export class HbarLimitService implements IHbarLimitService { try { return await this.getSpendingPlanByIPAddress(requestDetails); } catch (error) { - if (this.logger.isLevelEnabled('debug')) { - this.logger.debug(` Spending plan not found for IP address.`); - } + this.logger.debug('Spending plan not found for IP address.'); } } diff --git a/packages/relay/src/lib/services/metricService/metricService.ts b/packages/relay/src/lib/services/metricService/metricService.ts index 2b86f4e8b7..3464c2345d 100644 --- a/packages/relay/src/lib/services/metricService/metricService.ts +++ b/packages/relay/src/lib/services/metricService/metricService.ts @@ -151,11 +151,13 @@ export default class MetricService { requestDetails, originalCallerAddress, }: IExecuteQueryEventPayload): Promise => { - if (this.logger.isLevelEnabled('debug')) { - this.logger.debug( - `Capturing transaction fee charged to operator: executionMode=${executionMode} transactionId=${transactionId}, txConstructorName=${txConstructorName}, cost=${cost} tinybars`, - ); - } + this.logger.debug( + 'Capturing transaction fee charged to operator: executionMode=%s transactionId=%s, txConstructorName=%s, cost=%s tinybars', + executionMode, + transactionId, + txConstructorName, + cost, + ); await this.hbarLimitService.addExpense(cost, originalCallerAddress ?? '', requestDetails); this.captureMetrics(executionMode, txConstructorName, status, cost, gasUsed);