Skip to content

Commit 52de97d

Browse files
s1naqianhh
authored andcommitted
eth/tracers: fix concurrency issue for JS-tracing a block (#29238)
This change fixes a concurrency-issue where JS-tracers were accessing the block-ctx GetHash function in a in parallel, which is not safe.
1 parent fbd556d commit 52de97d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

eth/tracers/api.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,6 @@ func (api *API) traceBlockParallel(ctx context.Context, block *types.Block, stat
632632
var (
633633
txs = block.Transactions()
634634
blockHash = block.Hash()
635-
blockCtx = core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil)
636635
signer = types.MakeSigner(api.backend.ChainConfig(), block.Number(), block.Time())
637636
results = make([]*txTraceResult, len(txs))
638637
pend sync.WaitGroup
@@ -655,6 +654,11 @@ func (api *API) traceBlockParallel(ctx context.Context, block *types.Block, stat
655654
TxIndex: task.index,
656655
TxHash: txs[task.index].Hash(),
657656
}
657+
// Reconstruct the block context for each transaction
658+
// as the GetHash function of BlockContext is not safe for
659+
// concurrent use.
660+
// See: https://github.com/ethereum/go-ethereum/issues/29114
661+
blockCtx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil)
658662
res, err := api.traceTx(ctx, msg, txctx, blockCtx, task.statedb, config)
659663
if err != nil {
660664
results[task.index] = &txTraceResult{TxHash: txs[task.index].Hash(), Error: err.Error()}
@@ -667,6 +671,7 @@ func (api *API) traceBlockParallel(ctx context.Context, block *types.Block, stat
667671

668672
// Feed the transactions into the tracers and return
669673
var failed error
674+
blockCtx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil)
670675
txloop:
671676
for i, tx := range txs {
672677
// Send the trace task over for execution

0 commit comments

Comments
 (0)