Revert "refactor: reduce number of heap allocations in tracing (#952)" (#959)

This reverts commit b84f4ed6f8.
This commit is contained in:
Ömer Faruk Irmak 2024-08-02 16:59:50 +03:00 committed by GitHub
parent ee0410ec10
commit 2ba5ea3058
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 16 deletions

View file

@ -70,7 +70,7 @@ type ExecutionResult struct {
// currently they are just `from` and `to` account
AccountsAfter []*AccountWrapper `json:"accountAfter"`
StructLogs []StructLogRes `json:"structLogs"`
StructLogs []*StructLogRes `json:"structLogs"`
CallTrace json.RawMessage `json:"callTrace"`
}
@ -91,8 +91,8 @@ type StructLogRes struct {
// NewStructLogResBasic Basic StructLogRes skeleton, Stack&Memory&Storage&ExtraData are separated from it for GC optimization;
// still need to fill in with Stack&Memory&Storage&ExtraData
func NewStructLogResBasic(pc uint64, op string, gas, gasCost uint64, depth int, refundCounter uint64, err error) StructLogRes {
logRes := StructLogRes{
func NewStructLogResBasic(pc uint64, op string, gas, gasCost uint64, depth int, refundCounter uint64, err error) *StructLogRes {
logRes := &StructLogRes{
Pc: pc,
Op: op,
Gas: gas,

View file

@ -79,8 +79,8 @@ type StructLog struct {
Err error `json:"-"`
}
func NewStructlog(pc uint64, op OpCode, gas, cost uint64, depth int, err error) StructLog {
return StructLog{
func NewStructlog(pc uint64, op OpCode, gas, cost uint64, depth int, err error) *StructLog {
return &StructLog{
Pc: pc,
Op: op,
Gas: gas,
@ -90,6 +90,14 @@ func NewStructlog(pc uint64, op OpCode, gas, cost uint64, depth int, err error)
}
}
func (s *StructLog) clean() {
s.Memory.Reset()
s.Stack = s.Stack[:0]
s.ReturnData.Reset()
s.Storage = nil
s.Err = nil
}
// overrides for gencodec
type structLogMarshaling struct {
Gas math.HexOrDecimal64
@ -151,7 +159,7 @@ type StructLogger struct {
createdAccount *types.AccountWrapper
callStackLogInd []int
logs []StructLog
logs []*StructLog
output []byte
err error
}
@ -351,7 +359,7 @@ func (l *StructLogger) TracedBytecodes() map[common.Hash]CodeInfo {
func (l *StructLogger) CreatedAccount() *types.AccountWrapper { return l.createdAccount }
// StructLogs returns the captured log entries.
func (l *StructLogger) StructLogs() []StructLog { return l.logs }
func (l *StructLogger) StructLogs() []*StructLog { return l.logs }
// Error returns the VM error captured by the trace.
func (l *StructLogger) Error() error { return l.err }
@ -360,7 +368,7 @@ func (l *StructLogger) Error() error { return l.err }
func (l *StructLogger) Output() []byte { return l.output }
// WriteTrace writes a formatted trace to the given writer
func WriteTrace(writer io.Writer, logs []StructLog) {
func WriteTrace(writer io.Writer, logs []*StructLog) {
for _, log := range logs {
fmt.Fprintf(writer, "%-16spc=%08d gas=%v cost=%v", log.Op, log.Pc, log.Gas, log.GasCost)
if log.Err != nil {
@ -480,8 +488,8 @@ func (t *mdLogger) CaptureEnter(typ OpCode, from common.Address, to common.Addre
func (t *mdLogger) CaptureExit(output []byte, gasUsed uint64, err error) {}
// FormatLogs formats EVM returned structured logs for json output
func FormatLogs(logs []StructLog) []types.StructLogRes {
formatted := make([]types.StructLogRes, 0, len(logs))
func FormatLogs(logs []*StructLog) []*types.StructLogRes {
formatted := make([]*types.StructLogRes, 0, len(logs))
for _, trace := range logs {
logRes := types.NewStructLogResBasic(trace.Pc, trace.Op.String(), trace.Gas, trace.GasCost, trace.Depth, trace.RefundCounter, trace.Err)

View file

@ -227,7 +227,7 @@ func TestTraceCall(t *testing.T) {
Gas: params.TxGas,
Failed: false,
ReturnValue: "",
StructLogs: []types.StructLogRes{},
StructLogs: []*types.StructLogRes{},
},
},
// Standard JSON trace upon the head, plain transfer.
@ -245,7 +245,7 @@ func TestTraceCall(t *testing.T) {
Gas: params.TxGas,
Failed: false,
ReturnValue: "",
StructLogs: []types.StructLogRes{},
StructLogs: []*types.StructLogRes{},
},
},
// Standard JSON trace upon the non-existent block, error expects
@ -275,7 +275,7 @@ func TestTraceCall(t *testing.T) {
Gas: params.TxGas,
Failed: false,
ReturnValue: "",
StructLogs: []types.StructLogRes{},
StructLogs: []*types.StructLogRes{},
},
},
// Standard JSON trace upon the pending block
@ -293,7 +293,7 @@ func TestTraceCall(t *testing.T) {
Gas: params.TxGas,
Failed: false,
ReturnValue: "",
StructLogs: []types.StructLogRes{},
StructLogs: []*types.StructLogRes{},
},
},
}
@ -347,7 +347,7 @@ func TestTraceTransaction(t *testing.T) {
Gas: params.TxGas,
Failed: false,
ReturnValue: "",
StructLogs: []types.StructLogRes{},
StructLogs: []*types.StructLogRes{},
}) {
t.Error("Transaction tracing result is different")
}

View file

@ -24,7 +24,7 @@ import (
const (
VersionMajor = 5 // Major version component of the current release
VersionMinor = 5 // Minor version component of the current release
VersionPatch = 21 // Patch version component of the current release
VersionPatch = 22 // Patch version component of the current release
VersionMeta = "mainnet" // Version metadata to append to the version string
)