Skip to content

Commit

Permalink
Change rpcDebug option to allow enabling/disabling specific rpc modul…
Browse files Browse the repository at this point in the history
…e logs
  • Loading branch information
scorbajio committed Oct 13, 2023
1 parent 2405da8 commit b196a13
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
6 changes: 4 additions & 2 deletions packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,10 @@ const args: ClientOpts = yargs(hideBin(process.argv))
default: 5,
})
.option('rpcDebug', {
describe: 'Additionally log complete RPC calls on log level debug (i.e. --loglevel=debug)',
boolean: true,
describe:
'Additionally log complete RPC calls on log level debug (i.e. --loglevel=debug). Can indicate a specific module or a boolean.',
choices: ['true', 'false', 'eth', 'engine'],
default: 'false',
})
.option('rpcCors', {
describe: 'Configure the Access-Control-Allow-Origin CORS header for RPC server',
Expand Down
2 changes: 1 addition & 1 deletion packages/client/bin/startRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type RPCArgs = {
rpcEnginePort: number
wsEngineAddr: string
wsEnginePort: number
rpcDebug: boolean
rpcDebug: string
helpRpc: boolean
jwtSecret?: string
rpcEngineAuth: boolean
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export interface ClientOpts {
logLevelFile?: string
logRotate?: boolean
logMaxFiles?: number
rpcDebug?: boolean
rpcDebug?: string
rpcCors?: string
maxPerRequest?: number
maxFetcherJobs?: number
Expand Down
18 changes: 13 additions & 5 deletions packages/client/src/util/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const algorithm: TAlgorithm = 'HS256'

type CreateRPCServerOpts = {
methodConfig: MethodConfig
rpcDebug: boolean
rpcDebug: string
logger?: Logger
}
type CreateRPCServerReturn = {
Expand Down Expand Up @@ -67,7 +67,11 @@ export function createRPCServer(

const onRequest = (request: any) => {
let msg = ''
if (rpcDebug) {
if (
rpcDebug === 'true' ||
(rpcDebug === 'engine' && request.method.includes('engine_') === true) ||
(rpcDebug === 'eth' && request.method.includes('eth_') === true)
) {
msg += `${request.method} called with params:\n${inspectParams(request.params)}`
} else {
msg += `${request.method} called with params: ${inspectParams(request.params, 125)}`
Expand All @@ -77,7 +81,11 @@ export function createRPCServer(

const handleResponse = (request: any, response: any, batchAddOn = '') => {
let msg = ''
if (rpcDebug) {
if (
rpcDebug === 'true' ||
(rpcDebug === 'engine' && request.method.includes('engine_') === true) ||
(rpcDebug === 'eth' && request.method.includes('eth_') === true)
) {
msg = `${request.method}${batchAddOn} responded with:\n${inspectParams(response)}`
} else {
msg = `${request.method}${batchAddOn} responded with: `
Expand Down Expand Up @@ -107,11 +115,11 @@ export function createRPCServer(
}

let methods
const ethMethods = manager.getMethods(false, rpcDebug)
const ethMethods = manager.getMethods(false, rpcDebug !== 'false')

switch (methodConfig) {
case MethodConfig.WithEngine:
methods = { ...ethMethods, ...manager.getMethods(true, rpcDebug) }
methods = { ...ethMethods, ...manager.getMethods(true, rpcDebug !== 'false') }
break
case MethodConfig.WithoutEngine:
methods = { ...ethMethods }
Expand Down

0 comments on commit b196a13

Please sign in to comment.