Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: scroll parallel state root #100

Merged
merged 9 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/assets/check_wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ exclude_crates=(
reth-scroll-cli # tokio
reth-scroll-node # tokio
reth-scroll # tokio
reth-scroll-state-commitment # tokio
reth-scroll-chainspec # tokio
reth-scroll-evm # tokio
frisitano marked this conversation as resolved.
Show resolved Hide resolved
)

# Array to hold the results
Expand Down
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions crates/blockchain-tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ alloy-primitives.workspace = true
alloy-eips.workspace = true

# scroll
reth-scroll-state-commitment = { workspace = true, optional = true }
reth-scroll-storage = { workspace = true, optional = true }

# common
Expand Down Expand Up @@ -81,7 +82,8 @@ test-utils = [
"reth-provider/test-utils",
"reth-trie-db/test-utils",
"reth-trie/test-utils",
"revm/test-utils"
"revm/test-utils",
"reth-scroll-state-commitment?/test-utils"
]
optimism = [
"reth-primitives/optimism",
Expand All @@ -102,5 +104,6 @@ scroll = [
"reth-testing-utils/scroll",
"reth-trie/scroll",
"revm/scroll",
"reth-scroll-storage/scroll"
"reth-scroll-storage/scroll",
"reth-scroll-state-commitment/scroll"
]
18 changes: 12 additions & 6 deletions crates/blockchain-tree/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use reth_provider::{
StateRootProvider, TryIntoHistoricalStateProvider,
};
use reth_trie::{updates::TrieUpdates, TrieInput};
use reth_trie_parallel::root::ParallelStateRoot;
use std::{
collections::BTreeMap,
ops::{Deref, DerefMut},
Expand Down Expand Up @@ -228,13 +227,20 @@ impl AppendableChain {
let mut execution_outcome =
provider.block_execution_data_provider.execution_outcome().clone();
execution_outcome.extend(initial_execution_outcome.clone());
ParallelStateRoot::new(
#[cfg(feature = "scroll")]
let parallel_state_root = reth_scroll_state_commitment::ParallelStateRoot::new(
consistent_view,
TrieInput::from_state(provider.hashed_post_state(execution_outcome.state())),
)
.incremental_root_with_updates()
.map(|(root, updates)| (root, Some(updates)))
.map_err(ProviderError::from)?
);
#[cfg(not(feature = "scroll"))]
let parallel_state_root = reth_trie_parallel::root::ParallelStateRoot::new(
consistent_view,
TrieInput::from_state(provider.hashed_post_state(execution_outcome.state())),
);
parallel_state_root
.incremental_root_with_updates()
.map(|(root, updates)| (root, Some(updates)))
.map_err(ProviderError::from)?
} else {
let hashed_state = provider.hashed_post_state(initial_execution_outcome.state());
let state_root = provider.state_root_from_state(hashed_state)?;
Expand Down
1 change: 1 addition & 0 deletions crates/blockchain-tree/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#![cfg_attr(not(test), warn(unused_crate_dependencies))]

use reth_revm as _;
use reth_trie_parallel as _;

/// Re-export of the blockchain tree API.
pub use reth_blockchain_tree_api::*;
Expand Down
5 changes: 4 additions & 1 deletion crates/engine/tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ reth-trie-sparse.workspace = true
reth-trie.workspace = true

# scroll
reth-scroll-state-commitment = { workspace = true, optional = true }
reth-scroll-storage = { workspace = true, optional = true }

# alloy
Expand Down Expand Up @@ -119,8 +120,10 @@ test-utils = [
"reth-trie/test-utils",
"reth-prune-types?/test-utils",
"reth-trie-db/test-utils",
"reth-scroll-state-commitment?/test-utils"
]
scroll = [
"reth-scroll-primitives",
"reth-scroll-storage/scroll"
"reth-scroll-storage/scroll",
"reth-scroll-state-commitment/scroll"
]
10 changes: 8 additions & 2 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use reth_provider::{
};
use reth_stages_api::ControlFlow;
use reth_trie::{updates::TrieUpdates, HashedPostState, TrieInput};
use reth_trie_parallel::root::{ParallelStateRoot, ParallelStateRootError};
use reth_trie_parallel::root::ParallelStateRootError;
use revm_primitives::ResultAndState;
use std::{
cmp::Ordering,
Expand Down Expand Up @@ -2362,7 +2362,13 @@ where
// Extend with block we are validating root for.
input.append_ref(hashed_state);

ParallelStateRoot::new(consistent_view, input).incremental_root_with_updates()
#[cfg(feature = "scroll")]
let parallel_state_root =
reth_scroll_state_commitment::ParallelStateRoot::new(consistent_view, input);
#[cfg(not(feature = "scroll"))]
let parallel_state_root =
reth_trie_parallel::root::ParallelStateRoot::new(consistent_view, input);
parallel_state_root.incremental_root_with_updates()
}

/// Handles an error that occurred while inserting a block.
Expand Down
27 changes: 20 additions & 7 deletions crates/scroll/state-commitment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@ exclude.workspace = true
workspace = true

[dependencies]
reth-db.workspace = true
# reth
reth-db.workspace = true
reth-execution-errors.workspace = true
reth-primitives.workspace = true
reth-primitives-traits.workspace = true
reth-provider.workspace = true
reth-storage-api.workspace = true
reth-trie.workspace = true
reth-trie-db.workspace = true
reth-trie-parallel.workspace = true

# scroll
reth-scroll-execution.workspace = true
reth-scroll-primitives.workspace = true
reth-scroll-trie.workspace = true
reth-trie.workspace = true
reth-trie-db.workspace = true

# alloy
alloy-consensus.workspace = true
Expand All @@ -38,23 +44,26 @@ zktrie_rust = { git = "https://github.com/scroll-tech/zktrie.git", rev = "309160
zktrie = { git = "https://github.com/scroll-tech/zktrie.git", rev = "309160464c1cd2b87a578ed6d9b6e98205ae4640", features = ["rs_zktrie"], optional = true }

# misc
tracing.workspace = true
itertools.workspace = true
rayon.workspace = true
tracing.workspace = true

[dev-dependencies]
reth-db-api.workspace = true
reth-primitives = { workspace = true, features = ["test-utils", "arbitrary"] }
reth-node-types.workspace = true
reth-scroll-state-commitment = { workspace = true, features = ["test-utils"] }
reth-trie = { workspace = true, features = ["test-utils" ] }
reth-trie = { workspace = true, features = ["test-utils"] }
reth-trie-common = { workspace = true, features = ["test-utils", "arbitrary"] }
reth-provider = { workspace = true, features = ["test-utils" ] }
reth-provider = { workspace = true, features = ["test-utils"] }
alloy-consensus.workspace = true
zktrie_rust = { git = "https://github.com/scroll-tech/zktrie.git", rev = "309160464c1cd2b87a578ed6d9b6e98205ae4640" }
zktrie = { git = "https://github.com/scroll-tech/zktrie.git", rev = "309160464c1cd2b87a578ed6d9b6e98205ae4640", features = ["rs_zktrie"] }
proptest.workspace = true
proptest-arbitrary-interop.workspace = true

[features]
default = ["metrics"]
scroll = [
"reth-trie/scroll",
"reth-primitives-traits/scroll",
Expand All @@ -76,6 +85,10 @@ test-utils = [
"reth-trie-common/test-utils",
"reth-trie-db/test-utils"
]
metrics = ["reth-metrics", "dep:metrics"]
metrics = [
"reth-metrics",
"dep:metrics",
"reth-trie-parallel/metrics"
]


2 changes: 1 addition & 1 deletion crates/scroll/state-commitment/src/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use reth_trie_db::{DatabaseHashedCursorFactory, DatabaseTrieCursorFactory, State
pub struct BinaryMerklePatriciaTrie;

impl StateCommitment for BinaryMerklePatriciaTrie {
type KeyHasher = PoseidonKeyHasher;
type StateRoot<'a, TX: DbTx + 'a> =
StateRoot<DatabaseTrieCursorFactory<'a, TX>, DatabaseHashedCursorFactory<'a, TX>>;
type StorageRoot<'a, TX: DbTx + 'a> =
Expand All @@ -23,4 +22,5 @@ impl StateCommitment for BinaryMerklePatriciaTrie {
DatabaseTrieCursorFactory<'a, TX>,
DatabaseHashedCursorFactory<'a, TX>,
>;
type KeyHasher = PoseidonKeyHasher;
}
3 changes: 3 additions & 0 deletions crates/scroll/state-commitment/src/root/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ use tracing::{debug, trace};
#[cfg(feature = "metrics")]
use reth_trie::metrics::{StateRootMetrics, TrieRootMetrics, TrieType};

mod parallel;
pub use parallel::ParallelStateRoot;

mod utils;
pub use utils::*;

Expand Down
Loading
Loading