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

feat: abstract over Evm::Error #14085

Merged
merged 9 commits into from
Jan 30, 2025
Merged

feat: abstract over Evm::Error #14085

merged 9 commits into from
Jan 30, 2025

Conversation

klkvr
Copy link
Member

@klkvr klkvr commented Jan 29, 2025

Changes in this PR:

  • Evm::Error is no longer bounded to a concrete type (was EVMError<DB::Error> before). Instead, EvmError trait is introduced:

    reth/crates/evm/src/lib.rs

    Lines 98 to 113 in b1dfab9

    /// Abstraction over errors that can occur during EVM execution.
    ///
    /// Assumed that errors can occur either because of an invalid transaction, meaning that other
    /// transaction might still result in successful execution, or because of a general EVM
    /// misconfiguration.
    ///
    /// If caller occurs a error different from [`EvmError::InvalidTransaction`], it should most likely
    /// be treated as fatal error flagging some EVM misconfiguration.
    pub trait EvmError: core::error::Error + Send + Sync + 'static {
    /// Errors which might occur as a result of an invalid transaction. i.e unrelated to general EVM
    /// configuration.
    type InvalidTransaction: InvalidTxError;
    /// Returns the [`InvalidTransactionError`] if the error is an invalid transaction error.
    fn as_invalid_tx_err(&self) -> Option<&Self::InvalidTransaction>;
    }
  • Current revm does not yet have core::error::Error bound on Database::Error, so I've introduced a helper Database trait which is now used everywhere:

    reth/crates/evm/src/lib.rs

    Lines 129 to 131 in b1dfab9

    /// Helper trait to bound [`revm::Database::Error`] with common requirements.
    pub trait Database: revm::Database<Error: core::error::Error + Send + Sync + 'static> {}
    impl<T> Database for T where T: revm::Database<Error: core::error::Error + Send + Sync + 'static> {}

    This is not great and won't get solved with new revm because it doesn't have Send + Sync + 'static bounds. What we could do is just bound Error = ProviderError everywhere but this would also be a bit redundant.
  • On RPC side, EthApi::Error is now required to implement From<EthApi::Evm::EvmError<ProviderError>> which basically means that it should be able to convert any Evm error as long as underlying database has ProviderError error type which always holds for RPC.
    /// Helper trait to convert from revm errors.
    pub trait FromEvmError<Evm: ConfigureEvm>: From<Evm::EvmError<ProviderError>> {
    /// Converts from EVM error to this type.
    fn from_evm_err(err: Evm::EvmError<ProviderError>) -> Self {
    err.into()
    }
    }

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.

this is great, this should open up a few more things once we've migrated to new revm

smol nits

Comment on lines -75 to +69
EthExecutionStrategy<DB, EvmConfig>;
type Strategy<DB: Database> = EthExecutionStrategy<DB, EvmConfig>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

so much butter indeed

+ SpawnBlocking,
Self: LoadState<
Evm: ConfigureEvm<Header = ProviderHeader<Self::Provider>, TxEnv = TxEnv>,
Error: FromEvmError<Self::Evm>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is great

@mattsse mattsse added this to the Release 1.2.0 milestone Jan 30, 2025
klkvr and others added 2 commits January 30, 2025 16:13
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
@klkvr klkvr requested a review from mattsse January 30, 2025 12:20
@klkvr klkvr added this pull request to the merge queue Jan 30, 2025
Merged via the queue into main with commit 98a021e Jan 30, 2025
44 checks passed
@klkvr klkvr deleted the klkvr/generic-errors branch January 30, 2025 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants