Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Oct 3, 2024
1 parent 8b5a120 commit ef709c0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
18 changes: 9 additions & 9 deletions crates/storage/codecs/src/alloy/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B>(&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)
}
Expand All @@ -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)
}
Expand Down
16 changes: 8 additions & 8 deletions crates/trie/common/src/hash_builder/state.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,8 +16,8 @@ use serde::{Deserialize, Serialize};
pub struct HashBuilderState {
/// The current key.
pub key: Vec<u8>,
/// The current node input.
pub input: HashBuilderInput,
/// The current node value.
pub value: HashBuilderValue,
/// The builder stack.
pub stack: Vec<RlpNode>,

Expand All @@ -37,7 +37,7 @@ impl From<HashBuilderState> 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,
Expand All @@ -54,7 +54,7 @@ impl From<HashBuilder> 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,
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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)
}
}

Expand Down

0 comments on commit ef709c0

Please sign in to comment.