From aac1aaea2ad849cbde9fd031e47d2008945f62af Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Mon, 14 Oct 2024 04:02:46 +0100 Subject: [PATCH] Don't expose root level logger --- src/cli/setupServer.ts | 2 +- src/createConfig.ts | 12 +++++++++--- src/executor/executor.ts | 2 +- src/executor/executorManager.ts | 2 +- src/executor/senderManager.ts | 2 +- src/executor/utilityWalletMonitor.ts | 2 +- src/handlers/eventManager.ts | 2 +- src/handlers/gasPriceManager.ts | 2 +- src/mempool/mempool.ts | 2 +- src/mempool/reputationManager.ts | 2 +- src/rpc/nonceQueuer.ts | 2 +- src/rpc/rpcHandler.ts | 2 +- src/rpc/server.ts | 2 +- src/rpc/validation/SafeValidator.ts | 4 ++-- src/rpc/validation/UnsafeValidator.ts | 13 +++++++++---- 15 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/cli/setupServer.ts b/src/cli/setupServer.ts index ec821d24..281b0f58 100644 --- a/src/cli/setupServer.ts +++ b/src/cli/setupServer.ts @@ -344,7 +344,7 @@ export const setupServer = async ({ executor.flushStuckTransactions() } - const rootLogger = config.logger.child( + const rootLogger = config.getLogger( { module: "root" }, { level: config.logLevel } ) diff --git a/src/createConfig.ts b/src/createConfig.ts index b0696c69..6b4e8335 100644 --- a/src/createConfig.ts +++ b/src/createConfig.ts @@ -1,10 +1,13 @@ import type { IOptions } from "@alto/cli" import type { CamelCasedProperties } from "./cli/parseArgs" -import type { Logger } from "pino" +import type { Bindings, ChildLoggerOptions, Logger } from "pino" import type { Chain, PublicClient, Transport, WalletClient } from "viem" export type AltoConfig = Readonly> & { - readonly logger: Logger + getLogger: ( + bindings: Bindings, + options?: ChildLoggerOptions + ) => Logger readonly publicClient: PublicClient readonly walletClient: WalletClient } @@ -16,7 +19,10 @@ export function createConfig( walletClient: WalletClient } ): AltoConfig { + const { logger, ...rest } = config + return { - ...config + ...rest, + getLogger: (bindings, options) => logger.child(bindings, options) } } diff --git a/src/executor/executor.ts b/src/executor/executor.ts index 880c5be8..59e4dcf8 100644 --- a/src/executor/executor.ts +++ b/src/executor/executor.ts @@ -102,7 +102,7 @@ export class Executor { this.config = config this.senderManager = senderManager this.reputationManager = reputationManager - this.logger = config.logger.child( + this.logger = config.getLogger( { module: "executor" }, { level: config.executorLogLevel || config.logLevel diff --git a/src/executor/executorManager.ts b/src/executor/executorManager.ts index d4330be1..ec897064 100644 --- a/src/executor/executorManager.ts +++ b/src/executor/executorManager.ts @@ -87,7 +87,7 @@ export class ExecutorManager { this.executor = executor this.mempool = mempool this.monitor = monitor - this.logger = config.logger.child( + this.logger = config.getLogger( { module: "executor_manager" }, { level: config.executorLogLevel || config.logLevel diff --git a/src/executor/senderManager.ts b/src/executor/senderManager.ts index a96a2446..4bd7a2a8 100644 --- a/src/executor/senderManager.ts +++ b/src/executor/senderManager.ts @@ -47,7 +47,7 @@ export class SenderManager { gasPriceManager: GasPriceManager }) { this.config = config - this.logger = config.logger.child( + this.logger = config.getLogger( { module: "executor" }, { level: config.executorLogLevel || config.logLevel diff --git a/src/executor/utilityWalletMonitor.ts b/src/executor/utilityWalletMonitor.ts index 8d33b09f..41f92ae7 100644 --- a/src/executor/utilityWalletMonitor.ts +++ b/src/executor/utilityWalletMonitor.ts @@ -22,7 +22,7 @@ export class UtilityWalletMonitor { this.config = config this.utilityWalletAddress = utilityWalletAddress this.metrics = metrics - this.logger = config.logger.child( + this.logger = config.getLogger( { module: "utility_wallet_monitor" }, { level: config.logLevel diff --git a/src/handlers/eventManager.ts b/src/handlers/eventManager.ts index 8d078c22..e5a6589f 100644 --- a/src/handlers/eventManager.ts +++ b/src/handlers/eventManager.ts @@ -20,7 +20,7 @@ export class EventManager { }) { this.chainId = config.publicClient.chain.id - this.logger = config.logger.child( + this.logger = config.getLogger( { module: "event_manager" }, { level: config.logLevel diff --git a/src/handlers/gasPriceManager.ts b/src/handlers/gasPriceManager.ts index 1e5b6f7a..4d0094ba 100644 --- a/src/handlers/gasPriceManager.ts +++ b/src/handlers/gasPriceManager.ts @@ -144,7 +144,7 @@ export class GasPriceManager { constructor(config: AltoConfig) { this.config = config - this.logger = config.logger.child( + this.logger = config.getLogger( { module: "gas_price_manager" }, { level: config.publicClientLogLevel || config.logLevel diff --git a/src/mempool/mempool.ts b/src/mempool/mempool.ts index d16850bb..6539b05b 100644 --- a/src/mempool/mempool.ts +++ b/src/mempool/mempool.ts @@ -66,7 +66,7 @@ export class MemoryMempool { this.reputationManager = reputationManager this.monitor = monitor this.validator = validator - this.logger = config.logger.child( + this.logger = config.getLogger( { module: "mempool" }, { level: config.logLevel diff --git a/src/mempool/reputationManager.ts b/src/mempool/reputationManager.ts index 80dd78ec..c0c9235e 100644 --- a/src/mempool/reputationManager.ts +++ b/src/mempool/reputationManager.ts @@ -189,7 +189,7 @@ export class ReputationManager implements InterfaceReputationManager { constructor(config: AltoConfig) { this.config = config - this.logger = config.logger.child( + this.logger = config.getLogger( { module: "reputation_manager" }, { level: config.reputationManagerLogLevel || config.logLevel diff --git a/src/rpc/nonceQueuer.ts b/src/rpc/nonceQueuer.ts index 7be01150..527d5bfb 100644 --- a/src/rpc/nonceQueuer.ts +++ b/src/rpc/nonceQueuer.ts @@ -49,7 +49,7 @@ export class NonceQueuer { }) { this.config = config this.mempool = mempool - this.logger = config.logger.child( + this.logger = config.getLogger( { module: "nonce_queuer" }, { level: config.nonceQueuerLogLevel || config.logLevel diff --git a/src/rpc/rpcHandler.ts b/src/rpc/rpcHandler.ts index 22b92d8f..7d3f9277 100644 --- a/src/rpc/rpcHandler.ts +++ b/src/rpc/rpcHandler.ts @@ -157,7 +157,7 @@ export class RpcHandler implements IRpcEndpoint { this.executor = executor this.monitor = monitor this.nonceQueuer = nonceQueuer - this.logger = config.logger.child( + this.logger = config.getLogger( { module: "rpc" }, { level: config.rpcLogLevel || config.logLevel diff --git a/src/rpc/server.ts b/src/rpc/server.ts index 78a65ab0..9cc79383 100644 --- a/src/rpc/server.ts +++ b/src/rpc/server.ts @@ -88,7 +88,7 @@ export class Server { metrics: Metrics }) { this.config = config - const logger = config.logger.child( + const logger = config.getLogger( { module: "rpc" }, { level: config.rpcLogLevel || config.logLevel diff --git a/src/rpc/validation/SafeValidator.ts b/src/rpc/validation/SafeValidator.ts index 6abeadc5..ce1a2283 100644 --- a/src/rpc/validation/SafeValidator.ts +++ b/src/rpc/validation/SafeValidator.ts @@ -313,7 +313,7 @@ export class SafeValidator const now = Date.now() / 1000 - this.config.logger.debug({ + this.logger.debug({ validAfter: validationResult.returnInfo.validAfter, validUntil: validationResult.returnInfo.validUntil, now: now @@ -514,7 +514,7 @@ export class SafeValidator } ) - this.config.logger.info( + this.logger.info( `tracerResult: ${JSON.stringify(tracerResult, (_k, v) => typeof v === "bigint" ? v.toString() : v )}` diff --git a/src/rpc/validation/UnsafeValidator.ts b/src/rpc/validation/UnsafeValidator.ts index baa82b79..ab62bf2e 100644 --- a/src/rpc/validation/UnsafeValidator.ts +++ b/src/rpc/validation/UnsafeValidator.ts @@ -51,7 +51,7 @@ export class UnsafeValidator implements InterfaceValidator { config: AltoConfig metrics: Metrics gasPriceManager: GasPriceManager - + logger: Logger gasEstimationHandler: GasEstimationHandler constructor({ @@ -66,7 +66,12 @@ export class UnsafeValidator implements InterfaceValidator { this.config = config this.metrics = metrics this.gasPriceManager = gasPriceManager - + this.logger = config.getLogger( + { module: "validator" }, + { + level: config.logLevel + } + ) this.gasEstimationHandler = new GasEstimationHandler(config) } @@ -221,7 +226,7 @@ export class UnsafeValidator implements InterfaceValidator { ...((await this.getSimulationResult( isVersion06(userOperation), simulateValidationResult, - this.config.logger, + this.logger, "validation", this.config.tenderly )) as ValidationResultV06 | ValidationResultWithAggregationV06), @@ -237,7 +242,7 @@ export class UnsafeValidator implements InterfaceValidator { const now = Date.now() / 1000 - this.config.logger.debug({ + this.logger.debug({ validAfter: validationResult.returnInfo.validAfter, validUntil: validationResult.returnInfo.validUntil, now