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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth/tracers: use non-threaded traceBlock for native tracers #24283

Merged
merged 5 commits into from Jan 10, 2023

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Jan 24, 2022

This PR fixes #23205..
On master, when we trace a block, there are two things happening in parallel,

  • A bunch of threads are waiting for tasks, which contain a statedb and tx context info. Once they obtain a task, they to tracing on top of the given state.
  • A separate thread is racing through the block, generating statedb:s by executing transactions without tracing enabled. It does a statedb.Copy and then collects it into a task and sends to the waiting tracer-threads.

For some reason, this is not working as expected, and corruptions occur. Example block is given in #23205,
My repro script:

#!/bin/bash
js="{\"id\": 1, \"method\": \"debug_traceBlockByHash\", \"params\": [\"0x36fbbada3ecbeadc507daaf7ff72f43db5ac6439d2be11ae7e06679d8160a41a\", {\"tracer\": \"callTracer\", \"timeout\": \"60s\"}]}"
echo $js | nc -N -U /home/martin/.ethereum/geth.ipc |  jq . > out.$(date +%s).json

This script was executed against a node which had the stateroot, and was not importing blocks simultaneously.

Example output on master:

-rw-rw-r--  1 martin martin  1733636 jan 24 16:59 out.1643039993.json
-rw-rw-r--  1 martin martin  1736525 jan 24 16:59 out.1643039995.json
-rw-rw-r--  1 martin martin  1733636 jan 24 16:59 out.1643039996.json
-rw-rw-r--  1 martin martin  1733636 jan 24 16:59 out.1643039997.json
-rw-rw-r--  1 martin martin  1733636 jan 24 17:00 out.1643040014.json
-rw-rw-r--  1 martin martin  1738663 jan 24 17:00 out.1643040015.json
-rw-rw-r--  1 martin martin  1738663 jan 24 17:00 out.1643040016.json
-rw-rw-r--  1 martin martin  1733636 jan 24 17:00 out.1643040055.json
-rw-rw-r--  1 martin martin  1733636 jan 24 17:00 out.1643040056.json
-rw-rw-r--  1 martin martin  1733636 jan 24 17:00 out.1643040057.json
-rw-rw-r--  1 martin martin  1733636 jan 24 17:00 out.1643040058.json

This PR removs the multi-threading (with native tracing, the overhead of tracing is much lower, so it might make sense regardless. )
The same repro script with this PR produces a sequence of identical files;

-rw-rw-r--  1 martin martin  1738663 jan 24 17:30 new.1643041845.json
-rw-rw-r--  1 martin martin  1738663 jan 24 17:30 new.1643041846.json
-rw-rw-r--  1 martin martin  1738663 jan 24 17:30 new.1643041847.json
-rw-rw-r--  1 martin martin  1738663 jan 24 17:30 new.1643041848.json
-rw-rw-r--  1 martin martin  1738663 jan 24 17:30 new.1643041849.json
-rw-rw-r--  1 martin martin  1738663 jan 24 17:30 new.1643041850.json
-rw-rw-r--  1 martin martin  1738663 jan 24 17:30 new.1643041851.json
-rw-rw-r--  1 martin martin  1738663 jan 24 17:30 new.1643041852.json
-rw-rw-r--  1 martin martin  1738663 jan 24 17:30 new.1643041853.json
-rw-rw-r--  1 martin martin  1738663 jan 24 17:30 new.1643041854.json

Regarding speed differences, this PR actually seems to be performing better 馃憖
Master:

DEBUG[01-24|17:45:52.953] Served debug_traceBlockByHash            reqid=1 duration=509.518004ms
DEBUG[01-24|17:45:54.170] Served debug_traceBlockByHash            reqid=1 duration=337.698826ms
DEBUG[01-24|17:45:55.291] Served debug_traceBlockByHash            reqid=1 duration=331.638121ms
DEBUG[01-24|17:45:56.300] Served debug_traceBlockByHash            reqid=1 duration=317.069763ms
DEBUG[01-24|17:45:57.352] Served debug_traceBlockByHash            reqid=1 duration=345.110952ms
DEBUG[01-24|17:45:58.258] Served debug_traceBlockByHash            reqid=1 duration=328.854755ms
DEBUG[01-24|17:45:59.277] Served debug_traceBlockByHash            reqid=1 duration=322.600161ms
DEBUG[01-24|17:46:00.221] Served debug_traceBlockByHash            reqid=1 duration=346.298215ms
DEBUG[01-24|17:46:01.230] Served debug_traceBlockByHash            reqid=1 duration=329.619143ms

