Skip to content

Commit e0b7a86

Browse files
yongkangcmediocregopherCopilotshekhirin
authored
perf(tree): worker pooling for account proofs (#18901)
Co-authored-by: Brian Picciano <me@mediocregopher.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Alexey Shekhirin <5773434+shekhirin@users.noreply.github.com>
1 parent 169a1fb commit e0b7a86

File tree

8 files changed

+903
-573
lines changed

8 files changed

+903
-573
lines changed

crates/engine/primitives/src/config.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ fn default_storage_worker_count() -> usize {
2121
}
2222
}
2323

24+
/// Returns the default number of account worker threads.
25+
///
26+
/// Account workers coordinate storage proof collection and account trie traversal.
27+
/// They are set to the same count as storage workers for simplicity.
28+
fn default_account_worker_count() -> usize {
29+
default_storage_worker_count()
30+
}
31+
2432
/// The size of proof targets chunk to spawn in one multiproof calculation.
2533
pub const DEFAULT_MULTIPROOF_TASK_CHUNK_SIZE: usize = 10;
2634

@@ -123,6 +131,8 @@ pub struct TreeConfig {
123131
allow_unwind_canonical_header: bool,
124132
/// Number of storage proof worker threads.
125133
storage_worker_count: usize,
134+
/// Number of account proof worker threads.
135+
account_worker_count: usize,
126136
}
127137

128138
impl Default for TreeConfig {
@@ -150,6 +160,7 @@ impl Default for TreeConfig {
150160
prewarm_max_concurrency: DEFAULT_PREWARM_MAX_CONCURRENCY,
151161
allow_unwind_canonical_header: false,
152162
storage_worker_count: default_storage_worker_count(),
163+
account_worker_count: default_account_worker_count(),
153164
}
154165
}
155166
}
@@ -180,6 +191,7 @@ impl TreeConfig {
180191
prewarm_max_concurrency: usize,
181192
allow_unwind_canonical_header: bool,
182193
storage_worker_count: usize,
194+
account_worker_count: usize,
183195
) -> Self {
184196
assert!(max_proof_task_concurrency > 0, "max_proof_task_concurrency must be at least 1");
185197
Self {
@@ -205,6 +217,7 @@ impl TreeConfig {
205217
prewarm_max_concurrency,
206218
allow_unwind_canonical_header,
207219
storage_worker_count,
220+
account_worker_count,
208221
}
209222
}
210223

@@ -482,4 +495,15 @@ impl TreeConfig {
482495
self.storage_worker_count = storage_worker_count;
483496
self
484497
}
498+
499+
/// Return the number of account proof worker threads.
500+
pub const fn account_worker_count(&self) -> usize {
501+
self.account_worker_count
502+
}
503+
504+
/// Setter for the number of account proof worker threads.
505+
pub const fn with_account_worker_count(mut self, account_worker_count: usize) -> Self {
506+
self.account_worker_count = account_worker_count;
507+
self
508+
}
485509
}

crates/engine/tree/src/tree/payload_processor/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ where
192192
{
193193
let (to_sparse_trie, sparse_trie_rx) = channel();
194194
// spawn multiproof task, save the trie input
195-
let (trie_input, state_root_config) =
196-
MultiProofConfig::new_from_input(consistent_view, trie_input);
195+
let (trie_input, state_root_config) = MultiProofConfig::from_input(trie_input);
197196
self.trie_input = Some(trie_input);
198197

199198
// Create and spawn the storage proof task
@@ -202,14 +201,15 @@ where
202201
state_root_config.state_sorted.clone(),
203202
state_root_config.prefix_sets.clone(),
204203
);
205-
let max_proof_task_concurrency = config.max_proof_task_concurrency() as usize;
206204
let storage_worker_count = config.storage_worker_count();
205+
let account_worker_count = config.account_worker_count();
206+
let max_proof_task_concurrency = config.max_proof_task_concurrency() as usize;
207207
let proof_task = match ProofTaskManager::new(
208208
self.executor.handle().clone(),
209-
state_root_config.consistent_view.clone(),
209+
consistent_view,
210210
task_ctx,
211-
max_proof_task_concurrency,
212211
storage_worker_count,
212+
account_worker_count,
213213
) {
214214
Ok(task) => task,
215215
Err(error) => {

0 commit comments

Comments
 (0)