chore: make trie-common no-std (#13473)

This commit is contained in:
Matthias Seitz
2024-12-20 12:16:09 +01:00
committed by GitHub
parent 30e8c78171
commit 3966130844
13 changed files with 46 additions and 10 deletions

View File

@ -419,7 +419,7 @@ reth-tokio-util = { path = "crates/tokio-util" }
reth-tracing = { path = "crates/tracing" } reth-tracing = { path = "crates/tracing" }
reth-transaction-pool = { path = "crates/transaction-pool" } reth-transaction-pool = { path = "crates/transaction-pool" }
reth-trie = { path = "crates/trie/trie" } reth-trie = { path = "crates/trie/trie" }
reth-trie-common = { path = "crates/trie/common" } reth-trie-common = { path = "crates/trie/common", default-features = false }
reth-trie-db = { path = "crates/trie/db" } reth-trie-db = { path = "crates/trie/db" }
reth-trie-parallel = { path = "crates/trie/parallel" } reth-trie-parallel = { path = "crates/trie/parallel" }
reth-trie-sparse = { path = "crates/trie/sparse" } reth-trie-sparse = { path = "crates/trie/sparse" }

View File

@ -51,7 +51,8 @@ std = [
"alloy-rlp/std", "alloy-rlp/std",
"reth-ethereum-forks/std", "reth-ethereum-forks/std",
"derive_more/std", "derive_more/std",
"reth-network-peers/std" "reth-network-peers/std",
"reth-trie-common/std"
] ]
arbitrary = [ arbitrary = [
"alloy-chains/arbitrary", "alloy-chains/arbitrary",

View File

@ -64,5 +64,6 @@ std = [
"serde?/std", "serde?/std",
"reth-primitives-traits/std", "reth-primitives-traits/std",
"alloy-consensus/std", "alloy-consensus/std",
"serde_with?/std" "serde_with?/std",
"reth-trie-common?/std"
] ]

View File

@ -114,7 +114,8 @@ std = [
"bytes/std", "bytes/std",
"derive_more/std", "derive_more/std",
"reth-zstd-compressors?/std", "reth-zstd-compressors?/std",
"secp256k1?/std" "secp256k1?/std",
"reth-trie-common/std"
] ]
reth-codec = [ reth-codec = [
"dep:reth-codecs", "dep:reth-codecs",

View File

@ -58,6 +58,22 @@ serde_json.workspace = true
serde_with.workspace = true serde_with.workspace = true
[features] [features]
default = ["std"]
std = [
"alloy-consensus/std",
"alloy-genesis/std",
"alloy-primitives/std",
"alloy-rlp/std",
"alloy-rpc-types-eth?/std",
"alloy-serde?/std",
"alloy-trie/std",
"bytes?/std",
"derive_more/std",
"nybbles/std",
"reth-primitives-traits/std",
"serde?/std",
"serde_with?/std"
]
eip1186 = [ eip1186 = [
"alloy-rpc-types-eth/serde", "alloy-rpc-types-eth/serde",
"dep:alloy-serde", "dep:alloy-serde",

View File

@ -1,4 +1,5 @@
use crate::TrieMask; use crate::TrieMask;
use alloc::vec::Vec;
use alloy_trie::{hash_builder::HashBuilderValue, nodes::RlpNode, HashBuilder}; use alloy_trie::{hash_builder::HashBuilderValue, nodes::RlpNode, HashBuilder};
use nybbles::Nibbles; use nybbles::Nibbles;

View File

@ -7,6 +7,9 @@
)] )]
#![cfg_attr(not(test), warn(unused_crate_dependencies))] #![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
/// The implementation of hash builder. /// The implementation of hash builder.
pub mod hash_builder; pub mod hash_builder;

View File

