revert: "perf: reuse accounts trie in payload processing (#16181)" (#16834)

This commit is contained in:
Dan Cline
2025-06-16 15:16:49 -04:00
committed by GitHub
parent d12a9788d9
commit c4da80abaa
6 changed files with 36 additions and 221 deletions

View File

@@ -2283,7 +2283,7 @@ where
// background task or try to compute it in parallel
if use_state_root_task {
match handle.state_root() {
Ok(StateRootComputeOutcome { state_root, trie_updates, trie }) => {
Ok(StateRootComputeOutcome { state_root, trie_updates }) => {
let elapsed = execution_finish.elapsed();
info!(target: "engine::tree", ?state_root, ?elapsed, "State root task finished");
// we double check the state root here for good measure
@@ -2297,9 +2297,6 @@ where
"State root task returned incorrect state root"
);
}
// hold on to the sparse trie for the next payload
self.payload_processor.set_sparse_trie(trie);
}
Err(error) => {
debug!(target: "engine::tree", %error, "Background parallel state root computation failed");

View File

@@ -28,7 +28,6 @@ use reth_trie_parallel::{
proof_task::{ProofTaskCtx, ProofTaskManager},
root::ParallelStateRootError,
};
use reth_trie_sparse::SparseTrieState;
use std::{
collections::VecDeque,
sync::{
@@ -68,9 +67,6 @@ where
precompile_cache_disabled: bool,
/// Precompile cache map.
precompile_cache_map: PrecompileCacheMap<SpecFor<Evm>>,
/// A sparse trie, kept around to be used for the state root computation so that allocations
/// can be minimized.
sparse_trie: Option<SparseTrieState>,
_marker: std::marker::PhantomData<N>,
}
@@ -95,7 +91,6 @@ where
evm_config,
precompile_cache_disabled: config.precompile_cache_disabled(),
precompile_cache_map,
sparse_trie: None,
_marker: Default::default(),
}
}
@@ -139,7 +134,7 @@ where
/// This returns a handle to await the final state root and to interact with the tasks (e.g.
/// canceling)
pub fn spawn<P>(
&mut self,
&self,
header: SealedHeaderFor<N>,
transactions: VecDeque<Recovered<N::SignedTx>>,
provider_builder: StateProviderBuilder<N, P>,
@@ -196,15 +191,11 @@ where
multi_proof_task.run();
});
// take the sparse trie if it was set
let sparse_trie = self.sparse_trie.take();
let mut sparse_trie_task = SparseTrieTask::new_with_stored_trie(
let mut sparse_trie_task = SparseTrieTask::new(
self.executor.clone(),
sparse_trie_rx,
proof_task.handle(),
self.trie_metrics.clone(),
sparse_trie,
);
// wire the sparse trie to the state root response receiver
@@ -250,11 +241,6 @@ where
PayloadHandle { to_multi_proof: None, prewarm_handle, state_root: None }
}
/// Sets the sparse trie to be kept around for the state root computation.
pub(super) fn set_sparse_trie(&mut self, sparse_trie: SparseTrieState) {
self.sparse_trie = Some(sparse_trie);
}
/// Spawn prewarming optionally wired to the multiproof task for target updates.
fn spawn_caching_with<P>(
&self,
@@ -580,7 +566,7 @@ mod tests {
}
}
let mut payload_processor = PayloadProcessor::<EthPrimitives, _>::new(
let payload_processor = PayloadProcessor::<EthPrimitives, _>::new(
WorkloadExecutor::default(),
EthEvmConfig::new(factory.chain_spec()),
&TreeConfig::default(),

View File

@@ -11,7 +11,7 @@ use reth_trie_parallel::root::ParallelStateRootError;
use reth_trie_sparse::{
blinded::{BlindedProvider, BlindedProviderFactory},
errors::{SparseStateTrieResult, SparseTrieErrorKind},
SparseStateTrie, SparseTrieState,
SparseStateTrie,
};
use std::{
sync::mpsc,
@@ -63,43 +63,6 @@ where
}
}
/// Creates a new sparse trie, populating the accounts trie with the given cleared
/// `SparseTrieState` if it exists.
pub(super) fn new_with_stored_trie(
executor: WorkloadExecutor,
updates: mpsc::Receiver<SparseTrieUpdate>,
blinded_provider_factory: BPF,
trie_metrics: MultiProofTaskMetrics,
sparse_trie_state: Option<SparseTrieState>,
) -> Self {
if let Some(sparse_trie_state) = sparse_trie_state {
Self::with_accounts_trie(
executor,
updates,
blinded_provider_factory,
trie_metrics,
sparse_trie_state,
)
} else {
Self::new(executor, updates, blinded_provider_factory, trie_metrics)
}
}
/// Creates a new sparse trie task, using the given cleared `SparseTrieState` for the accounts
/// trie.
pub(super) fn with_accounts_trie(
executor: WorkloadExecutor,
updates: mpsc::Receiver<SparseTrieUpdate>,
blinded_provider_factory: BPF,
metrics: MultiProofTaskMetrics,
sparse_trie_state: SparseTrieState,
) -> Self {
let mut trie = SparseStateTrie::new(blinded_provider_factory).with_updates(true);
trie.populate_from(sparse_trie_state);
Self { executor, updates, metrics, trie }
}
/// Runs the sparse trie task to completion.
///
/// This waits for new incoming [`SparseTrieUpdate`].
@@ -146,10 +109,7 @@ where
self.metrics.sparse_trie_final_update_duration_histogram.record(start.elapsed());
self.metrics.sparse_trie_total_duration_histogram.record(now.elapsed());
// take the account trie
let trie = self.trie.take_cleared_account_trie_state();
Ok(StateRootComputeOutcome { state_root, trie_updates, trie })
Ok(StateRootComputeOutcome { state_root, trie_updates })
}
}
@@ -161,8 +121,6 @@ pub struct StateRootComputeOutcome {
pub state_root: B256,
/// The trie updates.
pub trie_updates: TrieUpdates,
/// The account state trie.
pub trie: SparseTrieState,
}
/// Updates the sparse trie with the given proofs and state, and returns the elapsed time.