execution: make block read aheader non-global#21056
Merged
Conversation
…t depend on testing.TB
…on into worktree-cmd-enginextest
…on into worktree-cmd-enginextest
AskAlexSharov
approved these changes
May 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
execution: make block read aheader non-global
Summary
Replaces the package-level
globalReadAheaderinexecution/exec/blocks_read_ahead.gowith a per-Ethereuminstance. Each backend now owns its own*BlockReadAheader(caches + warmupWaitGroup) and threads it through to the consumers that need it.Why
The
globalReadAheaderis a process-wide singleton. The exec module'sValidateChaincallsAddHeaderAndBody, which spawns a fire-and-forget warmup goroutine tracked on a sharedsync.WaitGroup. The eth backend'sStop()waits on that same WaitGroup before closing the chain DB. With multipleEthereuminstances in one process (e.g. the newevm enginextestrunner that creates ~36 k testers in a single run, or any other harness that spins up many backends),Add(1)from one tester races withWait()returning in another. Once the counter momentarily hits zero, a concurrentAdd(1)panics:This was reproducible at
--workers ≥ 16runningevm enginextestagainst the full EESTblockchain_tests_engine_xset on tmpfs. Single-Erigon-per-process production deployments never trigger it, which is why it has been latent.Approach
Make the read-aheader a regular struct owned by each
Ethereum. The lifetime is the same as the eth backend, the WaitGroup never escapes the backend, and the race vanishes.Files (13 changed, +69 / −58)
execution/exec/blocks_read_ahead.go— exportsBlockReadAheaderandNewBlockReadAheader(). Methods replace the package-level*Global*wrappers (AddHeaderAndBodyToGlobalReadAheader,AddSendersToGlobalReadAheader,ReadBodyWithTransactionsFromGlobalReadAheader,ReadBlockWithSendersFromGlobalReadAheader,WaitForWarmup). The unusedWarmBodyFromGlobalReadAheaderis dropped.node/eth/backend.go—Ethereum.readAheaderfield, initialized inNewtoexec.NewBlockReadAheader(), used byStop()and threaded into the staged-sync configs andNewExecModule.execution/execmodule/exec_module.go—ExecModule.readAheaderfield; new arg onNewExecModule.ValidateChainnow callse.readAheader.AddHeaderAndBody(...).execution/stagedsync/stage_senders.go(+stage_senders_test.go) —SendersCfg.readAheader; new arg onStageSendersCfg; callscfg.readAheader.{AddSenders, ReadBodyWithTransactions}.execution/stagedsync/stage_execute.go—ExecuteBlockCfg.readAheader; new arg onStageExecuteBlocksCfg.execution/stagedsync/exec3.go,exec3_serial.go— callte.cfg.readAheader.ReadBlockWithSenders(...)/se.cfg.readAheader.ReadBlockWithSenders(...).execution/stagedsync/stage_witness.go— passes a freshexec.NewBlockReadAheader()(rewind-only path, doesn't share with the live backend).execution/stagedsync/stageloop/stageloop.go—NewDefaultStages/NewPipelineStages/NewInMemoryExecutionacceptreadAheaderand plumb it into the senders + execute stage configs.execution/execmodule/execmoduletester/exec_module_tester.go— constructs onereadAheaderand reuses it across the tester's stage configs andNewExecModulecall (mirroring howEthereumshares a single instance).cmd/integration/commands/stages.go,state_stages.go— pass freshexec.NewBlockReadAheader()instances at the integration-CLI call sites (each invocation is its own short-lived process).No runtime semantics change inside the read-aheader itself: same caches, same one-warmup-at-a-time
atomic.Bool, sameWaitForWarmupbehaviour. The only change is that the WaitGroup is per-instance rather than process-wide.Verification
make lintclean.evm enginextestagainst the full EESTblockchain_tests_engine_xset (fixtures_developv5.4.0),--workers 8onTMPDIR=/dev/shm:No
WaitGrouppanic at any worker count tested (8, 16, 24).make test-allwithERIGON_EXECUTION_TESTS_TMPDIR=/mnt/erigon-ramdisk GOGC=80: 222 packages green, 0 failures. All packages this PR touches pass directly:execution/exec(0.10s)execution/execmodule(0.83s),execmoduletester(0.29s)execution/stagedsync(7.18s),stagedsync/bodydownload,stagedsync/headerdownloadexecution/tests(212.89s, contains the previously-flakyTestInvalidReceiptHashHighMgas)Leak-loop tooling test (build tag
leak, in the engine-x test runner package) shows goroutine count flat at 3 across 15 iterations — the read-aheader's warmup goroutine terminates cleanly per Close.Notes
cmd/integration/commands/stages.go,state_stages.go) and theRewindStagesForWitnesshelper construct freshexec.NewBlockReadAheader()instances rather than threading one through. Each is a one-shot, short-lived process where the cache wouldn't carry value across the call. If we ever want shared caching there, those sites have a clear seam to do it.Stop()wait, samedbg.ReadAheadgate insidewarmBody.