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

Introduce StateRootProviderExt and Integrate with StateCommitment #12896

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

frisitano
Copy link
Contributor

Overview

This PR introduces the StateRootProviderExt which is used for performing state root operations on the latest state stored in the database. We integrate both StateRootProvider and StateRootProviderExt with the StateRoot type from StateCommitment. This PR should be reviewed after #12895.

/// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Returns the state root of the current state and trie updates.
/// Tries to compute the state root of the current state and [`TrieUpdates`].

we appreciate well linked docs.

does this load state root saved to db "Tries to load the state root of the current state and [`TrieUpdates`]" or does it compute it "Tries to calculate the state root of the current state and [`TrieUpdates`]". this distinction tells us smthg about the cost of this method and is helpful.

/// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Returns the state root with trie updates associated with the given block range.
/// Tries to compute the state root with [`TrieUpdates`] associated with the given block range.

range: std::ops::RangeInclusive<BlockNumber>,
) -> ProviderResult<(B256, TrieUpdates)>;

/// Returns the state root progress.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Returns the state root progress.
/// Tries to compute the [`StateRootProgress`].

with this link, you spare yourself explaining here what StateRootProgress type is, since we're relying on the docs for StateRootProgress to explain this, which is accessible with a click when its linked.

state: Option<IntermediateStateRootState>,
) -> ProviderResult<StateRootProgress>;

/// Returns the state root of the current state with the provided prefix sets updated.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Returns the state root of the current state with the provided prefix sets updated.
/// Tries to compute the state root of the current state with the provided prefix sets updated ([`TrieUpdates`]).

@@ -116,13 +118,34 @@ pub trait DatabaseStateRoot<'a, TX>: Sized {
tx: &'a TX,
input: TrieInput,
) -> Result<(B256, TrieUpdates), StateRootError>;

/// Calculates the state root for the current state stored in the database.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Calculates the state root for the current state stored in the database.
/// Tries to calculate the state root for the current state stored in the database. Returns the state root hash or [`StateRootError`].

Comment on lines +125 to +126
/// Calculates the state root for the current state stored in the database and returns
/// trie updates.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Calculates the state root for the current state stored in the database and returns
/// trie updates.
/// Tries to calculate the state root for the current state stored in the database. Returns tuple of state root and corresponding [`TrieUpdates`], or [`StateRootError`].

Comment on lines +129 to +130
/// Calculates the state root for the current state stored in the database updating the paths
/// associated with the provided prefix sets and returns the trie updates.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Calculates the state root for the current state stored in the database updating the paths
/// associated with the provided prefix sets and returns the trie updates.
/// Tries to calculate the state root for the current state stored in the database, updating the paths
/// associated with the provided prefix sets. Returns tuple of state root and corresponding [`TrieUpdates`], or [`StateRootError`].

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unclear from docs how this method differs from DatabaseStateRoot::root_with_updates - "updating the paths associated with the provided prefix sets" where? it writes updates to database and DatabaseStateRoot::root_with_updates does not? does DatabaseStateRoot::root_with_updates calculate the prefix sets in its scope instead? could you pls make this clear in the docs. you could even have sentence "Unlike [`root_with_updates`](DatabaseStateRoot::root_with_updates), this method ..."

Comment on lines +136 to +137
/// Calculates the state root for the current state stored in the database and returns the
/// intermediate progress of the computation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Calculates the state root for the current state stored in the database and returns the
/// intermediate progress of the computation.
/// Tries to calculate the state root for the current state stored in the database. Returns the
/// intermediate progress ([`StateRootProgress`]) of the computation, or [`StateRootError`].

@@ -41,6 +42,33 @@ pub trait StateRootProvider: Send + Sync {
) -> ProviderResult<(B256, TrieUpdates)>;
}

/// A trait that is used to compute the state root of the latest state stored in the database.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering if ProviderError needs a new variant ProviderError::Custom(String) for this to be fully extensible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this would be useful. Shall I go ahead and include it in this PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up to core responsible for review here, scope is already big @Rjected @mattsse @shekhirin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an idea is to change the base in that case? so prs are stacked on top of each other, could speed up review process but may slow you down

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that the PR's would then target my private fork if I changed the base to the preceding PR.

@frisitano
Copy link
Contributor Author

@emhane very fair comment regarding the poor documentation of the introduced StateRootProviderExt trait. I will address this shortly.

@frisitano
Copy link
Contributor Author

@emhane I've update the doc comments, please let me know what you think.

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

Successfully merging this pull request may close these issues.

2 participants