Skip to content

Commit 6110f7d

Browse files
committed
improves validation
Signed-off-by: Konstantina Blazhukova <[email protected]>
1 parent 11f215c commit 6110f7d

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

packages/relay/src/lib/debug.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,6 @@ export class DebugImpl implements Debug {
118118
this.logger.trace(`${requestDetails.formattedRequestId} traceTransaction(${transactionIdOrHash})`);
119119
}
120120

121-
// we currently do not support prestate tracer
122-
if (tracerObject?.tracer === TracerType.PrestateTracer) {
123-
throw predefined.INTERNAL_ERROR('Prestate tracer is not yet supported on debug_traceTransaction');
124-
}
125-
126121
//we use a wrapper since we accept a transaction where a second param with tracer/tracerConfig may not be provided
127122
//and we will still default to opcodeLogger
128123
const tracer = tracerObject?.tracer ?? TracerType.OpcodeLogger;

packages/relay/src/lib/validators/objectTypes.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,19 +312,38 @@ export class TracerConfigWrapper extends DefaultValidation<ITracerConfigWrapper>
312312

313313
const { tracer, tracerConfig } = this.object;
314314

315+
// currently we don't support prestate tracer for traceTransaction
316+
if (tracer === TracerType.PrestateTracer) {
317+
throw predefined.INTERNAL_ERROR('Prestate tracer is not yet supported on debug_traceTransaction');
318+
}
319+
320+
if (!tracerConfig) {
321+
return valid;
322+
}
323+
324+
const keys = Object.keys(tracerConfig ?? {});
325+
326+
const callTracerKeys = ['onlyTopCall'];
327+
const opcodeLoggerKeys = ['enableMemory', 'disableStack', 'disableStorage'];
328+
329+
const hasCallTracerKeys = keys.some((k) => callTracerKeys.includes(k));
315330
// we want to accept ICallTracerConfig only if the tracer is callTracer
316-
// this config is not valid for opcodeLogger
317-
if (
318-
tracerConfig &&
319-
(tracerConfig as ICallTracerConfig).onlyTopCall !== undefined &&
320-
tracer !== TracerType.CallTracer
321-
) {
331+
// this config is not valid for opcodeLogger and vice versa
332+
// accept only IOpcodeLoggerConfig with opcodeLogger tracer
333+
if (hasCallTracerKeys && tracer !== TracerType.CallTracer) {
322334
throw predefined.INVALID_PARAMETER(
323335
1,
324-
`'tracerConfig' for ${this.name()} onlyTopCall is only valid when tracer=${TracerType.CallTracer}`,
336+
`callTracer 'tracerConfig' for ${this.name()} is only valid when tracer=${TracerType.CallTracer}`,
325337
);
326338
}
327339

340+
const hasOpcodeLoggerKeys = keys.some((k) => opcodeLoggerKeys.includes(k));
341+
if (hasOpcodeLoggerKeys && tracer !== TracerType.OpcodeLogger) {
342+
throw predefined.INVALID_PARAMETER(
343+
1,
344+
`opcodeLogger 'tracerConfig' for ${this.name()} is only valid when tracer=${TracerType.OpcodeLogger}`,
345+
);
346+
}
328347
return valid;
329348
}
330349
}

0 commit comments

Comments
 (0)