Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions storage/src/qmdb/any/ordered/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ pub use crate::qmdb::any::operation::{update::Ordered as Update, Ordered as Oper
/// Type alias for a location and its associated key data.
type LocatedKey<F, K, V> = Option<(Location<F>, Update<K, V>)>;

/// Whether the ordered-key span defined by `span_start` and `span_end` contains `key`.
pub(crate) fn span_contains<K: Key>(span_start: &K, span_end: &K, key: &K) -> bool {
if span_start >= span_end {
key >= span_start || key < span_end
} else {
key >= span_start && key < span_end
}
}

impl<
F: Family,
E: Context,
Expand All @@ -50,23 +59,6 @@ where
}
}

/// Whether the span defined by `span_start` and `span_end` contains `key`.
pub fn span_contains(span_start: &K, span_end: &K, key: &K) -> bool {
if span_start >= span_end {
// cyclic span case
if key >= span_start || key < span_end {
return true;
}
} else {
// normal span case
if key >= span_start && key < span_end {
return true;
}
}

false
}

/// Find the span produced by the provided locations that contains `key`, if any.
async fn find_span(
&self,
Expand All @@ -77,7 +69,7 @@ where
for loc in locs {
// Iterate over conflicts in the snapshot entry to find the span.
let data = Self::get_update_op(&reader, loc).await?;
if Self::span_contains(&data.key, &data.next_key, key) {
if span_contains(&data.key, &data.next_key, key) {
return Ok(Some((loc, data)));
}
}
Expand Down
30 changes: 14 additions & 16 deletions storage/src/qmdb/current/ordered/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
merkle::{self, hasher::Standard as StandardHasher, Location},
qmdb::{
any::{
ordered::{Operation, Update},
ordered::{self, Operation, Update},
ValueEncoding,
},
current::proof::OperationProof,
Expand Down Expand Up @@ -113,13 +113,15 @@ where
proof: &KeyValueProof<F, K, H::Digest, N>,
root: &H::Digest,
) -> bool {
let op = Operation::Update(Update {
key,
value,
next_key: proof.next_key.clone(),
});

proof.proof.verify(hasher, op, root)
proof.proof.verify(
hasher,
Operation::Update(Update {
key,
value,
next_key: proof.next_key.clone(),
}),
root,
)
}

/// Get the operation that currently defines the span whose range contains `key`, or None if the
Expand Down Expand Up @@ -149,22 +151,18 @@ where
root: &H::Digest,
) -> bool {
let (op_proof, op) = match proof {
super::ExclusionProof::KeyValue(op_proof, data) => {
if data.key == *key {
super::ExclusionProof::KeyValue(op_proof, update) => {
if update.key == *key {
// The provided `key` is in the DB if it matches the start of the span.
return false;
}
if !crate::qmdb::any::db::Db::<F, E, C, I, H, Update<K, V>, N, S>::span_contains(
&data.key,
&data.next_key,
key,
) {
if !ordered::span_contains(&update.key, &update.next_key, key) {
// If the key is not within the span, then this proof cannot prove its
// exclusion.
return false;
}

(op_proof, Operation::Update(data.clone()))
(op_proof, Operation::Update(update.clone()))
}
super::ExclusionProof::Commit(op_proof, metadata) => {
// Handle the case where the proof shows the db is empty, hence any key is proven
Expand Down
Loading