Skip to content

Commit

Permalink
fix: only increment proofs_processed for state update proofs results (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected authored Jan 23, 2025
1 parent b97d9b4 commit ee7820f
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion crates/engine/tree/src/tree/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,25 @@ pub struct ProofCalculated {
sequence_number: u64,
/// Sparse trie update
update: SparseTrieUpdate,
/// The source of the proof fetch, whether it was requested as a prefetch or as a result of a
/// state update.
source: ProofFetchSource,
}

impl ProofCalculated {
/// Returns true if the proof was calculated as a result of a state update.
pub(crate) const fn is_from_state_update(&self) -> bool {
matches!(self.source, ProofFetchSource::StateUpdate)
}
}

/// Whether or not a proof was fetched due to a state update, or due to a prefetch command.
#[derive(Debug)]
pub enum ProofFetchSource {
/// The proof was fetched due to a prefetch command.
Prefetch,
/// The proof was fetched due to a state update.
StateUpdate,
}

/// Handle to track proof calculation ordering
Expand Down Expand Up @@ -395,6 +414,7 @@ where
proof_sequence_number,
state_root_message_sender,
thread_pool,
ProofFetchSource::Prefetch,
);
}

Expand All @@ -421,6 +441,7 @@ where
proof_sequence_number,
state_root_message_sender,
thread_pool,
ProofFetchSource::StateUpdate,
);
}

Expand All @@ -431,6 +452,7 @@ where
proof_sequence_number: u64,
state_root_message_sender: Sender<StateRootMessage>,
thread_pool: Arc<rayon::ThreadPool>,
source: ProofFetchSource,
) {
// Dispatch proof gathering for this state update
thread_pool.clone().spawn(move || {
Expand Down Expand Up @@ -459,6 +481,7 @@ where
targets: proof_targets,
multiproof: proof,
},
source,
}),
));
}
Expand Down Expand Up @@ -548,7 +571,9 @@ where
updates_finished = true;
}
StateRootMessage::ProofCalculated(proof_calculated) => {
proofs_processed += 1;
if proof_calculated.is_from_state_update() {
proofs_processed += 1;
}
debug!(
target: "engine::root",
sequence = proof_calculated.sequence_number,
Expand Down

0 comments on commit ee7820f

Please sign in to comment.