diff --git a/crates/katana/storage/provider/src/lib.rs b/crates/katana/storage/provider/src/lib.rs index c14e408af3..667ff1b0e9 100644 --- a/crates/katana/storage/provider/src/lib.rs +++ b/crates/katana/storage/provider/src/lib.rs @@ -6,7 +6,7 @@ use katana_primitives::block::{ SealedBlockWithStatus, }; use katana_primitives::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; -use katana_primitives::contract::{ContractAddress, GenericContractInfo, StorageKey, StorageValue}; +use katana_primitives::contract::{ContractAddress, StorageKey, StorageValue}; use katana_primitives::env::BlockEnv; use katana_primitives::receipt::Receipt; use katana_primitives::state::{StateUpdates, StateUpdatesWithDeclaredClasses}; @@ -24,7 +24,6 @@ pub mod providers; pub mod traits; use crate::traits::block::{BlockHashProvider, BlockNumberProvider, BlockProvider, HeaderProvider}; -use crate::traits::contract::ContractInfoProvider; use crate::traits::state::{StateFactoryProvider, StateProvider}; use crate::traits::state_update::StateUpdateProvider; use crate::traits::transaction::{ReceiptProvider, TransactionProvider, TransactionsProviderExt}; @@ -298,15 +297,6 @@ where } } -impl ContractInfoProvider for BlockchainProvider -where - Db: ContractInfoProvider, -{ - fn contract(&self, address: ContractAddress) -> ProviderResult> { - self.provider.contract(address) - } -} - impl StateRootProvider for BlockchainProvider where Db: StateRootProvider, diff --git a/crates/katana/storage/provider/src/providers/fork/backend.rs b/crates/katana/storage/provider/src/providers/fork/backend.rs index a19e923946..657279bde0 100644 --- a/crates/katana/storage/provider/src/providers/fork/backend.rs +++ b/crates/katana/storage/provider/src/providers/fork/backend.rs @@ -11,9 +11,7 @@ use futures::stream::Stream; use futures::{Future, FutureExt}; use katana_primitives::block::BlockHashOrNumber; use katana_primitives::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; -use katana_primitives::contract::{ - ContractAddress, GenericContractInfo, Nonce, StorageKey, StorageValue, -}; +use katana_primitives::contract::{ContractAddress, Nonce, StorageKey, StorageValue}; use katana_primitives::conversion::rpc::{ compiled_class_hash_from_flattened_sierra_class, flattened_sierra_to_compiled_class, legacy_rpc_to_compiled_class, @@ -27,7 +25,7 @@ use tracing::{error, trace}; use crate::error::ProviderError; use crate::providers::in_memory::cache::CacheStateDb; -use crate::traits::contract::{ContractClassProvider, ContractInfoProvider}; +use crate::traits::contract::ContractClassProvider; use crate::traits::state::StateProvider; use crate::ProviderResult; @@ -344,13 +342,6 @@ impl SharedStateProvider { } } -impl ContractInfoProvider for SharedStateProvider { - fn contract(&self, address: ContractAddress) -> ProviderResult> { - let info = self.0.contract_state.read().get(&address).cloned(); - Ok(info) - } -} - impl StateProvider for SharedStateProvider { fn nonce(&self, address: ContractAddress) -> ProviderResult> { // TEMP: @@ -369,8 +360,13 @@ impl StateProvider for SharedStateProvider { // // Similar story with `class_hash_of_contract` // - if let nonce @ Some(_) = - self.contract(address)?.map(|i| i.nonce).filter(|n| n != &Nonce::ZERO) + if let nonce @ Some(_) = self + .0 + .contract_state + .read() + .get(&address) + .map(|i| i.nonce) + .filter(|n| n != &Nonce::ZERO) { return Ok(nonce); } @@ -432,8 +428,13 @@ impl StateProvider for SharedStateProvider { address: ContractAddress, ) -> ProviderResult> { // See comment at `nonce` for the explanation of this filter. - if let hash @ Some(_) = - self.contract(address)?.map(|i| i.class_hash).filter(|h| h != &ClassHash::ZERO) + if let hash @ Some(_) = self + .0 + .contract_state + .read() + .get(&address) + .map(|i| i.class_hash) + .filter(|h| h != &ClassHash::ZERO) { return Ok(hash); } diff --git a/crates/katana/storage/provider/src/providers/fork/state.rs b/crates/katana/storage/provider/src/providers/fork/state.rs index e265388b02..fb69c6f9d2 100644 --- a/crates/katana/storage/provider/src/providers/fork/state.rs +++ b/crates/katana/storage/provider/src/providers/fork/state.rs @@ -1,14 +1,12 @@ use std::sync::Arc; use katana_primitives::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; -use katana_primitives::contract::{ - ContractAddress, GenericContractInfo, Nonce, StorageKey, StorageValue, -}; +use katana_primitives::contract::{ContractAddress, Nonce, StorageKey, StorageValue}; use super::backend::SharedStateProvider; use crate::providers::in_memory::cache::CacheStateDb; use crate::providers::in_memory::state::StateSnapshot; -use crate::traits::contract::{ContractClassProvider, ContractInfoProvider}; +use crate::traits::contract::ContractClassProvider; use crate::traits::state::StateProvider; use crate::ProviderResult; @@ -24,15 +22,6 @@ impl ForkedStateDb { } } -impl ContractInfoProvider for ForkedStateDb { - fn contract(&self, address: ContractAddress) -> ProviderResult> { - if let info @ Some(_) = self.contract_state.read().get(&address).cloned() { - return Ok(info); - } - ContractInfoProvider::contract(&self.db, address) - } -} - impl StateProvider for ForkedStateDb { fn class_hash_of_contract( &self, @@ -101,12 +90,6 @@ impl ContractClassProvider for CacheStateDb { pub(super) struct LatestStateProvider(pub(super) Arc); -impl ContractInfoProvider for LatestStateProvider { - fn contract(&self, address: ContractAddress) -> ProviderResult> { - ContractInfoProvider::contract(&self.0, address) - } -} - impl StateProvider for LatestStateProvider { fn nonce(&self, address: ContractAddress) -> ProviderResult> { StateProvider::nonce(&self.0, address) @@ -145,15 +128,6 @@ impl ContractClassProvider for LatestStateProvider { } } -impl ContractInfoProvider for ForkedSnapshot { - fn contract(&self, address: ContractAddress) -> ProviderResult> { - if let info @ Some(_) = self.inner.contract_state.get(&address).cloned() { - return Ok(info); - } - ContractInfoProvider::contract(&self.inner.db, address) - } -} - impl StateProvider for ForkedSnapshot { fn nonce(&self, address: ContractAddress) -> ProviderResult> { if let nonce @ Some(_) = self diff --git a/crates/katana/storage/provider/src/providers/in_memory/state.rs b/crates/katana/storage/provider/src/providers/in_memory/state.rs index a481d7c21f..c50c254f2d 100644 --- a/crates/katana/storage/provider/src/providers/in_memory/state.rs +++ b/crates/katana/storage/provider/src/providers/in_memory/state.rs @@ -3,12 +3,10 @@ use std::sync::Arc; use katana_primitives::block::BlockNumber; use katana_primitives::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; -use katana_primitives::contract::{ - ContractAddress, GenericContractInfo, Nonce, StorageKey, StorageValue, -}; +use katana_primitives::contract::{ContractAddress, Nonce, StorageKey, StorageValue}; use super::cache::{CacheSnapshotWithoutClasses, CacheStateDb, SharedContractClasses}; -use crate::traits::contract::{ContractClassProvider, ContractInfoProvider}; +use crate::traits::contract::ContractClassProvider; use crate::traits::state::StateProvider; use crate::ProviderResult; @@ -117,16 +115,9 @@ impl InMemoryStateDb { } } -impl ContractInfoProvider for InMemorySnapshot { - fn contract(&self, address: ContractAddress) -> ProviderResult> { - let info = self.inner.contract_state.get(&address).cloned(); - Ok(info) - } -} - impl StateProvider for InMemorySnapshot { fn nonce(&self, address: ContractAddress) -> ProviderResult> { - let nonce = ContractInfoProvider::contract(&self, address)?.map(|i| i.nonce); + let nonce = self.inner.contract_state.get(&address).map(|i| i.nonce); Ok(nonce) } @@ -143,7 +134,7 @@ impl StateProvider for InMemorySnapshot { &self, address: ContractAddress, ) -> ProviderResult> { - let class_hash = ContractInfoProvider::contract(&self, address)?.map(|i| i.class_hash); + let class_hash = self.inner.contract_state.get(&address).map(|i| i.class_hash); Ok(class_hash) } } @@ -176,16 +167,9 @@ impl ContractClassProvider for InMemorySnapshot { pub(super) struct LatestStateProvider(pub(super) Arc); -impl ContractInfoProvider for LatestStateProvider { - fn contract(&self, address: ContractAddress) -> ProviderResult> { - let info = self.0.contract_state.read().get(&address).cloned(); - Ok(info) - } -} - impl StateProvider for LatestStateProvider { fn nonce(&self, address: ContractAddress) -> ProviderResult> { - let nonce = ContractInfoProvider::contract(&self, address)?.map(|i| i.nonce); + let nonce = self.0.contract_state.read().get(&address).map(|i| i.nonce); Ok(nonce) } @@ -202,7 +186,7 @@ impl StateProvider for LatestStateProvider { &self, address: ContractAddress, ) -> ProviderResult> { - let class_hash = ContractInfoProvider::contract(&self, address)?.map(|i| i.class_hash); + let class_hash = self.0.contract_state.read().get(&address).map(|i| i.class_hash); Ok(class_hash) } } diff --git a/crates/katana/storage/provider/src/traits/contract.rs b/crates/katana/storage/provider/src/traits/contract.rs index 7ff77f1999..8ad2d5c700 100644 --- a/crates/katana/storage/provider/src/traits/contract.rs +++ b/crates/katana/storage/provider/src/traits/contract.rs @@ -1,14 +1,7 @@ use katana_primitives::class::{ClassHash, CompiledClass, CompiledClassHash, FlattenedSierraClass}; -use katana_primitives::contract::{ContractAddress, GenericContractInfo}; use crate::ProviderResult; -#[auto_impl::auto_impl(&, Box, Arc)] -pub trait ContractInfoProvider: Send + Sync { - /// Returns the contract information given its address. - fn contract(&self, address: ContractAddress) -> ProviderResult>; -} - /// A provider trait for retrieving contract class related information. #[auto_impl::auto_impl(&, Box, Arc)] pub trait ContractClassProvider: Send + Sync {