From 8d54f2f8d3ea9fb3050369129e2c947dfa665bf6 Mon Sep 17 00:00:00 2001 From: 0xAtreides <103257861+JackG-eth@users.noreply.github.com> Date: Mon, 17 Jun 2024 07:57:46 +0100 Subject: [PATCH] feat: support `no_std` for `reth-primitives` (#8817) Co-authored-by: Matthias Seitz --- Cargo.lock | 2 +- crates/primitives/Cargo.toml | 5 +++-- crates/primitives/benches/integer_list.rs | 2 +- crates/primitives/src/alloy_compat.rs | 3 +++ crates/primitives/src/block.rs | 21 +++++++++++-------- crates/primitives/src/chain/spec.rs | 20 +++++++++++++----- crates/primitives/src/compression/mod.rs | 3 +++ crates/primitives/src/constants/eip4844.rs | 2 +- crates/primitives/src/error.rs | 7 ++++++- crates/primitives/src/integer_list.rs | 9 +++++--- crates/primitives/src/lib.rs | 4 ++++ crates/primitives/src/net.rs | 3 +++ crates/primitives/src/proofs.rs | 3 +++ crates/primitives/src/receipt.rs | 5 ++++- crates/primitives/src/request.rs | 3 +++ crates/primitives/src/revm/compat.rs | 3 +++ crates/primitives/src/revm/env.rs | 5 ++++- crates/primitives/src/transaction/eip1559.rs | 2 +- crates/primitives/src/transaction/eip2930.rs | 2 +- crates/primitives/src/transaction/eip4844.rs | 5 ++++- crates/primitives/src/transaction/error.rs | 6 +++--- crates/primitives/src/transaction/legacy.rs | 2 +- crates/primitives/src/transaction/mod.rs | 5 ++++- crates/primitives/src/transaction/pooled.rs | 3 +++ crates/primitives/src/transaction/sidecar.rs | 3 +++ .../primitives/src/transaction/signature.rs | 2 +- crates/primitives/src/transaction/variant.rs | 2 +- crates/primitives/src/withdrawal.rs | 11 ++++++---- 28 files changed, 104 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc8ebdd6a..d1719df91 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7676,7 +7676,7 @@ dependencies = [ "sucds", "tempfile", "test-fuzz", - "thiserror", + "thiserror-no-std", "toml", "triehash", "zstd", diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index dc3efc7d7..90fdb0e3e 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -50,7 +50,7 @@ rayon.workspace = true serde.workspace = true serde_json.workspace = true tempfile = { workspace = true, optional = true } -thiserror.workspace = true +thiserror-no-std = { workspace = true , default-features = false } zstd = { version = "0.13", features = ["experimental"], optional = true } roaring = "0.10.2" @@ -87,7 +87,7 @@ pprof = { workspace = true, features = [ secp256k1.workspace = true [features] -default = ["c-kzg", "zstd-codec", "alloy-compat"] +default = ["c-kzg", "zstd-codec", "alloy-compat", "std"] asm-keccak = ["alloy-primitives/asm-keccak"] arbitrary = [ "reth-primitives-traits/arbitrary", @@ -120,6 +120,7 @@ alloy-compat = [ "reth-primitives-traits/alloy-compat", "alloy-rpc-types", ] +std = ["thiserror-no-std/std"] test-utils = ["reth-primitives-traits/test-utils"] [[bench]] diff --git a/crates/primitives/benches/integer_list.rs b/crates/primitives/benches/integer_list.rs index 3ea3543e0..097280748 100644 --- a/crates/primitives/benches/integer_list.rs +++ b/crates/primitives/benches/integer_list.rs @@ -232,7 +232,7 @@ mod elias_fano { } /// Primitives error type. - #[derive(Debug, thiserror::Error)] + #[derive(Debug, thiserror_no_std::Error)] pub enum EliasFanoError { /// The provided input is invalid. #[error("{0}")] diff --git a/crates/primitives/src/alloy_compat.rs b/crates/primitives/src/alloy_compat.rs index 60618f587..d193b787f 100644 --- a/crates/primitives/src/alloy_compat.rs +++ b/crates/primitives/src/alloy_compat.rs @@ -8,6 +8,9 @@ use crate::{ use alloy_primitives::TxKind; use alloy_rlp::Error as RlpError; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + impl TryFrom for Block { type Error = alloy_rpc_types::ConversionError; diff --git a/crates/primitives/src/block.rs b/crates/primitives/src/block.rs index 686652778..1e14392bf 100644 --- a/crates/primitives/src/block.rs +++ b/crates/primitives/src/block.rs @@ -14,6 +14,9 @@ use reth_codecs::derive_arbitrary; pub use reth_primitives_traits::test_utils::{generate_valid_header, valid_header_strategy}; use serde::{Deserialize, Serialize}; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + // HACK(onbjerg): we need this to always set `requests` to `None` since we might otherwise generate // a block with `None` withdrawals and `Some` requests, in which case we end up trying to decode the // requests as withdrawals @@ -177,9 +180,9 @@ impl Block { pub fn size(&self) -> usize { self.header.size() + // take into account capacity - self.body.iter().map(TransactionSigned::size).sum::() + self.body.capacity() * std::mem::size_of::() + - self.ommers.iter().map(Header::size).sum::() + self.ommers.capacity() * std::mem::size_of::
() + - self.withdrawals.as_ref().map_or(std::mem::size_of::>(), Withdrawals::total_size) + self.body.iter().map(TransactionSigned::size).sum::() + self.body.capacity() * core::mem::size_of::() + + self.ommers.iter().map(Header::size).sum::() + self.ommers.capacity() * core::mem::size_of::
() + + self.withdrawals.as_ref().map_or(core::mem::size_of::>(), Withdrawals::total_size) } } @@ -392,9 +395,9 @@ impl SealedBlock { pub fn size(&self) -> usize { self.header.size() + // take into account capacity - self.body.iter().map(TransactionSigned::size).sum::() + self.body.capacity() * std::mem::size_of::() + - self.ommers.iter().map(Header::size).sum::() + self.ommers.capacity() * std::mem::size_of::
() + - self.withdrawals.as_ref().map_or(std::mem::size_of::>(), Withdrawals::total_size) + self.body.iter().map(TransactionSigned::size).sum::() + self.body.capacity() * core::mem::size_of::() + + self.ommers.iter().map(Header::size).sum::() + self.ommers.capacity() * core::mem::size_of::
() + + self.withdrawals.as_ref().map_or(core::mem::size_of::>(), Withdrawals::total_size) } /// Calculates the total gas used by blob transactions in the sealed block. @@ -573,12 +576,12 @@ impl BlockBody { #[inline] pub fn size(&self) -> usize { self.transactions.iter().map(TransactionSigned::size).sum::() + - self.transactions.capacity() * std::mem::size_of::() + + self.transactions.capacity() * core::mem::size_of::() + self.ommers.iter().map(Header::size).sum::() + - self.ommers.capacity() * std::mem::size_of::
() + + self.ommers.capacity() * core::mem::size_of::
() + self.withdrawals .as_ref() - .map_or(std::mem::size_of::>(), Withdrawals::total_size) + .map_or(core::mem::size_of::>(), Withdrawals::total_size) } } diff --git a/crates/primitives/src/chain/spec.rs b/crates/primitives/src/chain/spec.rs index 308a988d7..788acf7b1 100644 --- a/crates/primitives/src/chain/spec.rs +++ b/crates/primitives/src/chain/spec.rs @@ -10,15 +10,25 @@ use crate::{ Hardfork, Head, Header, NamedChain, NodeRecord, SealedHeader, B256, EMPTY_OMMER_ROOT_HASH, MAINNET_DEPOSIT_CONTRACT, U256, }; +use core::{ + fmt, + fmt::{Display, Formatter}, +}; use derive_more::From; use once_cell::sync::Lazy; use reth_trie_common::root::state_root_ref_unhashed; use serde::{Deserialize, Serialize}; -use std::{ + +#[cfg(not(feature = "std"))] +use alloc::{ collections::BTreeMap, - fmt::{Display, Formatter}, + format, + string::{String, ToString}, sync::Arc, + vec::Vec, }; +#[cfg(feature = "std")] +use std::{collections::BTreeMap, sync::Arc}; pub use alloy_eips::eip1559::BaseFeeParams; @@ -1477,7 +1487,7 @@ struct DisplayFork { } impl Display for DisplayFork { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { let name_with_eip = if let Some(eip) = &self.eip { format!("{} ({})", self.name, eip) } else { @@ -1551,13 +1561,13 @@ pub struct DisplayHardforks { } impl Display for DisplayHardforks { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { fn format( header: &str, forks: &[DisplayFork], next_is_empty: bool, f: &mut Formatter<'_>, - ) -> std::fmt::Result { + ) -> fmt::Result { writeln!(f, "{header}:")?; let mut iter = forks.iter().peekable(); while let Some(fork) = iter.next() { diff --git a/crates/primitives/src/compression/mod.rs b/crates/primitives/src/compression/mod.rs index 91bb544fe..f7af0acbe 100644 --- a/crates/primitives/src/compression/mod.rs +++ b/crates/primitives/src/compression/mod.rs @@ -1,6 +1,9 @@ use std::{cell::RefCell, thread_local}; use zstd::bulk::{Compressor, Decompressor}; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + /// Compression/Decompression dictionary for `Receipt`. pub static RECEIPT_DICTIONARY: &[u8] = include_bytes!("./receipt_dictionary.bin"); /// Compression/Decompression dictionary for `Transaction`. diff --git a/crates/primitives/src/constants/eip4844.rs b/crates/primitives/src/constants/eip4844.rs index 3379a9e48..c1748edf7 100644 --- a/crates/primitives/src/constants/eip4844.rs +++ b/crates/primitives/src/constants/eip4844.rs @@ -38,7 +38,7 @@ mod trusted_setup { } /// Error type for loading the trusted setup. - #[derive(Debug, thiserror::Error)] + #[derive(Debug, thiserror_no_std::Error)] pub enum LoadKzgSettingsError { /// Failed to create temp file to store bytes for loading [`KzgSettings`] via /// [`KzgSettings::load_trusted_setup_file`]. diff --git a/crates/primitives/src/error.rs b/crates/primitives/src/error.rs index 42257cc7b..8ae946c24 100644 --- a/crates/primitives/src/error.rs +++ b/crates/primitives/src/error.rs @@ -1,8 +1,11 @@ -use std::{ +use core::{ fmt, ops::{Deref, DerefMut}, }; +#[cfg(not(feature = "std"))] +use alloc::boxed::Box; + /// A pair of values, one of which is expected and one of which is actual. #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct GotExpected { @@ -18,6 +21,7 @@ impl fmt::Display for GotExpected { } } +#[cfg(feature = "std")] impl std::error::Error for GotExpected {} impl From<(T, T)> for GotExpected { @@ -55,6 +59,7 @@ impl fmt::Display for GotExpectedBoxed { } } +#[cfg(feature = "std")] impl std::error::Error for GotExpectedBoxed {} impl Deref for GotExpectedBoxed { diff --git a/crates/primitives/src/integer_list.rs b/crates/primitives/src/integer_list.rs index f81afda93..8e258fd8b 100644 --- a/crates/primitives/src/integer_list.rs +++ b/crates/primitives/src/integer_list.rs @@ -1,4 +1,5 @@ use bytes::BufMut; +use core::fmt; use derive_more::Deref; use roaring::RoaringTreemap; use serde::{ @@ -6,7 +7,9 @@ use serde::{ ser::SerializeSeq, Deserialize, Deserializer, Serialize, Serializer, }; -use std::fmt; + +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; /// Uses Roaring Bitmaps to hold a list of integers. It provides really good compression with the /// capability to access its elements without decoding it. @@ -98,7 +101,7 @@ struct IntegerListVisitor; impl<'de> Visitor<'de> for IntegerListVisitor { type Value = IntegerList; - fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("a usize array") } @@ -137,7 +140,7 @@ impl<'a> Arbitrary<'a> for IntegerList { } /// Primitives error type. -#[derive(Debug, thiserror::Error)] +#[derive(Debug, thiserror_no_std::Error)] pub enum RoaringBitmapError { /// The provided input is invalid. #[error("the provided input is invalid")] diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index e2f695935..e73670826 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -17,6 +17,10 @@ // TODO: remove when https://github.com/proptest-rs/proptest/pull/427 is merged #![allow(unknown_lints, non_local_definitions)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +#![cfg_attr(not(feature = "std"), no_std)] + +#[cfg(not(feature = "std"))] +extern crate alloc; mod account; #[cfg(feature = "alloy-compat")] diff --git a/crates/primitives/src/net.rs b/crates/primitives/src/net.rs index 41fc6dfe6..922a7df57 100644 --- a/crates/primitives/src/net.rs +++ b/crates/primitives/src/net.rs @@ -1,5 +1,8 @@ pub use reth_network_peers::{NodeRecord, NodeRecordParseError, TrustedPeer}; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + // Ethereum bootnodes come from // OP bootnodes come from diff --git a/crates/primitives/src/proofs.rs b/crates/primitives/src/proofs.rs index b5a050434..96ebf49ec 100644 --- a/crates/primitives/src/proofs.rs +++ b/crates/primitives/src/proofs.rs @@ -8,6 +8,9 @@ use reth_trie_common::root::{ordered_trie_root, ordered_trie_root_with_encoder}; use alloy_eips::eip7685::Encodable7685; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + /// Calculate a transaction root. /// /// `(rlp(index), encoded(tx))` pairs. diff --git a/crates/primitives/src/receipt.rs b/crates/primitives/src/receipt.rs index 21622f6e4..56be2d0a1 100644 --- a/crates/primitives/src/receipt.rs +++ b/crates/primitives/src/receipt.rs @@ -4,13 +4,16 @@ use crate::{logs_bloom, Bloom, Bytes, TxType, B256}; use alloy_primitives::Log; use alloy_rlp::{length_of_length, Decodable, Encodable, RlpDecodable, RlpEncodable}; use bytes::{Buf, BufMut}; +use core::{cmp::Ordering, ops::Deref}; use derive_more::{Deref, DerefMut, From, IntoIterator}; #[cfg(any(test, feature = "arbitrary"))] use proptest::strategy::Strategy; #[cfg(feature = "zstd-codec")] use reth_codecs::CompactZstd; use reth_codecs::{add_arbitrary_tests, main_codec, Compact}; -use std::{cmp::Ordering, ops::Deref}; + +#[cfg(not(feature = "std"))] +use alloc::{vec, vec::Vec}; /// Receipt containing result of transaction execution. #[cfg_attr(feature = "zstd-codec", main_codec(no_arbitrary, zstd))] diff --git a/crates/primitives/src/request.rs b/crates/primitives/src/request.rs index 937f71b00..e3b5f220b 100644 --- a/crates/primitives/src/request.rs +++ b/crates/primitives/src/request.rs @@ -7,6 +7,9 @@ use derive_more::{Deref, DerefMut, From, IntoIterator}; use reth_codecs::{main_codec, Compact}; use revm_primitives::Bytes; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + /// A list of EIP-7685 requests. #[main_codec] #[derive(Debug, Clone, PartialEq, Eq, Default, Hash, Deref, DerefMut, From, IntoIterator)] diff --git a/crates/primitives/src/revm/compat.rs b/crates/primitives/src/revm/compat.rs index 705fc1880..cb492e6aa 100644 --- a/crates/primitives/src/revm/compat.rs +++ b/crates/primitives/src/revm/compat.rs @@ -1,6 +1,9 @@ use crate::{revm_primitives::AccountInfo, Account, Address, TxKind, KECCAK_EMPTY, U256}; use revm::{interpreter::gas::validate_initial_tx_gas, primitives::SpecId}; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + /// Converts a Revm [`AccountInfo`] into a Reth [`Account`]. /// /// Sets `bytecode_hash` to `None` if `code_hash` is [`KECCAK_EMPTY`]. diff --git a/crates/primitives/src/revm/env.rs b/crates/primitives/src/revm/env.rs index db38bb533..0b12be6ae 100644 --- a/crates/primitives/src/revm/env.rs +++ b/crates/primitives/src/revm/env.rs @@ -9,6 +9,9 @@ use alloy_eips::{eip4788::BEACON_ROOTS_ADDRESS, eip7002::WITHDRAWAL_REQUEST_PRED #[cfg(feature = "optimism")] use revm_primitives::OptimismFields; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + /// Fill block environment from Block. pub fn fill_block_env( block_env: &mut BlockEnv, @@ -73,7 +76,7 @@ pub fn block_coinbase(chain_spec: &ChainSpec, header: &Header, after_merge: bool } /// Error type for recovering Clique signer from a header. -#[derive(Debug, thiserror::Error)] +#[derive(Debug, thiserror_no_std::Error)] pub enum CliqueSignerRecoveryError { /// Header extradata is too short. #[error("Invalid extra data length")] diff --git a/crates/primitives/src/transaction/eip1559.rs b/crates/primitives/src/transaction/eip1559.rs index 92f75db6a..878efaa4f 100644 --- a/crates/primitives/src/transaction/eip1559.rs +++ b/crates/primitives/src/transaction/eip1559.rs @@ -2,8 +2,8 @@ use super::access_list::AccessList; use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256}; use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use bytes::BytesMut; +use core::mem; use reth_codecs::{main_codec, Compact}; -use std::mem; /// A transaction with a priority fee ([EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)). #[main_codec] diff --git a/crates/primitives/src/transaction/eip2930.rs b/crates/primitives/src/transaction/eip2930.rs index 9dc461886..45bc5e67a 100644 --- a/crates/primitives/src/transaction/eip2930.rs +++ b/crates/primitives/src/transaction/eip2930.rs @@ -2,8 +2,8 @@ use super::access_list::AccessList; use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256}; use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use bytes::BytesMut; +use core::mem; use reth_codecs::{main_codec, Compact}; -use std::mem; /// Transaction with an [`AccessList`] ([EIP-2930](https://eips.ethereum.org/EIPS/eip-2930)). #[main_codec] diff --git a/crates/primitives/src/transaction/eip4844.rs b/crates/primitives/src/transaction/eip4844.rs index 214e2a5e1..f4a2be8e2 100644 --- a/crates/primitives/src/transaction/eip4844.rs +++ b/crates/primitives/src/transaction/eip4844.rs @@ -4,12 +4,15 @@ use crate::{ B256, U256, }; use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; +use core::mem; use reth_codecs::{main_codec, Compact, CompactPlaceholder}; -use std::mem; #[cfg(feature = "c-kzg")] use crate::kzg::KzgSettings; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + /// [EIP-4844 Blob Transaction](https://eips.ethereum.org/EIPS/eip-4844#blob-transaction) /// /// A transaction with blob hashes and max blob fee diff --git a/crates/primitives/src/transaction/error.rs b/crates/primitives/src/transaction/error.rs index 2b17fa718..c5199dda5 100644 --- a/crates/primitives/src/transaction/error.rs +++ b/crates/primitives/src/transaction/error.rs @@ -2,7 +2,7 @@ use crate::{GotExpectedBoxed, U256}; /// Represents error variants that can happen when trying to validate a /// [Transaction](crate::Transaction) -#[derive(Debug, Clone, Eq, PartialEq, thiserror::Error)] +#[derive(Debug, Clone, Eq, PartialEq, thiserror_no_std::Error)] pub enum InvalidTransactionError { /// The sender does not have enough funds to cover the transaction fees #[error( @@ -55,7 +55,7 @@ pub enum InvalidTransactionError { /// Represents error variants that can happen when trying to convert a transaction to /// [`PooledTransactionsElement`](crate::PooledTransactionsElement) -#[derive(Debug, Clone, Eq, PartialEq, thiserror::Error)] +#[derive(Debug, Clone, Eq, PartialEq, thiserror_no_std::Error)] pub enum TransactionConversionError { /// This error variant is used when a transaction cannot be converted into a /// [`PooledTransactionsElement`](crate::PooledTransactionsElement) because it is not supported @@ -66,7 +66,7 @@ pub enum TransactionConversionError { /// Represents error variants than can happen when trying to convert a /// [`TransactionSignedEcRecovered`](crate::TransactionSignedEcRecovered) transaction. -#[derive(Debug, Clone, Eq, PartialEq, thiserror::Error)] +#[derive(Debug, Clone, Eq, PartialEq, thiserror_no_std::Error)] pub enum TryFromRecoveredTransactionError { /// Thrown if the transaction type is unsupported. #[error("Unsupported transaction type: {0}")] diff --git a/crates/primitives/src/transaction/legacy.rs b/crates/primitives/src/transaction/legacy.rs index d6cb4ae2a..ebbe29a78 100644 --- a/crates/primitives/src/transaction/legacy.rs +++ b/crates/primitives/src/transaction/legacy.rs @@ -1,8 +1,8 @@ use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256}; use alloy_rlp::{length_of_length, Encodable, Header}; use bytes::BytesMut; +use core::mem; use reth_codecs::{main_codec, Compact}; -use std::mem; /// Legacy transaction. #[main_codec] diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index f517c5b62..42e420a5e 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -8,12 +8,12 @@ use alloy_rlp::{ Decodable, Encodable, Error as RlpError, Header, EMPTY_LIST_CODE, EMPTY_STRING_CODE, }; use bytes::Buf; +use core::mem; use derive_more::{AsRef, Deref}; use once_cell::sync::Lazy; use rayon::prelude::{IntoParallelIterator, ParallelIterator}; use reth_codecs::{add_arbitrary_tests, derive_arbitrary, Compact}; use serde::{Deserialize, Serialize}; -use std::mem; pub use access_list::{AccessList, AccessListItem}; pub use eip1559::TxEip1559; @@ -60,6 +60,9 @@ pub use optimism::TxDeposit; #[cfg(feature = "optimism")] pub use tx_type::DEPOSIT_TX_TYPE_ID; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + /// Either a transaction hash or number. pub type TxHashOrNumber = BlockHashOrNumber; diff --git a/crates/primitives/src/transaction/pooled.rs b/crates/primitives/src/transaction/pooled.rs index 23e2ad3c1..2ca58b179 100644 --- a/crates/primitives/src/transaction/pooled.rs +++ b/crates/primitives/src/transaction/pooled.rs @@ -13,6 +13,9 @@ use derive_more::{AsRef, Deref}; use reth_codecs::add_arbitrary_tests; use serde::{Deserialize, Serialize}; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + /// A response to `GetPooledTransactions`. This can include either a blob transaction, or a /// non-4844 signed transaction. #[add_arbitrary_tests] diff --git a/crates/primitives/src/transaction/sidecar.rs b/crates/primitives/src/transaction/sidecar.rs index da273db36..c45683ce7 100644 --- a/crates/primitives/src/transaction/sidecar.rs +++ b/crates/primitives/src/transaction/sidecar.rs @@ -12,6 +12,9 @@ pub use alloy_eips::eip4844::BlobTransactionSidecar; #[cfg(feature = "c-kzg")] pub use alloy_eips::eip4844::BlobTransactionValidationError; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + /// A response to `GetPooledTransactions` that includes blob data, their commitments, and their /// corresponding proofs. /// diff --git a/crates/primitives/src/transaction/signature.rs b/crates/primitives/src/transaction/signature.rs index d564c58ab..077858a3c 100644 --- a/crates/primitives/src/transaction/signature.rs +++ b/crates/primitives/src/transaction/signature.rs @@ -193,7 +193,7 @@ impl Signature { /// Calculates a heuristic for the in-memory size of the [Signature]. #[inline] pub const fn size(&self) -> usize { - std::mem::size_of::() + core::mem::size_of::() } } diff --git a/crates/primitives/src/transaction/variant.rs b/crates/primitives/src/transaction/variant.rs index b3f7a00be..5bff5215d 100644 --- a/crates/primitives/src/transaction/variant.rs +++ b/crates/primitives/src/transaction/variant.rs @@ -5,7 +5,7 @@ use crate::{ Address, Transaction, TransactionSigned, TransactionSignedEcRecovered, TransactionSignedNoHash, B256, }; -use std::ops::Deref; +use core::ops::Deref; /// Represents various different transaction formats used in reth. /// diff --git a/crates/primitives/src/withdrawal.rs b/crates/primitives/src/withdrawal.rs index 461908b26..cfd0de226 100644 --- a/crates/primitives/src/withdrawal.rs +++ b/crates/primitives/src/withdrawal.rs @@ -4,6 +4,9 @@ use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper}; use derive_more::{AsRef, Deref, DerefMut, From, IntoIterator}; use reth_codecs::{main_codec, Compact}; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + /// Re-export from `alloy_eips`. #[doc(inline)] pub use alloy_eips::eip4895::Withdrawal; @@ -37,22 +40,22 @@ impl Withdrawals { /// Calculate the total size, including capacity, of the Withdrawals. #[inline] pub fn total_size(&self) -> usize { - self.capacity() * std::mem::size_of::() + self.capacity() * core::mem::size_of::() } /// Calculate a heuristic for the in-memory size of the [Withdrawals]. #[inline] pub fn size(&self) -> usize { - self.len() * std::mem::size_of::() + self.len() * core::mem::size_of::() } /// Get an iterator over the Withdrawals. - pub fn iter(&self) -> std::slice::Iter<'_, Withdrawal> { + pub fn iter(&self) -> core::slice::Iter<'_, Withdrawal> { self.0.iter() } /// Get a mutable iterator over the Withdrawals. - pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, Withdrawal> { + pub fn iter_mut(&mut self) -> core::slice::IterMut<'_, Withdrawal> { self.0.iter_mut() }