diff --git a/Cargo.lock b/Cargo.lock index 0eae9ac1f9a1e..d1a20678a3447 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -739,6 +739,7 @@ dependencies = [ [[package]] name = "alloy-trie" version = "0.6.0" +source = "git+https://github.com/alloy-rs/trie#f4fb65d2b497a4b31b31924305106156572a3abd" dependencies = [ "alloy-primitives", "alloy-rlp", diff --git a/Cargo.toml b/Cargo.toml index 5a97d1400d841..885556d99b399 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -591,7 +591,7 @@ tikv-jemallocator = "0.6" tracy-client = "0.17.3" [patch.crates-io] -alloy-trie = { path = "../../alloy-rs/trie" } +alloy-trie = { git = "https://github.com/alloy-rs/trie" } #alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "8c499409"} #alloy-eips = { git = "https://github.com/alloy-rs/alloy", rev = "8c499409"} #alloy-genesis = { git = "https://github.com/alloy-rs/alloy", rev = "8c499409"} diff --git a/crates/storage/codecs/src/alloy/trie.rs b/crates/storage/codecs/src/alloy/trie.rs index 96068ecda217e..cc5273dd02734 100644 --- a/crates/storage/codecs/src/alloy/trie.rs +++ b/crates/storage/codecs/src/alloy/trie.rs @@ -4,28 +4,28 @@ use crate::Compact; use alloc::vec::Vec; use alloy_primitives::B256; use alloy_trie::{ - hash_builder::{HashBuilderInput, HashBuilderInputRef}, + hash_builder::{HashBuilderValue, HashBuilderValueRef}, BranchNodeCompact, TrieMask, }; use bytes::{Buf, BufMut}; -/// Identifier for [`HashBuilderInputRef::Hash`] +/// Identifier for [`HashBuilderValueRef::Hash`] const HASH_BUILDER_TYPE_HASH: u8 = 0; -/// Identifier for [`HashBuilderInputRef::Bytes`] +/// Identifier for [`HashBuilderValueRef::Bytes`] const HASH_BUILDER_TYPE_BYTES: u8 = 1; -impl Compact for HashBuilderInput { +impl Compact for HashBuilderValue { fn to_compact(&self, buf: &mut B) -> usize where B: BufMut + AsMut<[u8]>, { match self.as_ref() { - HashBuilderInputRef::Hash(hash) => { + HashBuilderValueRef::Hash(hash) => { buf.put_u8(HASH_BUILDER_TYPE_HASH); 1 + hash.to_compact(buf) } - HashBuilderInputRef::Bytes(bytes) => { + HashBuilderValueRef::Bytes(bytes) => { buf.put_u8(HASH_BUILDER_TYPE_BYTES); 1 + bytes.to_compact(buf) } @@ -37,15 +37,15 @@ impl Compact for HashBuilderInput { let buf = match buf.get_u8() { HASH_BUILDER_TYPE_HASH => { let (hash, buf) = B256::from_compact(buf, 32); - this.set_from_ref(HashBuilderInputRef::Hash(&hash)); + this.set_from_ref(HashBuilderValueRef::Hash(&hash)); buf } HASH_BUILDER_TYPE_BYTES => { let (bytes, buf) = Vec::from_compact(buf, 0); - this.set_from_ref(HashBuilderInputRef::Bytes(&bytes)); + this.set_bytes_owned(bytes); buf } - _ => unreachable!("Junk data in database: unknown HashBuilderInput variant"), + _ => unreachable!("Junk data in database: unknown HashBuilderValue variant"), }; (this, buf) } diff --git a/crates/trie/common/src/hash_builder/state.rs b/crates/trie/common/src/hash_builder/state.rs index a4c6dff25e191..99f729d84560c 100644 --- a/crates/trie/common/src/hash_builder/state.rs +++ b/crates/trie/common/src/hash_builder/state.rs @@ -1,5 +1,5 @@ use crate::TrieMask; -use alloy_trie::{hash_builder::HashBuilderInput, nodes::RlpNode, HashBuilder}; +use alloy_trie::{hash_builder::HashBuilderValue, nodes::RlpNode, HashBuilder}; use bytes::Buf; use nybbles::Nibbles; use reth_codecs::Compact; @@ -16,8 +16,8 @@ use serde::{Deserialize, Serialize}; pub struct HashBuilderState { /// The current key. pub key: Vec, - /// The current node input. - pub input: HashBuilderInput, + /// The current node value. + pub value: HashBuilderValue, /// The builder stack. pub stack: Vec, @@ -37,7 +37,7 @@ impl From for HashBuilder { Self { key: Nibbles::from_nibbles_unchecked(state.key), stack: state.stack, - input: state.input, + value: state.value, groups: state.groups, tree_masks: state.tree_masks, hash_masks: state.hash_masks, @@ -54,7 +54,7 @@ impl From for HashBuilderState { Self { key: state.key.into(), stack: state.stack, - input: state.input, + value: state.value, groups: state.groups, tree_masks: state.tree_masks, hash_masks: state.hash_masks, @@ -80,7 +80,7 @@ impl Compact for HashBuilderState { len += 2 + item.len(); } - len += self.input.to_compact(buf); + len += self.value.to_compact(buf); buf.put_u16(self.groups.len() as u16); len += 2; @@ -116,7 +116,7 @@ impl Compact for HashBuilderState { buf.advance(item_len); } - let (input, mut buf) = HashBuilderInput::from_compact(buf, 0); + let (value, mut buf) = HashBuilderValue::from_compact(buf, 0); let groups_len = buf.get_u16() as usize; let mut groups = Vec::with_capacity(groups_len); @@ -143,7 +143,7 @@ impl Compact for HashBuilderState { } let stored_in_database = buf.get_u8() != 0; - (Self { key, stack, input, groups, tree_masks, hash_masks, stored_in_database }, buf) + (Self { key, stack, value, groups, tree_masks, hash_masks, stored_in_database }, buf) } }