From 67d43579798cd65d72876427521cc9c5c748deb5 Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Thu, 4 Jul 2024 18:01:15 +0200 Subject: [PATCH] feat(trie): pass state reference to `StateProofProvider::proof` --- crates/revm/src/test_utils.rs | 7 ++++++- crates/rpc/rpc-eth-types/src/cache/db.rs | 5 +++-- .../provider/src/providers/bundle_state_provider.rs | 7 ++++++- .../storage/provider/src/providers/state/historical.rs | 7 ++++++- crates/storage/provider/src/providers/state/latest.rs | 7 ++++++- crates/storage/provider/src/providers/state/macros.rs | 2 +- crates/storage/provider/src/test_utils/mock.rs | 7 ++++++- crates/storage/provider/src/test_utils/noop.rs | 7 ++++++- crates/storage/storage-api/src/trie.rs | 10 ++++++++-- 9 files changed, 48 insertions(+), 11 deletions(-) diff --git a/crates/revm/src/test_utils.rs b/crates/revm/src/test_utils.rs index e3cf0cedd6cf0..0459cf679ec03 100644 --- a/crates/revm/src/test_utils.rs +++ b/crates/revm/src/test_utils.rs @@ -79,7 +79,12 @@ impl StateRootProvider for StateProviderTest { } impl StateProofProvider for StateProviderTest { - fn proof(&self, _address: Address, _slots: &[B256]) -> ProviderResult { + fn proof( + &self, + _state: &BundleState, + _address: Address, + _slots: &[B256], + ) -> ProviderResult { unimplemented!("proof generation is not supported") } } diff --git a/crates/rpc/rpc-eth-types/src/cache/db.rs b/crates/rpc/rpc-eth-types/src/cache/db.rs index 82713147c1ba5..cbc5e9a48698e 100644 --- a/crates/rpc/rpc-eth-types/src/cache/db.rs +++ b/crates/rpc/rpc-eth-types/src/cache/db.rs @@ -2,7 +2,7 @@ //! in default implementation of //! `reth_rpc_eth_api::helpers::Call`. -use reth_primitives::{B256, U256}; +use reth_primitives::{Address, B256, U256}; use reth_provider::StateProvider; use reth_revm::{database::StateProviderDatabase, db::CacheDB, DatabaseRef}; use revm::Database; @@ -34,10 +34,11 @@ impl<'a> reth_provider::StateRootProvider for StateProviderTraitObjWrapper<'a> { impl<'a> reth_provider::StateProofProvider for StateProviderTraitObjWrapper<'a> { fn proof( &self, + state: &revm::db::BundleState, address: revm_primitives::Address, slots: &[B256], ) -> reth_errors::ProviderResult { - self.0.proof(address, slots) + self.0.proof(state, address, slots) } } diff --git a/crates/storage/provider/src/providers/bundle_state_provider.rs b/crates/storage/provider/src/providers/bundle_state_provider.rs index 19dbff3862ac7..09a6de8647636 100644 --- a/crates/storage/provider/src/providers/bundle_state_provider.rs +++ b/crates/storage/provider/src/providers/bundle_state_provider.rs @@ -84,7 +84,12 @@ impl StateRootProvider impl StateProofProvider for BundleStateProvider { - fn proof(&self, _address: Address, _slots: &[B256]) -> ProviderResult { + fn proof( + &self, + _bundle: &BundleState, + _address: Address, + _slots: &[B256], + ) -> ProviderResult { Err(ProviderError::StateRootNotAvailableForHistoricalBlock) } } diff --git a/crates/storage/provider/src/providers/state/historical.rs b/crates/storage/provider/src/providers/state/historical.rs index eaf134beba17c..87de4102fd107 100644 --- a/crates/storage/provider/src/providers/state/historical.rs +++ b/crates/storage/provider/src/providers/state/historical.rs @@ -274,7 +274,12 @@ impl<'b, TX: DbTx> StateRootProvider for HistoricalStateProviderRef<'b, TX> { impl<'b, TX: DbTx> StateProofProvider for HistoricalStateProviderRef<'b, TX> { /// Get account and storage proofs. - fn proof(&self, _address: Address, _slots: &[B256]) -> ProviderResult { + fn proof( + &self, + _state: &BundleState, + _address: Address, + _slots: &[B256], + ) -> ProviderResult { Err(ProviderError::StateRootNotAvailableForHistoricalBlock) } } diff --git a/crates/storage/provider/src/providers/state/latest.rs b/crates/storage/provider/src/providers/state/latest.rs index a1e8256cf17cb..2234bb42165c0 100644 --- a/crates/storage/provider/src/providers/state/latest.rs +++ b/crates/storage/provider/src/providers/state/latest.rs @@ -92,7 +92,12 @@ impl<'b, TX: DbTx> StateRootProvider for LatestStateProviderRef<'b, TX> { } impl<'b, TX: DbTx> StateProofProvider for LatestStateProviderRef<'b, TX> { - fn proof(&self, address: Address, slots: &[B256]) -> ProviderResult { + fn proof( + &self, + state: &BundleState, + address: Address, + slots: &[B256], + ) -> ProviderResult { Ok(Proof::from_tx(self.tx) .account_proof(address, slots) .map_err(Into::::into)?) diff --git a/crates/storage/provider/src/providers/state/macros.rs b/crates/storage/provider/src/providers/state/macros.rs index 2b4638894e2e7..344a21101f436 100644 --- a/crates/storage/provider/src/providers/state/macros.rs +++ b/crates/storage/provider/src/providers/state/macros.rs @@ -46,7 +46,7 @@ macro_rules! delegate_provider_impls { fn state_root_with_updates(&self, state: &revm::db::BundleState) -> reth_storage_errors::provider::ProviderResult<(reth_primitives::B256, reth_trie::updates::TrieUpdates)>; } StateProofProvider $(where [$($generics)*])? { - fn proof(&self, address: reth_primitives::Address, slots: &[reth_primitives::B256]) -> reth_storage_errors::provider::ProviderResult; + fn proof(&self, state: &revm::db::BundleState, address: reth_primitives::Address, slots: &[reth_primitives::B256]) -> reth_storage_errors::provider::ProviderResult; } ); } diff --git a/crates/storage/provider/src/test_utils/mock.rs b/crates/storage/provider/src/test_utils/mock.rs index 75543462d3416..8a9916d09c341 100644 --- a/crates/storage/provider/src/test_utils/mock.rs +++ b/crates/storage/provider/src/test_utils/mock.rs @@ -555,7 +555,12 @@ impl StateRootProvider for MockEthProvider { } impl StateProofProvider for MockEthProvider { - fn proof(&self, address: Address, _slots: &[B256]) -> ProviderResult { + fn proof( + &self, + _state: &BundleState, + address: Address, + _slots: &[B256], + ) -> ProviderResult { Ok(AccountProof::new(address)) } } diff --git a/crates/storage/provider/src/test_utils/noop.rs b/crates/storage/provider/src/test_utils/noop.rs index fcfdb826152f9..445d5666ac614 100644 --- a/crates/storage/provider/src/test_utils/noop.rs +++ b/crates/storage/provider/src/test_utils/noop.rs @@ -328,7 +328,12 @@ impl StateRootProvider for NoopProvider { } impl StateProofProvider for NoopProvider { - fn proof(&self, address: Address, _slots: &[B256]) -> ProviderResult { + fn proof( + &self, + _state: &BundleState, + address: Address, + _slots: &[B256], + ) -> ProviderResult { Ok(AccountProof::new(address)) } } diff --git a/crates/storage/storage-api/src/trie.rs b/crates/storage/storage-api/src/trie.rs index e833234c89e4e..0ab25d18ad8dd 100644 --- a/crates/storage/storage-api/src/trie.rs +++ b/crates/storage/storage-api/src/trie.rs @@ -26,6 +26,12 @@ pub trait StateRootProvider: Send + Sync { /// A type that can generate state proof on top of a given post state. #[auto_impl::auto_impl(&, Box, Arc)] pub trait StateProofProvider: Send + Sync { - /// Get account and storage proofs. - fn proof(&self, address: Address, slots: &[B256]) -> ProviderResult; + /// Get account and storage proofs of target keys in the `BundleState` + /// on top of the current state. + fn proof( + &self, + state: &BundleState, + address: Address, + slots: &[B256], + ) -> ProviderResult; }