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

chore: feature gate reth-codecs in trie-common #13215

Merged
merged 1 commit into from
Dec 7, 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: 1 addition & 0 deletions crates/stages/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ reth-codec = [
"dep:reth-codecs",
"dep:bytes",
"dep:modular-bitfield",
"reth-trie-common/reth-codec"
]
test-utils = [
"dep:arbitrary",
Expand Down
16 changes: 12 additions & 4 deletions crates/trie/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -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"] }
Expand All @@ -62,15 +65,19 @@ eip1186 = [
]
serde = [
"dep:serde",
"bytes/serde",
"bytes?/serde",
"nybbles/serde",
"alloy-primitives/serde",
"alloy-consensus/serde",
"alloy-trie/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",
Expand All @@ -86,6 +93,7 @@ test-utils = [
"reth-codecs/test-utils",
]
arbitrary = [
"dep:reth-codecs",
"alloy-trie/arbitrary",
"dep:arbitrary",
"alloy-serde?/arbitrary",
Expand Down
8 changes: 5 additions & 3 deletions crates/trie/common/src/hash_builder/state.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -63,7 +61,8 @@ impl From<HashBuilder> for HashBuilderState {
}
}

impl Compact for HashBuilderState {
#[cfg(any(test, feature = "reth-codec"))]
impl reth_codecs::Compact for HashBuilderState {
fn to_compact<B>(&self, buf: &mut B) -> usize
where
B: bytes::BufMut + AsMut<[u8]>,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -150,6 +151,7 @@ impl Compact for HashBuilderState {
#[cfg(test)]
mod tests {
use super::*;
use reth_codecs::Compact;

#[test]
fn hash_builder_state_regression() {
Expand Down
12 changes: 7 additions & 5 deletions crates/trie/common/src/nibbles.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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<B>(&self, buf: &mut B) -> usize
where
B: bytes::BufMut + AsMut<[u8]>,
Expand All @@ -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)
Expand Down Expand Up @@ -88,7 +88,8 @@ impl From<StoredNibblesSubKey> for Nibbles {
}
}

impl Compact for StoredNibblesSubKey {
#[cfg(any(test, feature = "reth-codec"))]
impl reth_codecs::Compact for StoredNibblesSubKey {
fn to_compact<B>(&self, buf: &mut B) -> usize
where
B: bytes::BufMut + AsMut<[u8]>,
Expand All @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions crates/trie/common/src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use super::{BranchNodeCompact, StoredNibblesSubKey};
use reth_codecs::Compact;

/// Account storage trie node.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
Expand All @@ -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<B>(&self, buf: &mut B) -> usize
where
B: bytes::BufMut + AsMut<[u8]>,
Expand Down
8 changes: 5 additions & 3 deletions crates/trie/common/src/subnode.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -13,7 +11,8 @@ pub struct StoredSubNode {
pub node: Option<BranchNodeCompact>,
}

impl Compact for StoredSubNode {
#[cfg(any(test, feature = "reth-codec"))]
impl reth_codecs::Compact for StoredSubNode {
fn to_compact<B>(&self, buf: &mut B) -> usize
where
B: bytes::BufMut + AsMut<[u8]>,
Expand Down Expand Up @@ -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);
Expand All @@ -69,6 +70,7 @@ mod tests {
use super::*;
use crate::TrieMask;
use alloy_primitives::B256;
use reth_codecs::Compact;

#[test]
fn subnode_roundtrip() {
Expand Down
Loading