diff --git a/crates/stages/types/Cargo.toml b/crates/stages/types/Cargo.toml index d8ab63552571..0243415942b5 100644 --- a/crates/stages/types/Cargo.toml +++ b/crates/stages/types/Cargo.toml @@ -38,6 +38,7 @@ reth-codec = [ "dep:reth-codecs", "dep:bytes", "dep:modular-bitfield", + "reth-trie-common/reth-codec" ] test-utils = [ "dep:arbitrary", diff --git a/crates/trie/common/Cargo.toml b/crates/trie/common/Cargo.toml index 4f6a927d4344..eadbb3176b55 100644 --- a/crates/trie/common/Cargo.toml +++ b/crates/trie/common/Cargo.toml @@ -18,14 +18,14 @@ alloy-rlp = { workspace = true, features = ["arrayvec"] } alloy-trie.workspace = true alloy-consensus.workspace = true reth-primitives-traits.workspace = true -reth-codecs.workspace = true +reth-codecs = { workspace = true, optional = true } revm-primitives.workspace = true alloy-genesis.workspace = true alloy-rpc-types-eth = { workspace = true, optional = true } alloy-serde = { workspace = true, optional = true } -bytes.workspace = true +bytes = { workspace = true, optional = true } derive_more.workspace = true itertools.workspace = true nybbles = { workspace = true, features = ["rlp"] } @@ -42,8 +42,11 @@ arbitrary = { workspace = true, features = ["derive"], optional = true } [dev-dependencies] reth-primitives-traits = { workspace = true, features = ["serde"] } +reth-codecs.workspace = true + alloy-primitives = { workspace = true, features = ["getrandom"] } alloy-trie = { workspace = true, features = ["arbitrary", "serde"] } +bytes.workspace = true hash-db = "=0.15.2" plain_hasher = "0.2" arbitrary = { workspace = true, features = ["derive"] } @@ -62,7 +65,7 @@ eip1186 = [ ] serde = [ "dep:serde", - "bytes/serde", + "bytes?/serde", "nybbles/serde", "alloy-primitives/serde", "alloy-consensus/serde", @@ -70,7 +73,11 @@ serde = [ "alloy-rpc-types-eth?/serde", "revm-primitives/serde", "reth-primitives-traits/serde", - "reth-codecs/serde" + "reth-codecs?/serde" +] +reth-codec = [ + "dep:reth-codecs", + "dep:bytes", ] serde-bincode-compat = [ "serde", @@ -86,6 +93,7 @@ test-utils = [ "reth-codecs/test-utils", ] arbitrary = [ + "dep:reth-codecs", "alloy-trie/arbitrary", "dep:arbitrary", "alloy-serde?/arbitrary", diff --git a/crates/trie/common/src/hash_builder/state.rs b/crates/trie/common/src/hash_builder/state.rs index ec6b102d44ec..4bf3bade3986 100644 --- a/crates/trie/common/src/hash_builder/state.rs +++ b/crates/trie/common/src/hash_builder/state.rs @@ -1,8 +1,6 @@ use crate::TrieMask; use alloy_trie::{hash_builder::HashBuilderValue, nodes::RlpNode, HashBuilder}; -use bytes::Buf; use nybbles::Nibbles; -use reth_codecs::Compact; /// The hash builder state for storing in the database. /// Check the `reth-trie` crate for more info on hash builder. @@ -63,7 +61,8 @@ impl From for HashBuilderState { } } -impl Compact for HashBuilderState { +#[cfg(any(test, feature = "reth-codec"))] +impl reth_codecs::Compact for HashBuilderState { fn to_compact(&self, buf: &mut B) -> usize where B: bytes::BufMut + AsMut<[u8]>, @@ -106,6 +105,8 @@ impl Compact for HashBuilderState { } fn from_compact(buf: &[u8], _len: usize) -> (Self, &[u8]) { + use bytes::Buf; + let (key, mut buf) = Vec::from_compact(buf, 0); let stack_len = buf.get_u16() as usize; @@ -150,6 +151,7 @@ impl Compact for HashBuilderState { #[cfg(test)] mod tests { use super::*; + use reth_codecs::Compact; #[test] fn hash_builder_state_regression() { diff --git a/crates/trie/common/src/nibbles.rs b/crates/trie/common/src/nibbles.rs index 2d4e34b3e3bf..b1cc2f10c56f 100644 --- a/crates/trie/common/src/nibbles.rs +++ b/crates/trie/common/src/nibbles.rs @@ -1,7 +1,4 @@ -use bytes::Buf; use derive_more::Deref; -use reth_codecs::Compact; - pub use nybbles::Nibbles; /// The representation of nibbles of the merkle trie stored in the database. @@ -45,7 +42,8 @@ impl core::borrow::Borrow<[u8]> for StoredNibbles { } } -impl Compact for StoredNibbles { +#[cfg(any(test, feature = "reth-codec"))] +impl reth_codecs::Compact for StoredNibbles { fn to_compact(&self, buf: &mut B) -> usize where B: bytes::BufMut + AsMut<[u8]>, @@ -55,6 +53,8 @@ impl Compact for StoredNibbles { } fn from_compact(mut buf: &[u8], len: usize) -> (Self, &[u8]) { + use bytes::Buf; + let nibbles = &buf[..len]; buf.advance(len); (Self(Nibbles::from_nibbles_unchecked(nibbles)), buf) @@ -88,7 +88,8 @@ impl From for Nibbles { } } -impl Compact for StoredNibblesSubKey { +#[cfg(any(test, feature = "reth-codec"))] +impl reth_codecs::Compact for StoredNibblesSubKey { fn to_compact(&self, buf: &mut B) -> usize where B: bytes::BufMut + AsMut<[u8]>, @@ -114,6 +115,7 @@ impl Compact for StoredNibblesSubKey { mod tests { use super::*; use bytes::BytesMut; + use reth_codecs::Compact; #[test] fn test_stored_nibbles_from_nibbles() { diff --git a/crates/trie/common/src/storage.rs b/crates/trie/common/src/storage.rs index cf2945d9101a..3ebcc4e810e4 100644 --- a/crates/trie/common/src/storage.rs +++ b/crates/trie/common/src/storage.rs @@ -1,5 +1,4 @@ use super::{BranchNodeCompact, StoredNibblesSubKey}; -use reth_codecs::Compact; /// Account storage trie node. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] @@ -14,7 +13,8 @@ pub struct StorageTrieEntry { // NOTE: Removing reth_codec and manually encode subkey // and compress second part of the value. If we have compression // over whole value (Even SubKey) that would mess up fetching of values with seek_by_key_subkey -impl Compact for StorageTrieEntry { +#[cfg(any(test, feature = "reth-codec"))] +impl reth_codecs::Compact for StorageTrieEntry { fn to_compact(&self, buf: &mut B) -> usize where B: bytes::BufMut + AsMut<[u8]>, diff --git a/crates/trie/common/src/subnode.rs b/crates/trie/common/src/subnode.rs index c64b2317cf30..de65a7887806 100644 --- a/crates/trie/common/src/subnode.rs +++ b/crates/trie/common/src/subnode.rs @@ -1,6 +1,4 @@ use super::BranchNodeCompact; -use bytes::Buf; -use reth_codecs::Compact; /// Walker sub node for storing intermediate state root calculation state in the database. #[derive(Debug, Clone, PartialEq, Eq, Default)] @@ -13,7 +11,8 @@ pub struct StoredSubNode { pub node: Option, } -impl Compact for StoredSubNode { +#[cfg(any(test, feature = "reth-codec"))] +impl reth_codecs::Compact for StoredSubNode { fn to_compact(&self, buf: &mut B) -> usize where B: bytes::BufMut + AsMut<[u8]>, @@ -46,6 +45,8 @@ impl Compact for StoredSubNode { } fn from_compact(mut buf: &[u8], _len: usize) -> (Self, &[u8]) { + use bytes::Buf; + let key_len = buf.get_u16() as usize; let key = Vec::from(&buf[..key_len]); buf.advance(key_len); @@ -69,6 +70,7 @@ mod tests { use super::*; use crate::TrieMask; use alloy_primitives::B256; + use reth_codecs::Compact; #[test] fn subnode_roundtrip() {