From 5c752466dd19b0a2bf3f71ec0d4def949b8855bd Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Mon, 24 Jan 2022 17:28:20 +0100 Subject: [PATCH] eth/tracers: use non-threaded tracechain, fixes #23205 --- eth/tracers/api.go | 51 +++++++++++----------------------------------- 1 file changed, 12 insertions(+), 39 deletions(-) diff --git a/eth/tracers/api.go b/eth/tracers/api.go index b16b68c1fa043..59c20c50e059d 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -584,58 +584,31 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac signer = types.MakeSigner(api.backend.ChainConfig(), block.Number()) txs = block.Transactions() results = make([]*txTraceResult, len(txs)) - - pend = new(sync.WaitGroup) - jobs = make(chan *txTraceTask, len(txs)) ) - threads := runtime.NumCPU() - if threads > len(txs) { - threads = len(txs) - } + blockCtx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil) blockHash := block.Hash() - for th := 0; th < threads; th++ { - pend.Add(1) - go func() { - blockCtx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil) - defer pend.Done() - // Fetch and execute the next transaction trace tasks - for task := range jobs { - msg, _ := txs[task.index].AsMessage(signer, block.BaseFee()) - txctx := &Context{ - BlockHash: blockHash, - TxIndex: task.index, - TxHash: txs[task.index].Hash(), - } - res, err := api.traceTx(ctx, msg, txctx, blockCtx, task.statedb, config) - if err != nil { - results[task.index] = &txTraceResult{Error: err.Error()} - continue - } - results[task.index] = &txTraceResult{Result: res} - } - }() - } // Feed the transactions into the tracers and return var failed error - blockCtx := core.NewEVMBlockContext(block.Header(), api.chainContext(ctx), nil) + is158 := api.backend.ChainConfig().IsEIP158(block.Number()) for i, tx := range txs { - // Send the trace task over for execution - jobs <- &txTraceTask{statedb: statedb.Copy(), index: i} - // Generate the next state snapshot fast without tracing msg, _ := tx.AsMessage(signer, block.BaseFee()) - statedb.Prepare(tx.Hash(), i) - vmenv := vm.NewEVM(blockCtx, core.NewEVMTxContext(msg), statedb, api.backend.ChainConfig(), vm.Config{}) - if _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())); err != nil { + txctx := &Context{ + BlockHash: blockHash, + TxIndex: i, + TxHash: tx.Hash(), + } + res, err := api.traceTx(ctx, msg, txctx, blockCtx, statedb, config) + if err != nil { + results[i] = &txTraceResult{Error: err.Error()} failed = err break } + results[i] = &txTraceResult{Result: res} // Finalize the state so any modifications are written to the trie // Only delete empty objects if EIP158/161 (a.k.a Spurious Dragon) is in effect - statedb.Finalise(vmenv.ChainConfig().IsEIP158(block.Number())) + statedb.Finalise(is158) } - close(jobs) - pend.Wait() // If execution failed in between, abort if failed != nil {