Skip to content

Commit

Permalink
feat(trie): pass state reference to StateProofProvider::proof
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk committed Jul 4, 2024
1 parent 93f9a85 commit 67d4357
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 11 deletions.
7 changes: 6 additions & 1 deletion crates/revm/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ impl StateRootProvider for StateProviderTest {
}

impl StateProofProvider for StateProviderTest {
fn proof(&self, _address: Address, _slots: &[B256]) -> ProviderResult<AccountProof> {
fn proof(
&self,
_state: &BundleState,
_address: Address,
_slots: &[B256],
) -> ProviderResult<AccountProof> {
unimplemented!("proof generation is not supported")
}
}
Expand Down
5 changes: 3 additions & 2 deletions crates/rpc/rpc-eth-types/src/cache/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! <https://github.com/rust-lang/rust/issues/100013> 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;
Expand Down Expand Up @@ -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<reth_trie::AccountProof> {
self.0.proof(address, slots)
self.0.proof(state, address, slots)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ impl<SP: StateProvider, EDP: ExecutionDataProvider> StateRootProvider
impl<SP: StateProvider, EDP: ExecutionDataProvider> StateProofProvider
for BundleStateProvider<SP, EDP>
{
fn proof(&self, _address: Address, _slots: &[B256]) -> ProviderResult<AccountProof> {
fn proof(
&self,
_bundle: &BundleState,
_address: Address,
_slots: &[B256],
) -> ProviderResult<AccountProof> {
Err(ProviderError::StateRootNotAvailableForHistoricalBlock)
}
}
Expand Down
7 changes: 6 additions & 1 deletion crates/storage/provider/src/providers/state/historical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountProof> {
fn proof(
&self,
_state: &BundleState,
_address: Address,
_slots: &[B256],
) -> ProviderResult<AccountProof> {
Err(ProviderError::StateRootNotAvailableForHistoricalBlock)
}
}
Expand Down
7 changes: 6 additions & 1 deletion crates/storage/provider/src/providers/state/latest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountProof> {
fn proof(
&self,
state: &BundleState,
address: Address,
slots: &[B256],
) -> ProviderResult<AccountProof> {
Ok(Proof::from_tx(self.tx)
.account_proof(address, slots)
.map_err(Into::<reth_db::DatabaseError>::into)?)
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/provider/src/providers/state/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<reth_trie::AccountProof>;
fn proof(&self, state: &revm::db::BundleState, address: reth_primitives::Address, slots: &[reth_primitives::B256]) -> reth_storage_errors::provider::ProviderResult<reth_trie::AccountProof>;
}
);
}
Expand Down
7 changes: 6 additions & 1 deletion crates/storage/provider/src/test_utils/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,12 @@ impl StateRootProvider for MockEthProvider {
}

impl StateProofProvider for MockEthProvider {
fn proof(&self, address: Address, _slots: &[B256]) -> ProviderResult<AccountProof> {
fn proof(
&self,
_state: &BundleState,
address: Address,
_slots: &[B256],
) -> ProviderResult<AccountProof> {
Ok(AccountProof::new(address))
}
}
Expand Down
7 changes: 6 additions & 1 deletion crates/storage/provider/src/test_utils/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,12 @@ impl StateRootProvider for NoopProvider {
}

impl StateProofProvider for NoopProvider {
fn proof(&self, address: Address, _slots: &[B256]) -> ProviderResult<AccountProof> {
fn proof(
&self,
_state: &BundleState,
address: Address,
_slots: &[B256],
) -> ProviderResult<AccountProof> {
Ok(AccountProof::new(address))
}
}
Expand Down
10 changes: 8 additions & 2 deletions crates/storage/storage-api/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountProof>;
/// 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<AccountProof>;
}

0 comments on commit 67d4357

Please sign in to comment.