@@ -26,14 +26,18 @@ import {
26
26
const DUMMY_RETURN_DATA = Buffer . from ( [ ] ) ;
27
27
const DUMMY_GAS_USED = 0n ;
28
28
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
+ */
29
33
export class VMTracer {
30
34
public tracingSteps : TracingStep [ ] = [ ] ;
31
35
32
36
private _messageTraces : MessageTrace [ ] = [ ] ;
33
37
private _lastError : Error | undefined ;
34
38
private _maxPrecompileNumber ;
35
39
36
- constructor ( private readonly _throwErrors = true ) {
40
+ constructor ( ) {
37
41
// TODO: temporarily hardcoded to remove the need of using ethereumjs' common and evm here
38
42
this . _maxPrecompileNumber = 10 ;
39
43
}
@@ -47,7 +51,7 @@ export class VMTracer {
47
51
}
48
52
49
53
private _shouldKeepTracing ( ) {
50
- return this . _throwErrors || this . _lastError === undefined ;
54
+ return this . _lastError === undefined ;
51
55
}
52
56
53
57
public addBeforeMessage ( message : TracingMessage ) {
@@ -139,11 +143,7 @@ export class VMTracer {
139
143
140
144
this . _messageTraces . push ( trace ) ;
141
145
} catch ( error ) {
142
- if ( this . _throwErrors ) {
143
- throw error ;
144
- } else {
145
- this . _lastError = error as Error ;
146
- }
146
+ this . _lastError = error as Error ;
147
147
}
148
148
}
149
149
@@ -165,15 +165,11 @@ export class VMTracer {
165
165
166
166
trace . steps . push ( { pc : Number ( step . pc ) } ) ;
167
167
} catch ( error ) {
168
- if ( this . _throwErrors ) {
169
- throw error ;
170
- } else {
171
- this . _lastError = error as Error ;
172
- }
168
+ this . _lastError = error as Error ;
173
169
}
174
170
}
175
171
176
- public addAfterMessage ( result : ExecutionResult , haltOverride ?: Exit ) {
172
+ public addAfterMessage ( result : ExecutionResult ) {
177
173
if ( ! this . _shouldKeepTracing ( ) ) {
178
174
return ;
179
175
}
@@ -193,8 +189,7 @@ export class VMTracer {
193
189
) . address ;
194
190
}
195
191
} else if ( isHaltResult ( executionResult ) ) {
196
- trace . exit =
197
- haltOverride ?? Exit . fromEdrExceptionalHalt ( executionResult . reason ) ;
192
+ trace . exit = Exit . fromEdrExceptionalHalt ( executionResult . reason ) ;
198
193
199
194
trace . returnData = Buffer . from ( [ ] ) ;
200
195
} else {
@@ -207,11 +202,7 @@ export class VMTracer {
207
202
this . _messageTraces . pop ( ) ;
208
203
}
209
204
} catch ( error ) {
210
- if ( this . _throwErrors ) {
211
- throw error ;
212
- } else {
213
- this . _lastError = error as Error ;
214
- }
205
+ this . _lastError = error as Error ;
215
206
}
216
207
}
217
208
}
0 commit comments