all: move loggers to eth/tracers (#23892)

* all: mv loggers to eth/tracers

* core/vm: minor

* eth/tracers: tmp comment out testStoreCapture

* eth/tracers: uncomment and fix logger test

* eth/tracers: simplify test

* core/vm: re-add license

* core/vm: minor

* rename LogConfig to Config
This commit is contained in:
Sina Mahmoodi
2021-11-25 13:17:09 +01:00
committed by GitHub
parent 9055cc14ec
commit 1876cb443b
15 changed files with 441 additions and 401 deletions

View File

@ -36,6 +36,7 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/tracers/logger"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/log"
@ -165,7 +166,7 @@ func (api *API) blockByNumberAndHash(ctx context.Context, number rpc.BlockNumber
// TraceConfig holds extra parameters to trace functions.
type TraceConfig struct {
*vm.LogConfig
*logger.Config
Tracer *string
Timeout *string
Reexec *uint64
@ -174,7 +175,7 @@ type TraceConfig struct {
// TraceCallConfig is the config for traceCall API. It holds one more
// field to override the state for tracing.
type TraceCallConfig struct {
*vm.LogConfig
*logger.Config
Tracer *string
Timeout *string
Reexec *uint64
@ -183,7 +184,7 @@ type TraceCallConfig struct {
// StdTraceConfig holds extra parameters to standard-json trace functions.
type StdTraceConfig struct {
vm.LogConfig
logger.Config
Reexec *uint64
TxHash common.Hash
}
@ -669,11 +670,11 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
}
// Retrieve the tracing configurations, or use default values
var (
logConfig vm.LogConfig
logConfig logger.Config
txHash common.Hash
)
if config != nil {
logConfig = config.LogConfig
logConfig = config.Config
txHash = config.TxHash
}
logConfig.Debug = true
@ -698,7 +699,7 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
chainConfigCopy := new(params.ChainConfig)
*chainConfigCopy = *chainConfig
chainConfig = chainConfigCopy
if berlin := config.LogConfig.Overrides.BerlinBlock; berlin != nil {
if berlin := config.Config.Overrides.BerlinBlock; berlin != nil {
chainConfig.BerlinBlock = berlin
canon = false
}
@ -730,7 +731,7 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
writer = bufio.NewWriter(dump)
vmConf = vm.Config{
Debug: true,
Tracer: vm.NewJSONLogger(&logConfig, writer),
Tracer: logger.NewJSONLogger(&logConfig, writer),
EnablePreimageRecording: true,
}
}
@ -847,10 +848,10 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
var traceConfig *TraceConfig
if config != nil {
traceConfig = &TraceConfig{
LogConfig: config.LogConfig,
Tracer: config.Tracer,
Timeout: config.Timeout,
Reexec: config.Reexec,
Config: config.Config,
Tracer: config.Tracer,
Timeout: config.Timeout,
Reexec: config.Reexec,
}
}
return api.traceTx(ctx, msg, new(Context), vmctx, statedb, traceConfig)
@ -868,7 +869,7 @@ func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Contex
)
switch {
case config == nil:
tracer = vm.NewStructLogger(nil)
tracer = logger.NewStructLogger(nil)
case config.Tracer != nil:
// Define a meaningful timeout of a single transaction trace
timeout := defaultTraceTimeout
@ -891,7 +892,7 @@ func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Contex
tracer = t
}
default:
tracer = vm.NewStructLogger(config.LogConfig)
tracer = logger.NewStructLogger(config.Config)
}
// Run the transaction with tracing enabled.
vmenv := vm.NewEVM(vmctx, txContext, statedb, api.backend.ChainConfig(), vm.Config{Debug: true, Tracer: tracer, NoBaseFee: true})
@ -906,7 +907,7 @@ func (api *API) traceTx(ctx context.Context, message core.Message, txctx *Contex
// Depending on the tracer type, format and return the output.
switch tracer := tracer.(type) {
case *vm.StructLogger:
case *logger.StructLogger:
// If the result contains a revert reason, return it.
returnVal := fmt.Sprintf("%x", result.Return())
if len(result.Revert()) > 0 {