Skip to content

Commit

Permalink
feat(rpc): add getTxByTxTrace api, used for ccc testing & debugging (#…
Browse files Browse the repository at this point in the history
…1026)

* ++

* upgrade go lint version

* lint

* remove a useless "`"

* Update l2geth_ci.yml

---------

Co-authored-by: Ömer Faruk Irmak <[email protected]>
Co-authored-by: Péter Garamvölgyi <[email protected]>
Co-authored-by: colin <[email protected]>
  • Loading branch information
4 people authored Sep 6, 2024
1 parent a4b738f commit 665f6c3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
64 changes: 64 additions & 0 deletions eth/tracers/api_blocktrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
2 changes: 1 addition & 1 deletion rollup/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 665f6c3

Please sign in to comment.