Skip to content
Merged
Show file tree
Hide file tree
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
36 changes: 18 additions & 18 deletions packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import type { ClientOpts } from '../src/types.ts'
import type { RPCArgs } from './startRPC.ts'

let logger: Logger
let logger: Logger | undefined

Check warning on line 31 in packages/client/bin/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/cli.ts#L31

Added line #L31 was not covered by tests

const args: ClientOpts = getArgs()

Expand Down Expand Up @@ -118,7 +118,7 @@
}
try {
await client.chain.resetCanonicalHead(startBlock)
client.config.logger.info(`Chain height reset to ${client.chain.headers.height}`)
client.config.logger?.info(`Chain height reset to ${client.chain.headers.height}`)

Check warning on line 121 in packages/client/bin/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/cli.ts#L121

Added line #L121 was not covered by tests
} catch (err: any) {
throw EthereumJSErrorWithoutCode(`Error setting back chain in startBlock: ${err}`)
}
Expand Down Expand Up @@ -150,7 +150,7 @@
try {
await client.chain.blockchain.setIteratorHead('vm', startExecutionParent.hash())
await client.chain.update(false)
client.config.logger.info(
client.config.logger?.info(

Check warning on line 153 in packages/client/bin/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/cli.ts#L153

Added line #L153 was not covered by tests
`vmHead set to ${client.chain.headers.height} for starting stateless execution at hardfork=${startExecutionHardfork}`,
)
} catch (err: any) {
Expand All @@ -162,7 +162,7 @@
try {
await client.chain.blockchain.setIteratorHead('vm', startExecutionParent.hash())
await client.chain.update(false)
client.config.logger.info(
client.config.logger?.info(

Check warning on line 165 in packages/client/bin/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/cli.ts#L165

Added line #L165 was not covered by tests
`vmHead set to ${client.chain.headers.height} for starting stateful execution at hardfork=${startExecutionHardfork}`,
)
} catch (err: any) {
Expand All @@ -186,7 +186,7 @@
config: Config,
genesisMeta: { genesisState?: GenesisState; genesisStateRoot?: Uint8Array } = {},
) {
config.logger.info(`Data directory: ${config.datadir}`)
config.logger?.info(`Data directory: ${config.datadir}`)

Check warning on line 189 in packages/client/bin/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/cli.ts#L189

Added line #L189 was not covered by tests

const dbs = initDBs(config)

Expand Down Expand Up @@ -243,13 +243,13 @@
})
blocks.push(block)
buf = RLP.decode(buf.remainder, true)
config.logger.info(
config.logger?.info(

Check warning on line 246 in packages/client/bin/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/cli.ts#L246

Added line #L246 was not covered by tests
`Preloading block hash=${short(bytesToHex(block.header.hash()))} number=${
block.header.number
}`,
)
} catch (err: any) {
config.logger.info(
config.logger?.info(

Check warning on line 252 in packages/client/bin/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/cli.ts#L252

Added line #L252 was not covered by tests
`Encountered error while while preloading chain data error=${err.message}`,
)
break
Expand Down Expand Up @@ -310,28 +310,28 @@
servers: (RPCServer | http.Server)[]
} | null>,
) => {
config.logger.info('Caught interrupt signal. Obtaining client handle for clean shutdown...')
config.logger.info('(This might take a little longer if client not yet fully started)')
config.logger?.info('Caught interrupt signal. Obtaining client handle for clean shutdown...')
config.logger?.info('(This might take a little longer if client not yet fully started)')

Check warning on line 314 in packages/client/bin/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/cli.ts#L313-L314

Added lines #L313 - L314 were not covered by tests
let timeoutHandle
if (clientStartPromise?.toString().includes('Promise') === true)
// Client hasn't finished starting up so setting timeout to terminate process if not already shutdown gracefully
timeoutHandle = setTimeout(() => {
config.logger.warn('Client has become unresponsive while starting up.')
config.logger.warn('Check logging output for potential errors. Exiting...')
config.logger?.warn('Client has become unresponsive while starting up.')
config.logger?.warn('Check logging output for potential errors. Exiting...')

Check warning on line 320 in packages/client/bin/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/cli.ts#L319-L320

Added lines #L319 - L320 were not covered by tests
process.exit(1)
}, 30000)
const clientHandle = await clientStartPromise
if (clientHandle !== null) {
config.logger.info('Shutting down the client and the servers...')
config.logger?.info('Shutting down the client and the servers...')

Check warning on line 325 in packages/client/bin/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/cli.ts#L325

Added line #L325 was not covered by tests
const { client, servers } = clientHandle
for (const s of servers) {
//@ts-expect-error jayson.Server type doesn't play well with ESM for some reason
s['http'] !== undefined ? (s as RPCServer).http().close() : (s as http.Server).close()
}
await client.stop()
config.logger.info('Exiting.')
config.logger?.info('Exiting.')

Check warning on line 332 in packages/client/bin/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/cli.ts#L332

Added line #L332 was not covered by tests
} else {
config.logger.info('Client did not start properly, exiting ...')
config.logger?.info('Client did not start properly, exiting ...')

Check warning on line 334 in packages/client/bin/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/cli.ts#L334

Added line #L334 was not covered by tests
}
clearTimeout(timeoutHandle)
process.exit()
Expand Down Expand Up @@ -366,14 +366,14 @@
client.config.chainCommon.gteHardfork(Hardfork.Paris) &&
(args.rpcEngine === false || args.rpcEngine === undefined)
) {
config.logger.warn(`Engine RPC endpoint not activated on a post-Merge HF setup.`)
config.logger?.warn(`Engine RPC endpoint not activated on a post-Merge HF setup.`)

Check warning on line 369 in packages/client/bin/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/cli.ts#L369

Added line #L369 was not covered by tests
}
if (metricsServer !== undefined) servers.push(metricsServer)
config.superMsg('Client started successfully')
return { client, servers }
})
.catch((e) => {
config.logger.error('Error starting client', e)
config.logger?.error('Error starting client', e)

Check warning on line 376 in packages/client/bin/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/cli.ts#L376

Added line #L376 was not covered by tests
return null
})

