pub struct Db<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, M: MerkleizationState<DigestOf<H>> = Merkleized<H>, D: DurabilityState = Durable> { /* private fields */ }Expand description
A key-value QMDB based on an MMR over its log of operations, supporting key exclusion proofs and authentication of whether a currently has a specific 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, M: MerkleizationState<DigestOf<H>>, D: DurabilityState> Db<E, K, V, H, T, N, M, D>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, M: MerkleizationState<DigestOf<H>>, D: DurabilityState> Db<E, K, V, H, T, N, M, D>
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<K, H::Digest, N>,
root: &H::Digest,
) -> bool
pub fn verify_key_value_proof( hasher: &mut H, key: K, value: V, proof: &KeyValueProof<K, 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.
Sourcepub async fn get_span(
&self,
key: &K,
) -> Result<Option<(Location, Update<K, V>)>, Error>
pub async fn get_span( &self, key: &K, ) -> Result<Option<(Location, Update<K, V>)>, Error>
Get the operation that currently defines the span whose range contains key, or None if the
DB is empty.
Sourcepub async fn stream_range<'a>(
&'a self,
start: K,
) -> Result<impl Stream<Item = Result<(K, V), Error>> + 'a, Error>
pub async fn stream_range<'a>( &'a self, start: K, ) -> Result<impl Stream<Item = Result<(K, V), Error>> + 'a, Error>
Streams all active (key, value) pairs in the database in key order, starting from the first
active key greater than or equal to start.
Sourcepub fn verify_exclusion_proof(
hasher: &mut H,
key: &K,
proof: &ExclusionProof<K, V, H::Digest, N>,
root: &H::Digest,
) -> bool
pub fn verify_exclusion_proof( hasher: &mut H, key: &K, proof: &ExclusionProof<K, V, H::Digest, N>, root: &H::Digest, ) -> bool
Return true if the proof authenticates that key does not exist 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, Merkleized<H>, Durable>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> Db<E, K, V, H, T, N, Merkleized<H>, Durable>
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 from the given config. Leverages parallel Merkleization to initialize
the bitmap MMR if a thread pool is provided.
Sourcepub fn into_mutable(self) -> Db<E, K, V, H, T, N, Unmerkleized, NonDurable>
pub fn into_mutable(self) -> Db<E, K, V, H, T, N, Unmerkleized, NonDurable>
Transition into the mutable state.
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, D: State> Db<E, K, V, H, T, N, Merkleized<H>, D>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, D: State> Db<E, K, V, H, T, N, Merkleized<H>, D>
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<K, H::Digest, N>, Error>
pub async fn key_value_proof( &self, hasher: &mut H, key: K, ) -> Result<KeyValueProof<K, 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 exclusion_proof(
&self,
hasher: &mut H,
key: &K,
) -> Result<ExclusionProof<K, V, H::Digest, N>, Error>
pub async fn exclusion_proof( &self, hasher: &mut H, key: &K, ) -> Result<ExclusionProof<K, V, H::Digest, N>, Error>
Generate and return a proof that the specified key does not exist in the db.
§Errors
Returns Error::KeyExists if the key exists in the db.
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> Db<E, K, V, H, T, N, Unmerkleized, NonDurable>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> Db<E, K, V, H, T, N, Unmerkleized, NonDurable>
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 commit(
self,
metadata: Option<V>,
) -> Result<(Db<E, K, V, H, T, N, Unmerkleized, Durable>, Range<Location>), Error>
pub async fn commit( self, metadata: Option<V>, ) -> Result<(Db<E, K, V, H, T, N, Unmerkleized, Durable>, Range<Location>), Error>
Commit any pending operations to the database, ensuring their durability upon return.
This transitions to the Durable state without merkleizing. Returns the committed database
and the [start_loc, end_loc) range of committed operations. Note that even if no
operations were added since the last commit, this is a root-state changing operation.
Sourcepub async fn into_merkleized(
self,
) -> Result<Db<E, K, V, H, T, N, Merkleized<H>, NonDurable>, Error>
pub async fn into_merkleized( self, ) -> Result<Db<E, K, V, H, T, N, Merkleized<H>, NonDurable>, Error>
Merkleize the database and transition to the provable state without committing. This enables proof generation while keeping the database in the non-durable state.
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> Db<E, K, V, H, T, N, Merkleized<H>, NonDurable>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> Db<E, K, V, H, T, N, Merkleized<H>, NonDurable>
Sourcepub fn into_mutable(self) -> Db<E, K, V, H, T, N, Unmerkleized, NonDurable>
pub fn into_mutable(self) -> Db<E, K, V, H, T, N, Unmerkleized, NonDurable>
Transition into the mutable state.
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> Db<E, K, V, H, T, N, Unmerkleized, Durable>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> Db<E, K, V, H, T, N, Unmerkleized, Durable>
Sourcepub async fn into_merkleized(
self,
) -> Result<Db<E, K, V, H, T, N, Merkleized<H>, Durable>, Error>
pub async fn into_merkleized( self, ) -> Result<Db<E, K, V, H, T, N, Merkleized<H>, Durable>, Error>
Merkleize the database, transitioning to the provable state.
Sourcepub fn into_mutable(self) -> Db<E, K, V, H, T, N, Unmerkleized, NonDurable>
pub fn into_mutable(self) -> Db<E, K, V, H, T, N, Unmerkleized, NonDurable>
Transition into the mutable state.
Trait Implementations§
Source§impl<E, K, V, T, H, const N: usize> Batchable for Db<E, K, V, H, T, N, Unmerkleized, NonDurable>
impl<E, K, V, T, H, const N: usize> Batchable for Db<E, K, V, H, T, N, Unmerkleized, NonDurable>
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> Deletable for Db<E, K, V, H, T, N, Unmerkleized, NonDurable>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> Deletable for Db<E, K, V, H, T, N, Unmerkleized, NonDurable>
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, M: MerkleizationState<DigestOf<H>>, D: DurabilityState> Gettable for Db<E, K, V, H, T, N, M, D>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, M: MerkleizationState<DigestOf<H>>, D: DurabilityState> Gettable for Db<E, K, V, H, T, N, M, D>
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, M: MerkleizationState<DigestOf<H>>, D: DurabilityState> LogStore for Db<E, K, V, H, T, N, M, D>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, M: MerkleizationState<DigestOf<H>>, D: DurabilityState> LogStore for Db<E, K, V, H, T, N, M, D>
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, D: State> MerkleizedStore for Db<E, K, V, H, T, N, Merkleized<H>, D>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, D: State> MerkleizedStore for Db<E, K, V, H, T, N, Merkleized<H>, D>
Source§type Operation = Operation<K, FixedEncoding<V>, Update<K, FixedEncoding<V>>>
type Operation = Operation<K, FixedEncoding<V>, Update<K, FixedEncoding<V>>>
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> Persistable for Db<E, K, V, H, T, N, Merkleized<H>, Durable>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> Persistable for Db<E, K, V, H, T, N, Merkleized<H>, Durable>
Source§type Error = Error
type Error = Error
Source§async fn commit(&mut self) -> Result<(), Self::Error>
async fn commit(&mut self) -> Result<(), Self::Error>
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, D: DurabilityState> PrunableStore for Db<E, K, V, H, T, N, Merkleized<H>, D>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, D: DurabilityState> PrunableStore for Db<E, K, V, H, T, N, Merkleized<H>, D>
Source§impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> Updatable for Db<E, K, V, H, T, N, Unmerkleized, NonDurable>
impl<E: RStorage + Clock + Metrics, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize> Updatable for Db<E, K, V, H, T, N, Unmerkleized, NonDurable>
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>
Source§fn create<'a>(
&'a mut self,
key: Self::Key,
value: Self::Value,
) -> impl Future<Output = Result<bool, Self::Error>> + Send + use<'a, Self>where
Self: Send,
fn create<'a>(
&'a mut self,
key: Self::Key,
value: Self::Value,
) -> impl Future<Output = Result<bool, Self::Error>> + Send + use<'a, Self>where
Self: Send,
Auto Trait Implementations§
impl<E, K, V, H, T, const N: usize, M, D> Freeze for Db<E, K, V, H, T, N, M, D>
impl<E, K, V, H, T, const N: usize, M = Clean<<H as Hasher>::Digest>, D = Durable> !RefUnwindSafe for Db<E, K, V, H, T, N, M, D>
impl<E, K, V, H, T, const N: usize, M, D> Send for Db<E, K, V, H, T, N, M, D>
impl<E, K, V, H, T, const N: usize, M, D> Sync for Db<E, K, V, H, T, N, M, D>
impl<E, K, V, H, T, const N: usize, M, D> Unpin for Db<E, K, V, H, T, N, M, D>
impl<E, K, V, H, T, const N: usize, M = Clean<<H as Hasher>::Digest>, D = Durable> !UnwindSafe for Db<E, K, V, H, T, N, M, D>
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> 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