chore(deps): bump alloy-trie 0.7 (#11362)

Co-authored-by: Roman Krasiuk <rokrassyuk@gmail.com>
Co-authored-by: Alexey Shekhirin <a.shekhirin@gmail.com>
This commit is contained in:
DaniPopes
2024-10-15 12:53:34 +02:00
committed by GitHub
parent 39f0ab4116
commit 3cb4bf266d
6 changed files with 39 additions and 30 deletions

12
Cargo.lock generated
View File

@ -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]]

View File

@ -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 }

View File

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

View File

@ -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)
}
}

View File

@ -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<u8>,
/// The builder stack.
pub stack: Vec<Vec<u8>>,
/// The current node value.
pub value: HashBuilderValue,
/// The builder stack.
pub stack: Vec<RlpNode>,
/// Group masks.
pub groups: Vec<TrieMask>,
@ -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);

View File

@ -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 => {