PR:

DEBUG[01-24|17:30:45.894] Served debug_traceBlockByHash            reqid=1 duration=361.376709ms
DEBUG[01-24|17:30:46.886] Served debug_traceBlockByHash            reqid=1 duration=124.999718ms
DEBUG[01-24|17:30:47.908] Served debug_traceBlockByHash            reqid=1 duration=122.911391ms
DEBUG[01-24|17:30:48.748] Served debug_traceBlockByHash            reqid=1 duration=147.318742ms
DEBUG[01-24|17:30:49.451] Served debug_traceBlockByHash            reqid=1 duration=123.343294ms
DEBUG[01-24|17:30:50.183] Served debug_traceBlockByHash            reqid=1 duration=120.245653ms
DEBUG[01-24|17:30:50.880] Served debug_traceBlockByHash            reqid=1 duration=122.924598ms
DEBUG[01-24|17:30:51.608] Served debug_traceBlockByHash            reqid=1 duration=137.153618ms
DEBUG[01-24|17:30:52.309] Served debug_traceBlockByHash            reqid=1 duration=120.465886ms
DEBUG[01-24|17:30:52.926] Served debug_traceBlockByHash            reqid=1 duration=122.481182ms
DEBUG[01-24|17:30:53.525] Served debug_traceBlockByHash            reqid=1 duration=122.163566ms
DEBUG[01-24|17:30:54.269] Served debug_traceBlockByHash            reqid=1 duration=135.241252ms
DEBUG[01-24|17:30:54.971] Served debug_traceBlockByHash            reqid=1 duration=119.866079ms

@holiman
Copy link
Contributor Author

holiman commented Jan 24, 2022

I'm still debugging a bit what happens on master.
Tested this on a binary with -race enabled, and got this:

==================                                                                                                                                                                                                                                                                                                           
WARNING: DATA RACE                                                                                                                                                                                                                                                                                                           
Read at 0x00c007e6c690 by goroutine 148:                                                                                                                                                                                                                                                                                     
  github.com/ethereum/go-ethereum/core.GetHashFn.func1()                                                                                                                                                                                                                                                                     
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/evm.go:88 +0x9b                                                                                                                                                                                                                                               
  github.com/ethereum/go-ethereum/core/vm.opBlockhash()                                                                                                                                                                                                                                                                      
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/instructions.go:450 +0x36f                                                                                                                                                                                                                                 
  github.com/ethereum/go-ethereum/core/vm.(*EVMInterpreter).Run()                                                                                                                                                                                                                                                            
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/interpreter.go:235 +0x761                                                                                                                                                                                                                                  
  github.com/ethereum/go-ethereum/core/vm.(*EVM).Call()                                                                                                                                                                                                                                                                      
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/evm.go:228 +0x965                                                                                                                                                                                                                                          
  github.com/ethereum/go-ethereum/core/vm.opCall()                                                                                                                                                                                                                                                                           
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/instructions.go:691 +0xd76                                                                                                                                                                                                                                 
  github.com/ethereum/go-ethereum/core/vm.(*EVMInterpreter).Run()                                                                                                                                                                                                                                                            
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/interpreter.go:235 +0x761                                                                                                                                                                                                                                  
  github.com/ethereum/go-ethereum/core/vm.(*EVM).Call()                                                                                                                                                                                                                                                                      
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/evm.go:228 +0x965                                                                                                                                                                                                                                          
  github.com/ethereum/go-ethereum/core.(*StateTransition).TransitionDb()                                                                                                                                                                                                                                                     
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/state_transition.go:325 +0xe6f                                                                                                                                                                                                                                
  github.com/ethereum/go-ethereum/core.ApplyMessage()                                                                                                                                                                                                                                                                        
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/state_transition.go:181 +0x68                                                                                                                                                                                                                                 
  github.com/ethereum/go-ethereum/eth/tracers.(*API).traceTx()                                                                                                                                                                                                                                                               
      /home/martin/go/src/github.com/ethereum/go-ethereum/eth/tracers/api.go:903 +0x73d                                                                                                                                                                                                                                      
  github.com/ethereum/go-ethereum/eth/tracers.(*API).traceBlock.func1()                                                                                                                                                                                                                                                      
      /home/martin/go/src/github.com/ethereum/go-ethereum/eth/tracers/api.go:609 +0x519                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                                             
