feat(rpc): add getTxByTxTrace api, used for ccc testing & debugging (#1026)

* ++

* upgrade go lint version

* lint

* remove a useless "`"

* Update l2geth_ci.yml

---------

Co-authored-by: Ömer Faruk Irmak <omerfirmak@gmail.com>
Co-authored-by: Péter Garamvölgyi <peter@scroll.io>
Co-authored-by: colin <102356659+colinlyguo@users.noreply.github.com>
This commit is contained in:
Zhang Zhuo 2024-09-06 23:22:47 +08:00 committed by GitHub
parent a4b738f815
commit 665f6c3413
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 66 additions and 2 deletions

View file

@ -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 {

View file

@ -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
)

View file

@ -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