pub struct TempStorage { /* private fields */ }
Expand description
A Storage
instance backed by a tempfile::TempDir
for testing.
The TempDir
handle is bundled into the TempStorage
, so the temporary
directory is cleaned up when the TempStorage
instance is dropped.
Implementations§
Methods from Deref<Target = Storage>§
Sourcepub fn latest_version(&self) -> Version
pub fn latest_version(&self) -> Version
Returns the latest version (block height) of the tree recorded by the
Storage
.
If the tree is empty and has not been initialized, returns u64::MAX
.
Sourcepub fn subscribe(&self) -> Receiver<Snapshot>
pub fn subscribe(&self) -> Receiver<Snapshot>
Returns a [watch::Receiver
] that can be used to subscribe to new state versions.
Sourcepub fn subscribe_changes(&self) -> Receiver<(Version, Arc<Cache>)>
pub fn subscribe_changes(&self) -> Receiver<(Version, Arc<Cache>)>
Returns a [watch::Receiver
] that can be used to subscribe to state changes.
Sourcepub fn latest_snapshot(&self) -> Snapshot
pub fn latest_snapshot(&self) -> Snapshot
Returns a new Snapshot
on top of the latest version of the tree.
Sourcepub fn snapshot(&self, version: Version) -> Option<Snapshot>
pub fn snapshot(&self, version: Version) -> Option<Snapshot>
Fetches the Snapshot
corresponding to the supplied jmt::Version
from
the [SnapshotCache
]. Returns None
if no match was found.
Sourcepub async fn prepare_commit(
&self,
delta: StateDelta<Snapshot>,
) -> Result<StagedWriteBatch>
pub async fn prepare_commit( &self, delta: StateDelta<Snapshot>, ) -> Result<StagedWriteBatch>
Prepares a commit for the provided StateDelta
, returning a StagedWriteBatch
.
The batch can be committed to the database using the Storage::commit_batch
method.
Sourcepub async fn commit(&self, delta: StateDelta<Snapshot>) -> Result<RootHash>
pub async fn commit(&self, delta: StateDelta<Snapshot>) -> Result<RootHash>
Commits the provided StateDelta
to persistent storage as the latest
version of the chain state.
Sourcepub fn commit_batch(&self, batch: StagedWriteBatch) -> Result<RootHash>
pub fn commit_batch(&self, batch: StagedWriteBatch) -> Result<RootHash>
Commits the supplied StagedWriteBatch
to persistent storage.
§Migrations
In the case of chain state migrations we need to commit the new state
without incrementing the version. If perform_migration
is true
the
snapshot will not be written to the snapshot cache, and no subscribers
will be notified. Substore versions will not be updated.
Sourcepub async fn commit_in_place(
&self,
delta: StateDelta<Snapshot>,
) -> Result<RootHash>
Available on crate feature migration
only.
pub async fn commit_in_place( &self, delta: StateDelta<Snapshot>, ) -> Result<RootHash>
migration
only.Commit the provided StateDelta
to persistent storage without increasing the version
of the chain state, and skips the snapshot cache update.
Trait Implementations§
Source§impl AsRef<Storage> for TempStorage
impl AsRef<Storage> for TempStorage
Auto Trait Implementations§
impl Freeze for TempStorage
impl !RefUnwindSafe for TempStorage
impl Send for TempStorage
impl Sync for TempStorage
impl Unpin for TempStorage
impl !UnwindSafe for TempStorage
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request