From 665f6c3413636dbaa701bc5e17941edf58019591 Mon Sep 17 00:00:00 2001 From: Zhang Zhuo Date: Fri, 6 Sep 2024 23:22:47 +0800 Subject: [PATCH] feat(rpc): add getTxByTxTrace api, used for ccc testing & debugging (#1026) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ++ * upgrade go lint version * lint * remove a useless "`" * Update l2geth_ci.yml --------- Co-authored-by: Ömer Faruk Irmak Co-authored-by: Péter Garamvölgyi Co-authored-by: colin <102356659+colinlyguo@users.noreply.github.com> --- eth/tracers/api_blocktrace.go | 64 +++++++++++++++++++++++++++++++++++ params/version.go | 2 +- rollup/tracing/tracing.go | 2 +- 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/eth/tracers/api_blocktrace.go b/eth/tracers/api_blocktrace.go index a52daa29983d..048cee370a56 100644 --- a/eth/tracers/api_blocktrace.go +++ b/eth/tracers/api_blocktrace.go @@ -79,6 +79,70 @@ func (api *API) GetTxBlockTraceOnTopOfBlock(ctx context.Context, tx *types.Trans return api.createTraceEnvAndGetBlockTrace(ctx, config, block) } +func (api *API) GetTxByTxBlockTrace(ctx context.Context, 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") + } + + if config == nil { + config = &TraceConfig{ + LogConfig: &vm.LogConfig{ + DisableStorage: true, + DisableStack: true, + 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, err := api.backend.StateAtBlock(ctx, parent, reexec, nil, true, true) + if err != nil { + return nil, err + } + + chaindb := api.backend.ChainDb() + traces := []*types.BlockTrace{} + for _, tx := range block.Transactions() { + singleTxBlock := types.NewBlockWithHeader(block.Header()).WithBody([]*types.Transaction{tx}, nil) + trace, err := api.scrollTracerWrapper.CreateTraceEnvAndGetBlockTrace(api.backend.ChainConfig(), api.chainContext(ctx), api.backend.Engine(), chaindb, statedb, parent, singleTxBlock, true) + if err != nil { + return nil, err + } + traces = append(traces, trace) + } + return traces, nil +} + // 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 { diff --git a/params/version.go b/params/version.go index 5979c032121e..79c4f7e322b8 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 5 // Major version component of the current release VersionMinor = 7 // Minor version component of the current release - VersionPatch = 11 // Patch version component of the current release + VersionPatch = 12 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string ) diff --git a/rollup/tracing/tracing.go b/rollup/tracing/tracing.go index 1e667a4a9c29..3cd78149241d 100644 --- a/rollup/tracing/tracing.go +++ b/rollup/tracing/tracing.go @@ -69,7 +69,7 @@ type TraceEnv struct { // The following Mutexes are used to protect against parallel read/write, // since txs are executed in parallel. pMu sync.Mutex // for `TraceEnv.StorageTrace.Proofs` - sMu sync.Mutex // for `TraceEnv.state`` + sMu sync.Mutex // for `TraceEnv.state` cMu sync.Mutex // for `TraceEnv.Codes` *types.StorageTrace