Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth: add traceCallBlock method #24874

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,40 @@ type txTraceTask struct {
index int // Transaction offset in the block
}

type BlockArgs struct {
Number *hexutil.Big
Difficulty *hexutil.Big
Time *hexutil.Big
GasLimit *hexutil.Uint64
Coinbase *common.Address
Random *common.Hash
Transactions []*ethapi.TransactionArgs
}

func (diff *BlockArgs) Apply(blockCtx *vm.BlockContext) {
if diff == nil {
return
}
if diff.Number != nil {
blockCtx.BlockNumber = diff.Number.ToInt()
}
if diff.Difficulty != nil {
blockCtx.Difficulty = diff.Difficulty.ToInt()
}
if diff.Time != nil {
blockCtx.Time = diff.Time.ToInt()
}
if diff.GasLimit != nil {
blockCtx.GasLimit = uint64(*diff.GasLimit)
}
if diff.Coinbase != nil {
blockCtx.Coinbase = *diff.Coinbase
}
if diff.Random != nil {
blockCtx.Random = diff.Random
}
}

// TraceChain returns the structured logs created during the execution of EVM
// between two blocks (excluding start) and returns them as a JSON object.
func (api *API) TraceChain(ctx context.Context, start, end rpc.BlockNumber, config *TraceConfig) (*rpc.Subscription, error) { // Fetch the block interval that we want to trace
Expand Down Expand Up @@ -858,6 +892,66 @@ func (api *API) TraceCall(ctx context.Context, args ethapi.TransactionArgs, bloc
return api.traceTx(ctx, msg, new(Context), vmctx, statedb, traceConfig)
}

func (api *API) TraceCallBlock(ctx context.Context, args BlockArgs, blockNrOrHash rpc.BlockNumberOrHash, config *TraceCallConfig) ([]*txTraceResult, error) {
// Try to retrieve the specified block
var (
err error
block *types.Block
)
if hash, ok := blockNrOrHash.Hash(); ok {
block, err = api.blockByHash(ctx, hash)
} else if number, ok := blockNrOrHash.Number(); ok {
block, err = api.blockByNumber(ctx, number)
} else {
return nil, errors.New("invalid arguments; neither block nor hash specified")
}
if err != nil {
return nil, err
}
// try to recompute the state
reexec := defaultTraceReexec
if config != nil && config.Reexec != nil {
reexec = *config.Reexec
}
statedb, err := api.backend.StateAtBlock(ctx, block, reexec, nil, true, false)
if err != nil {
return nil, err
}
// Apply the customized state rules if required.
if config != nil {
if err := config.StateOverrides.Apply(statedb); err != nil {
return nil, err
}
}
vmctx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil)
args.Apply(&vmctx)
results := make([]*txTraceResult, len(args.Transactions))
for i, txArgs := range args.Transactions {
// Execute the trace
msg, err := txArgs.ToMessage(api.backend.RPCGasCap(), block.BaseFee())
if err != nil {
return nil, err
}

var traceConfig *TraceConfig
if config != nil {
traceConfig = &TraceConfig{
Config: config.Config,
Tracer: config.Tracer,
Timeout: config.Timeout,
Reexec: config.Reexec,
}
}
res, err := api.traceTx(ctx, msg, new(Context), vmctx, statedb, traceConfig)
if err != nil {
results[i] = &txTraceResult{Error: err.Error()}
continue
}
results[i] = &txTraceResult{Result: res}
}
return results, nil
}

// traceTx configures a new tracer according to the provided configuration, and
// executes the given message in the provided environment. The return value will
// be tracer dependent.
Expand Down
6 changes: 6 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,12 @@ web3._extend({
params: 3,
inputFormatter: [null, null, null]
}),
new web3._extend.Method({
name: 'traceCallBlock',
call: 'debug_traceCallBlock',
params: 3,
inputFormatter: [null, null, null]
}),
new web3._extend.Method({
name: 'preimage',
call: 'debug_preimage',
Expand Down