From 1ebb4299be79087d72b5d65c68224dd8217d0723 Mon Sep 17 00:00:00 2001 From: evalir Date: Wed, 23 Oct 2024 16:05:55 +0200 Subject: [PATCH 1/6] chore(general): use `core::error::Error` instead of `std::error::Error` on no-std compatible crates For `no-std` compatible crates, we can use `core::error::Error` instead of `std::error::Error` to avoid gating the Error impl under `std`. --- crates/eips/src/eip1898.rs | 16 ++++++---------- crates/eips/src/eip2718.rs | 5 ++--- crates/eips/src/eip4844/sidecar.rs | 6 +++--- crates/eips/src/eip4844/trusted_setup_points.rs | 3 +-- crates/rpc-types-engine/src/error.rs | 8 +++----- crates/rpc-types-engine/src/forkchoice.rs | 3 +-- crates/rpc-types-eth/src/block.rs | 5 ++--- crates/rpc-types-eth/src/filter.rs | 3 +-- crates/rpc-types-eth/src/transaction/error.rs | 5 ++--- 9 files changed, 21 insertions(+), 33 deletions(-) diff --git a/crates/eips/src/eip1898.rs b/crates/eips/src/eip1898.rs index 67d675c9428..3cacd0904b0 100644 --- a/crates/eips/src/eip1898.rs +++ b/crates/eips/src/eip1898.rs @@ -212,9 +212,8 @@ pub enum ParseBlockNumberError { } /// Error variants when parsing a [BlockNumberOrTag] -#[cfg(feature = "std")] -impl std::error::Error for ParseBlockNumberError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { +impl core::error::Error for ParseBlockNumberError { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { Self::ParseIntErr(err) => std::error::Error::source(err), Self::ParseErr(err) => std::error::Error::source(err), @@ -262,8 +261,7 @@ impl Display for HexStringMissingPrefixError { } } -#[cfg(feature = "std")] -impl std::error::Error for HexStringMissingPrefixError {} +impl core::error::Error for HexStringMissingPrefixError {} /// A Block Identifier. /// @@ -566,9 +564,8 @@ impl Display for ParseBlockIdError { } } -#[cfg(feature = "std")] -impl std::error::Error for ParseBlockIdError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { +impl core::error::Error for ParseBlockIdError { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { Self::ParseIntError(err) => std::error::Error::source(err), Self::FromHexError(err) => std::error::Error::source(err), @@ -784,8 +781,7 @@ impl fmt::Display for ParseBlockHashOrNumberError { } } -#[cfg(feature = "std")] -impl std::error::Error for ParseBlockHashOrNumberError {} +impl core::error::Error for ParseBlockHashOrNumberError {} impl FromStr for HashOrNumber { type Err = ParseBlockHashOrNumberError; diff --git a/crates/eips/src/eip2718.rs b/crates/eips/src/eip2718.rs index 82c11a1f759..d8888c6860f 100644 --- a/crates/eips/src/eip2718.rs +++ b/crates/eips/src/eip2718.rs @@ -52,9 +52,8 @@ impl From for alloy_rlp::Error { } } -#[cfg(feature = "std")] -impl std::error::Error for Eip2718Error { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { +impl core::error::Error for Eip2718Error { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { Self::RlpError(err) => Some(err), Self::UnexpectedType(_) => None, diff --git a/crates/eips/src/eip4844/sidecar.rs b/crates/eips/src/eip4844/sidecar.rs index d39b9535dc6..474ac5375c9 100644 --- a/crates/eips/src/eip4844/sidecar.rs +++ b/crates/eips/src/eip4844/sidecar.rs @@ -411,9 +411,9 @@ pub enum BlobTransactionValidationError { }, } -#[cfg(all(feature = "kzg", feature = "std"))] -impl std::error::Error for BlobTransactionValidationError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { +#[cfg(all(feature = "kzg"))] +impl core::error::Error for BlobTransactionValidationError { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { Self::KZGError(source) => Some(source), Self::InvalidProof { .. } diff --git a/crates/eips/src/eip4844/trusted_setup_points.rs b/crates/eips/src/eip4844/trusted_setup_points.rs index d3795e89074..50b5e916580 100644 --- a/crates/eips/src/eip4844/trusted_setup_points.rs +++ b/crates/eips/src/eip4844/trusted_setup_points.rs @@ -131,5 +131,4 @@ impl fmt::Display for KzgErrors { } } -#[cfg(feature = "std")] -impl std::error::Error for KzgErrors {} +impl core::error::Error for KzgErrors {} diff --git a/crates/rpc-types-engine/src/error.rs b/crates/rpc-types-engine/src/error.rs index 9867e3a23c1..4bc853baf81 100644 --- a/crates/rpc-types-engine/src/error.rs +++ b/crates/rpc-types-engine/src/error.rs @@ -69,9 +69,8 @@ pub enum PayloadError { Decode(alloy_rlp::Error), } -#[cfg(feature = "std")] -impl std::error::Error for PayloadError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { +impl core::error::Error for PayloadError { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { Self::Decode(err) => Some(err), _ => None, @@ -120,5 +119,4 @@ pub enum PayloadValidationError { }, } -#[cfg(feature = "std")] -impl std::error::Error for PayloadValidationError {} +impl core::error::Error for PayloadValidationError {} diff --git a/crates/rpc-types-engine/src/forkchoice.rs b/crates/rpc-types-engine/src/forkchoice.rs index 142d31b1c65..6c13d2856ba 100644 --- a/crates/rpc-types-engine/src/forkchoice.rs +++ b/crates/rpc-types-engine/src/forkchoice.rs @@ -85,8 +85,7 @@ pub enum ForkchoiceUpdateError { UnknownFinalBlock, } -#[cfg(feature = "std")] -impl std::error::Error for ForkchoiceUpdateError {} +impl core::error::Error for ForkchoiceUpdateError {} #[cfg(feature = "jsonrpsee-types")] impl From for jsonrpsee_types::error::ErrorObject<'static> { diff --git a/crates/rpc-types-eth/src/block.rs b/crates/rpc-types-eth/src/block.rs index a75cf4cb551..cee318b150a 100644 --- a/crates/rpc-types-eth/src/block.rs +++ b/crates/rpc-types-eth/src/block.rs @@ -283,9 +283,8 @@ pub enum BlockError { RlpDecodeRawBlock(alloy_rlp::Error), } -#[cfg(feature = "std")] -impl std::error::Error for BlockError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { +impl core::error::Error for BlockError { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { Self::RlpDecodeRawBlock(err) => Some(err), _ => None, diff --git a/crates/rpc-types-eth/src/filter.rs b/crates/rpc-types-eth/src/filter.rs index 659e6a7cd10..ab203fb9791 100644 --- a/crates/rpc-types-eth/src/filter.rs +++ b/crates/rpc-types-eth/src/filter.rs @@ -165,8 +165,7 @@ pub enum FilterBlockError { }, } -#[cfg(feature = "std")] -impl std::error::Error for FilterBlockError {} +impl core::error::Error for FilterBlockError {} /// Represents the target range of blocks for the filter #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] diff --git a/crates/rpc-types-eth/src/transaction/error.rs b/crates/rpc-types-eth/src/transaction/error.rs index eb4753f5fb3..ab3bfa317c0 100644 --- a/crates/rpc-types-eth/src/transaction/error.rs +++ b/crates/rpc-types-eth/src/transaction/error.rs @@ -74,9 +74,8 @@ pub enum ConversionError { Custom(String), } -#[cfg(feature = "std")] -impl std::error::Error for ConversionError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { +impl core::error::Error for ConversionError { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { Self::Eip2718Error(err) => Some(err), Self::SignatureError(err) => Some(err), From 28f008c521f15a4f24319e67bdaedb6b71fb9017 Mon Sep 17 00:00:00 2001 From: evalir Date: Wed, 23 Oct 2024 17:06:34 +0200 Subject: [PATCH 2/6] chore: bump MSRV --- .github/workflows/ci.yml | 10 +++++----- Cargo.toml | 2 +- README.md | 2 +- clippy.toml | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 433c4f44ea0..c816e4c011b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: rust: - "stable" - "nightly" - - "1.79" # MSRV + - "1.81" # MSRV flags: # No features - "--no-default-features" @@ -34,7 +34,7 @@ jobs: - "--all-features" exclude: # All features on MSRV - - rust: "1.79" # MSRV + - rust: "1.81" # MSRV flags: "--all-features" steps: - uses: actions/checkout@v4 @@ -53,14 +53,14 @@ jobs: cache-on-failure: true # Only run tests on latest stable and above - name: Install cargo-nextest - if: ${{ matrix.rust != '1.79' }} # MSRV + if: ${{ matrix.rust != '1.81' }} # MSRV uses: taiki-e/install-action@nextest - name: build - if: ${{ matrix.rust == '1.79' }} # MSRV + if: ${{ matrix.rust == '1.81' }} # MSRV run: cargo build --workspace ${{ matrix.flags }} - name: test shell: bash - if: ${{ matrix.rust != '1.79' }} # MSRV + if: ${{ matrix.rust != '1.81' }} # MSRV run: cargo nextest run --workspace ${{ matrix.flags }} doctest: diff --git a/Cargo.toml b/Cargo.toml index 65ab7623c32..cb798c194ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ resolver = "2" [workspace.package] version = "0.5.4" edition = "2021" -rust-version = "1.79" +rust-version = "1.81" authors = ["Alloy Contributors"] license = "MIT OR Apache-2.0" homepage = "https://github.com/alloy-rs/alloy" diff --git a/README.md b/README.md index c3eeecec195..c360b2111eb 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ When updating this, also update: - .github/workflows/ci.yml --> -The current MSRV (minimum supported rust version) is 1.79. +The current MSRV (minimum supported rust version) is 1.81. Alloy will keep a rolling MSRV policy of **at least** two versions behind the latest stable release (so if the latest stable release is 1.58, we would diff --git a/clippy.toml b/clippy.toml index f1acf4b1122..8c0bc009eb0 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1 @@ -msrv = "1.79" +msrv = "1.81" From 06c15560aa7992224f6ba83ca74606c8e966fa81 Mon Sep 17 00:00:00 2001 From: evalir Date: Wed, 23 Oct 2024 17:11:25 +0200 Subject: [PATCH 3/6] chore: std on 2718 --- crates/eips/src/eip1898.rs | 12 ++++++------ crates/eips/src/eip2718.rs | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/eips/src/eip1898.rs b/crates/eips/src/eip1898.rs index 3cacd0904b0..19a45fed43e 100644 --- a/crates/eips/src/eip1898.rs +++ b/crates/eips/src/eip1898.rs @@ -215,9 +215,9 @@ pub enum ParseBlockNumberError { impl core::error::Error for ParseBlockNumberError { fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { - Self::ParseIntErr(err) => std::error::Error::source(err), - Self::ParseErr(err) => std::error::Error::source(err), - Self::MissingPrefix(err) => std::error::Error::source(err), + Self::ParseIntErr(err) => core::error::Error::source(err), + Self::ParseErr(err) => core::error::Error::source(err), + Self::MissingPrefix(err) => core::error::Error::source(err), } } } @@ -567,9 +567,9 @@ impl Display for ParseBlockIdError { impl core::error::Error for ParseBlockIdError { fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { - Self::ParseIntError(err) => std::error::Error::source(err), - Self::FromHexError(err) => std::error::Error::source(err), - Self::ParseError(err) => std::error::Error::source(err), + Self::ParseIntError(err) => core::error::Error::source(err), + Self::FromHexError(err) => core::error::Error::source(err), + Self::ParseError(err) => core::error::Error::source(err), } } } diff --git a/crates/eips/src/eip2718.rs b/crates/eips/src/eip2718.rs index d8888c6860f..82c11a1f759 100644 --- a/crates/eips/src/eip2718.rs +++ b/crates/eips/src/eip2718.rs @@ -52,8 +52,9 @@ impl From for alloy_rlp::Error { } } -impl core::error::Error for Eip2718Error { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { +#[cfg(feature = "std")] +impl std::error::Error for Eip2718Error { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { Self::RlpError(err) => Some(err), Self::UnexpectedType(_) => None, From 43bf167209e582eac503a321a24865ab4d7cafa2 Mon Sep 17 00:00:00 2001 From: evalir Date: Wed, 23 Oct 2024 17:41:03 +0200 Subject: [PATCH 4/6] chore: readd std gate where alloy-rlp/ruint/const-hex have errs --- crates/eips/src/eip1898.rs | 22 ++++++++++--------- crates/rpc-types-engine/src/error.rs | 5 +++-- crates/rpc-types-eth/src/block.rs | 5 +++-- crates/rpc-types-eth/src/transaction/error.rs | 5 +++-- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/crates/eips/src/eip1898.rs b/crates/eips/src/eip1898.rs index 19a45fed43e..2b85497582e 100644 --- a/crates/eips/src/eip1898.rs +++ b/crates/eips/src/eip1898.rs @@ -212,12 +212,13 @@ pub enum ParseBlockNumberError { } /// Error variants when parsing a [BlockNumberOrTag] -impl core::error::Error for ParseBlockNumberError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { +#[cfg(feature = "std")] +impl std::error::Error for ParseBlockNumberError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { - Self::ParseIntErr(err) => core::error::Error::source(err), - Self::ParseErr(err) => core::error::Error::source(err), - Self::MissingPrefix(err) => core::error::Error::source(err), + Self::ParseIntErr(err) => std::error::Error::source(err), + Self::ParseErr(err) => std::error::Error::source(err), + Self::MissingPrefix(err) => std::error::Error::source(err), } } } @@ -564,12 +565,13 @@ impl Display for ParseBlockIdError { } } -impl core::error::Error for ParseBlockIdError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { +#[cfg(feature = "std")] +impl std::error::Error for ParseBlockIdError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { - Self::ParseIntError(err) => core::error::Error::source(err), - Self::FromHexError(err) => core::error::Error::source(err), - Self::ParseError(err) => core::error::Error::source(err), + Self::ParseIntError(err) => std::error::Error::source(err), + Self::FromHexError(err) => std::error::Error::source(err), + Self::ParseError(err) => std::error::Error::source(err), } } } diff --git a/crates/rpc-types-engine/src/error.rs b/crates/rpc-types-engine/src/error.rs index 4bc853baf81..b114be7bcf0 100644 --- a/crates/rpc-types-engine/src/error.rs +++ b/crates/rpc-types-engine/src/error.rs @@ -69,8 +69,9 @@ pub enum PayloadError { Decode(alloy_rlp::Error), } -impl core::error::Error for PayloadError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { +#[cfg(feature = "std")] +impl std::error::Error for PayloadError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { Self::Decode(err) => Some(err), _ => None, diff --git a/crates/rpc-types-eth/src/block.rs b/crates/rpc-types-eth/src/block.rs index cee318b150a..a75cf4cb551 100644 --- a/crates/rpc-types-eth/src/block.rs +++ b/crates/rpc-types-eth/src/block.rs @@ -283,8 +283,9 @@ pub enum BlockError { RlpDecodeRawBlock(alloy_rlp::Error), } -impl core::error::Error for BlockError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { +#[cfg(feature = "std")] +impl std::error::Error for BlockError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { Self::RlpDecodeRawBlock(err) => Some(err), _ => None, diff --git a/crates/rpc-types-eth/src/transaction/error.rs b/crates/rpc-types-eth/src/transaction/error.rs index ab3bfa317c0..eb4753f5fb3 100644 --- a/crates/rpc-types-eth/src/transaction/error.rs +++ b/crates/rpc-types-eth/src/transaction/error.rs @@ -74,8 +74,9 @@ pub enum ConversionError { Custom(String), } -impl core::error::Error for ConversionError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { +#[cfg(feature = "std")] +impl std::error::Error for ConversionError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { Self::Eip2718Error(err) => Some(err), Self::SignatureError(err) => Some(err), From ec7c628ce31b1b3b5968b10bf6122f3370b7d456 Mon Sep 17 00:00:00 2001 From: evalir Date: Wed, 23 Oct 2024 17:47:12 +0200 Subject: [PATCH 5/6] clippy --- crates/eips/src/eip4844/sidecar.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/eips/src/eip4844/sidecar.rs b/crates/eips/src/eip4844/sidecar.rs index 474ac5375c9..1d85a601a1a 100644 --- a/crates/eips/src/eip4844/sidecar.rs +++ b/crates/eips/src/eip4844/sidecar.rs @@ -411,7 +411,7 @@ pub enum BlobTransactionValidationError { }, } -#[cfg(all(feature = "kzg"))] +#[cfg(feature = "kzg")] impl core::error::Error for BlobTransactionValidationError { fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { From 5935847042a98e2c2ebf0849decbf8346fcb02c9 Mon Sep 17 00:00:00 2001 From: evalir Date: Wed, 23 Oct 2024 18:24:30 +0200 Subject: [PATCH 6/6] chore: std on kzg --- crates/eips/src/eip4844/sidecar.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/eips/src/eip4844/sidecar.rs b/crates/eips/src/eip4844/sidecar.rs index 1d85a601a1a..d39b9535dc6 100644 --- a/crates/eips/src/eip4844/sidecar.rs +++ b/crates/eips/src/eip4844/sidecar.rs @@ -411,9 +411,9 @@ pub enum BlobTransactionValidationError { }, } -#[cfg(feature = "kzg")] -impl core::error::Error for BlobTransactionValidationError { - fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { +#[cfg(all(feature = "kzg", feature = "std"))] +impl std::error::Error for BlobTransactionValidationError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { Self::KZGError(source) => Some(source), Self::InvalidProof { .. }