Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cfg: replace std feature gate alloc imports with extern crate alloc #10861

Merged
merged 6 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion crates/chainspec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
11 changes: 3 additions & 8 deletions crates/consensus/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions crates/ethereum-forks/src/display.rs
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
3 changes: 0 additions & 3 deletions crates/ethereum-forks/src/forkid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<u32> = Crc::<u32>::new(&CRC_32_ISO_HDLC);
const TIMESTAMP_BEFORE_ETHEREUM_MAINNET: u64 = 1_300_000_000;
Expand Down
4 changes: 1 addition & 3 deletions crates/ethereum-forks/src/hardfork/dev.rs
Original file line number Diff line number Diff line change
@@ -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<ChainHardforks> = Lazy::new(|| {
ChainHardforks::new(vec![
Expand Down
4 changes: 1 addition & 3 deletions crates/ethereum-forks/src/hardfork/ethereum.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion crates/ethereum-forks/src/hardfork/optimism.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(not(feature = "std"))]
use alloc::{boxed::Box, format, string::String, vec};
use core::{
any::Any,
Expand Down
1 change: 0 additions & 1 deletion crates/ethereum-forks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions crates/ethereum/evm/src/eip6110.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
//! 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;
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(
Expand Down
6 changes: 1 addition & 5 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<EvmConfig = EthEvmConfig> {
Expand Down
8 changes: 2 additions & 6 deletions crates/ethereum/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
4 changes: 1 addition & 3 deletions crates/evm/execution-errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions crates/evm/execution-errors/src/trie.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
6 changes: 1 addition & 5 deletions crates/evm/execution-types/src/chain.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
1 change: 0 additions & 1 deletion crates/evm/execution-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions crates/evm/src/builder.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
1 change: 0 additions & 1 deletion crates/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 2 additions & 7 deletions crates/evm/src/system_calls.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down
3 changes: 0 additions & 3 deletions crates/optimism/chainspec/src/base.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
3 changes: 0 additions & 3 deletions crates/optimism/chainspec/src/base_sepolia.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
3 changes: 0 additions & 3 deletions crates/optimism/chainspec/src/dev.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 0 additions & 1 deletion crates/optimism/chainspec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

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

pub mod constants;
Expand Down
3 changes: 0 additions & 3 deletions crates/optimism/chainspec/src/op.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
3 changes: 0 additions & 3 deletions crates/optimism/chainspec/src/op_sepolia.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
4 changes: 1 addition & 3 deletions crates/primitives-traits/src/constants/gas_units.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 1 addition & 5 deletions crates/primitives-traits/src/error.rs
Original file line number Diff line number Diff line change
@@ -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<T> {
Expand Down
4 changes: 1 addition & 3 deletions crates/primitives-traits/src/integer_list.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::vec::Vec;
use bytes::BufMut;
use core::fmt;
use derive_more::Deref;
Expand All @@ -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)]
Expand Down
1 change: 0 additions & 1 deletion crates/primitives-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions crates/primitives-traits/src/request.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions crates/primitives-traits/src/withdrawal.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading
Loading