perf: Skip state root calculation

This commit is contained in:
sprites0
2025-03-10 23:14:45 +00:00
parent a5e51afb36
commit 7fe7c06507
3 changed files with 22 additions and 94 deletions

View File

@ -195,6 +195,7 @@ pub enum StateRootMessage {
}
/// Message about completion of proof calculation for a specific state update
#[allow(dead_code)]
#[derive(Debug)]
pub struct ProofCalculated {
/// The index of this proof in the sequence of state updates
@ -255,7 +256,7 @@ impl ProofSequencer {
// return early if we don't have the next expected proof
if !self.pending_proofs.contains_key(&self.next_to_deliver) {
return Vec::new()
return Vec::new();
}
let mut consecutive_proofs = Vec::with_capacity(self.pending_proofs.len());
@ -390,7 +391,7 @@ where
sequence_number: input.proof_sequence_number,
state: input.hashed_state_update,
});
return
return;
}
if self.inflight >= self.max_concurrent {
@ -480,10 +481,13 @@ where
#[metrics(scope = "tree.root")]
struct StateRootTaskMetrics {
/// Histogram of proof calculation durations.
#[allow(unused)]
pub proof_calculation_duration_histogram: Histogram,
/// Histogram of proof calculation account targets.
#[allow(unused)]
pub proof_calculation_account_targets_histogram: Histogram,
/// Histogram of proof calculation storage targets.
#[allow(unused)]
pub proof_calculation_storage_targets_histogram: Histogram,
/// Histogram of sparse trie update durations.
@ -492,10 +496,13 @@ struct StateRootTaskMetrics {
pub sparse_trie_final_update_duration_histogram: Histogram,
/// Histogram of state updates received.
#[allow(unused)]
pub state_updates_received_histogram: Histogram,
/// Histogram of proofs processed.
#[allow(unused)]
pub proofs_processed_histogram: Histogram,
/// Histogram of state root update iterations.
#[allow(unused)]
pub state_root_iterations_histogram: Histogram,
/// Histogram of the number of updated state nodes.
@ -531,6 +538,7 @@ pub struct StateRootTask<Factory> {
/// Task configuration.
config: StateRootConfig<Factory>,
/// Receiver for state root related messages.
#[allow(unused)]
rx: Receiver<StateRootMessage>,
/// Sender for state root related messages.
tx: Sender<StateRootMessage>,
@ -539,6 +547,7 @@ pub struct StateRootTask<Factory> {
/// Proof sequencing handler.
proof_sequencer: ProofSequencer,
/// Reference to the shared thread pool for parallel proof generation.
#[allow(unused)]
thread_pool: Arc<rayon::ThreadPool>,
/// Manages calculation of multiproofs.
multiproof_manager: MultiproofManager<Factory>,
@ -591,12 +600,6 @@ where
/// Spawns the state root task and returns a handle to await its result.
pub fn spawn(self) -> StateRootHandle {
let sparse_trie_tx = Self::spawn_sparse_trie(
self.thread_pool.clone(),
self.config.clone(),
self.metrics.clone(),
self.tx.clone(),
);
let (tx, rx) = mpsc::sync_channel(1);
std::thread::Builder::new()
.name("State Root Task".to_string())
@ -605,8 +608,11 @@ where
self.observe_config();
let result = self.run(sparse_trie_tx);
let _ = tx.send(result);
let _ = tx.send(Ok(StateRootComputeOutcome {
state_root: (B256::default(), Default::default()),
total_time: Duration::default(),
time_from_last_update: Duration::default(),
}));
})
.expect("failed to spawn state root thread");
@ -614,6 +620,7 @@ where
}
/// Logs and records in metrics the state root config parameters.
#[allow(unused)]
fn observe_config(&self) {
let nodes_sorted_account_nodes = self.config.nodes_sorted.account_nodes.len();
let nodes_sorted_removed_nodes = self.config.nodes_sorted.removed_nodes.len();
@ -659,6 +666,7 @@ where
}
/// Spawn long running sparse trie task that forwards the final result upon completion.
#[allow(unused)]
fn spawn_sparse_trie(
thread_pool: Arc<rayon::ThreadPool>,
config: StateRootConfig<Factory>,
@ -682,6 +690,7 @@ where
}
/// Handles request for proof prefetch.
#[allow(unused)]
fn on_prefetch_proof(&mut self, targets: MultiProofTargets) {
let proof_targets = self.get_prefetch_proof_targets(targets);
extend_multi_proof_targets_ref(&mut self.fetched_proof_targets, &proof_targets);
@ -697,6 +706,7 @@ where
}
/// Calls `get_proof_targets` with existing proof targets for prefetching.
#[allow(unused)]
fn get_prefetch_proof_targets(&self, mut targets: MultiProofTargets) -> MultiProofTargets {
// Here we want to filter out any targets that are already fetched
//
@ -726,7 +736,7 @@ where
let Some(fetched_storage) = self.fetched_proof_targets.get(hashed_address) else {
// this means the account has not been fetched yet, so we must fetch everything
// associated with this account
continue
continue;
};
let prev_target_storage_len = target_storage.len();
@ -749,6 +759,7 @@ where
/// Handles state updates.
///
/// Returns proof targets derived from the state update.
#[allow(unused)]
fn on_state_update(
&mut self,
source: StateChangeSource,