Skip to main content

SnapshotStore

Trait SnapshotStore 

Source
pub trait SnapshotStore<S> {
    type Error: Error;

    // Required methods
    fn load(
        &self,
        id: &BatchId,
    ) -> impl Future<Output = Result<Option<S>, Self::Error>> + Send;
    fn persist(
        &self,
        id: &BatchId,
        snapshot: S,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send;
    fn remove(
        &self,
        id: &BatchId,
    ) -> impl Future<Output = Result<bool, Self::Error>> + Send;
    fn contains(
        &self,
        id: &BatchId,
    ) -> impl Future<Output = Result<bool, Self::Error>> + Send;
}
Available on crate feature std only.
Expand description

A cache for recovered issuer snapshot state, keyed by BatchId.

Implementations persist and load the snapshot state S for a batch. The network is the source of truth for this state (see the module-level docs); a store is only a warm-path cache, so a missing entry is reported as Ok(None) rather than an error and the caller recovers from the network instead.

§Async Design

The methods are async so an implementation may sit in front of a slow backend (disk, a key-value database) without forcing callers to block.

§Example

use nectar_postage::{BatchId, SnapshotStore};

async fn warm<S, T: SnapshotStore<S>>(store: &T, id: &BatchId) -> Option<S> {
    // Try the cache; on a miss the caller would recover from the network.
    store.load(id).await.ok().flatten()
}

Required Associated Types§

Source

type Error: Error

The error type returned by store operations.

Required Methods§

Source

fn load( &self, id: &BatchId, ) -> impl Future<Output = Result<Option<S>, Self::Error>> + Send

Loads the snapshot state for id.

Returns Ok(None) on a cache miss. A miss is expected on a cold store and is not an error: the caller recovers the state from the network and may persist it afterwards. A returned value is a cached hint and must still be validated against the network before it is trusted for issuance. When S is a nectar-postage-usage snapshot the loaded value is unvalidated and carries no persist capability; it must be admitted through that crate’s network-floor check before any persist.

Source

fn persist( &self, id: &BatchId, snapshot: S, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Persists the snapshot state for id, overwriting any cached entry.

This only updates the local cache; it does not publish to the network and confers no authority on the stored value.

Source

fn remove( &self, id: &BatchId, ) -> impl Future<Output = Result<bool, Self::Error>> + Send

Removes any cached snapshot state for id.

Returns true if an entry existed and was removed. Dropping an entry is always safe: the state can be recovered from the network.

Source

fn contains( &self, id: &BatchId, ) -> impl Future<Output = Result<bool, Self::Error>> + Send

Returns whether a snapshot state is cached for id.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§