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

Implement BMPT ParallelStateRoot #72

Open
Tracked by #89
frisitano opened this issue Dec 9, 2024 · 1 comment
Open
Tracked by #89

Implement BMPT ParallelStateRoot #72

frisitano opened this issue Dec 9, 2024 · 1 comment
Assignees
Milestone

Comments

@frisitano
Copy link
Collaborator

frisitano commented Dec 9, 2024

Describe the feature

Currently, we only have a StateRoot implementation for the BMPT (#36). However, in live sync mode, the engine uses a ParallelStateRoot object, which computes all storage tries in parallel. We should create a ParallelStateRoot type for the BMPT, introduce a ParallelStateRootProvider, and include it in the StateCommitment type.

Implementation

First, we should review usage of the ParallelStateRoot object within the reth codebase and implement a DatabaseParallelStateRoot trait in https://github.com/scroll-tech/reth/blob/scroll/crates/trie/db/src/state.rs. We should then introduce a ParallelStateRoot type for scroll in https://github.com/scroll-tech/reth/tree/scroll/crates/scroll/state-commitment/src/root. We should implement DatabaseParallelStateRoot on both the scroll and native ParallelStateRoot types. We should add ParallelStateRoot GAT which is bound by DatabaseParallelStateRoot in StateCommitment. We should update the concrete implementations of StateCommitment for both BMPT and MPT. We should introduce a ParallelStateRootProvider in https://github.com/scroll-tech/reth/tree/scroll/crates/storage/provider. Alternatively, it may be sufficient to add additional methods to StateRootProviderExt if we only use the ParallelStateRoot when calculating the state root for the most recent state (this should be investigated).

/// A trait that is used to compute the state root of the latest state stored in the database.
pub trait StateRootProviderExt: Send + Sync {
/// Returns the state root of the current state.
fn state_root(&self) -> ProviderResult<B256>;
/// Returns the state root of the current state and trie updates.
fn state_root_with_updates(&self) -> ProviderResult<(B256, TrieUpdates)>;
/// Returns the state root with trie updates associated with the given block range.
fn incremental_state_root_with_updates(
&self,
range: std::ops::RangeInclusive<BlockNumber>,
) -> ProviderResult<(B256, TrieUpdates)>;
/// Returns the state root progress.
fn state_root_with_progress(
&self,
state: Option<IntermediateStateRootState>,
) -> ProviderResult<StateRootProgress>;
/// Returns the state root of the current state with the provided prefix sets updated.
fn state_root_from_prefix_sets_with_updates(
&self,
prefix_set: TriePrefixSets,
) -> ProviderResult<(B256, TrieUpdates)>;
/// Returns the state root of the [`HashedPostState`] on top of the current, the trie updates
/// and the sorted hashed post state ([`HashedPostStateSorted`]).
fn state_root_from_state_with_updates_and_sorted_state(
&self,
hashed_state: HashedPostState,
) -> ProviderResult<(B256, TrieUpdates, HashedPostStateSorted)>;
}

We should replace direct instantiation and invocation of ParallelStateRoot in the codebase with invocations of the provider methods.

Additional context

No response

@frisitano frisitano added this to the Milestone 2 milestone Dec 9, 2024
@frisitano frisitano added this to Reth Dec 9, 2024
@frisitano
Copy link
Collaborator Author

@greged93 Can you explore this issue by exploring the open questions raised in the description to see what direction we should take please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants