mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-09 15:28:01 -05:00
feat: expose InvalidTxError in BlockExecutionError (#14597)
This commit is contained in:
@@ -14,6 +14,7 @@ workspace = true
|
||||
# reth
|
||||
reth-storage-errors.workspace = true
|
||||
|
||||
alloy-evm.workspace = true
|
||||
alloy-primitives.workspace = true
|
||||
alloy-rlp.workspace = true
|
||||
alloy-eips.workspace = true
|
||||
@@ -33,4 +34,5 @@ std = [
|
||||
"nybbles/std",
|
||||
"revm-database-interface/std",
|
||||
"reth-storage-errors/std",
|
||||
"alloy-evm/std",
|
||||
]
|
||||
|
||||
@@ -16,6 +16,7 @@ use alloc::{
|
||||
string::{String, ToString},
|
||||
};
|
||||
use alloy_eips::BlockNumHash;
|
||||
use alloy_evm::{EvmError, InvalidTxError};
|
||||
use alloy_primitives::B256;
|
||||
use reth_storage_errors::provider::ProviderError;
|
||||
use thiserror::Error;
|
||||
@@ -28,11 +29,11 @@ pub use trie::*;
|
||||
pub enum BlockValidationError {
|
||||
/// EVM error with transaction hash and message
|
||||
#[error("EVM reported invalid transaction ({hash}): {error}")]
|
||||
EVM {
|
||||
InvalidTx {
|
||||
/// The hash of the transaction
|
||||
hash: B256,
|
||||
/// The EVM error.
|
||||
error: Box<dyn core::error::Error + Send + Sync>,
|
||||
error: Box<dyn InvalidTxError>,
|
||||
},
|
||||
/// Error when incrementing balance in post execution
|
||||
#[error("incrementing balance in post execution failed")]
|
||||
@@ -141,6 +142,21 @@ impl BlockExecutionError {
|
||||
pub const fn is_state_root_error(&self) -> bool {
|
||||
matches!(self, Self::Validation(BlockValidationError::StateRoot(_)))
|
||||
}
|
||||
|
||||
/// Handles an EVM error occured when executing a transaction.
|
||||
///
|
||||
/// If an error matches [`EvmError::InvalidTransaction`], it will be wrapped into
|
||||
/// [`BlockValidationError::InvalidTx`], otherwise into [`InternalBlockExecutionError::EVM`].
|
||||
pub fn evm<E: EvmError>(error: E, hash: B256) -> Self {
|
||||
match error.try_into_invalid_tx_err() {
|
||||
Ok(err) => {
|
||||
Self::Validation(BlockValidationError::InvalidTx { hash, error: Box::new(err) })
|
||||
}
|
||||
Err(err) => {
|
||||
Self::Internal(InternalBlockExecutionError::EVM { hash, error: Box::new(err) })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ProviderError> for BlockExecutionError {
|
||||
@@ -164,6 +180,16 @@ pub enum InternalBlockExecutionError {
|
||||
/// The fork on the other chain
|
||||
other_chain_fork: Box<BlockNumHash>,
|
||||
},
|
||||
/// EVM error occurred when executing transaction. This is different from
|
||||
/// [`BlockValidationError::InvalidTx`] because it will only contain EVM errors which are not
|
||||
/// transaction validation errors and are assumed to be fatal.
|
||||
#[error("internal EVM error occurred when executing transaction {hash}: {error}")]
|
||||
EVM {
|
||||
/// The hash of the transaction
|
||||
hash: B256,
|
||||
/// The EVM error.
|
||||
error: Box<dyn core::error::Error + Send + Sync>,
|
||||
},
|
||||
/// Error when fetching data from the db.
|
||||
#[error(transparent)]
|
||||
Provider(#[from] ProviderError),
|
||||
|
||||
Reference in New Issue
Block a user