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

eth/tracers: avoid using blockCtx concurrently #24286

merged 1 commit into from Jan 25, 2022


Copy link

@holiman holiman commented Jan 24, 2022

This is an alternative to #24283, and also closes #23205.

This PR fixes the root cause, which are data-races in the blockhash cache. Although crisp new evm's were used, they all fell back to the same blockhash lookup closure.

This PR produces identical results each time:

-rw-rw-r-- 1 martin martin 1738663 jan 24 21:32 foo.1643056374.json
-rw-rw-r-- 1 martin martin 1738663 jan 24 21:32 foo.1643056376.json
-rw-rw-r-- 1 martin martin 1738663 jan 24 21:32 foo.1643056377.json
-rw-rw-r-- 1 martin martin 1738663 jan 24 21:32 foo.1643056378.json
-rw-rw-r-- 1 martin martin 1738663 jan 24 21:32 foo.1643056379.json
-rw-rw-r-- 1 martin martin 1738663 jan 24 21:33 foo.1643056383.json
-rw-rw-r-- 1 martin martin 1738663 jan 24 21:33 foo.1643056384.json
-rw-rw-r-- 1 martin martin 1738663 jan 24 21:33 foo.1643056385.json
-rw-rw-r-- 1 martin martin 1738663 jan 24 21:33 foo.1643056386.json

Timing-wise, this PR (like master) is still slower than the more simplistic approach in #24283, so I'd prefer that one actually. However, for a custom js-tracer, it's likely that this pr / master is faster, whereas #24283 is overall faster on native tracers.

DEBUG[01-24|21:32:55.378] Served debug_traceBlockByHash            reqid=1 duration=485.41308ms
DEBUG[01-24|21:32:56.568] Served debug_traceBlockByHash            reqid=1 duration=342.59002ms
DEBUG[01-24|21:32:57.683] Served debug_traceBlockByHash            reqid=1 duration=332.445518ms
DEBUG[01-24|21:32:58.695] Served debug_traceBlockByHash            reqid=1 duration=321.028948ms
DEBUG[01-24|21:32:59.639] Served debug_traceBlockByHash            reqid=1 duration=343.162541ms
DEBUG[01-24|21:33:03.618] Served debug_traceBlockByHash            reqid=1 duration=327.178375ms
DEBUG[01-24|21:33:04.644] Served debug_traceBlockByHash            reqid=1 duration=332.759627ms
DEBUG[01-24|21:33:05.602] Served debug_traceBlockByHash            reqid=1 duration=335.360167ms
DEBUG[01-24|21:33:06.489] Served debug_traceBlockByHash            reqid=1 duration=330.544238ms

Example race:

Read at 0x00c01150a240 by goroutine 148:
      /home/martin/go/src/ +0x1bc
      /home/martin/go/src/ +0x36f*EVMInterpreter).Run()
      /home/martin/go/src/ +0x761*EVM).Call()
      /home/martin/go/src/ +0x965
      /home/martin/go/src/ +0xd76*EVMInterpreter).Run()
      /home/martin/go/src/ +0x761*EVM).Call()
      /home/martin/go/src/ +0x965*StateTransition).TransitionDb()
      /home/martin/go/src/ +0xe6f
      /home/martin/go/src/ +0x68*API).traceTx()
      /home/martin/go/src/ +0x73d*API).traceBlock.func1()
      /home/martin/go/src/ +0x519

Previous write at 0x00c01150a240 by goroutine 144:
      /home/martin/go/src/ +0x36a
      /home/martin/go/src/ +0x36f*EVMInterpreter).Run()
      /home/martin/go/src/ +0x761*EVM).Call()
      /home/martin/go/src/ +0x965
      /home/martin/go/src/ +0xd76*EVMInterpreter).Run()
      /home/martin/go/src/ +0x761*EVM).Call()
      /home/martin/go/src/ +0x965*StateTransition).TransitionDb()
      /home/martin/go/src/ +0xe6f
      /home/martin/go/src/ +0x68*API).traceBlock()
      /home/martin/go/src/ +0xf7d*API).TraceBlockByHash()
      /home/martin/go/src/ +0x14d
      /usr/local/go/src/runtime/asm_amd64.s:553 +0x58

@holiman holiman merged commit 015fde9 into ethereum:master Jan 25, 2022
1 check passed
sidhujag pushed a commit to syscoin/go-ethereum that referenced this pull request Jan 28, 2022
JacekGlen pushed a commit to JacekGlen/go-ethereum that referenced this pull request May 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging this pull request may close these issues.

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