reth_trie_common/
storage.rs

1use super::{BranchNodeCompact, StoredNibblesSubKey};
2
3/// Account storage trie node.
4#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
5#[cfg_attr(any(test, feature = "serde"), derive(serde::Serialize, serde::Deserialize))]
6pub struct StorageTrieEntry {
7    /// The nibbles of the intermediate node
8    pub nibbles: StoredNibblesSubKey,
9    /// Encoded node.
10    pub node: BranchNodeCompact,
11}
12
13// NOTE: Removing reth_codec and manually encode subkey
14// and compress second part of the value. If we have compression
15// over whole value (Even SubKey) that would mess up fetching of values with seek_by_key_subkey
16#[cfg(any(test, feature = "reth-codec"))]
17impl reth_codecs::Compact for StorageTrieEntry {
18    fn to_compact<B>(&self, buf: &mut B) -> usize
19    where
20        B: bytes::BufMut + AsMut<[u8]>,
21    {
22        let nibbles_len = self.nibbles.to_compact(buf);
23        let node_len = self.node.to_compact(buf);
24        nibbles_len + node_len
25    }
26
27    fn from_compact(buf: &[u8], len: usize) -> (Self, &[u8]) {
28        let (nibbles, buf) = StoredNibblesSubKey::from_compact(buf, 33);
29        let (node, buf) = BranchNodeCompact::from_compact(buf, len - 33);
30        let this = Self { nibbles, node };
31        (this, buf)
32    }
33}