use crate::{
Context,
index::ordered::Index,
journal::contiguous::variable::Journal,
merkle::{Graftable, Location},
qmdb::{
Error,
any::{VariableValue, ordered::variable::Operation, value::VariableEncoding},
current::VariableConfig as Config,
operation::Key,
},
translator::OrderedTranslator,
};
use commonware_codec::Read;
use commonware_cryptography::Hasher;
use commonware_parallel::Strategy;
use commonware_runtime::Spawner;
pub type Db<F, E, K, V, H, T, const N: usize, S> = super::db::Db<
F,
E,
Journal<E, Operation<F, K, V>>,
K,
VariableEncoding<V>,
Index<T, Location<F>>,
H,
N,
S,
>;
impl<
F: Graftable,
E: Context + Spawner,
K: Key,
V: VariableValue,
H: Hasher,
T: OrderedTranslator,
const N: usize,
S: Strategy,
> Db<F, E, K, V, H, T, N, S>
{
pub async fn init(
context: E,
config: Config<T, <Operation<F, K, V> as Read>::Cfg, S>,
max_size: Option<Location<F>>,
) -> Result<Self, Error<F>> {
crate::qmdb::current::init(context, config, max_size).await
}
}
pub mod partitioned {
use super::*;
use crate::index::partitioned::ordered::Index;
pub type Db<F, E, K, V, H, T, const P: usize, const N: usize, S> =
crate::qmdb::current::ordered::db::Db<
F,
E,
Journal<E, Operation<F, K, V>>,
K,
VariableEncoding<V>,
Index<T, Location<F>, P>,
H,
N,
S,
>;
impl<
F: Graftable,
E: Context + Spawner,
K: Key,
V: VariableValue,
H: Hasher,
T: OrderedTranslator,
const P: usize,
const N: usize,
S: Strategy,
> Db<F, E, K, V, H, T, P, N, S>
{
pub async fn init(
context: E,
config: Config<T, <Operation<F, K, V> as Read>::Cfg, S, core::num::NonZeroUsize>,
max_size: Option<Location<F>>,
) -> Result<Self, Error<F>> {
crate::qmdb::current::init(context, config, max_size).await
}
}
}
#[cfg(test)]
mod test {
use crate::{
merkle::Graftable,
mmb, mmr,
qmdb::current::{ordered::tests as shared, tests::variable_config},
translator::OneCap,
};
use commonware_cryptography::{Sha256, sha256::Digest};
use commonware_macros::test_traced;
use commonware_runtime::deterministic;
type CurrentTest<F = mmr::Family> = super::Db<
F,
deterministic::Context,
Digest,
Digest,
Sha256,
OneCap,
32,
commonware_parallel::Sequential,
>;
async fn open_db<F: Graftable>(
context: deterministic::Context,
partition_prefix: String,
) -> CurrentTest<F> {
let cfg = variable_config::<OneCap>(&partition_prefix);
CurrentTest::<F>::init(context, cfg, None).await.unwrap()
}
#[test_traced("DEBUG")]
pub fn test_current_db_verify_proof_over_bits_in_uncommitted_chunk() {
shared::test_verify_proof_over_bits_in_uncommitted_chunk(open_db::<mmr::Family>);
}
#[test_traced("DEBUG")]
pub fn test_current_db_range_proofs() {
shared::test_range_proofs(open_db::<mmr::Family>);
}
#[test_traced("DEBUG")]
pub fn test_current_db_key_value_proof() {
shared::test_key_value_proof(open_db::<mmr::Family>);
}
#[test_traced("DEBUG")]
fn test_current_db_dynamic_key_value_proof_mmb() {
shared::test_key_value_proof(open_db::<mmb::Family>);
}
#[test_traced("DEBUG")]
fn test_current_db_dynamic_exclusion_proofs_mmb() {
shared::test_exclusion_proofs(open_db::<mmb::Family>);
}
#[test_traced("DEBUG")]
fn test_current_db_dynamic_inactive_proof_mmb() {
shared::test_verify_proof_over_bits_in_uncommitted_chunk(open_db::<mmb::Family>);
}
#[test_traced("WARN")]
pub fn test_current_db_proving_repeated_updates() {
shared::test_proving_repeated_updates(open_db::<mmr::Family>);
}
#[test_traced("DEBUG")]
pub fn test_current_db_exclusion_proofs() {
shared::test_exclusion_proofs(open_db::<mmr::Family>);
}
}