Expand All @@ -388,8 +388,8 @@
process.on('uncaughtException', (err) => {
// Handles uncaught exceptions that are thrown in async events/functions and aren't caught in
// main client process
config.logger.error(`Uncaught error: ${err.message}`)
config.logger.error(err)
config.logger?.error(`Uncaught error: ${err.message}`)
config.logger?.error(err)

Check warning on line 392 in packages/client/bin/cli.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/cli.ts#L391-L392

Added lines #L391 - L392 were not covered by tests

void stopClient(config, clientStartPromise)
})
Expand Down
7 changes: 6 additions & 1 deletion packages/client/bin/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@
action(params) {
const level = params
if (['debug', 'info', 'warn', 'error'].includes(level)) {
for (const transport of (replServer.context.client as EthereumClient).config.logger
const logger = (replServer.context.client as EthereumClient).config.logger
if (logger === undefined) {
this.displayPrompt()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nit: I understand the intention, but if the logger is turned off, we should not use the (a) logger at all, not even the console.log() logger and if it's only for informing the user. Have removed and directly pushed.

return
}
for (const transport of (replServer.context.client as EthereumClient).config.logger!

Check warning on line 91 in packages/client/bin/repl.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/repl.ts#L86-L91

Added lines #L86 - L91 were not covered by tests
.transports) {
transport.level = level
}
Expand Down
20 changes: 10 additions & 10 deletions packages/client/bin/startRPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@

jwtSecret = randomBytes(32)
writeFileSync(defaultJwtPath, bytesToUnprefixedHex(jwtSecret), {})
config.logger.info(`New Engine API JWT token created path=${defaultJwtPath}`)
config.logger?.info(`New Engine API JWT token created path=${defaultJwtPath}`)

Check warning on line 71 in packages/client/bin/startRPC.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/startRPC.ts#L71

Added line #L71 was not covered by tests
}
config.logger.info(`Using Engine API with JWT token authentication path=${usedJwtPath}`)
config.logger?.info(`Using Engine API with JWT token authentication path=${usedJwtPath}`)

Check warning on line 73 in packages/client/bin/startRPC.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/startRPC.ts#L73

Added line #L73 was not covered by tests
return jwtSecret
}

Expand Down Expand Up @@ -138,12 +138,12 @@
: undefined,
})
rpcHttpServer.listen(rpcPort, rpcAddr)
logger.info(
logger?.info(

Check warning on line 141 in packages/client/bin/startRPC.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/startRPC.ts#L141

Added line #L141 was not covered by tests
`Started JSON RPC Server address=http://${rpcAddr}:${rpcPort} namespaces=${namespaces}${
withEngineMethods ? ' rpcEngineAuth=' + rpcEngineAuth.toString() : ''
}`,
)
logger.debug(
logger?.debug(

Check warning on line 146 in packages/client/bin/startRPC.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/startRPC.ts#L146

Added line #L146 was not covered by tests
`Methods available at address=http://${rpcAddr}:${rpcPort} namespaces=${namespaces} methods=${Object.keys(
methods,
).join(',')}`,
Expand All @@ -162,12 +162,12 @@

const rpcWsServer = createWsRPCServerListener(opts)
if (rpcWsServer) rpcWsServer.listen(wsPort)
logger.info(
logger?.info(

Check warning on line 165 in packages/client/bin/startRPC.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/startRPC.ts#L165

Added line #L165 was not covered by tests
`Started JSON RPC Server address=ws://${wsAddr}:${wsPort} namespaces=${namespaces}${
withEngineMethods ? ` rpcEngineAuth=${rpcEngineAuth}` : ''
}`,
)
logger.debug(
logger?.debug(

Check warning on line 170 in packages/client/bin/startRPC.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/startRPC.ts#L170

Added line #L170 was not covered by tests
`Methods available at address=ws://${wsAddr}:${wsPort} namespaces=${namespaces} methods=${Object.keys(
methods,
).join(',')}`,
Expand All @@ -193,10 +193,10 @@
: undefined,
})
rpcHttpServer.listen(rpcEnginePort, rpcEngineAddr)
logger.info(
logger?.info(

Check warning on line 196 in packages/client/bin/startRPC.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/startRPC.ts#L196

Added line #L196 was not covered by tests
`Started JSON RPC server address=http://${rpcEngineAddr}:${rpcEnginePort} namespaces=${namespaces} rpcEngineAuth=${rpcEngineAuth}`,
)
logger.debug(
logger?.debug(

Check warning on line 199 in packages/client/bin/startRPC.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/startRPC.ts#L199

Added line #L199 was not covered by tests
`Methods available at address=http://${rpcEngineAddr}:${rpcEnginePort} namespaces=${namespaces} methods=${Object.keys(
methods,
).join(',')}`,
Expand All @@ -216,10 +216,10 @@

const rpcWsServer = createWsRPCServerListener(opts)
if (rpcWsServer) rpcWsServer.listen(wsEnginePort, wsEngineAddr)
logger.info(
logger?.info(

Check warning on line 219 in packages/client/bin/startRPC.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/startRPC.ts#L219

Added line #L219 was not covered by tests
`Started JSON RPC Server address=ws://${wsEngineAddr}:${wsEnginePort} namespaces=${namespaces} rpcEngineAuth=${rpcEngineAuth}`,
)
logger.debug(
logger?.debug(

Check warning on line 222 in packages/client/bin/startRPC.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/startRPC.ts#L222

Added line #L222 was not covered by tests
`Methods available at address=ws://${wsEngineAddr}:${wsEnginePort} namespaces=${namespaces} methods=${Object.keys(
methods,
).join(',')}`,
Expand Down
12 changes: 6 additions & 6 deletions packages/client/bin/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
})
.option('logLevel', {
describe: 'Logging verbosity',
choices: ['error', 'warn', 'info', 'debug'],
choices: ['error', 'warn', 'info', 'debug', 'off'],

Check warning on line 209 in packages/client/bin/utils.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/utils.ts#L209

Added line #L209 was not covered by tests
default: 'info',
})
.option('logFile', {
Expand Down Expand Up @@ -757,7 +757,7 @@
args.logFile = args.logFile ? `${networkDir}/ethereumjs.log` : undefined
}

const logger: Logger = getLogger(args)
const logger: Logger | undefined = getLogger(args)

Check warning on line 760 in packages/client/bin/utils.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/utils.ts#L760

Added line #L760 was not covered by tests
let bootnodes
if (args.bootnodes !== undefined) {
// File path passed, read bootnodes from disk
Expand All @@ -777,7 +777,7 @@
}
})
bootnodes = parseMultiaddrs(nodeURLs)
logger.info(`Reading bootnodes file=${args.bootnodes[0]} num=${nodeURLs.length}`)
logger?.info(`Reading bootnodes file=${args.bootnodes[0]} num=${nodeURLs.length}`)

Check warning on line 780 in packages/client/bin/utils.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/utils.ts#L780

Added line #L780 was not covered by tests
} else {
bootnodes = parseMultiaddrs(args.bootnodes)
}
Expand Down Expand Up @@ -824,7 +824,7 @@
}
})
// Start the HTTP server which exposes the metrics on http://localhost:${args.prometheusPort}/metrics
logger.info(`Starting Metrics Server on port ${args.prometheusPort}`)
logger?.info(`Starting Metrics Server on port ${args.prometheusPort}`)

Check warning on line 827 in packages/client/bin/utils.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/utils.ts#L827

Added line #L827 was not covered by tests
metricsServer.listen(args.prometheusPort)
}

Expand Down Expand Up @@ -884,12 +884,12 @@
writeFileSync(`${networkDir}/${details.transport}`, details.url)
} catch (e) {
// In case dir is not really setup, mostly to take care of mockserver in test
config.logger.error(`Error writing listener details to disk: ${(e as Error).message}`)
config.logger?.error(`Error writing listener details to disk: ${(e as Error).message}`)

Check warning on line 887 in packages/client/bin/utils.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/utils.ts#L887

Added line #L887 was not covered by tests
}
})
if (customGenesisState !== undefined) {
const numAccounts = Object.keys(customGenesisState).length
config.logger.info(`Reading custom genesis state accounts=${numAccounts}`)
config.logger?.info(`Reading custom genesis state accounts=${numAccounts}`)

Check warning on line 892 in packages/client/bin/utils.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/bin/utils.ts#L892

Added line #L892 was not covered by tests
}
const customGenesisStateRoot = args.verkleGenesisStateRoot

