Skip to content

Commit 1f35988

Browse files
holimans1na
andauthored
eth/tracers, core/vm: remove time from trace output and tracing interface (#26291)
This removes the 'time' field from logs, as well as from the tracer interface. This change makes the trace output deterministic. If a tracer needs the time they can measure it themselves. No need for evm to do this. Co-authored-by: Sina Mahmoodi <[email protected]>
1 parent 06632da commit 1f35988

File tree

12 files changed

+19
-34
lines changed

12 files changed

+19
-34
lines changed

core/vm/evm.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package vm
1919
import (
2020
"math/big"
2121
"sync/atomic"
22-
"time"
2322

2423
"github.com/ethereum/go-ethereum/common"
2524
"github.com/ethereum/go-ethereum/crypto"
@@ -183,7 +182,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
183182
if evm.Config.Debug {
184183
if evm.depth == 0 {
185184
evm.Config.Tracer.CaptureStart(evm, caller.Address(), addr, false, input, gas, value)
186-
evm.Config.Tracer.CaptureEnd(ret, 0, 0, nil)
185+
evm.Config.Tracer.CaptureEnd(ret, 0, nil)
187186
} else {
188187
evm.Config.Tracer.CaptureEnter(CALL, caller.Address(), addr, input, gas, value)
189188
evm.Config.Tracer.CaptureExit(ret, 0, nil)
@@ -199,9 +198,9 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
199198
if evm.Config.Debug {
200199
if evm.depth == 0 {
201200
evm.Config.Tracer.CaptureStart(evm, caller.Address(), addr, false, input, gas, value)
202-
defer func(startGas uint64, startTime time.Time) { // Lazy evaluation of the parameters
203-
evm.Config.Tracer.CaptureEnd(ret, startGas-gas, time.Since(startTime), err)
204-
}(gas, time.Now())
201+
defer func(startGas uint64) { // Lazy evaluation of the parameters
202+
evm.Config.Tracer.CaptureEnd(ret, startGas-gas, err)
203+
}(gas)
205204
} else {
206205
// Handle tracer events for entering and exiting a call frame
207206
evm.Config.Tracer.CaptureEnter(CALL, caller.Address(), addr, input, gas, value)
@@ -448,8 +447,6 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
448447
}
449448
}
450449

451-
start := time.Now()
452-
453450
ret, err := evm.interpreter.Run(contract, nil, false)
454451

455452
// Check whether the max code size has been exceeded, assign err if the case.
@@ -487,7 +484,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
487484

488485
if evm.Config.Debug {
489486
if evm.depth == 0 {
490-
evm.Config.Tracer.CaptureEnd(ret, gas-contract.Gas, time.Since(start), err)
487+
evm.Config.Tracer.CaptureEnd(ret, gas-contract.Gas, err)
491488
} else {
492489
evm.Config.Tracer.CaptureExit(ret, gas-contract.Gas, err)
493490
}

core/vm/logger.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package vm
1818

1919
import (
2020
"math/big"
21-
"time"
2221

2322
"github.com/ethereum/go-ethereum/common"
2423
)
@@ -34,7 +33,7 @@ type EVMLogger interface {
3433
CaptureTxEnd(restGas uint64)
3534
// Top call frame
3635
CaptureStart(env *EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int)
37-
CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error)
36+
CaptureEnd(output []byte, gasUsed uint64, err error)
3837
// Rest of call frames
3938
CaptureEnter(typ OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int)
4039
CaptureExit(output []byte, gasUsed uint64, err error)

eth/tracers/js/goja.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"errors"
2222
"fmt"
2323
"math/big"
24-
"time"
2524

2625
"github.com/dop251/goja"
2726

@@ -285,9 +284,8 @@ func (t *jsTracer) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, scope
285284
}
286285

287286
// CaptureEnd is called after the call finishes to finalize the tracing.
288-
func (t *jsTracer) CaptureEnd(output []byte, gasUsed uint64, duration time.Duration, err error) {
287+
func (t *jsTracer) CaptureEnd(output []byte, gasUsed uint64, err error) {
289288
t.ctx["output"] = t.vm.ToValue(output)
290-
t.ctx["time"] = t.vm.ToValue(duration.String())
291289
if err != nil {
292290
t.ctx["error"] = t.vm.ToValue(err.Error())
293291
}

eth/tracers/js/internal/tracers/call_tracer_legacy.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@
233233
input: call.input,
234234
output: call.output,
235235
error: call.error,
236-
time: call.time,
237236
calls: call.calls,
238237
}
239238
for (var key in sorted) {

eth/tracers/js/tracer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func runTrace(tracer tracers.Tracer, vmctx *vmContext, chaincfg *params.ChainCon
7676
tracer.CaptureTxStart(gasLimit)
7777
tracer.CaptureStart(env, contract.Caller(), contract.Address(), false, []byte{}, startGas, value)
7878
ret, err := env.Interpreter().Run(contract, []byte{}, false)
79-
tracer.CaptureEnd(ret, startGas-contract.Gas, 1, err)
79+
tracer.CaptureEnd(ret, startGas-contract.Gas, err)
8080
// Rest gas assumes no refund
8181
tracer.CaptureTxEnd(contract.Gas)
8282
if err != nil {
@@ -206,7 +206,7 @@ func TestNoStepExec(t *testing.T) {
206206
}
207207
env := vm.NewEVM(vm.BlockContext{BlockNumber: big.NewInt(1)}, vm.TxContext{GasPrice: big.NewInt(100)}, &dummyStatedb{}, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer})
208208
tracer.CaptureStart(env, common.Address{}, common.Address{}, false, []byte{}, 1000, big.NewInt(0))
209-
tracer.CaptureEnd(nil, 0, 1, nil)
209+
tracer.CaptureEnd(nil, 0, nil)
210210
ret, err := tracer.GetResult()
211211
if err != nil {
212212
t.Fatal(err)

eth/tracers/logger/access_list_tracer.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package logger
1818

1919
import (
2020
"math/big"
21-
"time"
2221

2322
"github.com/ethereum/go-ethereum/common"
2423
"github.com/ethereum/go-ethereum/core/types"
@@ -162,7 +161,7 @@ func (a *AccessListTracer) CaptureState(pc uint64, op vm.OpCode, gas, cost uint6
162161
func (*AccessListTracer) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, depth int, err error) {
163162
}
164163

165-
func (*AccessListTracer) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) {}
164+
func (*AccessListTracer) CaptureEnd(output []byte, gasUsed uint64, err error) {}
166165

167166
func (*AccessListTracer) CaptureEnter(typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
168167
}

eth/tracers/logger/logger.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"math/big"
2525
"strings"
2626
"sync/atomic"
27-
"time"
2827

2928
"github.com/ethereum/go-ethereum/common"
3029
"github.com/ethereum/go-ethereum/common/hexutil"
@@ -219,7 +218,7 @@ func (l *StructLogger) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, s
219218
}
220219

221220
// CaptureEnd is called after the call finishes to finalize the tracing.
222-
func (l *StructLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) {
221+
func (l *StructLogger) CaptureEnd(output []byte, gasUsed uint64, err error) {
223222
l.output = output
224223
l.err = err
225224
if l.cfg.Debug {
@@ -385,7 +384,7 @@ func (t *mdLogger) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, scope
385384
fmt.Fprintf(t.out, "\nError: at pc=%d, op=%v: %v\n", pc, op, err)
386385
}
387386

388-
func (t *mdLogger) CaptureEnd(output []byte, gasUsed uint64, tm time.Duration, err error) {
387+
func (t *mdLogger) CaptureEnd(output []byte, gasUsed uint64, err error) {
389388
fmt.Fprintf(t.out, "\nOutput: `%#x`\nConsumed gas: `%d`\nError: `%v`\n",
390389
output, gasUsed, err)
391390
}

eth/tracers/logger/logger_json.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"encoding/json"
2121
"io"
2222
"math/big"
23-
"time"
2423

2524
"github.com/ethereum/go-ethereum/common"
2625
"github.com/ethereum/go-ethereum/common/math"
@@ -80,18 +79,17 @@ func (l *JSONLogger) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, sco
8079
}
8180

8281
// CaptureEnd is triggered at end of execution.
83-
func (l *JSONLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) {
82+
func (l *JSONLogger) CaptureEnd(output []byte, gasUsed uint64, err error) {
8483
type endLog struct {
8584
Output string `json:"output"`
8685
GasUsed math.HexOrDecimal64 `json:"gasUsed"`
87-
Time time.Duration `json:"time"`
8886
Err string `json:"error,omitempty"`
8987
}
9088
var errMsg string
9189
if err != nil {
9290
errMsg = err.Error()
9391
}
94-
l.encoder.Encode(endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), t, errMsg})
92+
l.encoder.Encode(endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), errMsg})
9593
}
9694

9795
func (l *JSONLogger) CaptureEnter(typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {

eth/tracers/native/call.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"errors"
2222
"math/big"
2323
"sync/atomic"
24-
"time"
2524

2625
"github.com/ethereum/go-ethereum/accounts/abi"
2726
"github.com/ethereum/go-ethereum/common"
@@ -142,7 +141,7 @@ func (t *callTracer) CaptureStart(env *vm.EVM, from common.Address, to common.Ad
142141
}
143142

144143
// CaptureEnd is called after the call finishes to finalize the tracing.
145-
func (t *callTracer) CaptureEnd(output []byte, gasUsed uint64, _ time.Duration, err error) {
144+
func (t *callTracer) CaptureEnd(output []byte, gasUsed uint64, err error) {
146145
t.callstack[0].processOutput(output, err)
147146
}
148147

eth/tracers/native/mux.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package native
1919
import (
2020
"encoding/json"
2121
"math/big"
22-
"time"
2322

2423
"github.com/ethereum/go-ethereum/common"
2524
"github.com/ethereum/go-ethereum/core/vm"
@@ -67,9 +66,9 @@ func (t *muxTracer) CaptureStart(env *vm.EVM, from common.Address, to common.Add
6766
}
6867

6968
// CaptureEnd is called after the call finishes to finalize the tracing.
70-
func (t *muxTracer) CaptureEnd(output []byte, gasUsed uint64, elapsed time.Duration, err error) {
69+
func (t *muxTracer) CaptureEnd(output []byte, gasUsed uint64, err error) {
7170
for _, t := range t.tracers {
72-
t.CaptureEnd(output, gasUsed, elapsed, err)
71+
t.CaptureEnd(output, gasUsed, err)
7372
}
7473
}
7574

0 commit comments

Comments
 (0)