From de0ecb036bbbeeaa927f6aeb190dbcf25fa51b7a Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 10 Feb 2023 14:07:37 +0100 Subject: [PATCH] feat: add ChainState type (#1249) --- crates/storage/provider/src/providers/mod.rs | 1 + .../provider/src/providers/state/chain.rs | 18 ++++++++++++++++++ .../provider/src/providers/state/mod.rs | 1 + crates/storage/provider/src/traits/state.rs | 2 +- 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 crates/storage/provider/src/providers/state/chain.rs diff --git a/crates/storage/provider/src/providers/mod.rs b/crates/storage/provider/src/providers/mod.rs index 0b43c7ce80..036738e157 100644 --- a/crates/storage/provider/src/providers/mod.rs +++ b/crates/storage/provider/src/providers/mod.rs @@ -10,6 +10,7 @@ use std::sync::Arc; mod state; pub use state::{ + chain::ChainState, historical::{HistoricalStateProvider, HistoricalStateProviderRef}, latest::{LatestStateProvider, LatestStateProviderRef}, }; diff --git a/crates/storage/provider/src/providers/state/chain.rs b/crates/storage/provider/src/providers/state/chain.rs new file mode 100644 index 0000000000..00f8b81376 --- /dev/null +++ b/crates/storage/provider/src/providers/state/chain.rs @@ -0,0 +1,18 @@ +use crate::StateProvider; +use std::marker::PhantomData; + +/// A type that can access the state at a specific access point (block number or tag) +/// +/// Depending on the desired access point, the state must be accessed differently. For example, the +/// "Latest" state is stored in a different location than previous blocks. And the "Pending" state +/// is accessed differently than the "Latest" state. +/// +/// This unifies [StateProvider] access when the caller does not know or care where the state is +/// being accessed from, e.g. in RPC where the requested access point may be +/// `Pending|Latest|Number|Hash`. +/// +/// Note: The lifetime of this type is limited by the type that created it. +pub struct ChainState<'a> { + _inner: Box, + _phantom: PhantomData<&'a ()>, +} diff --git a/crates/storage/provider/src/providers/state/mod.rs b/crates/storage/provider/src/providers/state/mod.rs index 596850d142..4fb69fba13 100644 --- a/crates/storage/provider/src/providers/state/mod.rs +++ b/crates/storage/provider/src/providers/state/mod.rs @@ -1,3 +1,4 @@ //! [StateProvider](crate::StateProvider) implementations +pub(crate) mod chain; pub(crate) mod historical; pub(crate) mod latest; diff --git a/crates/storage/provider/src/traits/state.rs b/crates/storage/provider/src/traits/state.rs index 6db63cfeb9..4fb2faec12 100644 --- a/crates/storage/provider/src/traits/state.rs +++ b/crates/storage/provider/src/traits/state.rs @@ -7,7 +7,7 @@ use reth_primitives::{ }; /// An abstraction for a type that provides state data. -#[auto_impl(&)] +#[auto_impl(&, Box)] pub trait StateProvider: BlockHashProvider + AccountProvider + Send + Sync { /// Get storage. fn storage(&self, account: Address, storage_key: StorageKey) -> Result>;