Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(trie): replace ParallelStateRoot with AsyncStateRoot #11213

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/blockchain-tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ reth-execution-types.workspace = true
reth-stages-api.workspace = true
reth-trie = { workspace = true, features = ["metrics"] }
reth-trie-db = { workspace = true, features = ["metrics"] }
reth-trie-parallel = { workspace = true, features = ["parallel"] }
reth-trie-parallel.workspace = true
reth-network.workspace = true
reth-consensus.workspace = true
reth-node-types.workspace = true
Expand Down
16 changes: 8 additions & 8 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use reth_provider::{
use reth_revm::database::StateProviderDatabase;
use reth_stages_api::ControlFlow;
use reth_trie::{updates::TrieUpdates, HashedPostState, TrieInput};
use reth_trie_parallel::async_root::{AsyncStateRoot, AsyncStateRootError};
use reth_trie_parallel::parallel_root::{ParallelStateRoot, ParallelStateRootError};
use std::{
cmp::Ordering,
collections::{btree_map, hash_map, BTreeMap, HashMap, HashSet, VecDeque},
Expand Down Expand Up @@ -2195,11 +2195,11 @@ where
let persistence_in_progress = self.persistence_state.in_progress();
if !persistence_in_progress {
state_root_result = match self
.compute_state_root_async(block.parent_hash, &hashed_state)
.compute_state_root_parallel(block.parent_hash, &hashed_state)
{
Ok((state_root, trie_output)) => Some((state_root, trie_output)),
Err(AsyncStateRootError::Provider(ProviderError::ConsistentView(error))) => {
debug!(target: "engine::tree", %error, "Async state root computation failed consistency check, falling back");
Err(ParallelStateRootError::Provider(ProviderError::ConsistentView(error))) => {
debug!(target: "engine", %error, "Parallel state root computation failed consistency check, falling back");
None
}
Err(error) => return Err(InsertBlockErrorKindTwo::Other(Box::new(error))),
Expand Down Expand Up @@ -2265,19 +2265,19 @@ where
Ok(InsertPayloadOk2::Inserted(BlockStatus2::Valid))
}

/// Compute state root for the given hashed post state asynchronously.
/// Compute state root for the given hashed post state in parallel.
///
/// # Returns
///
/// Returns `Ok(_)` if computed successfully.
/// Returns `Err(_)` if error was encountered during computation.
/// `Err(ProviderError::ConsistentView(_))` can be safely ignored and fallback computation
/// should be used instead.
fn compute_state_root_async(
fn compute_state_root_parallel(
fgimenez marked this conversation as resolved.
Show resolved Hide resolved
&self,
parent_hash: B256,
hashed_state: &HashedPostState,
) -> Result<(B256, TrieUpdates), AsyncStateRootError> {
) -> Result<(B256, TrieUpdates), ParallelStateRootError> {
let consistent_view = ConsistentDbView::new_with_latest_tip(self.provider.clone())?;
let mut input = TrieInput::default();

Expand All @@ -2299,7 +2299,7 @@ where
// Extend with block we are validating root for.
input.append_ref(hashed_state);

AsyncStateRoot::new(consistent_view, input).incremental_root_with_updates()
ParallelStateRoot::new(consistent_view, input).incremental_root_with_updates()
}

/// Handles an error that occurred while inserting a block.
Expand Down
14 changes: 3 additions & 11 deletions crates/trie/parallel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@ tracing.workspace = true
# misc
thiserror.workspace = true
derive_more.workspace = true

# `async` feature
tokio = { workspace = true, optional = true, default-features = false }
itertools = { workspace = true, optional = true }

# `parallel` feature
rayon = { workspace = true, optional = true }
rayon.workspace = true
itertools.workspace = true

# `metrics` feature
reth-metrics = { workspace = true, optional = true }
Expand All @@ -58,12 +53,9 @@ proptest.workspace = true
proptest-arbitrary-interop.workspace = true

[features]
default = ["metrics", "async", "parallel"]
default = ["metrics"]
metrics = ["reth-metrics", "dep:metrics", "reth-trie/metrics"]
async = ["tokio/sync", "itertools"]
parallel = ["rayon"]

[[bench]]
name = "root"
required-features = ["async", "parallel"]
harness = false
10 changes: 1 addition & 9 deletions crates/trie/parallel/benches/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use reth_trie::{
TrieInput,
};
use reth_trie_db::{DatabaseHashedCursorFactory, DatabaseStateRoot};
use reth_trie_parallel::{async_root::AsyncStateRoot, parallel_root::ParallelStateRoot};
use reth_trie_parallel::parallel_root::ParallelStateRoot;
use std::collections::HashMap;

pub fn calculate_state_root(c: &mut Criterion) {
Expand Down Expand Up @@ -70,14 +70,6 @@ pub fn calculate_state_root(c: &mut Criterion) {
|calculator| async { calculator.incremental_root() },
);
});

// async root
group.bench_function(BenchmarkId::new("async root", size), |b| {
b.iter_with_setup(
|| AsyncStateRoot::new(view.clone(), TrieInput::from_state(updated_state.clone())),
|calculator| calculator.incremental_root(),
);
});
}
}

Expand Down
Loading
Loading