feat: add ChainState type (#1249)

This commit is contained in:
Matthias Seitz
2023-02-10 14:07:37 +01:00
committed by GitHub
parent 9a4df50a92
commit de0ecb036b
4 changed files with 21 additions and 1 deletions

View File

@ -10,6 +10,7 @@ use std::sync::Arc;
mod state;
pub use state::{
chain::ChainState,
historical::{HistoricalStateProvider, HistoricalStateProviderRef},
latest::{LatestStateProvider, LatestStateProviderRef},
};

View File

@ -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<dyn StateProvider>,
_phantom: PhantomData<&'a ()>,
}

View File

@ -1,3 +1,4 @@
//! [StateProvider](crate::StateProvider) implementations
pub(crate) mod chain;
pub(crate) mod historical;
pub(crate) mod latest;

View File

@ -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<Option<StorageValue>>;