pub struct Db<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, S: State<DigestOf<H>> = Clean<DigestOf<H>>> { /* private fields */ }Expand description
A key-value QMDB based on an MMR over its log of operations, supporting authentication of whether a key ever had a specific value, and whether the key currently has that value.
Note: The generic parameter N is not really generic, and must be manually set to double the size of the hash digest being produced by the hasher. A compile-time assertion is used to prevent any other setting.
Implementations§
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, S: State<DigestOf<H>>> Db<E, K, V, H, T, N, S>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, S: State<DigestOf<H>>> Db<E, K, V, H, T, N, S>
Sourcepub fn op_count(&self) -> Location
pub fn op_count(&self) -> Location
The number of operations that have been applied to this db, including those that have been pruned and those that are not yet committed.
Sourcepub const fn inactivity_floor_loc(&self) -> Location
pub const fn inactivity_floor_loc(&self) -> Location
Return the inactivity floor location. This is the location before which all operations are known to be inactive. Operations before this point can be safely pruned.
Sourcepub async fn get(&self, key: &K) -> Result<Option<V>, Error>
pub async fn get(&self, key: &K) -> Result<Option<V>, Error>
Get the value of key in the db, or None if it has no value.
Sourcepub async fn get_metadata(&self) -> Result<Option<V>, Error>
pub async fn get_metadata(&self) -> Result<Option<V>, Error>
Get the metadata associated with the last commit.
Sourcepub fn verify_key_value_proof(
hasher: &mut H,
key: K,
value: V,
proof: &KeyValueProof<H::Digest, N>,
root: &H::Digest,
) -> bool
pub fn verify_key_value_proof( hasher: &mut H, key: K, value: V, proof: &KeyValueProof<H::Digest, N>, root: &H::Digest, ) -> bool
Return true if the proof authenticates that key currently has value value in the db with
the provided root.
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> Db<E, K, V, H, T, N>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> Db<E, K, V, H, T, N>
Sourcepub async fn init(context: E, config: Config<T>) -> Result<Self, Error>
pub async fn init(context: E, config: Config<T>) -> Result<Self, Error>
Initializes a Db authenticated database from the given config. Leverages parallel
Merkleization to initialize the bitmap MMR if a thread pool is provided.
Sourcepub async fn range_proof(
&self,
hasher: &mut H,
start_loc: Location,
max_ops: NonZeroU64,
) -> Result<(RangeProof<H::Digest>, Vec<Operation<K, V>>, Vec<[u8; N]>), Error>
pub async fn range_proof( &self, hasher: &mut H, start_loc: Location, max_ops: NonZeroU64, ) -> Result<(RangeProof<H::Digest>, Vec<Operation<K, V>>, Vec<[u8; N]>), Error>
Returns a proof that the specified range of operations are part of the database, along with the operations from the range. A truncated range (from hitting the max) can be detected by looking at the length of the returned operations vector. Also returns the bitmap chunks required to verify the proof.
§Errors
Returns crate::mmr::Error::LocationOverflow if start_loc > crate::mmr::MAX_LOCATION.
Returns crate::mmr::Error::RangeOutOfBounds if start_loc >= number of leaves in the MMR.
Sourcepub async fn key_value_proof(
&self,
hasher: &mut H,
key: K,
) -> Result<KeyValueProof<H::Digest, N>, Error>
pub async fn key_value_proof( &self, hasher: &mut H, key: K, ) -> Result<KeyValueProof<H::Digest, N>, Error>
Generate and return a proof of the current value of key, along with the other
KeyValueProof required to verify the proof. Returns KeyNotFound error if the key is not
currently assigned any value.
§Errors
Returns Error::KeyNotFound if the key is not currently assigned any value.
Sourcepub async fn commit(
&mut self,
metadata: Option<V>,
) -> Result<Range<Location>, Error>
pub async fn commit( &mut self, metadata: Option<V>, ) -> Result<Range<Location>, Error>
Commit any pending operations to the database, ensuring their durability upon return from
this function. Also raises the inactivity floor according to the schedule. Returns the
(start_loc, end_loc] location range of committed operations.
Sourcepub async fn prune(&mut self, prune_loc: Location) -> Result<(), Error>
pub async fn prune(&mut self, prune_loc: Location) -> Result<(), Error>
Prune historical operations prior to prune_loc. This does not affect the db’s root
or current snapshot.
Sourcepub async fn close(self) -> Result<(), Error>
pub async fn close(self) -> Result<(), Error>
Close the db. Operations that have not been committed will be lost or rolled back on restart.
Sourcepub fn into_dirty(self) -> Db<E, K, V, H, T, N, Dirty>
pub fn into_dirty(self) -> Db<E, K, V, H, T, N, Dirty>
Convert this clean database into its dirty counterpart for performing mutations.
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> Db<E, K, V, H, T, N, Dirty>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> Db<E, K, V, H, T, N, Dirty>
Sourcepub async fn update(&mut self, key: K, value: V) -> Result<(), Error>
pub async fn update(&mut self, key: K, value: V) -> Result<(), Error>
Updates key to have value value. The operation is reflected in the snapshot, but will be
subject to rollback until the next successful commit.
Sourcepub async fn create(&mut self, key: K, value: V) -> Result<bool, Error>
pub async fn create(&mut self, key: K, value: V) -> Result<bool, Error>
Creates a new key-value pair in the db. The operation is reflected in the snapshot, but will
be subject to rollback until the next successful commit. Returns true if the key was
created, false if it already existed.
Sourcepub async fn delete(&mut self, key: K) -> Result<bool, Error>
pub async fn delete(&mut self, key: K) -> Result<bool, Error>
Delete key and its value from the db. Deleting a key that already has no value is a no-op.
The operation is reflected in the snapshot, but will be subject to rollback until the next
successful commit. Returns true if the key was deleted, false if it was already inactive.
Sourcepub async fn merkleize(
self,
) -> Result<Db<E, K, V, H, T, N, Clean<DigestOf<H>>>, Error>
pub async fn merkleize( self, ) -> Result<Db<E, K, V, H, T, N, Clean<DigestOf<H>>>, Error>
Merkleize the bitmap and convert this dirty database into its clean counterpart.
This computes the Merkle tree over any new bitmap entries but does NOT persist
changes to storage. Use commit() for durable state transitions.
Trait Implementations§
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> CleanAny for Db<E, K, V, H, T, N, Clean<DigestOf<H>>>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> CleanAny for Db<E, K, V, H, T, N, Clean<DigestOf<H>>>
Source§async fn get(&self, key: &Self::Key) -> Result<Option<Self::Value>, Error>
async fn get(&self, key: &Self::Key) -> Result<Option<Self::Value>, Error>
Source§async fn commit(
&mut self,
metadata: Option<Self::Value>,
) -> Result<Range<Location>, Error>
async fn commit( &mut self, metadata: Option<Self::Value>, ) -> Result<Range<Location>, Error>
Source§async fn prune(&mut self, prune_loc: Location) -> Result<(), Error>
async fn prune(&mut self, prune_loc: Location) -> Result<(), Error>
prune_loc.Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> CleanStore for Db<E, K, V, H, T, N, Clean<DigestOf<H>>>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> CleanStore for Db<E, K, V, H, T, N, Clean<DigestOf<H>>>
Source§type Operation = Operation<K, FixedEncoding<V>, Update<K, FixedEncoding<V>>>
type Operation = Operation<K, FixedEncoding<V>, Update<K, FixedEncoding<V>>>
Source§type Dirty = Db<E, K, V, H, T, N, Dirty>
type Dirty = Db<E, K, V, H, T, N, Dirty>
Source§async fn proof(
&self,
start_loc: Location,
max_ops: NonZeroU64,
) -> Result<(Proof<Self::Digest>, Vec<Self::Operation>), Error>
async fn proof( &self, start_loc: Location, max_ops: NonZeroU64, ) -> Result<(Proof<Self::Digest>, Vec<Self::Operation>), Error>
Source§async fn historical_proof(
&self,
historical_size: Location,
start_loc: Location,
max_ops: NonZeroU64,
) -> Result<(Proof<Self::Digest>, Vec<Self::Operation>), Error>
async fn historical_proof( &self, historical_size: Location, start_loc: Location, max_ops: NonZeroU64, ) -> Result<(Proof<Self::Digest>, Vec<Self::Operation>), Error>
Source§fn into_dirty(self) -> Self::Dirty
fn into_dirty(self) -> Self::Dirty
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> DirtyAny for Db<E, K, V, H, T, N, Dirty>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> DirtyAny for Db<E, K, V, H, T, N, Dirty>
Source§async fn get(&self, key: &Self::Key) -> Result<Option<Self::Value>, Error>
async fn get(&self, key: &Self::Key) -> Result<Option<Self::Value>, Error>
Source§async fn update(
&mut self,
key: Self::Key,
value: Self::Value,
) -> Result<(), Error>
async fn update( &mut self, key: Self::Key, value: Self::Value, ) -> Result<(), Error>
key to have value value. Subject to rollback until next commit.Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> DirtyStore for Db<E, K, V, H, T, N, Dirty>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> DirtyStore for Db<E, K, V, H, T, N, Dirty>
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, S: State<DigestOf<H>>> LogStore for Db<E, K, V, H, T, N, S>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, S: State<DigestOf<H>>> LogStore for Db<E, K, V, H, T, N, S>
type Value = V
Source§fn op_count(&self) -> Location
fn op_count(&self) -> Location
Source§fn inactivity_floor_loc(&self) -> Location
fn inactivity_floor_loc(&self) -> Location
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> LogStorePrunable for Db<E, K, V, H, T, N>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> LogStorePrunable for Db<E, K, V, H, T, N>
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, S: State<DigestOf<H>>> Store for Db<E, K, V, H, T, N, S>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, S: State<DigestOf<H>>> Store for Db<E, K, V, H, T, N, S>
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> StoreDeletable for Db<E, K, V, H, T, N, Dirty>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> StoreDeletable for Db<E, K, V, H, T, N, Dirty>
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> StoreMut for Db<E, K, V, H, T, N, Dirty>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> StoreMut for Db<E, K, V, H, T, N, Dirty>
Source§async fn update(
&mut self,
key: Self::Key,
value: Self::Value,
) -> Result<(), Self::Error>
async fn update( &mut self, key: Self::Key, value: Self::Value, ) -> Result<(), Self::Error>
Auto Trait Implementations§
impl<E, K, V, H, T, const N: usize, S> Freeze for Db<E, K, V, H, T, N, S>
impl<E, K, V, H, T, const N: usize, S = Clean<<H as Hasher>::Digest>> !RefUnwindSafe for Db<E, K, V, H, T, N, S>
impl<E, K, V, H, T, const N: usize, S> Send for Db<E, K, V, H, T, N, S>
impl<E, K, V, H, T, const N: usize, S> Sync for Db<E, K, V, H, T, N, S>
impl<E, K, V, H, T, const N: usize, S> Unpin for Db<E, K, V, H, T, N, S>
impl<E, K, V, H, T, const N: usize, S = Clean<<H as Hasher>::Digest>> !UnwindSafe for Db<E, K, V, H, T, N, S>
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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>
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 more