pub trait SnapshotStore<S> {
type Error: Error;
// Required methods
fn load(&self, id: &BatchId) -> Result<Option<S>, Self::Error>;
fn persist(&self, id: &BatchId, snapshot: S) -> Result<(), Self::Error>;
fn remove(&self, id: &BatchId) -> Result<bool, Self::Error>;
fn contains(&self, id: &BatchId) -> Result<bool, Self::Error>;
}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.
§Synchronous Design
The methods are synchronous. The known cache backends (in memory, a
key-value database such as redb) are themselves synchronous, so there is no
genuinely async work to drive here; any async behaviour belongs at the true
edges where it is added by the edge, not by this cache. Keeping the trait
synchronous avoids colouring callers with async and keeps it object-safe.
§Example
use nectar_postage::{BatchId, SnapshotStore};
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).ok().flatten()
}Required Associated Types§
Required Methods§
Sourcefn load(&self, id: &BatchId) -> Result<Option<S>, Self::Error>
fn load(&self, id: &BatchId) -> Result<Option<S>, Self::Error>
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) -> Result<(), Self::Error>
fn persist(&self, id: &BatchId, snapshot: S) -> Result<(), Self::Error>
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 dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".