Previous write at 0x00c007e6c690 by goroutine 144:                                                                                                                                                                                                                                                                           
  github.com/ethereum/go-ethereum/core.GetHashFn.func1()                                                                                                                                                                                                                                                                     
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/evm.go:103 +0x39a                                                                                                                                                                                                                                             
  github.com/ethereum/go-ethereum/core/vm.opBlockhash()                                                                                                                                                                                                                                                                      
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/instructions.go:450 +0x36f                                                                                                                                                                                                                                 
  github.com/ethereum/go-ethereum/core/vm.(*EVMInterpreter).Run()                                                                                                                                                                                                                                                            
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/interpreter.go:235 +0x761                                                                                                                                                                                                                                  
  github.com/ethereum/go-ethereum/core/vm.(*EVM).Call()                                                                                                                                                                                                                                                                      
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/evm.go:228 +0x965                                                                                                                                                                                                                                          
  github.com/ethereum/go-ethereum/core/vm.opCall()                                                                                                                                                                                                                                                                           
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/instructions.go:691 +0xd76                                                                                                                                                                                                                                 
  github.com/ethereum/go-ethereum/core/vm.(*EVMInterpreter).Run()                                                                                                                                                                                                                                                            
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/interpreter.go:235 +0x761                                                                                                                                                                                                                                  
  github.com/ethereum/go-ethereum/core/vm.(*EVM).Call()                                                                                                                                                                                                                                                                      
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/evm.go:228 +0x965                                                                                                                                                                                                                                          
  github.com/ethereum/go-ethereum/core.(*StateTransition).TransitionDb()                                                                                                                                                                                                                                                     
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/state_transition.go:325 +0xe6f                                                                                                                                                                                                                                
  github.com/ethereum/go-ethereum/core.ApplyMessage()                                                                                                                                                                                                                                                                        
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/state_transition.go:181 +0x68                                                                                                                                                                                                                                 
  github.com/ethereum/go-ethereum/eth/tracers.(*API).traceBlock()                                                                                                                                                                                                                                                            
      /home/martin/go/src/github.com/ethereum/go-ethereum/eth/tracers/api.go:628 +0xf7d                                                                                                                                                                                                                                      
  github.com/ethereum/go-ethereum/eth/tracers.(*API).TraceBlockByHash()                                                                                                                                                                                                                                                      
      /home/martin/go/src/github.com/ethereum/go-ethereum/eth/tracers/api.go:450 +0x14d                 

And

WARNING: DATA RACE
Read at 0x00c01150a240 by goroutine 148:
  github.com/ethereum/go-ethereum/core.GetHashFn.func1()
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/evm.go:95 +0x1bc 
  github.com/ethereum/go-ethereum/core/vm.opBlockhash()
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/instructions.go:450 +0x36f
  github.com/ethereum/go-ethereum/core/vm.(*EVMInterpreter).Run()
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/interpreter.go:235 +0x761
  github.com/ethereum/go-ethereum/core/vm.(*EVM).Call()
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/evm.go:228 +0x965
  github.com/ethereum/go-ethereum/core/vm.opCall()
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/instructions.go:691 +0xd76
  github.com/ethereum/go-ethereum/core/vm.(*EVMInterpreter).Run()
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/interpreter.go:235 +0x761
  github.com/ethereum/go-ethereum/core/vm.(*EVM).Call()
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/evm.go:228 +0x965
  github.com/ethereum/go-ethereum/core.(*StateTransition).TransitionDb()
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/state_transition.go:325 +0xe6f
  github.com/ethereum/go-ethereum/core.ApplyMessage()
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/state_transition.go:181 +0x68
  github.com/ethereum/go-ethereum/eth/tracers.(*API).traceTx()
      /home/martin/go/src/github.com/ethereum/go-ethereum/eth/tracers/api.go:903 +0x73d
  github.com/ethereum/go-ethereum/eth/tracers.(*API).traceBlock.func1()
      /home/martin/go/src/github.com/ethereum/go-ethereum/eth/tracers/api.go:609 +0x519

