pub struct StateStore<S: StateStorage> { /* private fields */ }Expand description
StateStore wraps a persistent storage backend with an optional in-memory cache.
It is Clone when the underlying storage S is Clone (e.g., ReDb with Arc
For deterministic simulation testing, use new_uncached() to bypass the stretto
cache which has non-deterministic TinyLFU admission policy and background workers.
Implementations§
Source§impl<S> StateStore<S>
impl<S> StateStore<S>
Sourcepub fn new(store: S, max_size: u32) -> Result<Self, StateStoreError>
pub fn new(store: S, max_size: u32) -> Result<Self, StateStoreError>
Create a StateStore with stretto caching enabled.
§Arguments
- max_size: max number of bytes for the mem cache
Sourcepub fn new_uncached(store: S) -> Self
pub fn new_uncached(store: S) -> Self
Create a StateStore without caching for deterministic simulation.
This bypasses the stretto AsyncCache which has non-deterministic behavior:
- TinyLFU admission policy can reject inserts non-deterministically
- Background workers for cache eviction and write batching
Use this constructor for deterministic simulation testing under turmoil.
pub async fn update( &mut self, key: &ContractKey, state: WrappedState, ) -> Result<(), StateStoreError>
pub async fn store( &mut self, key: ContractKey, state: WrappedState, params: Parameters<'static>, ) -> Result<(), StateStoreError>
pub async fn get( &self, key: &ContractKey, ) -> Result<WrappedState, StateStoreError>
pub async fn get_params<'a>( &'a self, key: &'a ContractKey, ) -> Result<Option<Parameters<'static>>, StateStoreError>
Trait Implementations§
Source§impl<S: Clone + StateStorage> Clone for StateStore<S>
impl<S: Clone + StateStorage> Clone for StateStore<S>
Source§fn clone(&self) -> StateStore<S>
fn clone(&self) -> StateStore<S>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<S> Freeze for StateStore<S>where
S: Freeze,
impl<S> !RefUnwindSafe for StateStore<S>
impl<S> Send for StateStore<S>where
S: Send,
impl<S> Sync for StateStore<S>where
S: Sync,
impl<S> Unpin for StateStore<S>where
S: Unpin,
impl<S> UnsafeUnpin for StateStore<S>where
S: UnsafeUnpin,
impl<S> !UnwindSafe for StateStore<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more