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

This commit is contained in:
Matthias Seitz
2024-12-07 22:15:32 +01:00
committed by GitHub
parent 2846dd242e
commit 08b875f4f5
6 changed files with 32 additions and 17 deletions

View File

@ -38,6 +38,7 @@ reth-codec = [
"dep:reth-codecs",
"dep:bytes",
"dep:modular-bitfield",
"reth-trie-common/reth-codec"
]
test-utils = [
"dep:arbitrary",

View File

@ -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",

View File

@ -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<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]>,
@ -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() {

View File

@ -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<B>(&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<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]>,
@ -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() {

View File

@ -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<B>(&self, buf: &mut B) -> usize
where
B: bytes::BufMut + AsMut<[u8]>,

View File

@ -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<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]>,
@ -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() {