@ -1,3 +1,4 @@
use alloc::vec::Vec;
use derive_more::Deref; use derive_more::Deref;
pub use nybbles::Nibbles; pub use nybbles::Nibbles;
@ -30,7 +31,7 @@ impl PartialEq<[u8]> for StoredNibbles {
impl PartialOrd<[u8]> for StoredNibbles { impl PartialOrd<[u8]> for StoredNibbles {
#[inline] #[inline]
fn partial_cmp(&self, other: &[u8]) -> Option<std::cmp::Ordering> { fn partial_cmp(&self, other: &[u8]) -> Option<core::cmp::Ordering> {
self.0.as_slice().partial_cmp(other) self.0.as_slice().partial_cmp(other)
} }
} }

View File

@ -1,6 +1,6 @@
use crate::Nibbles; use crate::Nibbles;
use alloc::{sync::Arc, vec::Vec};
use alloy_primitives::map::{B256HashMap, B256HashSet}; use alloy_primitives::map::{B256HashMap, B256HashSet};
use std::sync::Arc;
/// Collection of mutable prefix sets. /// Collection of mutable prefix sets.
#[derive(Clone, Default, Debug)] #[derive(Clone, Default, Debug)]
@ -209,7 +209,7 @@ impl PrefixSet {
impl<'a> IntoIterator for &'a PrefixSet { impl<'a> IntoIterator for &'a PrefixSet {
type Item = &'a Nibbles; type Item = &'a Nibbles;
type IntoIter = std::slice::Iter<'a, Nibbles>; type IntoIter = core::slice::Iter<'a, Nibbles>;
fn into_iter(self) -> Self::IntoIter { fn into_iter(self) -> Self::IntoIter {
self.iter() self.iter()
} }

View File

@ -1,6 +1,7 @@
//! Merkle trie proofs. //! Merkle trie proofs.
use crate::{Nibbles, TrieAccount}; use crate::{Nibbles, TrieAccount};
use alloc::vec::Vec;
use alloy_consensus::constants::KECCAK_EMPTY; use alloy_consensus::constants::KECCAK_EMPTY;
use alloy_primitives::{ use alloy_primitives::{
keccak256, keccak256,

View File

@ -1,6 +1,7 @@
//! Common root computation functions. //! Common root computation functions.
use crate::TrieAccount; use crate::TrieAccount;
use alloc::vec::Vec;
use alloy_primitives::{keccak256, Address, B256, U256}; use alloy_primitives::{keccak256, Address, B256, U256};
use alloy_rlp::Encodable; use alloy_rlp::Encodable;
use alloy_trie::HashBuilder; use alloy_trie::HashBuilder;

View File

@ -1,4 +1,5 @@
use super::BranchNodeCompact; use super::BranchNodeCompact;
use alloc::vec::Vec;
/// Walker sub node for storing intermediate state root calculation state in the database. /// Walker sub node for storing intermediate state root calculation state in the database.
#[derive(Debug, Clone, PartialEq, Eq, Default)] #[derive(Debug, Clone, PartialEq, Eq, Default)]

View File

@ -1,4 +1,5 @@
use crate::{BranchNodeCompact, HashBuilder, Nibbles}; use crate::{BranchNodeCompact, HashBuilder, Nibbles};
use alloc::vec::Vec;
use alloy_primitives::{ use alloy_primitives::{
map::{B256HashMap, B256HashSet, HashMap, HashSet}, map::{B256HashMap, B256HashSet, HashMap, HashSet},
B256, B256,
@ -230,6 +231,10 @@ impl StorageTrieUpdates {
#[cfg(any(test, feature = "serde"))] #[cfg(any(test, feature = "serde"))]
mod serde_nibbles_set { mod serde_nibbles_set {
use crate::Nibbles; use crate::Nibbles;
use alloc::{
string::{String, ToString},
vec::Vec,
};
use alloy_primitives::map::HashSet; use alloy_primitives::map::HashSet;
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
@ -266,13 +271,17 @@ mod serde_nibbles_set {
#[cfg(any(test, feature = "serde"))] #[cfg(any(test, feature = "serde"))]
mod serde_nibbles_map { mod serde_nibbles_map {
use crate::Nibbles; use crate::Nibbles;
use alloc::{
string::{String, ToString},
vec::Vec,
};
use alloy_primitives::{hex, map::HashMap}; use alloy_primitives::{hex, map::HashMap};
use core::marker::PhantomData;
use serde::{ use serde::{
de::{Error, MapAccess, Visitor}, de::{Error, MapAccess, Visitor},
ser::SerializeMap, ser::SerializeMap,
Deserialize, Deserializer, Serialize, Serializer, Deserialize, Deserializer, Serialize, Serializer,
}; };
use std::marker::PhantomData;
pub(super) fn serialize<S, T>( pub(super) fn serialize<S, T>(
map: &HashMap<Nibbles, T>, map: &HashMap<Nibbles, T>,
@ -308,7 +317,7 @@ mod serde_nibbles_map {
{ {
type Value = HashMap<Nibbles, T>; type Value = HashMap<Nibbles, T>;
fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
formatter.write_str("a map with hex-encoded Nibbles keys") formatter.write_str("a map with hex-encoded Nibbles keys")
} }
@ -411,10 +420,10 @@ fn exclude_empty_from_pair<V>(
#[cfg(feature = "serde-bincode-compat")] #[cfg(feature = "serde-bincode-compat")]
pub mod serde_bincode_compat { pub mod serde_bincode_compat {
use crate::{BranchNodeCompact, Nibbles}; use crate::{BranchNodeCompact, Nibbles};
use alloc::borrow::Cow;
use alloy_primitives::map::{B256HashMap, HashMap, HashSet}; use alloy_primitives::map::{B256HashMap, HashMap, HashSet};
use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_with::{DeserializeAs, SerializeAs}; use serde_with::{DeserializeAs, SerializeAs};
use std::borrow::Cow;
/// Bincode-compatible [`super::TrieUpdates`] serde implementation. /// Bincode-compatible [`super::TrieUpdates`] serde implementation.
/// ///