Skip to content

Commit

Permalink
Merge branch 're-write' of github.com:pimlicolabs/alto into functional
Browse files Browse the repository at this point in the history
  • Loading branch information
plusminushalf committed Oct 14, 2024
2 parents 134b019 + aac1aae commit ef0df53
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/cli/setupServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export const setupServer = async ({
executor.flushStuckTransactions()
}

const rootLogger = config.logger.child(
const rootLogger = config.getLogger(
{ module: "root" },
{ level: config.logLevel }
)
Expand Down
12 changes: 9 additions & 3 deletions src/createConfig.ts
Original file line number Diff line number Diff line change
@@ -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<CamelCasedProperties<IOptions>> & {
readonly logger: Logger
getLogger: <ChildCustomLevels extends string = never>(
bindings: Bindings,
options?: ChildLoggerOptions<ChildCustomLevels>
) => Logger<ChildCustomLevels>
readonly publicClient: PublicClient<Transport, Chain>
readonly walletClient: WalletClient<Transport, Chain>
}
Expand All @@ -16,7 +19,10 @@ export function createConfig(
walletClient: WalletClient<Transport, Chain>
}
): AltoConfig {
const { logger, ...rest } = config

return {
...config
...rest,
getLogger: (bindings, options) => logger.child(bindings, options)
}
}
2 changes: 1 addition & 1 deletion src/executor/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/executor/executorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/executor/senderManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/executor/utilityWalletMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/eventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/gasPriceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ const getGasPrice = ({
export type GasPriceManager = Awaited<ReturnType<typeof createGasPriceManager>>

export async function createGasPriceManager(config: AltoConfig) {
const logger = config.logger.child(
const logger = config.getLogger(
{ module: "gas_price_manager" },
{
level: config.publicClientLogLevel || config.logLevel
Expand Down
2 changes: 1 addition & 1 deletion src/mempool/mempool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/mempool/reputationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/nonceQueuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/rpcHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/validation/SafeValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)}`
Expand Down
13 changes: 9 additions & 4 deletions src/rpc/validation/UnsafeValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class UnsafeValidator implements InterfaceValidator {
config: AltoConfig
metrics: Metrics
gasPriceManager: GasPriceManager

logger: Logger
gasEstimationHandler: GasEstimationHandler

constructor({
Expand All @@ -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)
}

Expand Down Expand Up @@ -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),
Expand All @@ -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
Expand Down

0 comments on commit ef0df53

Please sign in to comment.