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

refactor(consensus, evm): move post-execution validation to consensus #8321

Merged
merged 15 commits into from
May 22, 2024

Conversation

shekhirin
Copy link
Collaborator

@shekhirin shekhirin commented May 20, 2024

Resolves #8313

It also includes a change to the Executor and BatchExecutor semantics, as per discussed with @mattsse.

/// A general purpose executor trait that executes an input (e.g. block) and produces an output
/// (e.g. state changes and receipts).
///
/// This executor does not validate the output, see [BatchExecutor] for that.
pub trait Executor<DB> {
/// The input type for the executor.
type Input<'a>;
/// The output type for the executor.
type Output;
/// The error type returned by the executor.
type Error;
/// Consumes the type and executes the block.
///
/// # Note
/// Execution happens without any validation of the output. To validate the output, use the
/// [BatchExecutor].
///
/// # Returns
/// The output of the block execution.
fn execute(self, input: Self::Input<'_>) -> Result<Self::Output, Self::Error>;
/// A general purpose executor that can execute multiple inputs in sequence, validate the outputs,
/// and keep track of the state over the entire batch.
pub trait BatchExecutor<DB> {
/// The input type for the executor.
type Input<'a>;
/// The output type for the executor.
type Output;
/// The error type returned by the executor.
type Error;
/// Executes the next block in the batch, veryfies the output and updates the state internally.
fn execute_and_verify_one(&mut self, input: Self::Input<'_>) -> Result<(), Self::Error>;
/// Executes multiple inputs in the batch, verifies the output, and updates the state
/// internally.
///
/// This method is a convenience function for calling [`BatchExecutor::execute_and_verify_one`]
/// for each input.
fn execute_and_verify_many<'a, I>(&mut self, inputs: I) -> Result<(), Self::Error>
where
I: IntoIterator<Item = Self::Input<'a>>,
{
for input in inputs {
self.execute_and_verify_one(input)?;
}
Ok(())
}
/// Executes the entire batch, verifies the output, and returns the final state.
///
/// This method is a convenience function for calling [`BatchExecutor::execute_and_verify_many`]
/// and [`BatchExecutor::finalize`].
fn execute_and_verify_batch<'a, I>(mut self, batch: I) -> Result<Self::Output, Self::Error>
where
I: IntoIterator<Item = Self::Input<'a>>,
Self: Sized,
{
self.execute_and_verify_many(batch)?;
Ok(self.finalize())
}

@shekhirin shekhirin added C-debt A section of code is hard to understand or change A-execution Related to the Execution and EVM A-consensus Related to the consensus engine labels May 21, 2024
@shekhirin shekhirin marked this pull request as ready for review May 22, 2024 08:34
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renaming and additional fn makes sense,

the receipt verify functions need to be moved to the network specific implementations

crates/ethereum/evm/src/execute.rs Show resolved Hide resolved
crates/consensus/common/src/validation.rs Outdated Show resolved Hide resolved
crates/optimism/consensus/src/lib.rs Outdated Show resolved Hide resolved
crates/consensus/consensus/src/lib.rs Show resolved Hide resolved
@shekhirin shekhirin force-pushed the alexey/evm-post-block-validation branch from a0d47a6 to ff3d107 Compare May 22, 2024 12:47
@shekhirin shekhirin requested a review from mattsse May 22, 2024 13:22
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!

crates/consensus/auto-seal/src/lib.rs Show resolved Hide resolved
@shekhirin shekhirin added this pull request to the merge queue May 22, 2024
Merged via the queue into main with commit f45ca74 May 22, 2024
30 checks passed
@shekhirin shekhirin deleted the alexey/evm-post-block-validation branch May 22, 2024 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-consensus Related to the consensus engine A-execution Related to the Execution and EVM C-debt A section of code is hard to understand or change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move post-execution block validation from EthBlockExecutor to Consensus trait
2 participants