Skip to content

Commit 2e03e7b

Browse files
committed
refactor: Remove dead code in VMTracer
1 parent 95af341 commit 2e03e7b

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

packages/hardhat-core/src/internal/hardhat-network/provider/provider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ export class EdrProviderWrapper
576576
private async _rawTraceToSolidityStackTrace(
577577
rawTrace: RawTrace
578578
): Promise<SolidityStackTrace | undefined> {
579-
const vmTracer = new VMTracer(false);
579+
const vmTracer = new VMTracer();
580580

581581
const trace = rawTrace.trace();
582582
for (const traceItem of trace) {

packages/hardhat-core/src/internal/hardhat-network/stack-traces/vm-tracer.ts

+11-20
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@ import {
2626
const DUMMY_RETURN_DATA = Buffer.from([]);
2727
const DUMMY_GAS_USED = 0n;
2828

29+
/**
30+
* Consumes the incoming VM trace events, until an error occurs, to keep track
31+
* of the last top level message trace/error.
32+
*/
2933
export class VMTracer {
3034
public tracingSteps: TracingStep[] = [];
3135

3236
private _messageTraces: MessageTrace[] = [];
3337
private _lastError: Error | undefined;
3438
private _maxPrecompileNumber;
3539

36-
constructor(private readonly _throwErrors = true) {
40+
constructor() {
3741
// TODO: temporarily hardcoded to remove the need of using ethereumjs' common and evm here
3842
this._maxPrecompileNumber = 10;
3943
}
@@ -47,7 +51,7 @@ export class VMTracer {
4751
}
4852

4953
private _shouldKeepTracing() {
50-
return this._throwErrors || this._lastError === undefined;
54+
return this._lastError === undefined;
5155
}
5256

5357
public addBeforeMessage(message: TracingMessage) {
@@ -139,11 +143,7 @@ export class VMTracer {
139143

140144
this._messageTraces.push(trace);
141145
} catch (error) {
142-
if (this._throwErrors) {
143-
throw error;
144-
} else {
145-
this._lastError = error as Error;
146-
}
146+
this._lastError = error as Error;
147147
}
148148
}
149149

@@ -165,15 +165,11 @@ export class VMTracer {
165165

166166
trace.steps.push({ pc: Number(step.pc) });
167167
} catch (error) {
168-
if (this._throwErrors) {
169-
throw error;
170-
} else {
171-
this._lastError = error as Error;
172-
}
168+
this._lastError = error as Error;
173169
}
174170
}
175171

176-
public addAfterMessage(result: ExecutionResult, haltOverride?: Exit) {
172+
public addAfterMessage(result: ExecutionResult) {
177173
if (!this._shouldKeepTracing()) {
178174
return;
179175
}
@@ -193,8 +189,7 @@ export class VMTracer {
193189
).address;
194190
}
195191
} else if (isHaltResult(executionResult)) {
196-
trace.exit =
197-
haltOverride ?? Exit.fromEdrExceptionalHalt(executionResult.reason);
192+
trace.exit = Exit.fromEdrExceptionalHalt(executionResult.reason);
198193

199194
trace.returnData = Buffer.from([]);
200195
} else {
@@ -207,11 +202,7 @@ export class VMTracer {
207202
this._messageTraces.pop();
208203
}
209204
} catch (error) {
210-
if (this._throwErrors) {
211-
throw error;
212-
} else {
213-
this._lastError = error as Error;
214-
}
205+
this._lastError = error as Error;
215206
}
216207
}
217208
}

packages/hardhat-core/test/internal/hardhat-network/stack-traces/execution.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export async function traceTransaction(
105105
provider: EdrProviderWrapper,
106106
txData: TxData
107107
): Promise<MessageTrace> {
108-
const vmTracer = new VMTracer(false);
108+
const vmTracer = new VMTracer();
109109
provider.injectVmTracer(vmTracer);
110110

111111
try {

0 commit comments

Comments
 (0)