mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-30 03:01:58 -04:00
refactor: streamline worker count validation
- Introduced a `clamp_worker_count` function to centralize the logic for enforcing the minimum worker count. - Updated setter methods in `TreeConfig` to utilize the new clamping function, improving code readability and maintainability.
This commit is contained in:
@@ -12,6 +12,17 @@ pub const DEFAULT_MAX_PROOF_TASK_CONCURRENCY: u64 = 256;
|
||||
/// Minimum number of workers we allow configuring explicitly.
|
||||
pub const MIN_WORKER_COUNT: usize = 2;
|
||||
|
||||
/// Clamps the worker count to the minimum allowed value.
|
||||
///
|
||||
/// Ensures that the worker count is at least [`MIN_WORKER_COUNT`].
|
||||
const fn clamp_worker_count(count: usize) -> usize {
|
||||
if count >= MIN_WORKER_COUNT {
|
||||
count
|
||||
} else {
|
||||
MIN_WORKER_COUNT
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the default number of storage worker threads based on available parallelism.
|
||||
fn default_storage_worker_count() -> usize {
|
||||
#[cfg(feature = "std")]
|
||||
@@ -499,11 +510,7 @@ impl TreeConfig {
|
||||
|
||||
/// Setter for the number of storage proof worker threads.
|
||||
pub const fn with_storage_worker_count(mut self, storage_worker_count: usize) -> Self {
|
||||
self.storage_worker_count = if storage_worker_count >= MIN_WORKER_COUNT {
|
||||
storage_worker_count
|
||||
} else {
|
||||
MIN_WORKER_COUNT
|
||||
};
|
||||
self.storage_worker_count = clamp_worker_count(storage_worker_count);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -514,11 +521,7 @@ impl TreeConfig {
|
||||
|
||||
/// Setter for the number of account proof worker threads.
|
||||
pub const fn with_account_worker_count(mut self, account_worker_count: usize) -> Self {
|
||||
self.account_worker_count = if account_worker_count >= MIN_WORKER_COUNT {
|
||||
account_worker_count
|
||||
} else {
|
||||
MIN_WORKER_COUNT
|
||||
};
|
||||
self.account_worker_count = clamp_worker_count(account_worker_count);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user