mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-14 09:48:03 -05:00
Add INFO-level logs with DEBUG: prefix to trace multiproof task lifecycle: - Log worker system initialization with concurrency limits - Log when queue is full and requests are enqueued - Log when tasks are spawned (storage and account multiproofs) - Log when ProofCalculated messages are received - Log when on_calculation_complete is called - Log when pending tasks are dequeued and spawned These logs will help diagnose why inflight_multiproofs_histogram drops to 0 and identify if the feedback loop between task completion and metric updates is functioning correctly.
2.9 KiB
2.9 KiB
Proof Worker Context Refresh – Minimal Plan
Goal
Stop respawning proof workers every block while still giving them the latest ProofTaskCtx and read-only transaction.
Core Approach
- Spawn the storage/account worker threads once during startup and keep the crossbeam queues alive.
- Teach the worker job enums a single control message (
UpdateWorkerContext) that carries a fresh read-only transaction and a refreshedProofTaskCtx. - Before processing block N+1, wait until all block N jobs finish, broadcast one
UpdateWorkerContextper worker, wait for acknowledgements, then resume normal job dispatching.
Step-by-step Implementation Plan
-
Extend
ProofTaskCtx- Add a
consistent_view: ConsistentDbView<Factory>field. - Update the constructor, tests, and every call site (payload processor, multiproof task, benches) to pass the view along with the existing trie overlays.
- Add a
-
Add control variants to worker jobs
- Update
StorageWorkerJob/AccountWorkerJobwithUpdateWorkerContext { tx, task_ctx, ack }andShutdown. - Keep the enums generic so the control message can carry the concrete transaction type.
- Update
-
Handle context refresh inside workers
- Make
ProofTaskTxmutable inside each worker loop. - On
UpdateWorkerContext, replace the stored tx andProofTaskCtx, rebuild cursor factories and any cached providers, thenack. - On
Shutdown, break the loop so the thread exits cleanly.
- Make
-
Track in-flight jobs
- Introduce an
Arc<AtomicUsize>shared by handles and workers. - Increment when queuing any job (storage/account/blinded); wrap execution in an RAII guard that decrements on completion/panic.
- Expose a helper to read the current count.
- Introduce an
-
Wire into
PayloadProcessor- Initialise the workers once during setup.
- Before each new block: wait until
in_flight == 0, send oneUpdateWorkerContext(with a fresh tx from the ctx’s view) to each worker, await all acknowledgements, then hand out a refreshed handle for the next block. - Drop any old handles during the refresh window so callers cannot enqueue work mid-swap.
-
Shutdown path
- When the owner drops the pool/handle, broadcast
Shutdownonce per worker so every thread exits.
- When the owner drops the pool/handle, broadcast
Integration Notes
PayloadProcessordrives the refresh inline: wait forin_flight == 0, dispatchUpdateWorkerContextto each worker, await all acknowledgements, then resume normal job flow.- Drop old handles before the refresh window so no new jobs sneak in while the workers are swapping state.
- On shutdown, send
Shutdownonce per worker so threads exit cleanly.
Testing Checklist
- Unit test that
UpdateWorkerContextswaps the worker’s tx/ctx and triggers the ack. - Unit test that the in-flight counter blocks the refresh loop until outstanding work completes.
- Integration test that reuses the same workers across two block contexts and observes updated state.