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 moka
cache which uses TinyLFU admission and may introduce non-determinism.
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 moka 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 moka cache which uses TinyLFU admission and may introduce non-determinism in tests.
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>
Sourcepub async fn ensure_params(
&self,
key: ContractKey,
params: Parameters<'static>,
) -> Result<(), StateStoreError>
pub async fn ensure_params( &self, key: ContractKey, params: Parameters<'static>, ) -> Result<(), StateStoreError>
Persist contract parameters to the backing store, unconditionally.
This is idempotent — safe to call even if params are already stored.
Used to ensure params survive node restarts: the initial PUT path
writes params via store(), but subsequent code paths (merge, update)
go through update() which only writes state. Calling ensure_params
closes the gap where params could be lost after restart.
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>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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
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>
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>
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