mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore(trie): introduce serde feature on reth-trie-common (#12864)
This commit is contained in:
@ -21,8 +21,8 @@ reth-storage-errors.workspace = true
|
||||
reth-nippy-jar.workspace = true
|
||||
reth-prune-types.workspace = true
|
||||
reth-stages-types.workspace = true
|
||||
reth-trie-common = { workspace = true, features = ["serde"] }
|
||||
reth-tracing.workspace = true
|
||||
reth-trie-common.workspace = true
|
||||
|
||||
# ethereum
|
||||
alloy-primitives.workspace = true
|
||||
|
||||
@ -12,21 +12,24 @@ description = "Commonly used types for trie usage in reth."
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
reth-primitives-traits = { workspace = true, features = ["serde"] }
|
||||
reth-codecs.workspace = true
|
||||
|
||||
# alloy
|
||||
alloy-primitives.workspace = true
|
||||
alloy-rlp = { workspace = true, features = ["arrayvec"] }
|
||||
alloy-trie = { workspace = true, features = ["serde"] }
|
||||
alloy-trie.workspace = true
|
||||
alloy-consensus.workspace = true
|
||||
alloy-genesis.workspace = true
|
||||
|
||||
reth-primitives-traits.workspace = true
|
||||
reth-codecs.workspace = true
|
||||
revm-primitives.workspace = true
|
||||
|
||||
bytes.workspace = true
|
||||
derive_more.workspace = true
|
||||
serde.workspace = true
|
||||
itertools.workspace = true
|
||||
nybbles = { workspace = true, features = ["serde", "rlp"] }
|
||||
nybbles = { workspace = true, features = ["rlp"] }
|
||||
|
||||
# `serde` feature
|
||||
serde = { workspace = true, optional = true }
|
||||
|
||||
# `test-utils` feature
|
||||
hash-db = { version = "=0.15.2", optional = true }
|
||||
@ -45,6 +48,17 @@ proptest-arbitrary-interop.workspace = true
|
||||
criterion.workspace = true
|
||||
|
||||
[features]
|
||||
serde = [
|
||||
"dep:serde",
|
||||
"bytes/serde",
|
||||
"nybbles/serde",
|
||||
"alloy-primitives/serde",
|
||||
"alloy-consensus/serde",
|
||||
"alloy-trie/serde",
|
||||
"revm-primitives/serde",
|
||||
"reth-primitives-traits/serde",
|
||||
"reth-codecs/serde"
|
||||
]
|
||||
test-utils = [
|
||||
"dep:plain_hasher",
|
||||
"dep:hash-db",
|
||||
|
||||
@ -3,11 +3,11 @@ use alloy_trie::{hash_builder::HashBuilderValue, nodes::RlpNode, HashBuilder};
|
||||
use bytes::Buf;
|
||||
use nybbles::Nibbles;
|
||||
use reth_codecs::Compact;
|
||||
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, Eq, Default, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "arbitrary",
|
||||
derive(arbitrary::Arbitrary),
|
||||
|
||||
@ -1,24 +1,12 @@
|
||||
use bytes::Buf;
|
||||
use derive_more::Deref;
|
||||
use reth_codecs::Compact;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub use nybbles::Nibbles;
|
||||
|
||||
/// The representation of nibbles of the merkle trie stored in the database.
|
||||
#[derive(
|
||||
Clone,
|
||||
Debug,
|
||||
Default,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Hash,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
derive_more::Index,
|
||||
)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, derive_more::Index)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "test-utils", derive(arbitrary::Arbitrary))]
|
||||
pub struct StoredNibbles(pub Nibbles);
|
||||
|
||||
@ -74,7 +62,8 @@ impl Compact for StoredNibbles {
|
||||
}
|
||||
|
||||
/// The representation of nibbles of the merkle trie stored in the database.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Ord, Hash, Deref)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deref)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "test-utils", derive(arbitrary::Arbitrary))]
|
||||
pub struct StoredNibblesSubKey(pub Nibbles);
|
||||
|
||||
|
||||
@ -11,7 +11,6 @@ use alloy_trie::{
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use reth_primitives_traits::Account;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{hash_map, HashMap};
|
||||
|
||||
/// The state multiproof of target accounts and multiproofs of their storage tries.
|
||||
@ -171,8 +170,9 @@ impl StorageMultiProof {
|
||||
}
|
||||
|
||||
/// The merkle proof with the relevant account info.
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
|
||||
pub struct AccountProof {
|
||||
/// The address associated with the account.
|
||||
pub address: Address,
|
||||
@ -227,7 +227,8 @@ impl AccountProof {
|
||||
}
|
||||
|
||||
/// The merkle proof of the storage entry.
|
||||
#[derive(Clone, PartialEq, Eq, Default, Debug, Serialize, Deserialize)]
|
||||
#[derive(Clone, PartialEq, Eq, Default, Debug)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct StorageProof {
|
||||
/// The raw storage key.
|
||||
pub key: B256,
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
use super::{BranchNodeCompact, StoredNibblesSubKey};
|
||||
use reth_codecs::Compact;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Account storage trie node.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Ord)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct StorageTrieEntry {
|
||||
/// The nibbles of the intermediate node
|
||||
pub nibbles: StoredNibblesSubKey,
|
||||
|
||||
@ -18,7 +18,6 @@ reth-execution-errors.workspace = true
|
||||
reth-db.workspace = true
|
||||
reth-db-api.workspace = true
|
||||
reth-storage-errors.workspace = true
|
||||
reth-trie-common.workspace = true
|
||||
reth-trie.workspace = true
|
||||
|
||||
revm.workspace = true
|
||||
@ -70,6 +69,7 @@ serde = [
|
||||
"dep:serde",
|
||||
"reth-provider/serde",
|
||||
"reth-trie/serde",
|
||||
"reth-trie-common/serde",
|
||||
"alloy-consensus/serde",
|
||||
"alloy-primitives/serde",
|
||||
"revm/serde",
|
||||
|
||||
@ -8,8 +8,10 @@ use reth_db_api::{
|
||||
DatabaseError,
|
||||
};
|
||||
use reth_primitives::StorageEntry;
|
||||
use reth_trie::prefix_set::{PrefixSetMut, TriePrefixSets};
|
||||
use reth_trie_common::Nibbles;
|
||||
use reth_trie::{
|
||||
prefix_set::{PrefixSetMut, TriePrefixSets},
|
||||
Nibbles,
|
||||
};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
ops::RangeInclusive,
|
||||
|
||||
@ -10,9 +10,8 @@ use reth_trie::{
|
||||
hashed_cursor::HashedPostStateCursorFactory,
|
||||
proof::{Proof, StorageProof},
|
||||
trie_cursor::InMemoryTrieCursorFactory,
|
||||
HashedPostStateSorted, HashedStorage, MultiProof, TrieInput,
|
||||
AccountProof, HashedPostStateSorted, HashedStorage, MultiProof, TrieInput,
|
||||
};
|
||||
use reth_trie_common::AccountProof;
|
||||
|
||||
/// Extends [`Proof`] with operations specific for working with a database transaction.
|
||||
pub trait DatabaseProof<'a, TX> {
|
||||
@ -96,7 +95,7 @@ pub trait DatabaseStorageProof<'a, TX> {
|
||||
address: Address,
|
||||
slot: B256,
|
||||
storage: HashedStorage,
|
||||
) -> Result<reth_trie_common::StorageProof, StateProofError>;
|
||||
) -> Result<reth_trie::StorageProof, StateProofError>;
|
||||
}
|
||||
|
||||
impl<'a, TX: DbTx> DatabaseStorageProof<'a, TX>
|
||||
@ -111,7 +110,7 @@ impl<'a, TX: DbTx> DatabaseStorageProof<'a, TX>
|
||||
address: Address,
|
||||
slot: B256,
|
||||
storage: HashedStorage,
|
||||
) -> Result<reth_trie_common::StorageProof, StateProofError> {
|
||||
) -> Result<reth_trie::StorageProof, StateProofError> {
|
||||
let hashed_address = keccak256(address);
|
||||
let prefix_set = storage.construct_prefix_set();
|
||||
let state_sorted = HashedPostStateSorted::new(
|
||||
|
||||
@ -11,9 +11,8 @@ use reth_storage_errors::db::DatabaseError;
|
||||
use reth_trie::{
|
||||
trie_cursor::{TrieCursor, TrieCursorFactory},
|
||||
updates::StorageTrieUpdates,
|
||||
BranchNodeCompact, Nibbles, StoredNibbles, StoredNibblesSubKey,
|
||||
BranchNodeCompact, Nibbles, StorageTrieEntry, StoredNibbles, StoredNibblesSubKey,
|
||||
};
|
||||
use reth_trie_common::StorageTrieEntry;
|
||||
|
||||
/// Wrapper struct for database transaction implementing trie cursor factory trait.
|
||||
#[derive(Debug)]
|
||||
|
||||
@ -6,8 +6,7 @@ use alloy_rlp::EMPTY_STRING_CODE;
|
||||
use reth_chainspec::{Chain, ChainSpec, HOLESKY, MAINNET};
|
||||
use reth_primitives::Account;
|
||||
use reth_provider::test_utils::{create_test_provider_factory, insert_genesis};
|
||||
use reth_trie::{proof::Proof, Nibbles};
|
||||
use reth_trie_common::{AccountProof, StorageProof};
|
||||
use reth_trie::{proof::Proof, AccountProof, Nibbles, StorageProof};
|
||||
use reth_trie_db::DatabaseProof;
|
||||
use std::{
|
||||
str::FromStr,
|
||||
|
||||
@ -17,9 +17,9 @@ use reth_provider::{
|
||||
use reth_trie::{
|
||||
prefix_set::PrefixSetMut,
|
||||
test_utils::{state_root, state_root_prehashed, storage_root, storage_root_prehashed},
|
||||
triehash::KeccakHasher,
|
||||
BranchNodeCompact, StateRoot, StorageRoot, TrieMask,
|
||||
};
|
||||
use reth_trie_common::triehash::KeccakHasher;
|
||||
use reth_trie_db::{DatabaseStateRoot, DatabaseStorageRoot};
|
||||
use std::{
|
||||
collections::{BTreeMap, HashMap},
|
||||
|
||||
@ -5,9 +5,9 @@ use reth_db::tables;
|
||||
use reth_db_api::{cursor::DbCursorRW, transaction::DbTxMut};
|
||||
use reth_provider::test_utils::create_test_provider_factory;
|
||||
use reth_trie::{
|
||||
prefix_set::PrefixSetMut, trie_cursor::TrieCursor, walker::TrieWalker, StorageTrieEntry,
|
||||
prefix_set::PrefixSetMut, trie_cursor::TrieCursor, walker::TrieWalker, BranchNodeCompact,
|
||||
Nibbles, StorageTrieEntry,
|
||||
};
|
||||
use reth_trie_common::{BranchNodeCompact, Nibbles};
|
||||
use reth_trie_db::{DatabaseAccountTrieCursor, DatabaseStorageTrieCursor};
|
||||
|
||||
#[test]
|
||||
|
||||
@ -70,7 +70,8 @@ serde = [
|
||||
"alloy-consensus/serde",
|
||||
"alloy-primitives/serde",
|
||||
"revm/serde",
|
||||
"alloy-trie/serde"
|
||||
"alloy-trie/serde",
|
||||
"reth-trie-common/serde"
|
||||
]
|
||||
serde-bincode-compat = [
|
||||
"serde_with",
|
||||
|
||||
Reference in New Issue
Block a user