From 7df34889c2c0a509fc48f4a3f04cb524b74ba5bf Mon Sep 17 00:00:00 2001 From: Yong Kang Date: Thu, 9 Oct 2025 02:01:19 +0000 Subject: [PATCH] refactor: simplify `ProofTaskManager` by removing generic type parameter - Removed the generic type parameter `Factory` from the `ProofTaskManager` struct and its implementation, streamlining the code. - Updated the `new` and `spawn_worker_pool` methods to maintain functionality while simplifying type handling. - Enhanced clarity and reduced complexity in the proof task management logic. --- crates/trie/parallel/src/proof_task.rs | 27 +++++++++----------------- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/crates/trie/parallel/src/proof_task.rs b/crates/trie/parallel/src/proof_task.rs index 61be9e1a4c..3cf35b7857 100644 --- a/crates/trie/parallel/src/proof_task.rs +++ b/crates/trie/parallel/src/proof_task.rs @@ -128,7 +128,7 @@ enum StorageWorkerJob { /// - Use standard `std::mpsc` message passing /// - Receive consistent return types and error handling #[derive(Debug)] -pub struct ProofTaskManager { +pub struct ProofTaskManager { /// Sender for storage worker jobs to worker pool. storage_work_tx: CrossbeamSender, @@ -158,9 +158,6 @@ pub struct ProofTaskManager { /// Metrics tracking proof task operations. #[cfg(feature = "metrics")] metrics: ProofTaskMetrics, - - /// Marker to keep the Factory type parameter. - _phantom: std::marker::PhantomData, } /// Worker loop for storage trie operations. @@ -690,23 +687,23 @@ where Ok(storage_proofs) } -impl ProofTaskManager -where - Factory: DatabaseProviderFactory, -{ +impl ProofTaskManager { /// Creates a new [`ProofTaskManager`] with pre-spawned storage and account proof workers. /// /// The `storage_worker_count` determines how many storage workers to spawn, and /// `account_worker_count` determines how many account workers to spawn. /// Returns an error if the underlying provider fails to create the transactions required for /// spawning workers. - pub fn new( + pub fn new( executor: Handle, view: ConsistentDbView, task_ctx: ProofTaskCtx, storage_worker_count: usize, account_worker_count: usize, - ) -> ProviderResult { + ) -> ProviderResult + where + Factory: DatabaseProviderFactory, + { let (proof_task_tx, proof_task_rx) = channel(); // Use unbounded channel to ensure all storage operations are queued to workers. @@ -766,8 +763,6 @@ where #[cfg(feature = "metrics")] metrics: ProofTaskMetrics::default(), - - _phantom: std::marker::PhantomData, // TODO: we can remove this once we remove ProofTaskManager / ConsistentDbView }) } @@ -790,7 +785,7 @@ where /// /// Returns /// The number of workers successfully spawned - fn spawn_worker_pool( + fn spawn_worker_pool( executor: &Handle, view: &ConsistentDbView, task_ctx: &ProofTaskCtx, @@ -800,6 +795,7 @@ where worker_fn: F, ) -> ProviderResult where + Factory: DatabaseProviderFactory, Job: Send + 'static, F: Fn(ProofTaskTx>, CrossbeamReceiver, usize) + Send @@ -831,12 +827,7 @@ where Ok(spawned_workers) } -} -impl ProofTaskManager -where - Factory: DatabaseProviderFactory + 'static, -{ /// Loops, managing the proof tasks, routing them to the appropriate worker pools. /// /// # Task Routing