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: implement HistoricalStateProviderRef::proof #9327

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 0 additions & 3 deletions crates/storage/errors/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ pub enum ProviderError {
/// Thrown when we were unable to find a state for a block hash.
#[error("no state found for block {0}")]
StateForHashNotFound(B256),
/// Unable to compute state root on top of historical block.
#[error("unable to compute state root on top of historical block")]
StateRootNotAvailableForHistoricalBlock,
/// Unable to find the block number for a given transaction index.
#[error("unable to find the block number for a given transaction index")]
BlockNumberForTransactionIndexNotFound,
Expand Down
12 changes: 7 additions & 5 deletions crates/storage/provider/src/providers/bundle_state_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
};
use reth_primitives::{Account, Address, BlockNumber, Bytecode, B256};
use reth_storage_api::StateProofProvider;
use reth_storage_errors::provider::{ProviderError, ProviderResult};
use reth_storage_errors::provider::ProviderResult;
use reth_trie::{updates::TrieUpdates, AccountProof};
use revm::db::BundleState;

Expand Down Expand Up @@ -86,11 +86,13 @@ impl<SP: StateProvider, EDP: ExecutionDataProvider> StateProofProvider
{
fn proof(
&self,
_bundle: &BundleState,
_address: Address,
_slots: &[B256],
bundle_state: &BundleState,
address: Address,
slots: &[B256],
) -> ProviderResult<AccountProof> {
Err(ProviderError::StateRootNotAvailableForHistoricalBlock)
let mut state = self.block_execution_data_provider.execution_outcome().state().clone();
state.extend(bundle_state.clone());
self.state_provider.proof(&state, address, slots)
}
}

Expand Down
12 changes: 8 additions & 4 deletions crates/storage/provider/src/providers/state/historical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,15 @@ impl<'b, TX: DbTx> StateProofProvider for HistoricalStateProviderRef<'b, TX> {
/// Get account and storage proofs.
fn proof(
&self,
_state: &BundleState,
_address: Address,
_slots: &[B256],
state: &BundleState,
address: Address,
slots: &[B256],
) -> ProviderResult<AccountProof> {
Err(ProviderError::StateRootNotAvailableForHistoricalBlock)
let mut revert_state = self.revert_state()?;
revert_state.extend(HashedPostState::from_bundle_state(&state.state));
revert_state
.account_proof(self.tx, address, slots)
.map_err(|err| ProviderError::Database(err.into()))
}
}

Expand Down
Loading