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

extract trace block common logic #608

Merged
merged 1 commit into from
Oct 3, 2024
Merged
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
29 changes: 15 additions & 14 deletions api/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/rs/zerolog"

"github.com/onflow/flow-evm-gateway/metrics"
"github.com/onflow/flow-evm-gateway/models"
"github.com/onflow/flow-evm-gateway/storage"
)

Expand Down Expand Up @@ -39,7 +40,7 @@ func NewDebugAPI(tracer storage.TraceIndexer, blocks storage.BlockIndexer, logge
// TraceTransaction will return a debug execution trace of a transaction if it exists,
// currently we only support CALL traces, so the config is ignored.
func (d *DebugAPI) TraceTransaction(
ctx context.Context,
_ context.Context,
hash gethCommon.Hash,
_ *tracers.TraceConfig,
) (json.RawMessage, error) {
Comment on lines +43 to 46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Utilize the context.Context parameter in TraceTransaction

Currently, TraceTransaction ignores the context.Context parameter by naming it _ context.Context. However, in the traceBlock function, you pass ctx to TraceTransaction, indicating that the context should be propagated. To ensure proper context handling, consider changing the parameter back to ctx context.Context and using it within TraceTransaction.

Expand All @@ -53,39 +54,39 @@ func (d *DebugAPI) TraceTransaction(
func (d *DebugAPI) TraceBlockByNumber(
ctx context.Context,
number rpc.BlockNumber,
_ *tracers.TraceConfig,
cfg *tracers.TraceConfig,
) ([]*txTraceResult, error) {
block, err := d.blocks.GetByHeight(uint64(number.Int64()))
if err != nil {
return handleError[[]*txTraceResult](err, d.logger, d.collector)
}

results := make([]*txTraceResult, len(block.TransactionHashes))
for i, h := range block.TransactionHashes {
txTrace, err := d.TraceTransaction(ctx, h, nil)
if err != nil {
results[i] = &txTraceResult{TxHash: h, Error: err.Error()}
} else {
results[i] = &txTraceResult{TxHash: h, Result: txTrace}
}
}

return results, nil
return d.traceBlock(ctx, block, cfg)
}

func (d *DebugAPI) TraceBlockByHash(
ctx context.Context,
hash gethCommon.Hash,
_ *tracers.TraceConfig,
cfg *tracers.TraceConfig,
) ([]*txTraceResult, error) {
block, err := d.blocks.GetByID(hash)
if err != nil {
return handleError[[]*txTraceResult](err, d.logger, d.collector)
}

return d.traceBlock(ctx, block, cfg)
}

func (d *DebugAPI) traceBlock(
ctx context.Context,
block *models.Block,
_ *tracers.TraceConfig,
) ([]*txTraceResult, error) {
results := make([]*txTraceResult, len(block.TransactionHashes))
for i, h := range block.TransactionHashes {

txTrace, err := d.TraceTransaction(ctx, h, nil)

if err != nil {
results[i] = &txTraceResult{TxHash: h, Error: err.Error()}
} else {
Expand Down
Loading