Skip to content

Commit bc63e0a

Browse files
Moved HashedPostState to trie-common crate
1 parent a63f92e commit bc63e0a

File tree

7 files changed

+30
-19
lines changed

7 files changed

+30
-19
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/trie/common/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ derive_more.workspace = true
2828
itertools = { workspace = true, features = ["use_alloc"] }
2929
nybbles = { workspace = true, features = ["rlp"] }
3030

31+
# reth
32+
revm.workspace = true
33+
3134
# `serde` feature
3235
serde = { workspace = true, optional = true }
3336

@@ -38,6 +41,9 @@ hash-db = { version = "=0.15.2", optional = true }
3841
plain_hasher = { version = "0.2", optional = true }
3942
arbitrary = { workspace = true, features = ["derive"], optional = true }
4043

44+
# misc
45+
rayon.workspace = true
46+
4147
[dev-dependencies]
4248
reth-primitives-traits = { workspace = true, features = ["serde"] }
4349
reth-codecs.workspace = true
@@ -74,6 +80,7 @@ std = [
7480
"serde?/std",
7581
"serde_with?/std",
7682
"serde_json/std",
83+
"revm/std",
7784
]
7885
eip1186 = [
7986
"alloy-rpc-types-eth/serde",
@@ -89,6 +96,7 @@ serde = [
8996
"alloy-rpc-types-eth?/serde",
9097
"reth-primitives-traits/serde",
9198
"reth-codecs?/serde",
99+
"revm/serde",
92100
]
93101
reth-codec = [
94102
"dep:reth-codecs",
@@ -106,6 +114,7 @@ test-utils = [
106114
"arbitrary",
107115
"reth-primitives-traits/test-utils",
108116
"reth-codecs/test-utils",
117+
"revm/test-utils",
109118
]
110119
arbitrary = [
111120
"std",
@@ -119,6 +128,7 @@ arbitrary = [
119128
"nybbles/arbitrary",
120129
"reth-codecs/arbitrary",
121130
"alloy-rpc-types-eth?/arbitrary",
131+
"revm/arbitrary",
122132
]
123133

124134
[[bench]]

crates/trie/trie/src/state.rs renamed to crates/trie/common/src/hashedstate.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
prefix_set::{PrefixSetMut, TriePrefixSetsMut},
3-
Nibbles,
3+
KeyHasher, Nibbles,
44
};
55
use alloy_primitives::{
66
keccak256,
@@ -10,7 +10,7 @@ use alloy_primitives::{
1010
use itertools::Itertools;
1111
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
1212
use reth_primitives_traits::Account;
13-
use reth_trie_common::KeyHasher;
13+
1414
use revm::db::{AccountStatus, BundleAccount};
1515
use std::borrow::Cow;
1616

@@ -260,9 +260,9 @@ impl HashedStorage {
260260
#[derive(PartialEq, Eq, Clone, Default, Debug)]
261261
pub struct HashedPostStateSorted {
262262
/// Updated state of accounts.
263-
pub(crate) accounts: HashedAccountsSorted,
263+
pub accounts: HashedAccountsSorted,
264264
/// Map of hashed addresses to hashed storage.
265-
pub(crate) storages: B256HashMap<HashedStorageSorted>,
265+
pub storages: B256HashMap<HashedStorageSorted>,
266266
}
267267

268268
impl HashedPostStateSorted {
@@ -289,9 +289,9 @@ impl HashedPostStateSorted {
289289
#[derive(Clone, Eq, PartialEq, Default, Debug)]
290290
pub struct HashedAccountsSorted {
291291
/// Sorted collection of hashed addresses and their account info.
292-
pub(crate) accounts: Vec<(B256, Account)>,
292+
pub accounts: Vec<(B256, Account)>,
293293
/// Set of destroyed account keys.
294-
pub(crate) destroyed_accounts: B256HashSet,
294+
pub destroyed_accounts: B256HashSet,
295295
}
296296

297297
impl HashedAccountsSorted {
@@ -309,11 +309,11 @@ impl HashedAccountsSorted {
309309
#[derive(Clone, Eq, PartialEq, Debug)]
310310
pub struct HashedStorageSorted {
311311
/// Sorted hashed storage slots with non-zero value.
312-
pub(crate) non_zero_valued_slots: Vec<(B256, U256)>,
312+
pub non_zero_valued_slots: Vec<(B256, U256)>,
313313
/// Slots that have been zero valued.
314-
pub(crate) zero_valued_slots: B256HashSet,
314+
pub zero_valued_slots: B256HashSet,
315315
/// Flag indicating whether the storage was wiped or not.
316-
pub(crate) wiped: bool,
316+
pub wiped: bool,
317317
}
318318

319319
impl HashedStorageSorted {
@@ -335,8 +335,8 @@ impl HashedStorageSorted {
335335
#[cfg(test)]
336336
mod tests {
337337
use super::*;
338+
use crate::KeccakKeyHasher;
338339
use alloy_primitives::Bytes;
339-
use reth_trie_common::KeccakKeyHasher;
340340
use revm::{
341341
db::{states::StorageSlot, StorageWithOriginalValues},
342342
primitives::{AccountInfo, Bytecode},

crates/trie/common/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
extern crate alloc;
1313

14+
/// In-memory hashed state.
15+
mod hashedstate;
16+
pub use hashedstate::*;
17+
1418
/// The implementation of hash builder.
1519
pub mod hash_builder;
1620

crates/trie/trie/src/hashed_cursor/post_state.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use super::{HashedCursor, HashedCursorFactory, HashedStorageCursor};
2-
use crate::{
3-
forward_cursor::ForwardInMemoryCursor, HashedAccountsSorted, HashedPostStateSorted,
4-
HashedStorageSorted,
5-
};
2+
use crate::forward_cursor::ForwardInMemoryCursor;
63
use alloy_primitives::{map::B256HashSet, B256, U256};
74
use reth_primitives_traits::Account;
85
use reth_storage_errors::db::DatabaseError;
6+
use reth_trie_common::{HashedAccountsSorted, HashedPostStateSorted, HashedStorageSorted};
97

108
/// The hashed cursor factory for the post state.
119
#[derive(Clone, Debug)]

crates/trie/trie/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ pub mod walker;
2828
/// The iterators for traversing existing intermediate hashes and updated trie leaves.
2929
pub mod node_iter;
3030

31-
/// In-memory hashed state.
32-
mod state;
33-
pub use state::*;
34-
3531
/// Input for trie computation.
3632
mod input;
3733
pub use input::TrieInput;

crates/trie/trie/src/witness.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use crate::{
33
prefix_set::TriePrefixSetsMut,
44
proof::{Proof, ProofBlindedProviderFactory},
55
trie_cursor::TrieCursorFactory,
6-
HashedPostState,
76
};
7+
use reth_trie_common::HashedPostState;
8+
89
use alloy_primitives::{
910
keccak256,
1011
map::{B256HashMap, B256HashSet, Entry, HashMap},

0 commit comments

Comments
 (0)