Skip to content
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ serde_with = "3.3.0"
humantime = "2.1"
humantime-serde = "1.1"
rand = "0.8.5"
rustc-hash = "2.0"
rustc-hash = { version = "2.0", default-features = false }
schnellru = "0.2"
strum = "0.26"
rayon = "1.7"
Expand Down
7 changes: 4 additions & 3 deletions crates/ethereum-forks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ serde = { workspace = true, features = ["derive"], optional = true }
thiserror-no-std = { workspace = true, default-features = false }
once_cell.workspace = true
dyn-clone.workspace = true
rustc-hash.workspace = true
rustc-hash = { workspace = true, optional = true }

# arbitrary utils
arbitrary = { workspace = true, features = ["derive"], optional = true }
Expand All @@ -39,8 +39,9 @@ proptest.workspace = true
proptest-derive.workspace = true

[features]
default = ["std", "serde"]
default = ["std", "serde", "rustc-hash"]
arbitrary = ["dep:arbitrary", "dep:proptest", "dep:proptest-derive"]
optimism = []
serde = ["dep:serde"]
std = ["thiserror-no-std/std"]
std = ["thiserror-no-std/std", "rustc-hash/std"]
rustc-hash = ["dep:rustc-hash"]
1 change: 0 additions & 1 deletion crates/ethereum-forks/src/display.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#[cfg(not(feature = "std"))]
use alloc::{
collections::BTreeMap,
format,
string::{String, ToString},
vec::Vec,
Expand Down
3 changes: 3 additions & 0 deletions crates/ethereum-forks/src/hardfork/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use crate::{ChainHardforks, EthereumHardfork, ForkCondition};
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
3 changes: 3 additions & 0 deletions crates/ethereum-forks/src/hardfork/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ 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
3 changes: 0 additions & 3 deletions crates/ethereum-forks/src/hardfork/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ use core::{
};
use dyn_clone::DynClone;

#[cfg(not(feature = "std"))]
use alloc::{format, string::String};

/// Generic hardfork trait.
#[auto_impl::auto_impl(&, Box)]
pub trait Hardfork: Any + DynClone + Send + Sync + 'static {
Expand Down
3 changes: 3 additions & 0 deletions crates/ethereum-forks/src/hardfork/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use core::{
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

#[cfg(not(feature = "std"))]
use alloc::{boxed::Box, format, string::String, vec};

hardfork!(
/// The name of an optimism hardfork.
///
Expand Down
13 changes: 11 additions & 2 deletions crates/ethereum-forks/src/hardforks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ mod optimism;
pub use optimism::OptimismHardforks;

use crate::{ForkCondition, Hardfork};
#[cfg(feature = "std")]
use rustc_hash::FxHashMap;
#[cfg(feature = "std")]
use std::collections::hash_map::Entry;

#[cfg(not(feature = "std"))]
use alloc::{boxed::Box, collections::btree_map::Entry, vec::Vec};

/// Generic trait over a set of ordered hardforks
pub trait Hardforks: Default + Clone {
Expand All @@ -33,7 +39,10 @@ pub trait Hardforks: Default + Clone {
#[derive(Default, Clone, PartialEq, Eq)]
pub struct ChainHardforks {
forks: Vec<(Box<dyn Hardfork>, ForkCondition)>,
#[cfg(feature = "std")]
map: FxHashMap<&'static str, ForkCondition>,
#[cfg(not(feature = "std"))]
map: alloc::collections::BTreeMap<&'static str, ForkCondition>,
}

impl ChainHardforks {
Expand Down Expand Up @@ -100,15 +109,15 @@ impl ChainHardforks {
/// Inserts `fork` into list, updating with a new [`ForkCondition`] if it already exists.
pub fn insert<H: Hardfork>(&mut self, fork: H, condition: ForkCondition) {
match self.map.entry(fork.name()) {
std::collections::hash_map::Entry::Occupied(mut entry) => {
Entry::Occupied(mut entry) => {
*entry.get_mut() = condition;
if let Some((_, inner)) =
self.forks.iter_mut().find(|(inner, _)| inner.name() == fork.name())
{
*inner = condition;
}
}
std::collections::hash_map::Entry::Vacant(entry) => {
Entry::Vacant(entry) => {
entry.insert(condition);
self.forks.push((Box::new(fork), condition));
}
Expand Down