Previous write at 0x00c01150a240 by goroutine 144:
  github.com/ethereum/go-ethereum/core.GetHashFn.func1()
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/evm.go:103 +0x36a
  github.com/ethereum/go-ethereum/core/vm.opBlockhash()
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/instructions.go:450 +0x36f
  github.com/ethereum/go-ethereum/core/vm.(*EVMInterpreter).Run()
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/interpreter.go:235 +0x761
  github.com/ethereum/go-ethereum/core/vm.(*EVM).Call()
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/evm.go:228 +0x965
  github.com/ethereum/go-ethereum/core/vm.opCall()
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/instructions.go:691 +0xd76
  github.com/ethereum/go-ethereum/core/vm.(*EVMInterpreter).Run()
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/interpreter.go:235 +0x761
  github.com/ethereum/go-ethereum/core/vm.(*EVM).Call()
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/vm/evm.go:228 +0x965
  github.com/ethereum/go-ethereum/core.(*StateTransition).TransitionDb()
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/state_transition.go:325 +0xe6f
  github.com/ethereum/go-ethereum/core.ApplyMessage()
      /home/martin/go/src/github.com/ethereum/go-ethereum/core/state_transition.go:181 +0x68
  github.com/ethereum/go-ethereum/eth/tracers.(*API).traceBlock()
      /home/martin/go/src/github.com/ethereum/go-ethereum/eth/tracers/api.go:628 +0xf7d
  github.com/ethereum/go-ethereum/eth/tracers.(*API).TraceBlockByHash()
      /home/martin/go/src/github.com/ethereum/go-ethereum/eth/tracers/api.go:450 +0x14d
  runtime.call128()
      /usr/local/go/src/runtime/asm_amd64.s:553 +0x58

@holiman
Copy link
Contributor Author

holiman commented Jan 25, 2022

Triage discussion: merge ##24286 asap, fix this so it uses 'non-threaded' for native tracers but falls back to parallel tracing for js-based tracers

@holiman
Copy link
Contributor Author

holiman commented Jan 27, 2022

Some measurements

Native tracing

Master, native

DEBUG[01-27|09:24:54.766] Served debug_traceBlockByHash            reqid=1 duration=338.506387ms
DEBUG[01-27|09:24:56.313] Served debug_traceBlockByHash            reqid=1 duration=354.190774ms
DEBUG[01-27|09:24:57.406] Served debug_traceBlockByHash            reqid=1 duration=317.297016ms
DEBUG[01-27|09:24:58.553] Served debug_traceBlockByHash            reqid=1 duration=356.440457ms
DEBUG[01-27|09:24:59.687] Served debug_traceBlockByHash            reqid=1 duration=345.935448ms
DEBUG[01-27|09:25:00.813] Served debug_traceBlockByHash            reqid=1 duration=347.359489ms
DEBUG[01-27|09:25:01.753] Served debug_traceBlockByHash            reqid=1 duration=343.412059ms
DEBUG[01-27|09:25:02.768] Served debug_traceBlockByHash            reqid=1 duration=313.043359ms

PR, native

DEBUG[01-27|09:29:22.171] Served debug_traceBlockByHash            reqid=1 duration=140.486446ms
DEBUG[01-27|09:29:23.148] Served debug_traceBlockByHash            reqid=1 duration=123.064375ms
DEBUG[01-27|09:29:24.098] Served debug_traceBlockByHash            reqid=1 duration=151.192919ms
DEBUG[01-27|09:29:24.812] Served debug_traceBlockByHash            reqid=1 duration=148.915863ms
DEBUG[01-27|09:29:25.638] Served debug_traceBlockByHash            reqid=1 duration=152.067312ms
DEBUG[01-27|09:29:26.282] Served debug_traceBlockByHash            reqid=1 duration=152.362424ms
DEBUG[01-27|09:29:26.938] Served debug_traceBlockByHash            reqid=1 duration=128.348669ms

JS but scoped

Master, js-scoped

