Skip to content

Commit

Permalink
feat: implement HistoricalStateProviderRef::proof (paradigmxyz#9327)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk authored Jul 5, 2024
1 parent 3b29ed7 commit c13af1e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
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

0 comments on commit c13af1e

Please sign in to comment.