From 47d188cb8e1adcc6a018d5e41fb3045f6f1d5a94 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Fri, 13 Sep 2024 18:01:12 +0200 Subject: [PATCH] cfg: replace std feature gate alloc imports with extern crate alloc (#10861) --- crates/chainspec/src/lib.rs | 1 - crates/chainspec/src/spec.rs | 6 +----- crates/consensus/consensus/src/lib.rs | 11 +++-------- crates/ethereum-forks/src/display.rs | 4 +--- crates/ethereum-forks/src/forkid.rs | 3 --- crates/ethereum-forks/src/hardfork/dev.rs | 4 +--- crates/ethereum-forks/src/hardfork/ethereum.rs | 4 +--- crates/ethereum-forks/src/hardfork/optimism.rs | 1 - crates/ethereum-forks/src/lib.rs | 1 - crates/ethereum/evm/src/eip6110.rs | 4 +--- crates/ethereum/evm/src/execute.rs | 6 +----- crates/ethereum/evm/src/lib.rs | 8 ++------ crates/evm/execution-errors/src/lib.rs | 4 +--- crates/evm/execution-errors/src/trie.rs | 4 +--- crates/evm/execution-types/src/chain.rs | 6 +----- crates/evm/execution-types/src/lib.rs | 1 - crates/evm/src/builder.rs | 2 -- crates/evm/src/lib.rs | 1 - crates/evm/src/system_calls.rs | 9 ++------- crates/optimism/chainspec/src/base.rs | 3 --- crates/optimism/chainspec/src/base_sepolia.rs | 3 --- crates/optimism/chainspec/src/dev.rs | 3 --- crates/optimism/chainspec/src/lib.rs | 1 - crates/optimism/chainspec/src/op.rs | 3 --- crates/optimism/chainspec/src/op_sepolia.rs | 3 --- crates/primitives-traits/src/constants/gas_units.rs | 4 +--- crates/primitives-traits/src/error.rs | 6 +----- crates/primitives-traits/src/integer_list.rs | 4 +--- crates/primitives-traits/src/lib.rs | 1 - crates/primitives-traits/src/request.rs | 4 +--- crates/primitives-traits/src/withdrawal.rs | 4 +--- crates/primitives/src/alloy_compat.rs | 4 +--- crates/primitives/src/block.rs | 4 +--- crates/primitives/src/compression/mod.rs | 7 +++---- crates/primitives/src/lib.rs | 1 - crates/primitives/src/proofs.rs | 4 +--- crates/primitives/src/receipt.rs | 4 +--- crates/primitives/src/transaction/mod.rs | 1 - crates/primitives/src/transaction/pooled.rs | 4 +--- crates/primitives/src/transaction/sidecar.rs | 1 - crates/revm/src/batch.rs | 11 ++--------- crates/revm/src/lib.rs | 1 - crates/revm/src/test_utils.rs | 4 +--- crates/storage/codecs/src/alloy/access_list.rs | 4 +--- crates/storage/codecs/src/alloy/genesis_account.rs | 4 +--- crates/storage/codecs/src/alloy/log.rs | 4 +--- .../storage/codecs/src/alloy/transaction/eip4844.rs | 4 +--- .../storage/codecs/src/alloy/transaction/eip7702.rs | 4 +--- crates/storage/codecs/src/alloy/trie.rs | 4 +--- crates/storage/codecs/src/lib.rs | 2 -- crates/storage/errors/src/db.rs | 5 ----- crates/storage/errors/src/lib.rs | 1 - crates/storage/errors/src/lockfile.rs | 4 +--- crates/storage/errors/src/provider.rs | 1 - 54 files changed, 39 insertions(+), 163 deletions(-) diff --git a/crates/chainspec/src/lib.rs b/crates/chainspec/src/lib.rs index 4badac6bce..62ea1aa9bc 100644 --- a/crates/chainspec/src/lib.rs +++ b/crates/chainspec/src/lib.rs @@ -9,7 +9,6 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(not(feature = "std"))] extern crate alloc; /// Chain specific constants diff --git a/crates/chainspec/src/spec.rs b/crates/chainspec/src/spec.rs index d0c113f881..eb25d0e5b0 100644 --- a/crates/chainspec/src/spec.rs +++ b/crates/chainspec/src/spec.rs @@ -1,9 +1,5 @@ -pub use alloy_eips::eip1559::BaseFeeParams; - -#[cfg(not(feature = "std"))] use alloc::{boxed::Box, sync::Arc, vec::Vec}; -#[cfg(feature = "std")] -use std::sync::Arc; +pub use alloy_eips::eip1559::BaseFeeParams; use alloy_chains::{Chain, ChainKind, NamedChain}; use alloy_genesis::Genesis; diff --git a/crates/consensus/consensus/src/lib.rs b/crates/consensus/consensus/src/lib.rs index 5dfe466566..91b93c8a75 100644 --- a/crates/consensus/consensus/src/lib.rs +++ b/crates/consensus/consensus/src/lib.rs @@ -9,20 +9,15 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(feature = "std"), no_std)] +extern crate alloc; + +use alloc::{fmt::Debug, vec::Vec}; use alloy_primitives::{BlockHash, BlockNumber, Bloom, B256, U256}; use reth_primitives::{ constants::MINIMUM_GAS_LIMIT, BlockWithSenders, GotExpected, GotExpectedBoxed, Header, InvalidTransactionError, Receipt, Request, SealedBlock, SealedHeader, }; -#[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; diff --git a/crates/ethereum-forks/src/display.rs b/crates/ethereum-forks/src/display.rs index b0bc06a777..98372ea30d 100644 --- a/crates/ethereum-forks/src/display.rs +++ b/crates/ethereum-forks/src/display.rs @@ -1,12 +1,10 @@ -#[cfg(not(feature = "std"))] +use crate::{hardforks::Hardforks, ForkCondition}; use alloc::{ format, string::{String, ToString}, vec::Vec, }; -use crate::{hardforks::Hardforks, ForkCondition}; - /// A container to pretty-print a hardfork. /// /// The fork is formatted depending on its fork condition: diff --git a/crates/ethereum-forks/src/forkid.rs b/crates/ethereum-forks/src/forkid.rs index 48ef778fcf..8a344e2dd2 100644 --- a/crates/ethereum-forks/src/forkid.rs +++ b/crates/ethereum-forks/src/forkid.rs @@ -3,7 +3,6 @@ //! Previously version of Apache licenced [`ethereum-forkid`](https://crates.io/crates/ethereum-forkid). use crate::Head; -#[cfg(not(feature = "std"))] use alloc::{ collections::{BTreeMap, BTreeSet}, vec::Vec, @@ -22,8 +21,6 @@ use crc::*; use proptest_derive::Arbitrary as PropTestArbitrary; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -#[cfg(feature = "std")] -use std::collections::{BTreeMap, BTreeSet}; const CRC_32_IEEE: Crc = Crc::::new(&CRC_32_ISO_HDLC); const TIMESTAMP_BEFORE_ETHEREUM_MAINNET: u64 = 1_300_000_000; diff --git a/crates/ethereum-forks/src/hardfork/dev.rs b/crates/ethereum-forks/src/hardfork/dev.rs index 6ba54a4217..11e4f764e7 100644 --- a/crates/ethereum-forks/src/hardfork/dev.rs +++ b/crates/ethereum-forks/src/hardfork/dev.rs @@ -1,10 +1,8 @@ use crate::{ChainHardforks, EthereumHardfork, ForkCondition}; +use alloc::vec; use alloy_primitives::U256; use once_cell::sync::Lazy; -#[cfg(not(feature = "std"))] -use alloc::vec; - /// Dev hardforks pub static DEV_HARDFORKS: Lazy = Lazy::new(|| { ChainHardforks::new(vec![ diff --git a/crates/ethereum-forks/src/hardfork/ethereum.rs b/crates/ethereum-forks/src/hardfork/ethereum.rs index 650e88ad0d..3d85b54a96 100644 --- a/crates/ethereum-forks/src/hardfork/ethereum.rs +++ b/crates/ethereum-forks/src/hardfork/ethereum.rs @@ -1,4 +1,5 @@ use crate::{hardfork, ChainHardforks, ForkCondition, Hardfork}; +use alloc::{boxed::Box, format, string::String}; use alloy_chains::Chain; use alloy_primitives::{uint, U256}; use core::{ @@ -9,9 +10,6 @@ use core::{ #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, format, string::String}; - hardfork!( /// The name of an Ethereum hardfork. EthereumHardfork { diff --git a/crates/ethereum-forks/src/hardfork/optimism.rs b/crates/ethereum-forks/src/hardfork/optimism.rs index 2d763d2d9b..eccbc784da 100644 --- a/crates/ethereum-forks/src/hardfork/optimism.rs +++ b/crates/ethereum-forks/src/hardfork/optimism.rs @@ -1,4 +1,3 @@ -#[cfg(not(feature = "std"))] use alloc::{boxed::Box, format, string::String, vec}; use core::{ any::Any, diff --git a/crates/ethereum-forks/src/lib.rs b/crates/ethereum-forks/src/lib.rs index 51e619f4db..63b0fd535b 100644 --- a/crates/ethereum-forks/src/lib.rs +++ b/crates/ethereum-forks/src/lib.rs @@ -15,7 +15,6 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(not(feature = "std"))] extern crate alloc; mod display; diff --git a/crates/ethereum/evm/src/eip6110.rs b/crates/ethereum/evm/src/eip6110.rs index 722c38da76..605427276a 100644 --- a/crates/ethereum/evm/src/eip6110.rs +++ b/crates/ethereum/evm/src/eip6110.rs @@ -1,4 +1,5 @@ //! EIP-6110 deposit requests parsing +use alloc::{string::ToString, vec::Vec}; use alloy_eips::eip6110::{DepositRequest, MAINNET_DEPOSIT_CONTRACT_ADDRESS}; use alloy_sol_types::{sol, SolEvent}; use reth_chainspec::ChainSpec; @@ -6,9 +7,6 @@ use reth_evm::execute::BlockValidationError; use reth_primitives::{Receipt, Request}; use revm_primitives::Log; -#[cfg(not(feature = "std"))] -use alloc::{string::ToString, vec::Vec}; - sol! { #[allow(missing_docs)] event DepositEvent( diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index cdac05ac4c..483cce9f07 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -4,6 +4,7 @@ use crate::{ dao_fork::{DAO_HARDFORK_BENEFICIARY, DAO_HARDKFORK_ACCOUNTS}, EthEvmConfig, }; +use alloc::{boxed::Box, sync::Arc, vec, vec::Vec}; use core::fmt::Display; use reth_chainspec::{ChainSpec, EthereumHardforks, MAINNET}; use reth_ethereum_consensus::validate_block_post_execution; @@ -32,11 +33,6 @@ use revm_primitives::{ BlockEnv, CfgEnvWithHandlerCfg, EVMError, EnvWithHandlerCfg, ResultAndState, }; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, sync::Arc, vec, vec::Vec}; -#[cfg(feature = "std")] -use std::sync::Arc; - /// Provides executors to execute regular ethereum blocks #[derive(Debug, Clone)] pub struct EthExecutorProvider { diff --git a/crates/ethereum/evm/src/lib.rs b/crates/ethereum/evm/src/lib.rs index 58db911ebe..b854b78ac0 100644 --- a/crates/ethereum/evm/src/lib.rs +++ b/crates/ethereum/evm/src/lib.rs @@ -9,18 +9,14 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(not(feature = "std"))] extern crate alloc; -use std::sync::Arc; - +use alloc::vec::Vec; use reth_chainspec::{ChainSpec, Head}; use reth_evm::{ConfigureEvm, ConfigureEvmEnv}; use reth_primitives::{transaction::FillTxEnv, Address, Header, TransactionSigned, U256}; use revm_primitives::{AnalysisKind, Bytes, CfgEnvWithHandlerCfg, Env, TxEnv, TxKind}; - -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; +use std::sync::Arc; mod config; pub use config::{revm_spec, revm_spec_by_timestamp_after_merge}; diff --git a/crates/evm/execution-errors/src/lib.rs b/crates/evm/execution-errors/src/lib.rs index 1c3c8fa4d0..674b5168e9 100644 --- a/crates/evm/execution-errors/src/lib.rs +++ b/crates/evm/execution-errors/src/lib.rs @@ -9,11 +9,9 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(not(feature = "std"))] extern crate alloc; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, string::String}; +use alloc::{boxed::Box, string::String}; use alloy_eips::BlockNumHash; use alloy_primitives::B256; use derive_more::Display; diff --git a/crates/evm/execution-errors/src/trie.rs b/crates/evm/execution-errors/src/trie.rs index b95af1ef6d..5396540b25 100644 --- a/crates/evm/execution-errors/src/trie.rs +++ b/crates/evm/execution-errors/src/trie.rs @@ -1,13 +1,11 @@ //! Errors when computing the state root. +use alloc::string::ToString; use alloy_primitives::B256; use derive_more::Display; use nybbles::Nibbles; use reth_storage_errors::{db::DatabaseError, provider::ProviderError}; -#[cfg(not(feature = "std"))] -use alloc::string::ToString; - /// State root errors. #[derive(Display, Debug, PartialEq, Eq, Clone)] pub enum StateRootError { diff --git a/crates/evm/execution-types/src/chain.rs b/crates/evm/execution-types/src/chain.rs index 1c24f09084..ca88fa87a1 100644 --- a/crates/evm/execution-types/src/chain.rs +++ b/crates/evm/execution-types/src/chain.rs @@ -1,12 +1,8 @@ //! Contains [Chain], a chain of blocks and their final state. -#[cfg(not(feature = "std"))] +use crate::ExecutionOutcome; use alloc::{borrow::Cow, collections::BTreeMap}; use core::{fmt, ops::RangeInclusive}; -#[cfg(feature = "std")] -use std::{borrow::Cow, collections::BTreeMap}; - -use crate::ExecutionOutcome; use reth_execution_errors::{BlockExecutionError, InternalBlockExecutionError}; use reth_primitives::{ Address, BlockHash, BlockNumHash, BlockNumber, ForkBlock, Receipt, SealedBlock, diff --git a/crates/evm/execution-types/src/lib.rs b/crates/evm/execution-types/src/lib.rs index 86abd98de1..8965f04d7c 100644 --- a/crates/evm/execution-types/src/lib.rs +++ b/crates/evm/execution-types/src/lib.rs @@ -8,7 +8,6 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -#[cfg(not(feature = "std"))] extern crate alloc; mod chain; diff --git a/crates/evm/src/builder.rs b/crates/evm/src/builder.rs index e238ba8cca..4b7511494a 100644 --- a/crates/evm/src/builder.rs +++ b/crates/evm/src/builder.rs @@ -1,8 +1,6 @@ //! Builder for creating an EVM with a database and environment. -#[cfg(not(feature = "std"))] use alloc::boxed::Box; - use revm::{inspector_handle_register, Database, Evm, EvmBuilder, GetInspector}; use revm_primitives::EnvWithHandlerCfg; diff --git a/crates/evm/src/lib.rs b/crates/evm/src/lib.rs index 83e3606d8a..2c8e26cd7c 100644 --- a/crates/evm/src/lib.rs +++ b/crates/evm/src/lib.rs @@ -9,7 +9,6 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(not(feature = "std"))] extern crate alloc; use core::ops::Deref; diff --git a/crates/evm/src/system_calls.rs b/crates/evm/src/system_calls.rs index 530ed3cfaf..88cb2f9016 100644 --- a/crates/evm/src/system_calls.rs +++ b/crates/evm/src/system_calls.rs @@ -1,12 +1,7 @@ //! System contract call functions. -#[cfg(feature = "std")] -use std::fmt::Display; -#[cfg(not(feature = "std"))] -use { - alloc::{boxed::Box, format, string::ToString, vec::Vec}, - core::fmt::Display, -}; +use alloc::{boxed::Box, format, string::ToString, vec::Vec}; +use core::fmt::Display; use crate::ConfigureEvm; use alloy_eips::{ diff --git a/crates/optimism/chainspec/src/base.rs b/crates/optimism/chainspec/src/base.rs index d14a6b3d69..436fdaabed 100644 --- a/crates/optimism/chainspec/src/base.rs +++ b/crates/optimism/chainspec/src/base.rs @@ -1,9 +1,6 @@ //! Chain specification for the Base Mainnet network. -#[cfg(not(feature = "std"))] use alloc::sync::Arc; -#[cfg(feature = "std")] -use std::sync::Arc; use alloy_chains::Chain; use alloy_primitives::{b256, U256}; diff --git a/crates/optimism/chainspec/src/base_sepolia.rs b/crates/optimism/chainspec/src/base_sepolia.rs index 916e47cf90..0a52c52fcc 100644 --- a/crates/optimism/chainspec/src/base_sepolia.rs +++ b/crates/optimism/chainspec/src/base_sepolia.rs @@ -1,9 +1,6 @@ //! Chain specification for the Base Sepolia testnet network. -#[cfg(not(feature = "std"))] use alloc::sync::Arc; -#[cfg(feature = "std")] -use std::sync::Arc; use alloy_chains::Chain; use alloy_primitives::{b256, U256}; diff --git a/crates/optimism/chainspec/src/dev.rs b/crates/optimism/chainspec/src/dev.rs index 3351ee03bb..b1d42a94c7 100644 --- a/crates/optimism/chainspec/src/dev.rs +++ b/crates/optimism/chainspec/src/dev.rs @@ -1,9 +1,6 @@ //! Chain specification in dev mode for custom chain. -#[cfg(not(feature = "std"))] use alloc::sync::Arc; -#[cfg(feature = "std")] -use std::sync::Arc; use alloy_chains::Chain; use alloy_primitives::U256; diff --git a/crates/optimism/chainspec/src/lib.rs b/crates/optimism/chainspec/src/lib.rs index 952fee7625..17dadd7cc3 100644 --- a/crates/optimism/chainspec/src/lib.rs +++ b/crates/optimism/chainspec/src/lib.rs @@ -7,7 +7,6 @@ )] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -#[cfg(not(feature = "std"))] extern crate alloc; pub mod constants; diff --git a/crates/optimism/chainspec/src/op.rs b/crates/optimism/chainspec/src/op.rs index 15a952ae65..14a0b9770e 100644 --- a/crates/optimism/chainspec/src/op.rs +++ b/crates/optimism/chainspec/src/op.rs @@ -1,9 +1,6 @@ //! Chain specification for the Optimism Mainnet network. -#[cfg(not(feature = "std"))] use alloc::sync::Arc; -#[cfg(feature = "std")] -use std::sync::Arc; use alloy_chains::Chain; use alloy_primitives::{b256, U256}; diff --git a/crates/optimism/chainspec/src/op_sepolia.rs b/crates/optimism/chainspec/src/op_sepolia.rs index 9f223f7e0d..8c05863608 100644 --- a/crates/optimism/chainspec/src/op_sepolia.rs +++ b/crates/optimism/chainspec/src/op_sepolia.rs @@ -1,9 +1,6 @@ //! Chain specification for the Optimism Sepolia testnet network. -#[cfg(not(feature = "std"))] use alloc::sync::Arc; -#[cfg(feature = "std")] -use std::sync::Arc; use alloy_chains::{Chain, NamedChain}; use alloy_primitives::{b256, U256}; diff --git a/crates/primitives-traits/src/constants/gas_units.rs b/crates/primitives-traits/src/constants/gas_units.rs index ed287e6d29..312ae51cbc 100644 --- a/crates/primitives-traits/src/constants/gas_units.rs +++ b/crates/primitives-traits/src/constants/gas_units.rs @@ -1,7 +1,5 @@ -use core::time::Duration; - -#[cfg(not(feature = "std"))] use alloc::string::String; +use core::time::Duration; /// Represents one Kilogas, or `1_000` gas. pub const KILOGAS: u64 = 1_000; diff --git a/crates/primitives-traits/src/error.rs b/crates/primitives-traits/src/error.rs index 144c210ba9..ef088a920e 100644 --- a/crates/primitives-traits/src/error.rs +++ b/crates/primitives-traits/src/error.rs @@ -1,13 +1,9 @@ +use alloc::boxed::Box; use core::{ fmt, ops::{Deref, DerefMut}, }; -#[cfg(not(feature = "std"))] -use alloc::boxed::Box; -#[cfg(not(feature = "std"))] -extern crate alloc; - /// 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 { diff --git a/crates/primitives-traits/src/integer_list.rs b/crates/primitives-traits/src/integer_list.rs index df68d612aa..e5c87d7a1c 100644 --- a/crates/primitives-traits/src/integer_list.rs +++ b/crates/primitives-traits/src/integer_list.rs @@ -1,3 +1,4 @@ +use alloc::vec::Vec; use bytes::BufMut; use core::fmt; use derive_more::Deref; @@ -8,9 +9,6 @@ use serde::{ Deserialize, Deserializer, Serialize, Serializer, }; -#[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. #[derive(Clone, PartialEq, Default, Deref)] diff --git a/crates/primitives-traits/src/lib.rs b/crates/primitives-traits/src/lib.rs index c8c1cbd8dd..46df75d455 100644 --- a/crates/primitives-traits/src/lib.rs +++ b/crates/primitives-traits/src/lib.rs @@ -9,7 +9,6 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(not(feature = "std"))] #[macro_use] extern crate alloc; diff --git a/crates/primitives-traits/src/request.rs b/crates/primitives-traits/src/request.rs index 53e174d147..c08af3fd62 100644 --- a/crates/primitives-traits/src/request.rs +++ b/crates/primitives-traits/src/request.rs @@ -1,5 +1,6 @@ //! EIP-7685 requests. +use alloc::vec::Vec; pub use alloy_consensus::Request; use alloy_eips::eip7685::{Decodable7685, Encodable7685}; use alloy_rlp::{Decodable, Encodable}; @@ -8,9 +9,6 @@ use reth_codecs::{add_arbitrary_tests, Compact}; use revm_primitives::Bytes; use serde::{Deserialize, Serialize}; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// A list of EIP-7685 requests. #[derive( Debug, diff --git a/crates/primitives-traits/src/withdrawal.rs b/crates/primitives-traits/src/withdrawal.rs index 52e0495fc2..995e60292c 100644 --- a/crates/primitives-traits/src/withdrawal.rs +++ b/crates/primitives-traits/src/withdrawal.rs @@ -1,12 +1,10 @@ //! [EIP-4895](https://eips.ethereum.org/EIPS/eip-4895) Withdrawal types. +use alloc::vec::Vec; use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper}; use derive_more::{AsRef, Deref, DerefMut, From, IntoIterator}; use reth_codecs::{add_arbitrary_tests, Compact}; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// Re-export from `alloy_eips`. #[doc(inline)] pub use alloy_eips::eip4895::Withdrawal; diff --git a/crates/primitives/src/alloy_compat.rs b/crates/primitives/src/alloy_compat.rs index f8a05a0f6f..37bda55359 100644 --- a/crates/primitives/src/alloy_compat.rs +++ b/crates/primitives/src/alloy_compat.rs @@ -5,14 +5,12 @@ use crate::{ TransactionSigned, TransactionSignedEcRecovered, TransactionSignedNoHash, TxEip1559, TxEip2930, TxEip4844, TxLegacy, TxType, }; +use alloc::{string::ToString, vec::Vec}; use alloy_primitives::TxKind; use alloy_rlp::Error as RlpError; use alloy_serde::WithOtherFields; use op_alloy_rpc_types as _; -#[cfg(not(feature = "std"))] -use alloc::{string::ToString, 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 166a43b82f..d6ed39540c 100644 --- a/crates/primitives/src/block.rs +++ b/crates/primitives/src/block.rs @@ -2,6 +2,7 @@ use crate::{ Address, Bytes, GotExpected, Header, SealedHeader, TransactionSigned, TransactionSignedEcRecovered, Withdrawals, B256, }; +use alloc::vec::Vec; pub use alloy_eips::eip1898::{ BlockHashOrNumber, BlockId, BlockNumHash, BlockNumberOrTag, ForkBlock, RpcBlockHash, }; @@ -14,9 +15,6 @@ pub use reth_primitives_traits::test_utils::{generate_valid_header, valid_header use reth_primitives_traits::Requests; 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 diff --git a/crates/primitives/src/compression/mod.rs b/crates/primitives/src/compression/mod.rs index f7af0acbe4..476f5d06b2 100644 --- a/crates/primitives/src/compression/mod.rs +++ b/crates/primitives/src/compression/mod.rs @@ -1,8 +1,7 @@ -use std::{cell::RefCell, thread_local}; -use zstd::bulk::{Compressor, Decompressor}; - -#[cfg(not(feature = "std"))] use alloc::vec::Vec; +use core::cell::RefCell; +use std::thread_local; +use zstd::bulk::{Compressor, Decompressor}; /// Compression/Decompression dictionary for `Receipt`. pub static RECEIPT_DICTIONARY: &[u8] = include_bytes!("./receipt_dictionary.bin"); diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 0c4f25057f..1d95ad8b33 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -19,7 +19,6 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(not(feature = "std"))] extern crate alloc; #[cfg(feature = "alloy-compat")] diff --git a/crates/primitives/src/proofs.rs b/crates/primitives/src/proofs.rs index f8ed334cea..c7f34c2f2d 100644 --- a/crates/primitives/src/proofs.rs +++ b/crates/primitives/src/proofs.rs @@ -4,12 +4,10 @@ use crate::{ constants::EMPTY_OMMER_ROOT_HASH, keccak256, Header, Receipt, ReceiptWithBloom, ReceiptWithBloomRef, Request, TransactionSigned, Withdrawal, B256, }; +use alloc::vec::Vec; use alloy_eips::eip7685::Encodable7685; use reth_trie_common::root::{ordered_trie_root, ordered_trie_root_with_encoder}; -#[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 5bce92c3c0..6883b4f3b1 100644 --- a/crates/primitives/src/receipt.rs +++ b/crates/primitives/src/receipt.rs @@ -4,6 +4,7 @@ use crate::{ logs_bloom, Bloom, Bytes, TxType, B256, EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, EIP7702_TX_TYPE_ID, }; +use alloc::{vec, vec::Vec}; use alloy_primitives::Log; use alloy_rlp::{length_of_length, Decodable, Encodable, RlpDecodable, RlpEncodable}; use bytes::{Buf, BufMut}; @@ -13,9 +14,6 @@ use derive_more::{DerefMut, From, IntoIterator}; use reth_codecs::{Compact, CompactZstd}; use serde::{Deserialize, Serialize}; -#[cfg(not(feature = "std"))] -use alloc::{vec, vec::Vec}; - /// Receipt containing result of transaction execution. #[derive( Clone, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable, Serialize, Deserialize, diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index 012e64954e..68b2792413 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -58,7 +58,6 @@ pub use tx_type::DEPOSIT_TX_TYPE_ID; #[cfg(test)] use reth_codecs::Compact; -#[cfg(not(feature = "std"))] use alloc::vec::Vec; /// Either a transaction hash or number. diff --git a/crates/primitives/src/transaction/pooled.rs b/crates/primitives/src/transaction/pooled.rs index 1ef05577a8..a883e739a1 100644 --- a/crates/primitives/src/transaction/pooled.rs +++ b/crates/primitives/src/transaction/pooled.rs @@ -7,15 +7,13 @@ use crate::{ TransactionSigned, TransactionSignedEcRecovered, TxEip1559, TxEip2930, TxEip4844, TxHash, TxLegacy, B256, EIP4844_TX_TYPE_ID, }; +use alloc::vec::Vec; use alloy_consensus::{SignableTransaction, TxEip4844WithSidecar}; use alloy_rlp::{Decodable, Encodable, Error as RlpError, Header, EMPTY_LIST_CODE}; use bytes::Buf; use derive_more::{AsRef, Deref}; 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. #[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests)] diff --git a/crates/primitives/src/transaction/sidecar.rs b/crates/primitives/src/transaction/sidecar.rs index b9583a349d..340d7662d8 100644 --- a/crates/primitives/src/transaction/sidecar.rs +++ b/crates/primitives/src/transaction/sidecar.rs @@ -13,7 +13,6 @@ 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 diff --git a/crates/revm/src/batch.rs b/crates/revm/src/batch.rs index ad71f38b44..4502732a42 100644 --- a/crates/revm/src/batch.rs +++ b/crates/revm/src/batch.rs @@ -4,14 +4,12 @@ use crate::{ precompile::{Address, HashSet}, primitives::alloy_primitives::BlockNumber, }; +use alloc::vec::Vec; use reth_execution_errors::{BlockExecutionError, InternalBlockExecutionError}; use reth_primitives::{Receipt, Receipts, Request, Requests}; use reth_prune_types::{PruneMode, PruneModes, PruneSegmentError, MINIMUM_PRUNING_DISTANCE}; use revm::db::states::bundle_state::BundleRetention; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// Takes care of: /// - recording receipts during execution of multiple blocks. /// - pruning receipts according to the pruning configuration. @@ -183,14 +181,9 @@ impl BlockBatchRecord { #[cfg(test)] mod tests { use super::*; + use alloc::collections::BTreeMap; use reth_primitives::{Address, Log, Receipt}; use reth_prune_types::{PruneMode, ReceiptsLogPruneConfig}; - #[cfg(feature = "std")] - use std::collections::BTreeMap; - #[cfg(not(feature = "std"))] - extern crate alloc; - #[cfg(not(feature = "std"))] - use alloc::collections::BTreeMap; #[test] fn test_save_receipts_empty() { diff --git a/crates/revm/src/lib.rs b/crates/revm/src/lib.rs index 4fb6c30d1c..5515357d0d 100644 --- a/crates/revm/src/lib.rs +++ b/crates/revm/src/lib.rs @@ -9,7 +9,6 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(not(feature = "std"))] extern crate alloc; /// Contains glue code for integrating reth database into revm's [Database]. diff --git a/crates/revm/src/test_utils.rs b/crates/revm/src/test_utils.rs index 92f09e461d..f54f10a381 100644 --- a/crates/revm/src/test_utils.rs +++ b/crates/revm/src/test_utils.rs @@ -1,4 +1,5 @@ use crate::precompile::HashMap; +use alloc::vec::Vec; use reth_primitives::{ keccak256, Account, Address, BlockNumber, Bytecode, Bytes, StorageKey, B256, U256, }; @@ -12,9 +13,6 @@ use reth_trie::{ HashedStorage, }; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// Mock state for testing #[derive(Debug, Default, Clone, Eq, PartialEq)] pub struct StateProviderTest { diff --git a/crates/storage/codecs/src/alloy/access_list.rs b/crates/storage/codecs/src/alloy/access_list.rs index 306ef4f494..306b64d7e4 100644 --- a/crates/storage/codecs/src/alloy/access_list.rs +++ b/crates/storage/codecs/src/alloy/access_list.rs @@ -1,10 +1,8 @@ use crate::Compact; +use alloc::vec::Vec; use alloy_eips::eip2930::{AccessList, AccessListItem}; use alloy_primitives::Address; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// Implement `Compact` for `AccessListItem` and `AccessList`. impl Compact for AccessListItem { fn to_compact(&self, buf: &mut B) -> usize diff --git a/crates/storage/codecs/src/alloy/genesis_account.rs b/crates/storage/codecs/src/alloy/genesis_account.rs index 463c94fa3a..84c8ee77a3 100644 --- a/crates/storage/codecs/src/alloy/genesis_account.rs +++ b/crates/storage/codecs/src/alloy/genesis_account.rs @@ -1,12 +1,10 @@ use crate::Compact; +use alloc::vec::Vec; use alloy_genesis::GenesisAccount as AlloyGenesisAccount; use alloy_primitives::{Bytes, B256, U256}; use reth_codecs_derive::add_arbitrary_tests; use serde::{Deserialize, Serialize}; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// `GenesisAccount` acts as bridge which simplifies Compact implementation for /// `AlloyGenesisAccount`. /// diff --git a/crates/storage/codecs/src/alloy/log.rs b/crates/storage/codecs/src/alloy/log.rs index 2a3aa07b70..7f0a0e3625 100644 --- a/crates/storage/codecs/src/alloy/log.rs +++ b/crates/storage/codecs/src/alloy/log.rs @@ -1,12 +1,10 @@ //! Native Compact codec impl for primitive alloy log types. use crate::Compact; +use alloc::vec::Vec; use alloy_primitives::{Address, Bytes, Log, LogData}; use bytes::BufMut; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// Implement `Compact` for `LogData` and `Log`. impl Compact for LogData { fn to_compact(&self, buf: &mut B) -> usize diff --git a/crates/storage/codecs/src/alloy/transaction/eip4844.rs b/crates/storage/codecs/src/alloy/transaction/eip4844.rs index 7ac815820d..15a5f443c4 100644 --- a/crates/storage/codecs/src/alloy/transaction/eip4844.rs +++ b/crates/storage/codecs/src/alloy/transaction/eip4844.rs @@ -1,13 +1,11 @@ use crate::{Compact, CompactPlaceholder}; +use alloc::vec::Vec; use alloy_consensus::transaction::TxEip4844 as AlloyTxEip4844; use alloy_eips::eip2930::AccessList; use alloy_primitives::{Address, Bytes, ChainId, B256, U256}; use reth_codecs_derive::add_arbitrary_tests; use serde::{Deserialize, Serialize}; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// [EIP-4844 Blob Transaction](https://eips.ethereum.org/EIPS/eip-4844#blob-transaction) /// /// This is a helper type to use derive on it instead of manually managing `bitfield`. diff --git a/crates/storage/codecs/src/alloy/transaction/eip7702.rs b/crates/storage/codecs/src/alloy/transaction/eip7702.rs index ecb7d66a00..a44e97ee1d 100644 --- a/crates/storage/codecs/src/alloy/transaction/eip7702.rs +++ b/crates/storage/codecs/src/alloy/transaction/eip7702.rs @@ -1,13 +1,11 @@ use crate::Compact; +use alloc::vec::Vec; use alloy_consensus::transaction::TxEip7702 as AlloyTxEip7702; use alloy_eips::{eip2930::AccessList, eip7702::SignedAuthorization}; use alloy_primitives::{Address, Bytes, ChainId, U256}; use reth_codecs_derive::add_arbitrary_tests; use serde::{Deserialize, Serialize}; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// [EIP-7702 Set Code Transaction](https://eips.ethereum.org/EIPS/eip-7702) /// /// This is a helper type to use derive on it instead of manually managing `bitfield`. diff --git a/crates/storage/codecs/src/alloy/trie.rs b/crates/storage/codecs/src/alloy/trie.rs index 73e82af63a..c89ef0bf6e 100644 --- a/crates/storage/codecs/src/alloy/trie.rs +++ b/crates/storage/codecs/src/alloy/trie.rs @@ -1,13 +1,11 @@ //! Native Compact codec impl for EIP-7685 requests. use crate::Compact; +use alloc::vec::Vec; use alloy_primitives::B256; use alloy_trie::{hash_builder::HashBuilderValue, BranchNodeCompact, TrieMask}; use bytes::{Buf, BufMut}; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; - /// Identifier for [`HashBuilderValue::Hash`] const HASH_BUILDER_TYPE_HASH: u8 = 0; diff --git a/crates/storage/codecs/src/lib.rs b/crates/storage/codecs/src/lib.rs index 4419dbee2a..b668c759ef 100644 --- a/crates/storage/codecs/src/lib.rs +++ b/crates/storage/codecs/src/lib.rs @@ -22,9 +22,7 @@ pub use reth_codecs_derive::*; use alloy_primitives::{Address, Bloom, Bytes, FixedBytes, U256}; use bytes::{Buf, BufMut}; -#[cfg(not(feature = "std"))] extern crate alloc; -#[cfg(not(feature = "std"))] use alloc::vec::Vec; #[cfg(any(test, feature = "alloy"))] diff --git a/crates/storage/errors/src/db.rs b/crates/storage/errors/src/db.rs index 079a7d56fd..e2c275d5ab 100644 --- a/crates/storage/errors/src/db.rs +++ b/crates/storage/errors/src/db.rs @@ -1,14 +1,9 @@ -#[cfg(feature = "std")] -use std::{fmt, fmt::Display, str::FromStr, string::String}; - -#[cfg(not(feature = "std"))] use alloc::{ boxed::Box, format, string::{String, ToString}, vec::Vec, }; -#[cfg(not(feature = "std"))] use core::{ fmt, fmt::{Debug, Display}, diff --git a/crates/storage/errors/src/lib.rs b/crates/storage/errors/src/lib.rs index cf1a1a9762..6abb0cd9b4 100644 --- a/crates/storage/errors/src/lib.rs +++ b/crates/storage/errors/src/lib.rs @@ -9,7 +9,6 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(not(feature = "std"))] extern crate alloc; /// Database error diff --git a/crates/storage/errors/src/lockfile.rs b/crates/storage/errors/src/lockfile.rs index 17687cb69c..667197f571 100644 --- a/crates/storage/errors/src/lockfile.rs +++ b/crates/storage/errors/src/lockfile.rs @@ -1,7 +1,5 @@ -use reth_fs_util::FsPathError; - -#[cfg(not(feature = "std"))] use alloc::string::{String, ToString}; +use reth_fs_util::FsPathError; /// Storage lock error. #[derive(Debug, Clone, PartialEq, Eq, derive_more::Display)] diff --git a/crates/storage/errors/src/provider.rs b/crates/storage/errors/src/provider.rs index 2f20f1ab8a..e478ca2ebe 100644 --- a/crates/storage/errors/src/provider.rs +++ b/crates/storage/errors/src/provider.rs @@ -6,7 +6,6 @@ use reth_primitives::{BlockHashOrNumber, GotExpected, StaticFileSegment, TxHashO #[cfg(feature = "std")] use std::path::PathBuf; -#[cfg(not(feature = "std"))] use alloc::{boxed::Box, string::String}; /// Provider result type.