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 HashedStorageProvider #11874

Closed

Conversation

frisitano
Copy link
Contributor

Dependencies

This PR builds on #11872 and should be reviewed after #11872 is merged

Overview

We need to make the HashedStorage generic over the KeyHasher such that we can instantiate HashedStorage with different key hashing algorithms. We modify HashedStorage::from_plain_storage and introduce HashedStorage::from_bundle_account (for convenience) such that we have the following signatures:

HashedStorage::from_plain_storage<'a, KH: KeyHasher>(status: AccountStatus, storage: impl IntoIterator<Item = (&'a U256, &'a U256)>,) -> Self;
HashedStorage::from_bundle_account<KH: KeyHasher>(account: &BundleAccount) -> Self;

The BundleStateProvider needs to invoke this method as seen below:

impl<SP: StateProvider, EDP: ExecutionDataProvider> BundleStateProvider<SP, EDP> {
/// Create new bundle state provider
pub const fn new(state_provider: SP, block_execution_data_provider: EDP) -> Self {
Self { state_provider, block_execution_data_provider }
}
/// Retrieve hashed storage for target address.
fn get_hashed_storage(&self, address: Address) -> HashedStorage {
let bundle_state = self.block_execution_data_provider.execution_outcome().state();
bundle_state
.account(&address)
.map(|account| {
HashedStorage::from_plain_storage(
account.status,
account.storage.iter().map(|(slot, value)| (slot, &value.present_value)),
)
})
.unwrap_or_default()
}
}

Therefore we either need to make the StateCommitment type available in BundleStateProvider by the introduction of an additional generic and PhantonData marker or alternatively introduce a HashedStorageProvider trait and add it to the StateProvider supertrait such that we can leverage the StateProvider that the BundleStateProvider has to create the HashedStorage object. This PR takes the latter approach but I would seek guidance from maintainers on what is the preferred approach.

supports: #11830

@Rjected Rjected added C-enhancement New feature or request A-trie Related to Merkle Patricia Trie implementation A-sdk Related to reth's use as a library labels Oct 30, 2024
@mattsse mattsse requested a review from klkvr as a code owner November 23, 2024 04:53
@frisitano
Copy link
Contributor Author

superseded by #12894

@frisitano frisitano closed this Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sdk Related to reth's use as a library A-trie Related to Merkle Patricia Trie implementation C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants