diff --git a/Cargo.lock b/Cargo.lock index 8b4d9d628c9..f8646ae64da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6591,7 +6591,7 @@ version = "1.0.0-rc.1" dependencies = [ "auto_impl", "reth-primitives", - "thiserror", + "thiserror-no-std", ] [[package]] diff --git a/crates/consensus/consensus/Cargo.toml b/crates/consensus/consensus/Cargo.toml index 8ea4236bfa1..1d4d6d758c4 100644 --- a/crates/consensus/consensus/Cargo.toml +++ b/crates/consensus/consensus/Cargo.toml @@ -16,7 +16,9 @@ reth-primitives.workspace = true # misc auto_impl.workspace = true -thiserror.workspace = true +thiserror-no-std = {workspace = true, default-features = false } [features] +default = ["std"] +std = ["thiserror-no-std/std"] test-utils = [] diff --git a/crates/consensus/consensus/src/lib.rs b/crates/consensus/consensus/src/lib.rs index fd3c694c2fa..5768fee46f2 100644 --- a/crates/consensus/consensus/src/lib.rs +++ b/crates/consensus/consensus/src/lib.rs @@ -7,14 +7,23 @@ )] #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +#![cfg_attr(not(feature = "std"), no_std)] use reth_primitives::{ BlockHash, BlockNumber, BlockWithSenders, Bloom, GotExpected, GotExpectedBoxed, Header, HeaderValidationError, InvalidTransactionError, Receipt, Request, SealedBlock, SealedHeader, B256, U256, }; + +#[cfg(feature = "std")] use std::fmt::Debug; +#[cfg(not(feature = "std"))] +extern crate alloc; + +#[cfg(not(feature = "std"))] +use alloc::{fmt::Debug, vec::Vec}; + /// A consensus implementation that does nothing. pub mod noop; @@ -119,7 +128,7 @@ pub trait Consensus: Debug + Send + Sync { } /// Consensus Errors -#[derive(thiserror::Error, Debug, PartialEq, Eq, Clone)] +#[derive(thiserror_no_std::Error, Debug, PartialEq, Eq, Clone)] pub enum ConsensusError { /// Error when the gas used in the header exceeds the gas limit. #[error("block used gas ({gas_used}) is greater than gas limit ({gas_limit})")] @@ -333,6 +342,6 @@ impl ConsensusError { } /// `HeaderConsensusError` combines a `ConsensusError` with the `SealedHeader` it relates to. -#[derive(thiserror::Error, Debug)] +#[derive(thiserror_no_std::Error, Debug)] #[error("Consensus error: {0}, Invalid header: {1:?}")] pub struct HeaderConsensusError(ConsensusError, SealedHeader);