forked from cerc-io/plugeth
core, rpc: disable memory output by default in traces (#23558)
* core: cmd: invert disableMemory * core: fix missed inversion * cmd/evm: preserve Flags but change default value * Apply suggestions from code review Co-authored-by: Martin Holst Swende <martin@swende.se> Co-authored-by: Martin Holst Swende <martin@swende.se>
This commit is contained in:
parent
babe9b993e
commit
b8d7c662cd
@ -46,7 +46,7 @@ func disasmCmd(ctx *cli.Context) error {
|
|||||||
case ctx.GlobalIsSet(InputFlag.Name):
|
case ctx.GlobalIsSet(InputFlag.Name):
|
||||||
in = ctx.GlobalString(InputFlag.Name)
|
in = ctx.GlobalString(InputFlag.Name)
|
||||||
default:
|
default:
|
||||||
return errors.New("Missing filename or --input value")
|
return errors.New("missing filename or --input value")
|
||||||
}
|
}
|
||||||
|
|
||||||
code := strings.TrimSpace(in)
|
code := strings.TrimSpace(in)
|
||||||
|
@ -30,7 +30,7 @@ var (
|
|||||||
Name: "trace",
|
Name: "trace",
|
||||||
Usage: "Output full trace logs to files <txhash>.jsonl",
|
Usage: "Output full trace logs to files <txhash>.jsonl",
|
||||||
}
|
}
|
||||||
TraceDisableMemoryFlag = cli.BoolFlag{
|
TraceDisableMemoryFlag = cli.BoolTFlag{
|
||||||
Name: "trace.nomemory",
|
Name: "trace.nomemory",
|
||||||
Usage: "Disable full memory dump in traces",
|
Usage: "Disable full memory dump in traces",
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ var (
|
|||||||
Name: "trace.nostack",
|
Name: "trace.nostack",
|
||||||
Usage: "Disable stack output in traces",
|
Usage: "Disable stack output in traces",
|
||||||
}
|
}
|
||||||
TraceDisableReturnDataFlag = cli.BoolFlag{
|
TraceDisableReturnDataFlag = cli.BoolTFlag{
|
||||||
Name: "trace.noreturndata",
|
Name: "trace.noreturndata",
|
||||||
Usage: "Disable return data output in traces",
|
Usage: "Disable return data output in traces",
|
||||||
}
|
}
|
||||||
|
@ -108,8 +108,8 @@ func Transition(ctx *cli.Context) error {
|
|||||||
// Configure the EVM logger
|
// Configure the EVM logger
|
||||||
logConfig := &vm.LogConfig{
|
logConfig := &vm.LogConfig{
|
||||||
DisableStack: ctx.Bool(TraceDisableStackFlag.Name),
|
DisableStack: ctx.Bool(TraceDisableStackFlag.Name),
|
||||||
DisableMemory: ctx.Bool(TraceDisableMemoryFlag.Name),
|
EnableMemory: !ctx.Bool(TraceDisableMemoryFlag.Name),
|
||||||
DisableReturnData: ctx.Bool(TraceDisableReturnDataFlag.Name),
|
EnableReturnData: !ctx.Bool(TraceDisableReturnDataFlag.Name),
|
||||||
Debug: true,
|
Debug: true,
|
||||||
}
|
}
|
||||||
var prevFile *os.File
|
var prevFile *os.File
|
||||||
|
@ -113,7 +113,7 @@ var (
|
|||||||
Name: "receiver",
|
Name: "receiver",
|
||||||
Usage: "The transaction receiver (execution context)",
|
Usage: "The transaction receiver (execution context)",
|
||||||
}
|
}
|
||||||
DisableMemoryFlag = cli.BoolFlag{
|
DisableMemoryFlag = cli.BoolTFlag{
|
||||||
Name: "nomemory",
|
Name: "nomemory",
|
||||||
Usage: "disable memory output",
|
Usage: "disable memory output",
|
||||||
}
|
}
|
||||||
@ -125,9 +125,9 @@ var (
|
|||||||
Name: "nostorage",
|
Name: "nostorage",
|
||||||
Usage: "disable storage output",
|
Usage: "disable storage output",
|
||||||
}
|
}
|
||||||
DisableReturnDataFlag = cli.BoolFlag{
|
DisableReturnDataFlag = cli.BoolTFlag{
|
||||||
Name: "noreturndata",
|
Name: "noreturndata",
|
||||||
Usage: "disable return data output",
|
Usage: "enable return data output",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -108,10 +108,10 @@ func runCmd(ctx *cli.Context) error {
|
|||||||
glogger.Verbosity(log.Lvl(ctx.GlobalInt(VerbosityFlag.Name)))
|
glogger.Verbosity(log.Lvl(ctx.GlobalInt(VerbosityFlag.Name)))
|
||||||
log.Root().SetHandler(glogger)
|
log.Root().SetHandler(glogger)
|
||||||
logconfig := &vm.LogConfig{
|
logconfig := &vm.LogConfig{
|
||||||
DisableMemory: ctx.GlobalBool(DisableMemoryFlag.Name),
|
EnableMemory: !ctx.GlobalBool(DisableMemoryFlag.Name),
|
||||||
DisableStack: ctx.GlobalBool(DisableStackFlag.Name),
|
DisableStack: ctx.GlobalBool(DisableStackFlag.Name),
|
||||||
DisableStorage: ctx.GlobalBool(DisableStorageFlag.Name),
|
DisableStorage: ctx.GlobalBool(DisableStorageFlag.Name),
|
||||||
DisableReturnData: ctx.GlobalBool(DisableReturnDataFlag.Name),
|
EnableReturnData: !ctx.GlobalBool(DisableReturnDataFlag.Name),
|
||||||
Debug: ctx.GlobalBool(DebugFlag.Name),
|
Debug: ctx.GlobalBool(DebugFlag.Name),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,10 +59,10 @@ func stateTestCmd(ctx *cli.Context) error {
|
|||||||
|
|
||||||
// Configure the EVM logger
|
// Configure the EVM logger
|
||||||
config := &vm.LogConfig{
|
config := &vm.LogConfig{
|
||||||
DisableMemory: ctx.GlobalBool(DisableMemoryFlag.Name),
|
EnableMemory: !ctx.GlobalBool(DisableMemoryFlag.Name),
|
||||||
DisableStack: ctx.GlobalBool(DisableStackFlag.Name),
|
DisableStack: ctx.GlobalBool(DisableStackFlag.Name),
|
||||||
DisableStorage: ctx.GlobalBool(DisableStorageFlag.Name),
|
DisableStorage: ctx.GlobalBool(DisableStorageFlag.Name),
|
||||||
DisableReturnData: ctx.GlobalBool(DisableReturnDataFlag.Name),
|
EnableReturnData: !ctx.GlobalBool(DisableReturnDataFlag.Name),
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
tracer vm.Tracer
|
tracer vm.Tracer
|
||||||
|
@ -46,10 +46,10 @@ func (s Storage) Copy() Storage {
|
|||||||
|
|
||||||
// LogConfig are the configuration options for structured logger the EVM
|
// LogConfig are the configuration options for structured logger the EVM
|
||||||
type LogConfig struct {
|
type LogConfig struct {
|
||||||
DisableMemory bool // disable memory capture
|
EnableMemory bool // enable memory capture
|
||||||
DisableStack bool // disable stack capture
|
DisableStack bool // disable stack capture
|
||||||
DisableStorage bool // disable storage capture
|
DisableStorage bool // disable storage capture
|
||||||
DisableReturnData bool // disable return data capture
|
EnableReturnData bool // enable return data capture
|
||||||
Debug bool // print output during capture end
|
Debug bool // print output during capture end
|
||||||
Limit int // maximum length of output, but zero means unlimited
|
Limit int // maximum length of output, but zero means unlimited
|
||||||
// Chain overrides, can be used to execute a trace using future fork rules
|
// Chain overrides, can be used to execute a trace using future fork rules
|
||||||
@ -160,7 +160,7 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui
|
|||||||
}
|
}
|
||||||
// Copy a snapshot of the current memory state to a new buffer
|
// Copy a snapshot of the current memory state to a new buffer
|
||||||
var mem []byte
|
var mem []byte
|
||||||
if !l.cfg.DisableMemory {
|
if l.cfg.EnableMemory {
|
||||||
mem = make([]byte, len(memory.Data()))
|
mem = make([]byte, len(memory.Data()))
|
||||||
copy(mem, memory.Data())
|
copy(mem, memory.Data())
|
||||||
}
|
}
|
||||||
@ -199,7 +199,7 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost ui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var rdata []byte
|
var rdata []byte
|
||||||
if !l.cfg.DisableReturnData {
|
if l.cfg.EnableReturnData {
|
||||||
rdata = make([]byte, len(rData))
|
rdata = make([]byte, len(rData))
|
||||||
copy(rdata, rData)
|
copy(rdata, rData)
|
||||||
}
|
}
|
||||||
|
@ -61,13 +61,13 @@ func (l *JSONLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint
|
|||||||
RefundCounter: env.StateDB.GetRefund(),
|
RefundCounter: env.StateDB.GetRefund(),
|
||||||
Err: err,
|
Err: err,
|
||||||
}
|
}
|
||||||
if !l.cfg.DisableMemory {
|
if l.cfg.EnableMemory {
|
||||||
log.Memory = memory.Data()
|
log.Memory = memory.Data()
|
||||||
}
|
}
|
||||||
if !l.cfg.DisableStack {
|
if !l.cfg.DisableStack {
|
||||||
log.Stack = stack.data
|
log.Stack = stack.data
|
||||||
}
|
}
|
||||||
if !l.cfg.DisableReturnData {
|
if l.cfg.EnableReturnData {
|
||||||
log.ReturnData = rData
|
log.ReturnData = rData
|
||||||
}
|
}
|
||||||
l.encoder.Encode(log)
|
l.encoder.Encode(log)
|
||||||
|
@ -353,8 +353,8 @@ func BenchmarkTransactionTrace(b *testing.B) {
|
|||||||
tracer := vm.NewStructLogger(&vm.LogConfig{
|
tracer := vm.NewStructLogger(&vm.LogConfig{
|
||||||
Debug: false,
|
Debug: false,
|
||||||
//DisableStorage: true,
|
//DisableStorage: true,
|
||||||
//DisableMemory: true,
|
//EnableMemory: false,
|
||||||
//DisableReturnData: true,
|
//EnableReturnData: false,
|
||||||
})
|
})
|
||||||
evm := vm.NewEVM(context, txContext, statedb, params.AllEthashProtocolChanges, vm.Config{Debug: true, Tracer: tracer})
|
evm := vm.NewEVM(context, txContext, statedb, params.AllEthashProtocolChanges, vm.Config{Debug: true, Tracer: tracer})
|
||||||
msg, err := tx.AsMessage(signer, nil)
|
msg, err := tx.AsMessage(signer, nil)
|
||||||
|
@ -115,7 +115,7 @@ func withTrace(t *testing.T, gasLimit uint64, test func(vm.Config) error) {
|
|||||||
}
|
}
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
w := bufio.NewWriter(buf)
|
w := bufio.NewWriter(buf)
|
||||||
tracer := vm.NewJSONLogger(&vm.LogConfig{DisableMemory: true}, w)
|
tracer := vm.NewJSONLogger(&vm.LogConfig{}, w)
|
||||||
config.Debug, config.Tracer = true, tracer
|
config.Debug, config.Tracer = true, tracer
|
||||||
err2 := test(config)
|
err2 := test(config)
|
||||||
if !reflect.DeepEqual(err, err2) {
|
if !reflect.DeepEqual(err, err2) {
|
||||||
|
Loading…
Reference in New Issue
Block a user