DEBUG[01-27|09:22:43.599] Served debug_traceBlockByHash            reqid=1 duration=1.06413365s
DEBUG[01-27|09:22:45.695] Served debug_traceBlockByHash            reqid=1 duration=1.113322122s
DEBUG[01-27|09:22:47.737] Served debug_traceBlockByHash            reqid=1 duration=1.106433767s
DEBUG[01-27|09:22:49.797] Served debug_traceBlockByHash            reqid=1 duration=1.118566878s
DEBUG[01-27|09:22:51.591] Served debug_traceBlockByHash            reqid=1 duration=1.075630451s
DEBUG[01-27|09:22:53.565] Served debug_traceBlockByHash            reqid=1 duration=1.199504204s
DEBUG[01-27|09:22:55.501] Served debug_traceBlockByHash            reqid=1 duration=1.20137146s
DEBUG[01-27|09:22:57.469] Served debug_traceBlockByHash            reqid=1 duration=1.213022454s
DEBUG[01-27|09:22:59.311] Served debug_traceBlockByHash            reqid=1 duration=1.109185545s

PR, js-scoped

DEBUG[01-27|09:26:36.804] Served debug_traceBlockByHash            reqid=1 duration=2.014930422s
DEBUG[01-27|09:26:39.805] Served debug_traceBlockByHash            reqid=1 duration=1.955208542s
DEBUG[01-27|09:26:42.946] Served debug_traceBlockByHash            reqid=1 duration=2.021341008s
DEBUG[01-27|09:26:45.796] Served debug_traceBlockByHash            reqid=1 duration=2.005384111s
DEBUG[01-27|09:26:48.732] Served debug_traceBlockByHash            reqid=1 duration=2.077768198s
DEBUG[01-27|09:27:03.009] Served debug_traceBlockByHash            reqid=1 duration=2.322705601s
DEBUG[01-27|09:27:06.196] Served debug_traceBlockByHash            reqid=1 duration=2.232071681s

JS legacy

Master, js-legacy

DEBUG[01-27|09:23:46.126] Served debug_traceBlockByHash            reqid=1 duration=6.041472402s
DEBUG[01-27|09:23:53.359] Served debug_traceBlockByHash            reqid=1 duration=6.107365105s
DEBUG[01-27|09:24:00.560] Served debug_traceBlockByHash            reqid=1 duration=6.139797943s
DEBUG[01-27|09:24:07.933] Served debug_traceBlockByHash            reqid=1 duration=6.352074484s
DEBUG[01-27|09:24:15.209] Served debug_traceBlockByHash            reqid=1 duration=6.35066638s

PR, js-legacy

DEBUG[01-27|09:27:52.055] Served debug_traceBlockByHash            reqid=1 duration=13.689256797s
DEBUG[01-27|09:28:05.723] Served debug_traceBlockByHash            reqid=1 duration=12.608050404s
DEBUG[01-27|09:28:18.986] Served debug_traceBlockByHash            reqid=1 duration=12.252208696s
DEBUG[01-27|09:28:32.058] Served debug_traceBlockByHash            reqid=1 duration=11.929315797s
DEBUG[01-27|09:28:50.049] Served debug_traceBlockByHash            reqid=1 duration=12.90068961s

@eliane345

This comment was marked as spam.

@eliane345

This comment was marked as spam.

Co-authored-by: Martin Holst Swende <martin@swende.se>
@s1na
Copy link
Contributor

s1na commented Dec 15, 2022

fix this so it uses 'non-threaded' for native tracers but falls back to parallel tracing for js-based tracers

After this JS times stay the same (no change in logic) and as @holiman showed native tracing of blocks becomes faster. At least for more computational ones. prestateTracer stays roughly same speed as master.

Master
       callTracer  callTracerLegacy  prestateTracer  prestateTracerLegacy
count   15.000000          15.00000       15.000000             15.000000
mean   269.533333        1489.40000     1288.333333           3771.133333
std     88.330440         358.88892      281.315701            817.721387
min    160.000000        1003.00000      878.000000           2682.000000
25%    218.000000        1263.00000     1051.500000           3179.000000
50%    254.000000        1359.00000     1256.000000           3647.000000
75%    281.000000        1591.00000     1568.500000           4135.500000
max    455.000000        2434.00000     1759.000000           5472.000000
Branch
       callTracer  callTracerLegacy  prestateTracer  prestateTracerLegacy
