mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix(root): spawn state root task only if host has enough parallelism (#14555)
This commit is contained in:
@ -2431,8 +2431,11 @@ where
|
|||||||
// Atomic bool for letting the prewarm tasks know when to stop
|
// Atomic bool for letting the prewarm tasks know when to stop
|
||||||
let cancel_execution = ManualCancel::default();
|
let cancel_execution = ManualCancel::default();
|
||||||
|
|
||||||
|
let use_legacy_state_root =
|
||||||
|
self.config.legacy_state_root() || !root::has_enough_parallelism();
|
||||||
|
|
||||||
let (state_root_handle, state_root_task_config, state_root_sender, state_hook) =
|
let (state_root_handle, state_root_task_config, state_root_sender, state_hook) =
|
||||||
if is_descendant_of_persisting_blocks && !self.config.legacy_state_root() {
|
if is_descendant_of_persisting_blocks && !use_legacy_state_root {
|
||||||
let consistent_view = ConsistentDbView::new_with_latest_tip(self.provider.clone())?;
|
let consistent_view = ConsistentDbView::new_with_latest_tip(self.provider.clone())?;
|
||||||
|
|
||||||
// Compute trie input
|
// Compute trie input
|
||||||
@ -2557,7 +2560,7 @@ where
|
|||||||
// a different database transaction per thread and it might end up with a
|
// a different database transaction per thread and it might end up with a
|
||||||
// different view of the database.
|
// different view of the database.
|
||||||
let (state_root, trie_output, root_elapsed) = if is_descendant_of_persisting_blocks {
|
let (state_root, trie_output, root_elapsed) = if is_descendant_of_persisting_blocks {
|
||||||
if self.config.legacy_state_root() {
|
if use_legacy_state_root {
|
||||||
match self.compute_state_root_parallel(block.header().parent_hash(), &hashed_state)
|
match self.compute_state_root_parallel(block.header().parent_hash(), &hashed_state)
|
||||||
{
|
{
|
||||||
Ok(result) => {
|
Ok(result) => {
|
||||||
|
|||||||
@ -52,6 +52,18 @@ pub(crate) fn thread_pool_size() -> usize {
|
|||||||
std::thread::available_parallelism().map_or(3, |num| (num.get() / 2).max(3))
|
std::thread::available_parallelism().map_or(3, |num| (num.get() / 2).max(3))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Determines if the host has enough parallelism to run the state root task.
|
||||||
|
///
|
||||||
|
/// It requires at least 5 parallel threads:
|
||||||
|
/// - Engine in main thread that spawns the state root task.
|
||||||
|
/// - State Root Task spawned in [`StateRootTask::spawn`]
|
||||||
|
/// - Sparse Trie spawned in [`run_sparse_trie`]
|
||||||
|
/// - Multiproof computation spawned in [`MultiproofManager::spawn_multiproof`]
|
||||||
|
/// - Storage root computation spawned in [`ParallelProof::multiproof`]
|
||||||
|
pub(crate) fn has_enough_parallelism() -> bool {
|
||||||
|
std::thread::available_parallelism().is_ok_and(|num| num.get() >= 5)
|
||||||
|
}
|
||||||
|
|
||||||
/// Outcome of the state root computation, including the state root itself with
|
/// Outcome of the state root computation, including the state root itself with
|
||||||
/// the trie updates and the total time spent.
|
/// the trie updates and the total time spent.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
Reference in New Issue
Block a user