Skip to content

Commit

Permalink
feat: support no_std for reth-execution-errors (paradigmxyz#8729)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
JackG-eth and mattsse authored Jun 11, 2024
1 parent 268e768 commit 2bc1642
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
22 changes: 21 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ generic-array = "0.14"
tracing = "0.1.0"
tracing-appender = "0.2"
thiserror = "1.0"
thiserror-no-std = { version = "2.0.2", default-features = false }
serde_json = "1.0.94"
serde = { version = "1.0", default-features = false }
serde_with = "3.3.0"
Expand Down
7 changes: 6 additions & 1 deletion crates/evm/execution-errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ reth-consensus.workspace = true
reth-primitives.workspace = true
reth-storage-errors.workspace = true
reth-prune-types.workspace = true
thiserror.workspace = true
thiserror-no-std = { workspace = true, default-features = false }


[features]
default = ["std"]
std = ["thiserror-no-std/std"]
20 changes: 14 additions & 6 deletions crates/evm/execution-errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(not(feature = "std"))]
extern crate alloc;

use reth_consensus::ConsensusError;
use reth_primitives::{revm_primitives::EVMError, BlockNumHash, B256};
use reth_prune_types::PruneSegmentError;
use reth_storage_errors::provider::ProviderError;
use std::fmt::Display;
use thiserror::Error;

#[cfg(not(feature = "std"))]
use alloc::{boxed::Box, string::String};

pub mod trie;
pub use trie::{StateRootError, StorageRootError};

/// Transaction validation errors
#[derive(Error, Debug, Clone, PartialEq, Eq)]
#[derive(thiserror_no_std::Error, Debug, Clone, PartialEq, Eq)]
pub enum BlockValidationError {
/// EVM error with transaction hash and message
#[error("EVM reported invalid transaction ({hash}): {error}")]
Expand Down Expand Up @@ -99,7 +104,7 @@ pub enum BlockValidationError {
}

/// `BlockExecutor` Errors
#[derive(Error, Debug)]
#[derive(thiserror_no_std::Error, Debug)]
pub enum BlockExecutionError {
/// Validation error, transparently wrapping `BlockValidationError`
#[error(transparent)]
Expand All @@ -119,7 +124,7 @@ pub enum BlockExecutionError {
/// Transaction error on commit with inner details
#[error("transaction error on commit: {inner}")]
CanonicalCommit {
/// The inner error message
/// The inner error message.
inner: String,
},
/// Error when appending chain on fork is not possible
Expand All @@ -136,12 +141,14 @@ pub enum BlockExecutionError {
#[error(transparent)]
LatestBlock(#[from] ProviderError),
/// Arbitrary Block Executor Errors
#[cfg(feature = "std")]
#[error(transparent)]
Other(Box<dyn std::error::Error + Send + Sync>),
}

impl BlockExecutionError {
/// Create a new `BlockExecutionError::Other` variant.
#[cfg(feature = "std")]
pub fn other<E>(error: E) -> Self
where
E: std::error::Error + Send + Sync + 'static,
Expand All @@ -150,7 +157,8 @@ impl BlockExecutionError {
}

/// Create a new [`BlockExecutionError::Other`] from a given message.
pub fn msg(msg: impl Display) -> Self {
#[cfg(feature = "std")]
pub fn msg(msg: impl std::fmt::Display) -> Self {
Self::Other(msg.to_string().into())
}

Expand Down
2 changes: 1 addition & 1 deletion crates/evm/execution-errors/src/trie.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Errors when computing the state root.
use reth_storage_errors::db::DatabaseError;
use thiserror::Error;
use thiserror_no_std::Error;

/// State root errors.
#[derive(Error, Debug, PartialEq, Eq, Clone)]
Expand Down

0 comments on commit 2bc1642

Please sign in to comment.