Skip to content

Commit c98fd66

Browse files
committed
eth/tracers: fix concurrency issue for JS-tracing a block ethereum#29238
1 parent bb7da37 commit c98fd66

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
@@ -624,7 +624,6 @@ func (api *API) traceBlockParallel(ctx context.Context, block *types.Block, stat
624624
var (
625625
txs = block.Transactions()
626626
blockHash = block.Hash()
627-
blockCtx = core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil)
628627
signer = types.MakeSigner(api.backend.ChainConfig(), block.Number())
629628
results = make([]*txTraceResult, len(txs))
630629
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()}
@@ -668,6 +672,7 @@ func (api *API) traceBlockParallel(ctx context.Context, block *types.Block, stat
668672
// Feed the transactions into the tracers and return
669673
feeCapacity := state.GetTRC21FeeCapacityFromState(statedb)
670674
var failed error
675+
blockCtx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil)
671676
txloop:
672677
for i, tx := range txs {
673678
// Send the trace task over for execution

0 commit comments

Comments
 (0)