count   15.000000         15.000000       15.000000             15.000000
mean   142.466667       1470.866667     1227.000000           3747.666667
std     35.225532        329.767205      266.053969            785.829286
min     93.000000       1005.000000      886.000000           2776.000000
25%    125.000000       1290.000000      980.000000           3176.000000
50%    134.000000       1371.000000     1314.000000           3556.000000
75%    147.000000       1601.000000     1442.500000           4135.000000
max    231.000000       2364.000000     1683.000000           5458.000000

@@ -42,6 +42,12 @@ type Tracer interface {
Stop(err error)
}

// JSTracer is implemented by tracers evaluating JS code.
Copy link
Contributor

Choose a reason for hiding this comment

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

I use this trick to detect JS tracers. It's not very elegant. I thought about adding a Type() method which is more general, or Name(), or something. But not sure realistically where else this logic would be required.

Comment on lines 613 to 621
if config != nil && config.Tracer != nil && *config.Tracer != "" {
t, err := New(*config.Tracer, nil, nil)
if err != nil {
return nil, err
}
if _, ok := t.(JSTracer); ok {
return api.traceBlockParallel(ctx, block, statedb, config)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This whole thing is a bit wonky, but I guess we can live with it. The alternative would be that they register with some special attribute, and then you can query IsJs(*config.Tracer) or ParallelTracing(*config.Tracer).

I'm fine with it as is, though

Copy link
Contributor Author

@holiman holiman Dec 16, 2022

Choose a reason for hiding this comment

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

Now that I've seen that you also needed to add that wonky interface just to distinguish the type, I think a less hacky solution would be to change the registration phase, so they register with some attriubute.
Then this whole thing can become less clunky, and also does not have to run the constructor twice

if config != nil && config.Tracer != nil{
		if err, ok := IsInterpreted(config.Tracer); err  != nil {
			return nil, err
		}else if ok{
			return api.traceBlockParallel(ctx, block, statedb, config)
		}
	}

// JSTracer is implemented by tracers evaluating JS code.
type JSTracer interface {
Tracer
IsJS() bool
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Funky interface.
You can drop the return value, though

@s1na
Copy link
Contributor

s1na commented Dec 19, 2022

Ok now tracers signal whether they evaluate JS during registration. It's much less [wonky, hacky, clunky, funky] 馃槃

At the same time I refactored the registration code a bit.

Copy link
Member

@rjl493456442 rjl493456442 left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -606,24 +607,64 @@ func (api *API) traceBlock(ctx context.Context, block *types.Block, config *Trac
return nil, err
}
defer release()
Copy link
Member

Choose a reason for hiding this comment

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

nitpick, please add a blank line afterwards.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok done

@fjl fjl removed the status:triage label Jan 10, 2023
@fjl fjl added this to the 1.11.0 milestone Jan 10, 2023
@fjl fjl merged commit 2c6dda5 into ethereum:master Jan 10, 2023
shekhirin pushed a commit to shekhirin/go-ethereum that referenced this pull request Jun 6, 2023
This makes non-JS tracers execute all block txs on a single goroutine.
In the previous implementation, we used to prepare every tx pre-state
on one goroutine, and then run the transactions again with tracing enabled.
Native tracers are usually faster, so it is faster overall to use their output as
the pre-state for tracing the next transaction.

Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
@s1na s1na changed the title eth/tracers: use non-threaded tracechain eth/tracers: use non-threaded traceBlock Jun 27, 2023
@s1na s1na changed the title eth/tracers: use non-threaded traceBlock eth/tracers: use non-threaded traceBlock for native tracers Jun 27, 2023
MoonShiesty pushed a commit to MoonShiesty/go-ethereum that referenced this pull request Aug 30, 2023
This makes non-JS tracers execute all block txs on a single goroutine.
In the previous implementation, we used to prepare every tx pre-state
on one goroutine, and then run the transactions again with tracing enabled.
Native tracers are usually faster, so it is faster overall to use their output as
the pre-state for tracing the next transaction.

Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trace response of traceBlockByHash is non-deterministic and get "execution reverted" error
7 participants