mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
no_std in reth-ethereum-forks (#9589)
This commit is contained in:
@ -449,7 +449,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"
|
||||
|
||||
@ -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 }
|
||||
@ -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,6 +1,5 @@
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::{
|
||||
collections::BTreeMap,
|
||||
format,
|
||||
string::{String, ToString},
|
||||
vec::Vec,
|
||||
|
||||
@ -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![
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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.
|
||||
///
|
||||
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
@ -100,7 +109,7 @@ 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())
|
||||
@ -108,7 +117,7 @@ impl ChainHardforks {
|
||||
*inner = condition;
|
||||
}
|
||||
}
|
||||
std::collections::hash_map::Entry::Vacant(entry) => {
|
||||
Entry::Vacant(entry) => {
|
||||
entry.insert(condition);
|
||||
self.forks.push((Box::new(fork), condition));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user