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