Skip to content

Conversation

yongkangc
Copy link
Member

@yongkangc yongkangc commented Oct 8, 2025

This PR builds on top of #18887 by adding worker pooling to account and blinded account proofs, which allows us to reduce overhead from spawning the worker.

Changes:

  • Move Account to pooling logic
  • Move Blinded Account Nodes to pooling logic. Removed underlying structure and functions (pending tasks)

Core logic:

  1. Determine workers based on parallelism
  2. Spawn x workers each with its own tx
  3. Queue storage proofs via crossbeam channels to the workers
  4. Await Storage proofs to build account proofs
Caller
    ↓ (requests account multiproof)
ProofTaskManager
    ↓ (routes to account worker pool)
Account Worker
    ↓ (calls collect_storage_proofs)
    ↓ (queues all storage proofs to storage worker pool)
Storage Workers (parallel computation)
    ↓ (return storage proofs)
Account Worker
    ↓ (calls build_account_multiproof_with_storage_roots)
    ↓ (walks account trie, looks up pre-computed storage roots)
Return to Caller (final account multiproof)

Issues closed:

References:

Next Steps:

  • Removing ProofTaskManager + other cleanups

yongkangc and others added 30 commits October 7, 2025 06:35
- Added configuration for maximum and minimum storage proof workers.
- Implemented a worker pool for processing storage proof tasks, improving efficiency by reusing transactions.
- Updated `ProofTaskManager` to handle storage proof tasks via a dedicated channel.
- Enhanced metrics to track storage proof requests and fallback scenarios.
- Adjusted existing tests to accommodate the new storage worker functionality.
- Enhanced documentation for `StorageProofJob` to clarify its current unused status and potential for future type-safe design.
- Updated comments in `ProofTaskManager` regarding the handling of on-demand tasks and the possibility of refactoring to a more type-safe enum.
- Improved logging for worker pool disconnection scenarios, emphasizing fallback to on-demand execution.
…clarity

- Updated comments in `ProofTaskManager` to enhance clarity regarding on-demand transaction handling and queue management.
- Renamed `pending_on_demand` to `on_demand_queue` for better understanding of its purpose.
- Adjusted the `new` function documentation to reflect the correct allocation of concurrency budget between storage workers and on-demand transactions.
- Improved the `queue_proof_task` method to use the new queue name.
…ement

- Removed the unused `OnDemandTask` enum and updated comments in `ProofTaskManager` to clarify the distinction between storage worker pool and on-demand execution.
- Enhanced documentation to better describe the public interface and task submission process.
- Improved clarity regarding transaction handling and execution paths for proof requests.
- Eliminated the `storage_proof_workers` field and related constants from `TreeConfig`.
- Updated the default implementation and related methods to reflect the removal, streamlining the configuration structure.
- Improved comments in `ProofTaskManager` and related functions for better clarity on task management and processing.
- Updated queue capacity calculation to use 4x buffering, reducing fallback to slower on-demand execution during burst loads.
- Removed redundant variable assignments to streamline the code.
…ursor factories

- Introduced pre-created cursor factories in `storage_worker_loop` to reduce overhead during proof computation.
- Updated `compute_storage_proof` to accept cursor factories as parameters, enhancing efficiency and clarity.
- Improved logging to provide better insights into proof task calculations.
- not change the logic for pending_tasks and proof_tasks_txs (on-demand proofs) and just continue using it for the BlindedAccountNode requests, but start using dedicated storage workers for StorageProof and BlindedStorageNode requests
- Added a function to determine the default number of storage worker threads based on available parallelism.
- Updated TreeConfig to include a storage_worker_count field, initialized with the default value.
- Modified payload processor to utilize the new storage_worker_count instead of a hardcoded value.
@yongkangc
Copy link
Member Author

Latest bench on reth4 mainnet

Mean percent difference ~4%

image latency_comparison

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@yongkangc yongkangc requested a review from Copilot October 10, 2025 10:55
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@yongkangc yongkangc requested a review from shekhirin October 10, 2025 12:35
@yongkangc
Copy link
Member Author

yongkangc commented Oct 13, 2025

@Rjected @shekhirin @mediocregopher ready for a final review 🙏🏻

Comment on lines +358 to +360
storage_proof_task_handle: ProofTaskManagerHandle,
/// Handle to the proof task manager used for account multiproofs.
account_proof_task_handle: ProofTaskManagerHandle,
Copy link
Member Author

Choose a reason for hiding this comment

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

this isaddressed later on in the pr for cleanup where we use proof_task_handle instead

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

haven't looked too close into the actual proof logic

other than that lgtm

pending @Rjected

Comment on lines +175 to 178
let storage_root_targets_len = StorageRootTargets::count(
&prefix_sets.account_prefix_set,
&prefix_sets.storage_prefix_sets,
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

as a small optimization for future PRs, this calculation can be skipped if trace logs below won't be emitted

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the note

Copy link
Collaborator

@shekhirin shekhirin left a comment

Choose a reason for hiding this comment

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

LGTM, my only suggestion is the same as Dan's — about free functions instead of structs with methods that keep the state.

Copy link
Member

@Rjected Rjected left a comment

Choose a reason for hiding this comment

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

lgtm with the one suggestions about putting the worker state into structs

}

impl<Factory> ProofTaskManager<Factory>
// TODO: Refactor this with storage_worker_loop. ProofTaskManager should be removed in the following
Copy link
Member

Choose a reason for hiding this comment

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

do you mean that we should keep the ProofTaskManager?

no, I just mean that a struct, and a method on the struct called run or something similar, makes more sense to me than having _loop functions, since they are tasks with state

ie something like

let worker = AccountProofWorker::new(...);
executor.spawn_blocking(move || {
    worker.run();
});

makes more sense to me than how we currently spawn

@yongkangc
Copy link
Member Author

@shekhirin @Rjected will address Ur comments about structs in another pr

@yongkangc yongkangc added this pull request to the merge queue Oct 15, 2025
Merged via the queue into main with commit e0b7a86 Oct 15, 2025
40 of 41 checks passed
@yongkangc yongkangc deleted the yk/worker_pool_acc branch October 15, 2025 00:41
@github-project-automation github-project-automation bot moved this from In Progress to Done in Reth Tracker Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants