From 0ad3649a5c97df019bfc9ad8e734165e40fde209 Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Fri, 5 Jul 2024 13:11:03 +0200 Subject: [PATCH 1/2] feat: implement `HistoricalStateProviderRef::proof` --- crates/storage/errors/src/provider.rs | 3 --- .../provider/src/providers/bundle_state_provider.rs | 10 ++++++---- .../provider/src/providers/state/historical.rs | 12 ++++++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/crates/storage/errors/src/provider.rs b/crates/storage/errors/src/provider.rs index 52a010474f96..db59d671fef7 100644 --- a/crates/storage/errors/src/provider.rs +++ b/crates/storage/errors/src/provider.rs @@ -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, diff --git a/crates/storage/provider/src/providers/bundle_state_provider.rs b/crates/storage/provider/src/providers/bundle_state_provider.rs index 09a6de864763..c441ec536e9e 100644 --- a/crates/storage/provider/src/providers/bundle_state_provider.rs +++ b/crates/storage/provider/src/providers/bundle_state_provider.rs @@ -86,11 +86,13 @@ impl StateProofProvider { fn proof( &self, - _bundle: &BundleState, - _address: Address, - _slots: &[B256], + bundle_state: &BundleState, + address: Address, + slots: &[B256], ) -> ProviderResult { - 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) } } diff --git a/crates/storage/provider/src/providers/state/historical.rs b/crates/storage/provider/src/providers/state/historical.rs index 87de4102fd10..c65c6ddc17ff 100644 --- a/crates/storage/provider/src/providers/state/historical.rs +++ b/crates/storage/provider/src/providers/state/historical.rs @@ -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 { - 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())) } } From b76f7a1512c284dccedceabaf488759bdd360398 Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Fri, 5 Jul 2024 13:14:32 +0200 Subject: [PATCH 2/2] rm unused import --- crates/storage/provider/src/providers/bundle_state_provider.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/storage/provider/src/providers/bundle_state_provider.rs b/crates/storage/provider/src/providers/bundle_state_provider.rs index c441ec536e9e..6e09ff389987 100644 --- a/crates/storage/provider/src/providers/bundle_state_provider.rs +++ b/crates/storage/provider/src/providers/bundle_state_provider.rs @@ -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;