Skip to content

Commit

Permalink
perf(engine): use ParallelProof::multiproof in StateRootTask
Browse files Browse the repository at this point in the history
  • Loading branch information
fgimenez committed Dec 13, 2024
1 parent 02f76b8 commit b44ff11
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions crates/engine/tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ reth-consensus.workspace = true
reth-engine-primitives.workspace = true
reth-errors.workspace = true
reth-evm.workspace = true
reth-execution-errors.workspace = true
reth-network-p2p.workspace = true
reth-payload-builder-primitives.workspace = true
reth-payload-builder.workspace = true
Expand All @@ -33,7 +32,6 @@ reth-prune.workspace = true
reth-revm.workspace = true
reth-stages-api.workspace = true
reth-tasks.workspace = true
reth-trie-db.workspace = true
reth-trie-parallel.workspace = true
reth-trie-sparse.workspace = true
reth-trie.workspace = true
Expand Down Expand Up @@ -82,6 +80,7 @@ reth-stages = { workspace = true, features = ["test-utils"] }
reth-static-file.workspace = true
reth-testing-utils.workspace = true
reth-tracing.workspace = true
reth-trie-db.workspace = true

# alloy
alloy-rlp.workspace = true
Expand Down Expand Up @@ -121,5 +120,4 @@ test-utils = [
"reth-tracing",
"reth-trie/test-utils",
"reth-prune-types?/test-utils",
"reth-trie-db/test-utils",
]
35 changes: 12 additions & 23 deletions crates/engine/tree/src/tree/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
use alloy_primitives::map::HashSet;
use rayon::iter::{ParallelBridge, ParallelIterator};
use reth_evm::system_calls::OnStateHook;
use reth_execution_errors::StateProofError;
use reth_provider::{
providers::ConsistentDbView, BlockReader, DBProvider, DatabaseProviderFactory,
StateCommitmentProvider,
providers::ConsistentDbView, BlockReader, DatabaseProviderFactory, StateCommitmentProvider,
};
use reth_trie::{
proof::Proof, updates::TrieUpdates, HashedPostState, HashedStorage, MultiProof,
MultiProofTargets, Nibbles, TrieInput,
updates::TrieUpdates, HashedPostState, HashedStorage, MultiProof, MultiProofTargets, Nibbles,
TrieInput,
};
use reth_trie_db::DatabaseProof;
use reth_trie_parallel::root::ParallelStateRootError;
use reth_trie_parallel::{proof::ParallelProof, root::ParallelStateRootError};
use reth_trie_sparse::{
blinded::{BlindedProvider, BlindedProviderFactory},
errors::{SparseStateTrieError, SparseStateTrieResult, SparseTrieError, SparseTrieErrorKind},
Expand Down Expand Up @@ -77,7 +74,7 @@ pub enum StateRootMessage<BPF: BlindedProviderFactory> {
/// Proof calculation completed for a specific state update
ProofCalculated(Box<ProofCalculated>),
/// Error during proof calculation
ProofCalculationError(StateProofError),
ProofCalculationError(ParallelStateRootError),
/// State root calculation completed
RootCalculated {
/// The updated sparse trie
Expand Down Expand Up @@ -330,21 +327,13 @@ where

// Dispatch proof gathering for this state update
scope.spawn(move |_| {
let provider = match view.provider_ro() {
Ok(provider) => provider,
Err(error) => {
error!(target: "engine::root", ?error, "Could not get provider");
return;
}
};

// TODO: replace with parallel proof
let result = Proof::overlay_multiproof(
provider.tx_ref(),
// TODO(alexey): this clone can be expensive, we should avoid it
input.as_ref().clone(),
proof_targets.clone(),
);
let nodes_sorted = Arc::new(input.nodes.clone().into_sorted());
let state_sorted = Arc::new(input.state.clone().into_sorted());
let prefix_sets = Arc::new(input.prefix_sets.clone());

let result = ParallelProof::new(view, nodes_sorted, state_sorted, prefix_sets)
.multiproof(proof_targets.clone());

match result {
Ok(proof) => {
let _ = state_root_message_sender.send(StateRootMessage::ProofCalculated(
Expand Down

0 comments on commit b44ff11

Please sign in to comment.