mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
* add rollup/tracing/tracing.go * update eth/tracers/logger/access_list_tracer.go * update core/types/l2trace.go * update core/vm/evm.go * update core/evm.go * update core/vm/interpreter.go * update eth/tracers/logger/logger_json.go * update core/vm/logger_trace.go * mv core/vm/logger_trace.go mv core/vm/logger_trace.go * update eth/tracers/api_blocktrace.go * update eth/tracers/js/tracer.go * update `EVMLogger` interface * fix `JSONLogger`'s `CaptureStateAfter` * fix `OpcodeExecs` * minor fixes * fix eth/tracers/api_blocktrace.go * comment out eth/tracers/logger/logger_trace.go * fix * update eth/tracers/api.go * some renamings * update cmd/utils/flags.go * update rollup/tracing/tracing.go WIP * fix interface * minor * fix `FormatLogs` * Fix tracers (#663) * export `CallTracer` * export `CallTracer` * export `PrestateTracer` * export `MuxTracer` * refactor * merge `StructLogRes` (#662) * merge `StructLogRes` * clean up * fix * fix * update core/block_validator.go * update ethclient/ethclient.go * merge `ExecutionResult` (#667) * merge `ExecutionResult` * fix l1datafee * fix eth/tracers/api_test.go (#669) * clean up * WIP: update eth/tracers/logger/logger.go * update `CaptureStart` * update `CaptureExit` * init `CaptureEnter` * update `CaptureEnter` 1 * fix `CaptureEnter` 1 * fix depth * fix `CaptureEnter` 2 * update `CaptureEnter` 2
112 lines
3.8 KiB
Go
112 lines
3.8 KiB
Go
package tracers
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/ethereum/go-ethereum/consensus"
|
|
"github.com/ethereum/go-ethereum/core"
|
|
"github.com/ethereum/go-ethereum/core/state"
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
"github.com/ethereum/go-ethereum/eth/tracers/logger"
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
|
"github.com/ethereum/go-ethereum/log"
|
|
"github.com/ethereum/go-ethereum/params"
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
)
|
|
|
|
var errNoScrollTracerWrapper = errors.New("no ScrollTracerWrapper")
|
|
|
|
type TraceBlock interface {
|
|
GetBlockTraceByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash, config *TraceConfig) (trace *types.BlockTrace, err error)
|
|
GetTxBlockTraceOnTopOfBlock(ctx context.Context, tx *types.Transaction, blockNrOrHash rpc.BlockNumberOrHash, config *TraceConfig) (*types.BlockTrace, error)
|
|
}
|
|
|
|
type scrollTracerWrapper interface {
|
|
CreateTraceEnvAndGetBlockTrace(*params.ChainConfig, core.ChainContext, consensus.Engine, ethdb.Database, *state.StateDB, *types.Block, *types.Block, bool) (*types.BlockTrace, error)
|
|
}
|
|
|
|
// GetBlockTraceByNumberOrHash replays the block and returns the structured BlockTrace by hash or number.
|
|
func (api *API) GetBlockTraceByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash, config *TraceConfig) (trace *types.BlockTrace, err error) {
|
|
if api.scrollTracerWrapper == nil {
|
|
return nil, errNoScrollTracerWrapper
|
|
}
|
|
|
|
var block *types.Block
|
|
if number, ok := blockNrOrHash.Number(); ok {
|
|
block, err = api.blockByNumber(ctx, number)
|
|
} else if hash, ok := blockNrOrHash.Hash(); ok {
|
|
block, err = api.blockByHash(ctx, hash)
|
|
} else {
|
|
return nil, errors.New("invalid arguments; neither block number nor hash specified")
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if block.NumberU64() == 0 {
|
|
return nil, errors.New("genesis is not traceable")
|
|
}
|
|
|
|
return api.createTraceEnvAndGetBlockTrace(ctx, config, block)
|
|
}
|
|
|
|
func (api *API) GetTxBlockTraceOnTopOfBlock(ctx context.Context, tx *types.Transaction, blockNrOrHash rpc.BlockNumberOrHash, config *TraceConfig) (*types.BlockTrace, error) {
|
|
if api.scrollTracerWrapper == nil {
|
|
return nil, errNoScrollTracerWrapper
|
|
}
|
|
|
|
// Try to retrieve the specified block
|
|
var (
|
|
err error
|
|
block *types.Block
|
|
)
|
|
if number, ok := blockNrOrHash.Number(); ok {
|
|
block, err = api.blockByNumber(ctx, number)
|
|
} else if hash, ok := blockNrOrHash.Hash(); ok {
|
|
block, err = api.blockByHash(ctx, hash)
|
|
} else {
|
|
return nil, errors.New("invalid arguments; neither block number nor hash specified")
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if block.NumberU64() == 0 {
|
|
return nil, errors.New("genesis is not traceable")
|
|
}
|
|
|
|
block = types.NewBlockWithHeader(block.Header()).WithBody([]*types.Transaction{tx}, nil)
|
|
|
|
return api.createTraceEnvAndGetBlockTrace(ctx, config, block)
|
|
}
|
|
|
|
// Make trace environment for current block, and then get the trace for the block.
|
|
func (api *API) createTraceEnvAndGetBlockTrace(ctx context.Context, config *TraceConfig, block *types.Block) (*types.BlockTrace, error) {
|
|
if config == nil {
|
|
config = &TraceConfig{
|
|
Config: &logger.Config{
|
|
EnableMemory: false,
|
|
EnableReturnData: true,
|
|
},
|
|
}
|
|
} else if config.Tracer != nil {
|
|
config.Tracer = nil
|
|
log.Warn("Tracer params is unsupported")
|
|
}
|
|
|
|
parent, err := api.blockByNumberAndHash(ctx, rpc.BlockNumber(block.NumberU64()-1), block.ParentHash())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
reexec := defaultTraceReexec
|
|
if config != nil && config.Reexec != nil {
|
|
reexec = *config.Reexec
|
|
}
|
|
statedb, release, err := api.backend.StateAtBlock(ctx, parent, reexec, nil, true, true)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer release()
|
|
|
|
chaindb := api.backend.ChainDb()
|
|
return api.scrollTracerWrapper.CreateTraceEnvAndGetBlockTrace(api.backend.ChainConfig(), api.chainContext(ctx), api.backend.Engine(), chaindb, statedb, parent, block, true)
|
|
}
|