Skip to content

Commit

Permalink
feat: backport flatCallTracer (#895)
Browse files Browse the repository at this point in the history
  • Loading branch information
draganm committed Aug 23, 2024
1 parent 9de4980 commit 972fe8a
Show file tree
Hide file tree
Showing 11 changed files with 527 additions and 27 deletions.
31 changes: 22 additions & 9 deletions eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ type StdTraceConfig struct {

// txTraceResult is the result of a single transaction trace.
type txTraceResult struct {
TxHash common.Hash `json:"txHash"` // Hash of the transaction being traced
Result interface{} `json:"result,omitempty"` // Trace results produced by the tracer
Error string `json:"error,omitempty"` // Trace failure produced by the tracer
}
Expand Down Expand Up @@ -280,9 +281,10 @@ func (api *API) traceChain(ctx context.Context, start, end *types.Block, config
for i, tx := range task.block.Transactions() {
msg, _ := tx.AsMessage(signer, task.block.BaseFee())
txctx := &Context{
BlockHash: task.block.Hash(),
TxIndex: i,
TxHash: tx.Hash(),
BlockNumber: task.block.NumberU64(),
BlockHash: task.block.Hash(),
TxIndex: i,
TxHash: tx.Hash(),
}

l1DataFee, err := fees.CalculateL1DataFee(tx, task.statedb, api.backend.ChainConfig(), task.block.Number())
Expand Down Expand Up @@ -613,6 +615,7 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
}
blockCtx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), api.backend.ChainConfig(), nil)
blockHash := block.Hash()
blockNumber := block.NumberU64()
for th := 0; th < threads; th++ {
pend.Add(1)
go func() {
Expand All @@ -621,23 +624,33 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
for task := range jobs {
msg, _ := txs[task.index].AsMessage(signer, block.BaseFee())
txctx := &Context{
BlockHash: blockHash,
TxIndex: task.index,
TxHash: txs[task.index].Hash(),
BlockNumber: blockNumber,
BlockHash: blockHash,
TxIndex: task.index,
TxHash: txs[task.index].Hash(),
}

l1DataFee, err := fees.CalculateL1DataFee(txs[task.index], task.statedb, api.backend.ChainConfig(), block.Number())
if err != nil {
// though it's not a "tracing error", we still need to put it here
results[task.index] = &txTraceResult{Error: err.Error()}
results[task.index] = &txTraceResult{
TxHash: txs[task.index].Hash(),
Error: err.Error(),
}
continue
}
res, err := api.traceTx(ctx, msg, txctx, blockCtx, task.statedb, config, l1DataFee)
if err != nil {
results[task.index] = &txTraceResult{Error: err.Error()}
results[task.index] = &txTraceResult{
TxHash: txs[task.index].Hash(),
Error: err.Error(),
}
continue
}
results[task.index] = &txTraceResult{Result: res}
results[task.index] = &txTraceResult{
TxHash: txs[task.index].Hash(),
Result: res,
}
}
}()
}
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/native/4byte.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type fourByteTracer struct {

// newFourByteTracer returns a native go tracer which collects
// 4 byte-identifiers of a tx, and implements vm.EVMLogger.
func newFourByteTracer() tracers.Tracer {
func newFourByteTracer(ctx *tracers.Context) tracers.Tracer {
t := &fourByteTracer{
ids: make(map[string]int),
}
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/native/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type callTracer struct {

// newCallTracer returns a native go tracer which tracks
// call frames of a tx, and implements vm.EVMLogger.
func newCallTracer() tracers.Tracer {
func newCallTracer(ctx *tracers.Context) tracers.Tracer {
// First callframe contains tx context info
// and is populated on start and end.
t := &callTracer{callstack: make([]callFrame, 1)}
Expand Down
Loading

0 comments on commit 972fe8a

Please sign in to comment.