Skip to content

Commit 665f6c3

Browse files
lispcomerfirmakThegaramcolinlyguo
authored
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>
1 parent a4b738f commit 665f6c3

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

eth/tracers/api_blocktrace.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,70 @@ func (api *API) GetTxBlockTraceOnTopOfBlock(ctx context.Context, tx *types.Trans
7979
return api.createTraceEnvAndGetBlockTrace(ctx, config, block)
8080
}
8181

82+
func (api *API) GetTxByTxBlockTrace(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash, config *TraceConfig) ([]*types.BlockTrace, error) {
83+
if api.scrollTracerWrapper == nil {
84+
return nil, errNoScrollTracerWrapper
85+
}
86+
87+
// Try to retrieve the specified block
88+
var (
89+
err error
90+
block *types.Block
91+
)
92+
if number, ok := blockNrOrHash.Number(); ok {
93+
block, err = api.blockByNumber(ctx, number)
94+
} else if hash, ok := blockNrOrHash.Hash(); ok {
95+
block, err = api.blockByHash(ctx, hash)
96+
} else {
97+
return nil, errors.New("invalid arguments; neither block number nor hash specified")
98+
}
99+
if err != nil {
100+
return nil, err
101+
}
102+
if block.NumberU64() == 0 {
103+
return nil, errors.New("genesis is not traceable")
104+
}
105+
106+
if config == nil {
107+
config = &TraceConfig{
108+
LogConfig: &vm.LogConfig{
109+
DisableStorage: true,
110+
DisableStack: true,
111+
EnableMemory: false,
112+
EnableReturnData: true,
113+
},
114+
}
115+
} else if config.Tracer != nil {
116+
config.Tracer = nil
117+
log.Warn("Tracer params is unsupported")
118+
}
119+
120+
parent, err := api.blockByNumberAndHash(ctx, rpc.BlockNumber(block.NumberU64()-1), block.ParentHash())
121+
if err != nil {
122+
return nil, err
123+
}
124+
reexec := defaultTraceReexec
125+
if config != nil && config.Reexec != nil {
126+
reexec = *config.Reexec
127+
}
128+
statedb, err := api.backend.StateAtBlock(ctx, parent, reexec, nil, true, true)
129+
if err != nil {
130+
return nil, err
131+
}
132+
133+
chaindb := api.backend.ChainDb()
134+
traces := []*types.BlockTrace{}
135+
for _, tx := range block.Transactions() {
136+
singleTxBlock := types.NewBlockWithHeader(block.Header()).WithBody([]*types.Transaction{tx}, nil)
137+
trace, err := api.scrollTracerWrapper.CreateTraceEnvAndGetBlockTrace(api.backend.ChainConfig(), api.chainContext(ctx), api.backend.Engine(), chaindb, statedb, parent, singleTxBlock, true)
138+
if err != nil {
139+
return nil, err
140+
}
141+
traces = append(traces, trace)
142+
}
143+
return traces, nil
144+
}
145+
82146
// Make trace environment for current block, and then get the trace for the block.
83147
func (api *API) createTraceEnvAndGetBlockTrace(ctx context.Context, config *TraceConfig, block *types.Block) (*types.BlockTrace, error) {
84148
if config == nil {

params/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
const (
2525
VersionMajor = 5 // Major version component of the current release
2626
VersionMinor = 7 // Minor version component of the current release
27-
VersionPatch = 11 // Patch version component of the current release
27+
VersionPatch = 12 // Patch version component of the current release
2828
VersionMeta = "mainnet" // Version metadata to append to the version string
2929
)
3030

rollup/tracing/tracing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type TraceEnv struct {
6969
// The following Mutexes are used to protect against parallel read/write,
7070
// since txs are executed in parallel.
7171
pMu sync.Mutex // for `TraceEnv.StorageTrace.Proofs`
72-
sMu sync.Mutex // for `TraceEnv.state``
72+
sMu sync.Mutex // for `TraceEnv.state`
7373
cMu sync.Mutex // for `TraceEnv.Codes`
7474

7575
*types.StorageTrace

0 commit comments

Comments
 (0)