From 3cb4bf266d624b9f985fc9273540f353f34f6b94 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Tue, 15 Oct 2024 12:53:34 +0200 Subject: [PATCH] chore(deps): bump alloy-trie 0.7 (#11362) Co-authored-by: Roman Krasiuk Co-authored-by: Alexey Shekhirin --- Cargo.lock | 12 ++++--- Cargo.toml | 2 +- crates/stages/types/src/checkpoints.rs | 2 +- crates/storage/codecs/src/alloy/trie.rs | 33 +++++++++++--------- crates/trie/common/src/hash_builder/state.rs | 12 +++---- crates/trie/trie/src/witness.rs | 8 +++-- 6 files changed, 39 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3fbcc7514..828444080 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -741,13 +741,14 @@ dependencies = [ [[package]] name = "alloy-trie" -version = "0.6.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9703ce68b97f8faae6f7739d1e003fc97621b856953cbcdbb2b515743f23288" +checksum = "6fa8acead43cb238a7b7f47238c71137f4677a0b8d90e7e3be6e6ca59a28194e" dependencies = [ "alloy-primitives", "alloy-rlp", "arbitrary", + "arrayvec", "derive_arbitrary", "derive_more 1.0.0", "nybbles", @@ -992,6 +993,9 @@ name = "arrayvec" version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" +dependencies = [ + "serde", +] [[package]] name = "asn1_der" @@ -4460,7 +4464,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "windows-targets 0.52.6", + "windows-targets 0.48.5", ] [[package]] @@ -11348,7 +11352,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.48.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index f734fd44c..e3ec1c1fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -424,7 +424,7 @@ alloy-dyn-abi = "0.8.0" alloy-primitives = { version = "0.8.7", default-features = false } alloy-rlp = "0.3.4" alloy-sol-types = "0.8.0" -alloy-trie = { version = "0.6", default-features = false } +alloy-trie = { version = "0.7", default-features = false } alloy-consensus = { version = "0.4.2", default-features = false } alloy-eips = { version = "0.4.2", default-features = false } diff --git a/crates/stages/types/src/checkpoints.rs b/crates/stages/types/src/checkpoints.rs index e88e933d6..79e896bf4 100644 --- a/crates/stages/types/src/checkpoints.rs +++ b/crates/stages/types/src/checkpoints.rs @@ -8,7 +8,7 @@ use std::ops::RangeInclusive; use super::StageId; /// Saves the progress of Merkle stage. -#[derive(Default, Debug, Clone, PartialEq)] +#[derive(Default, Debug, Clone, PartialEq, Eq)] pub struct MerkleCheckpoint { /// The target block number. pub target_block: BlockNumber, diff --git a/crates/storage/codecs/src/alloy/trie.rs b/crates/storage/codecs/src/alloy/trie.rs index c89ef0bf6..cc5273dd0 100644 --- a/crates/storage/codecs/src/alloy/trie.rs +++ b/crates/storage/codecs/src/alloy/trie.rs @@ -1,15 +1,18 @@ -//! Native Compact codec impl for EIP-7685 requests. +//! Native Compact codec impl for alloy-trie types. use crate::Compact; use alloc::vec::Vec; use alloy_primitives::B256; -use alloy_trie::{hash_builder::HashBuilderValue, BranchNodeCompact, TrieMask}; +use alloy_trie::{ + hash_builder::{HashBuilderValue, HashBuilderValueRef}, + BranchNodeCompact, TrieMask, +}; use bytes::{Buf, BufMut}; -/// Identifier for [`HashBuilderValue::Hash`] +/// Identifier for [`HashBuilderValueRef::Hash`] const HASH_BUILDER_TYPE_HASH: u8 = 0; -/// Identifier for [`HashBuilderValue::Bytes`] +/// Identifier for [`HashBuilderValueRef::Bytes`] const HASH_BUILDER_TYPE_BYTES: u8 = 1; impl Compact for HashBuilderValue { @@ -17,34 +20,34 @@ impl Compact for HashBuilderValue { where B: BufMut + AsMut<[u8]>, { - match self { - Self::Hash(hash) => { + match self.as_ref() { + HashBuilderValueRef::Hash(hash) => { buf.put_u8(HASH_BUILDER_TYPE_HASH); 1 + hash.to_compact(buf) } - Self::Bytes(bytes) => { + HashBuilderValueRef::Bytes(bytes) => { buf.put_u8(HASH_BUILDER_TYPE_BYTES); 1 + bytes.to_compact(buf) } } } - // # Panics - // - // A panic will be triggered if a HashBuilderValue variant greater than 1 is passed from the - // database. fn from_compact(mut buf: &[u8], _: usize) -> (Self, &[u8]) { - match buf.get_u8() { + let mut this = Self::default(); + let buf = match buf.get_u8() { HASH_BUILDER_TYPE_HASH => { let (hash, buf) = B256::from_compact(buf, 32); - (Self::Hash(hash), buf) + this.set_from_ref(HashBuilderValueRef::Hash(&hash)); + buf } HASH_BUILDER_TYPE_BYTES => { let (bytes, buf) = Vec::from_compact(buf, 0); - (Self::Bytes(bytes), buf) + this.set_bytes_owned(bytes); + buf } _ => 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 467931672..c5cae21a1 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::HashBuilderValue, HashBuilder}; +use alloy_trie::{hash_builder::HashBuilderValue, nodes::RlpNode, HashBuilder}; use bytes::Buf; use nybbles::Nibbles; use reth_codecs::Compact; @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; /// The hash builder state for storing in the database. /// Check the `reth-trie` crate for more info on hash builder. -#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] #[cfg_attr( feature = "arbitrary", derive(arbitrary::Arbitrary), @@ -16,10 +16,10 @@ use serde::{Deserialize, Serialize}; pub struct HashBuilderState { /// The current key. pub key: Vec, - /// The builder stack. - pub stack: Vec>, /// The current node value. pub value: HashBuilderValue, + /// The builder stack. + pub stack: Vec, /// Group masks. pub groups: Vec, @@ -112,7 +112,7 @@ impl Compact for HashBuilderState { let mut stack = Vec::with_capacity(stack_len); for _ in 0..stack_len { let item_len = buf.get_u16() as usize; - stack.push(Vec::from(&buf[..item_len])); + stack.push(RlpNode::from_raw(&buf[..item_len]).unwrap()); buf.advance(item_len); } @@ -154,7 +154,7 @@ mod tests { #[test] fn hash_builder_state_regression() { let mut state = HashBuilderState::default(); - state.stack.push(vec![]); + state.stack.push(Default::default()); let mut buf = vec![]; let len = state.clone().to_compact(&mut buf); let (decoded, _) = HashBuilderState::from_compact(&buf, len); diff --git a/crates/trie/trie/src/witness.rs b/crates/trie/trie/src/witness.rs index 582319c7f..971f10cfb 100644 --- a/crates/trie/trie/src/witness.rs +++ b/crates/trie/trie/src/witness.rs @@ -1,5 +1,3 @@ -use std::collections::BTreeMap; - use crate::{ hashed_cursor::{HashedCursor, HashedCursorFactory}, prefix_set::TriePrefixSetsMut, @@ -19,6 +17,7 @@ use reth_primitives::constants::EMPTY_ROOT_HASH; use reth_trie_common::{ BranchNode, HashBuilder, Nibbles, StorageMultiProof, TrieAccount, TrieNode, CHILD_INDEX_RANGE, }; +use std::collections::BTreeMap; /// State transition witness for the trie. #[derive(Debug)] @@ -229,7 +228,10 @@ where TrieNode::Leaf(leaf) => { next_path.extend_from_slice(&leaf.key); if next_path != key { - trie_nodes.insert(next_path.clone(), Either::Right(leaf.value.clone())); + trie_nodes.insert( + next_path.clone(), + Either::Right(leaf.value.as_slice().to_vec()), + ); } } TrieNode::EmptyRoot => {