pub struct Storage(/* private fields */);
Expand description
A handle for a storage instance, backed by RocksDB.
The handle is cheaply clonable; all clones share the same backing data store.
Implementations§
Source§impl Storage
impl Storage
Sourcepub async fn load(path: PathBuf, default_prefixes: Vec<String>) -> Result<Self>
pub async fn load(path: PathBuf, default_prefixes: Vec<String>) -> Result<Self>
Loads a storage instance from the given path, initializing it if necessary.
Sourcepub async fn init(path: PathBuf, prefixes: Vec<String>) -> Result<Self>
pub async fn init(path: PathBuf, prefixes: Vec<String>) -> Result<Self>
Initializes a new storage instance at the given path. Takes a list of default prefixes to initialize the storage configuration with. Here is a high-level overview of the initialization process:
- Create a new RocksDB instance at the given path.
- Read the prefix list and create a [
SubstoreConfig
] for each prefix. - Create a new [
MultistoreConfig
] from supplied prefixes. - Initialize the substore cache with the latest version of each substore.
- Spawn a dispatcher task that forwards new snapshots to subscribers.
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§
Auto Trait Implementations§
impl Freeze for Storage
impl !RefUnwindSafe for Storage
impl Send for Storage
impl Sync for Storage
impl Unpin for Storage
impl !UnwindSafe for Storage
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,
§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