Expand Down
8 changes: 4 additions & 4 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@
const name = this.config.chainCommon.chainName()
const chainId = this.config.chainCommon.chainId()
const packageJSON = getPackageJSON()
this.config.logger.info(
this.config.logger?.info(
`Initializing Ethereumjs client version=v${packageJSON.version} network=${name} chainId=${chainId}`,
)

this.config.events.on(Event.SERVER_ERROR, (error) => {
this.config.logger.warn(`Server error: ${error.name} - ${error.message}`)
this.config.logger?.warn(`Server error: ${error.name} - ${error.message}`)

Check warning on line 118 in packages/client/src/client.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/src/client.ts#L118

Added line #L118 was not covered by tests
})
this.config.events.on(Event.SERVER_LISTENING, (details) => {
this.config.logger.info(
this.config.logger?.info(

Check warning on line 121 in packages/client/src/client.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/src/client.ts#L121

Added line #L121 was not covered by tests
`Server listener up transport=${details.transport} url=${details.url}`,
)
})
Expand All @@ -135,7 +135,7 @@
if (this.started) {
return false
}
this.config.logger.info('Setup networking and services.')
this.config.logger?.info('Setup networking and services.')

await this.service.start()
this.config.server && (await this.config.server.start())
Expand Down
17 changes: 8 additions & 9 deletions packages/client/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { type Address, BIGINT_0, BIGINT_1, BIGINT_2, BIGINT_256 } from '@ethereu
import { EventEmitter } from 'eventemitter3'
import { Level } from 'level'

import { getLogger } from './logging.ts'
import { RlpxServer } from './net/server/index.ts'
import { Event } from './types.ts'
import { isBrowser, short } from './util/index.ts'
Expand Down Expand Up @@ -398,7 +397,7 @@ export class Config {
// support blobs and proofs cache for CL getBlobs for upto 1 epoch of data
public static readonly BLOBS_AND_PROOFS_CACHE_BLOCKS = 32

public readonly logger: Logger
public readonly logger: Logger | undefined
public readonly syncmode: SyncMode
public readonly vm?: VM
public readonly datadir: string
Expand Down Expand Up @@ -566,9 +565,9 @@ export class Config {
this.discDns = this.getDnsDiscovery(options.discDns)
this.discV4 = options.discV4 ?? true

this.logger = options.logger ?? getLogger({ logLevel: 'error' })
this.logger = options.logger

this.logger.info(`Sync Mode ${this.syncmode}`)
this.logger?.info(`Sync Mode ${this.syncmode}`)
if (this.syncmode !== SyncMode.None) {
if (options.server !== undefined) {
this.server = options.server
Expand Down Expand Up @@ -628,15 +627,15 @@ export class Config {
const diff = Date.now() - this.lastSyncDate
if (diff >= this.syncedStateRemovalPeriod) {
this.synchronized = false
this.logger.info(
this.logger?.info(
`Sync status reset (no chain updates for ${Math.round(diff / 1000)} seconds).`,
)
}
}
}

if (this.synchronized !== this.lastSynchronized) {
this.logger.debug(
this.logger?.debug(
`Client synchronized=${this.synchronized}${
latest !== null && latest !== undefined ? ' height=' + latest.number : ''
} syncTargetHeight=${this.syncTargetHeight} lastSyncDate=${
Expand Down Expand Up @@ -712,11 +711,11 @@ export class Config {
for (const msg of msgs) {
len = msg.length > len ? msg.length : len
}
this.logger.info('-'.repeat(len), meta)
this.logger?.info('-'.repeat(len), meta)
for (const msg of msgs) {
this.logger.info(msg, meta)
this.logger?.info(msg, meta)
}
this.logger.info('-'.repeat(len), meta)
this.logger?.info('-'.repeat(len), meta)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/execution/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ export abstract class Execution {
*/
async open(): Promise<void> {
this.started = true
this.config.logger.info('Setup EVM execution.')
this.config.logger?.info('Setup EVM execution.')
}

/**
* Stop execution. Returns a promise that resolves once stopped.
*/
async stop(): Promise<boolean> {
this.started = false
this.config.logger.info('Stopped execution.')
this.config.logger?.info('Stopped execution.')
return true
}
}
Loading
Loading