mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
feat(rpc): add getTxByTxTrace api, used for ccc testing & debugging (#1034)
* cherry pick * fix
This commit is contained in:
parent
1460aed2cc
commit
a6c654318b
2 changed files with 69 additions and 1 deletions
|
|
@ -79,13 +79,81 @@ 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{
|
||||
Config: &logger.Config{
|
||||
DisableStorage: true,
|
||||
DisableStack: true,
|
||||
EnableMemory: false,
|
||||
EnableReturnData: true,
|
||||
Debug: 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) // TODO: release?
|
||||
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.Header(), 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 {
|
||||
config = &TraceConfig{
|
||||
Config: &logger.Config{
|
||||
DisableStorage: true,
|
||||
DisableStack: true,
|
||||
EnableMemory: false,
|
||||
EnableReturnData: true,
|
||||
Debug: true,
|
||||
},
|
||||
}
|
||||
} else if config.Tracer != nil {
|
||||
|
|
|
|||
|
|
@ -70,7 +70,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`
|
||||
|
||||
ExecutionResults []*types.ExecutionResult
|
||||
|
|
|
|||
Loading…
Reference in a new issue