diff --git a/core/block_validator.go b/core/block_validator.go index 6773649c6d13..4f07f5022260 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -26,6 +26,7 @@ import ( "github.com/scroll-tech/go-ethereum/core/rawdb" "github.com/scroll-tech/go-ethereum/core/state" "github.com/scroll-tech/go-ethereum/core/types" + "github.com/scroll-tech/go-ethereum/core/vm" "github.com/scroll-tech/go-ethereum/ethdb" "github.com/scroll-tech/go-ethereum/log" "github.com/scroll-tech/go-ethereum/metrics" @@ -69,7 +70,7 @@ func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, engin } type tracerWrapper interface { - CreateTraceEnvAndGetBlockTrace(*params.ChainConfig, ChainContext, consensus.Engine, ethdb.Database, *state.StateDB, *types.Block, *types.Block, bool) (*types.BlockTrace, error) + CreateTraceEnvAndGetBlockTrace(*params.ChainConfig, *vm.LogConfig, ChainContext, consensus.Engine, ethdb.Database, *state.StateDB, *types.Block, *types.Block, bool) (*types.BlockTrace, error) } func (v *BlockValidator) SetupTracerAndCircuitCapacityChecker(tracer tracerWrapper) { @@ -298,7 +299,7 @@ func (v *BlockValidator) createTraceEnvAndGetBlockTrace(block *types.Block) (*ty return nil, err } - return v.tracer.CreateTraceEnvAndGetBlockTrace(v.config, v.bc, v.engine, v.bc.db, statedb, parent, block, true) + return v.tracer.CreateTraceEnvAndGetBlockTrace(v.config, nil, v.bc, v.engine, v.bc.db, statedb, parent, block, true) } func (v *BlockValidator) validateCircuitRowConsumption(block *types.Block) (*types.RowConsumption, error) { diff --git a/eth/tracers/api_blocktrace.go b/eth/tracers/api_blocktrace.go index 194bf59b1b1c..9f3db94eda4f 100644 --- a/eth/tracers/api_blocktrace.go +++ b/eth/tracers/api_blocktrace.go @@ -24,7 +24,7 @@ type TraceBlock interface { } type scrollTracerWrapper interface { - CreateTraceEnvAndGetBlockTrace(*params.ChainConfig, core.ChainContext, consensus.Engine, ethdb.Database, *state.StateDB, *types.Block, *types.Block, bool) (*types.BlockTrace, error) + CreateTraceEnvAndGetBlockTrace(*params.ChainConfig, *vm.LogConfig, 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. @@ -123,5 +123,5 @@ func (api *API) createTraceEnvAndGetBlockTrace(ctx context.Context, config *Trac } log.Info("chainConfig overrided by traceConfig.Overrides", "chainConfig", chainConfig, "config.Overrides", config.Overrides) } - return api.scrollTracerWrapper.CreateTraceEnvAndGetBlockTrace(chainConfig, api.chainContext(ctx), api.backend.Engine(), chaindb, statedb, parent, block, true) + return api.scrollTracerWrapper.CreateTraceEnvAndGetBlockTrace(chainConfig, config.LogConfig, api.chainContext(ctx), api.backend.Engine(), chaindb, statedb, parent, block, true) } diff --git a/rollup/pipeline/pipeline.go b/rollup/pipeline/pipeline.go index 787b176e00e1..f75f62e5c262 100644 --- a/rollup/pipeline/pipeline.go +++ b/rollup/pipeline/pipeline.go @@ -479,7 +479,7 @@ func (p *Pipeline) traceAndApply(tx *types.Transaction) (*types.Receipt, *types. // 2.1 when starting handling the first tx, `state.refund` is 0 by default, // 2.2 after tracing, the state is either committed in `core.ApplyTransaction`, or reverted, so the `state.refund` can be cleared, // 2.3 when starting handling the following txs, `state.refund` comes as 0 - trace, err = tracing.NewTracerWrapper().CreateTraceEnvAndGetBlockTrace(p.chain.Config(), p.chain, p.chain.Engine(), p.chain.Database(), + trace, err = tracing.NewTracerWrapper().CreateTraceEnvAndGetBlockTrace(p.chain.Config(), nil, p.chain, p.chain.Engine(), p.chain.Database(), p.state, p.parent, types.NewBlockWithHeader(&p.Header).WithBody([]*types.Transaction{tx}, nil), commitStateAfterApply) // `w.current.traceEnv.State` & `w.current.state` share a same pointer to the state, so only need to revert `w.current.state` // revert to snapshot for calling `core.ApplyMessage` again, (both `traceEnv.GetBlockTrace` & `core.ApplyTransaction` will call `core.ApplyMessage`) diff --git a/rollup/tracing/tracing.go b/rollup/tracing/tracing.go index 93feb4711698..3d73b5dcb084 100644 --- a/rollup/tracing/tracing.go +++ b/rollup/tracing/tracing.go @@ -45,8 +45,8 @@ func NewTracerWrapper() *TracerWrapper { } // CreateTraceEnvAndGetBlockTrace wraps the whole block tracing logic for a block -func (tw *TracerWrapper) CreateTraceEnvAndGetBlockTrace(chainConfig *params.ChainConfig, chainContext core.ChainContext, engine consensus.Engine, chaindb ethdb.Database, statedb *state.StateDB, parent *types.Block, block *types.Block, commitAfterApply bool) (*types.BlockTrace, error) { - traceEnv, err := CreateTraceEnv(chainConfig, chainContext, engine, chaindb, statedb, parent, block, commitAfterApply) +func (tw *TracerWrapper) CreateTraceEnvAndGetBlockTrace(chainConfig *params.ChainConfig, logConfig *vm.LogConfig, chainContext core.ChainContext, engine consensus.Engine, chaindb ethdb.Database, statedb *state.StateDB, parent *types.Block, block *types.Block, commitAfterApply bool) (*types.BlockTrace, error) { + traceEnv, err := CreateTraceEnv(chainConfig, logConfig, chainContext, engine, chaindb, statedb, parent, block, commitAfterApply) if err != nil { return nil, err } @@ -98,6 +98,15 @@ type txTraceTask struct { } func CreateTraceEnvHelper(chainConfig *params.ChainConfig, logConfig *vm.LogConfig, blockCtx vm.BlockContext, startL1QueueIndex uint64, coinbase common.Address, statedb *state.StateDB, rootBefore common.Hash, block *types.Block, commitAfterApply bool) *TraceEnv { + if logConfig == nil { + logConfig = &vm.LogConfig{ + DisableStorage: true, + DisableStack: true, + EnableMemory: false, + EnableReturnData: true, + } + } + return &TraceEnv{ logConfig: logConfig, commitAfterApply: commitAfterApply, @@ -119,7 +128,7 @@ func CreateTraceEnvHelper(chainConfig *params.ChainConfig, logConfig *vm.LogConf } } -func CreateTraceEnv(chainConfig *params.ChainConfig, chainContext core.ChainContext, engine consensus.Engine, chaindb ethdb.Database, statedb *state.StateDB, parent *types.Block, block *types.Block, commitAfterApply bool) (*TraceEnv, error) { +func CreateTraceEnv(chainConfig *params.ChainConfig, logConfig *vm.LogConfig, chainContext core.ChainContext, engine consensus.Engine, chaindb ethdb.Database, statedb *state.StateDB, parent *types.Block, block *types.Block, commitAfterApply bool) (*TraceEnv, error) { var coinbase common.Address var err error @@ -150,12 +159,7 @@ func CreateTraceEnv(chainConfig *params.ChainConfig, chainContext core.ChainCont } env := CreateTraceEnvHelper( chainConfig, - &vm.LogConfig{ - DisableStorage: true, - DisableStack: true, - EnableMemory: false, - EnableReturnData: true, - }, + logConfig, core.NewEVMBlockContext(block.Header(), chainContext, chainConfig, nil), *startL1QueueIndex, coinbase,