pub struct StateDB { /* private fields */ }
Expand description
A typed wrapper around the db for storing rollup state. Internally,
this is roughly just an Arc<SchemaDB>
.
StateDB implements several convenience functions for state storage -
notably the TreeReader
and TreeWriter
traits.
Implementations§
Source§impl StateDB
impl StateDB
Sourcepub fn with_path(path: impl AsRef<Path>) -> Result<Self, Error>
pub fn with_path(path: impl AsRef<Path>) -> Result<Self, Error>
Open a StateDB
(backed by RocksDB) at the specified path.
The returned instance will be at the path {path}/state-db
.
Sourcepub fn put_preimage(
&self,
key_hash: KeyHash,
key: &Vec<u8>,
) -> Result<(), Error>
pub fn put_preimage( &self, key_hash: KeyHash, key: &Vec<u8>, ) -> Result<(), Error>
Put the preimage of a hashed key into the database. Note that the preimage is not checked for correctness, since the DB is unaware of the hash function used by the JMT.
Sourcepub fn get_value_option_by_key(
&self,
version: Version,
key: &Vec<u8>,
) -> Result<Option<OwnedValue>>
pub fn get_value_option_by_key( &self, version: Version, key: &Vec<u8>, ) -> Result<Option<OwnedValue>>
Get an optional value from the database, given a version and a key hash.
Sourcepub fn inc_next_version(&self)
pub fn inc_next_version(&self)
Increment the next_version
counter by 1.
Sourcepub fn get_next_version(&self) -> Version
pub fn get_next_version(&self) -> Version
Get the current value of the next_version
counter
Trait Implementations§
Source§impl TreeReader for StateDB
impl TreeReader for StateDB
Source§fn get_node_option(&self, node_key: &NodeKey) -> Result<Option<Node>>
fn get_node_option(&self, node_key: &NodeKey) -> Result<Option<Node>>
Gets node given a node key. Returns
None
if the node does not exist.Source§fn get_value_option(
&self,
version: Version,
key_hash: KeyHash,
) -> Result<Option<OwnedValue>>
fn get_value_option( &self, version: Version, key_hash: KeyHash, ) -> Result<Option<OwnedValue>>
Gets a value by identifier, returning the newest value whose version is less than or
equal to the specified version. Returns None if the value does not exist.
Source§fn get_rightmost_leaf(&self) -> Result<Option<(NodeKey, LeafNode)>>
fn get_rightmost_leaf(&self) -> Result<Option<(NodeKey, LeafNode)>>
Gets the rightmost leaf. Note that this assumes we are in the process of restoring the tree
and all nodes are at the same version.
Source§impl TreeWriter for StateDB
impl TreeWriter for StateDB
Auto Trait Implementations§
impl Freeze for StateDB
impl RefUnwindSafe for StateDB
impl Send for StateDB
impl Sync for StateDB
impl Unpin for StateDB
impl UnwindSafe for StateDB
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
Converts
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>
Converts
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 more