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;
}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§
Required Methods§
Sourcefn load(
&self,
id: &BatchId,
) -> impl Future<Output = Result<Option<S>, Self::Error>> + Send
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.
Sourcefn persist(
&self,
id: &BatchId,
snapshot: S,
) -> impl Future<Output = Result<(), Self::Error>> + Send
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".