Skip to content
Draft
1 change: 1 addition & 0 deletions firewood/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ plain_hasher = "0.2.3"
hex-literal = "1.0.0"
env_logger = "0.11.7"
hash-db = "0.16.0"
metrics-util = "0.19.0"

[[bench]]
name = "hashops"
Expand Down
1,744 changes: 1,744 additions & 0 deletions firewood/src/diff.rs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions firewood/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ pub mod proof;
/// Range proof module
pub mod range_proof;

/// Change proof module
pub mod diff;

/// Stream module, for both node and key-value streams
pub mod stream;

Expand Down
40 changes: 18 additions & 22 deletions firewood/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,11 @@ impl<T: TrieReader> Merkle<T> {
PathIterator::new(&self.nodestore, key)
}

#[allow(dead_code)]
pub(super) fn key_value_iter(&self) -> MerkleKeyValueStream<'_, T> {
pub(crate) fn key_value_iter(&self) -> MerkleKeyValueStream<'_, T> {
MerkleKeyValueStream::from(&self.nodestore)
}

#[allow(dead_code)]
pub(super) fn key_value_iter_from_key<K: AsRef<[u8]>>(
pub(crate) fn key_value_iter_from_key<K: AsRef<[u8]>>(
&self,
key: K,
) -> MerkleKeyValueStream<'_, T> {
Expand Down Expand Up @@ -255,7 +253,7 @@ impl<T: TrieReader> Merkle<T> {
};

// fetch the first key from the stream
let first_result = stream.next().await;
let first_result = StreamExt::next(&mut stream).await;

// transpose the Option<Result<T, E>> to Result<Option<T>, E>
// If this is an error, the ? operator will return it
Expand Down Expand Up @@ -287,25 +285,23 @@ impl<T: TrieReader> Merkle<T> {
// we stop streaming if either we hit the limit or the key returned was larger
// than the largest key requested
key_values.extend(
stream
.take(limit.unwrap_or(usize::MAX))
.take_while(|kv| {
// no last key asked for, so keep going
let Some(last_key) = end_key else {
return ready(true);
};
StreamExt::take_while(StreamExt::take(stream, limit.unwrap_or(usize::MAX)), |kv| {
// no last key asked for, so keep going
let Some(last_key) = end_key else {
return ready(true);
};

// return the error if there was one
let Ok(kv) = kv else {
return ready(true);
};
// return the error if there was one
let Ok(kv) = kv else {
return ready(true);
};

// keep going if the key returned is less than the last key requested
ready(&*kv.0 <= last_key)
})
.map(|kv| kv.map(|(k, v)| (k, v.into())))
.try_collect::<Vec<(Box<[u8]>, Box<[u8]>)>>()
.await?,
// keep going if the key returned is less than the last key requested
ready(&*kv.0 <= last_key)
})
.map(|kv| kv.map(|(k, v)| (k, v.into())))
.try_collect::<Vec<(Box<[u8]>, Box<[u8]>)>>()
.await?,
);

let end_proof = key_values
Expand Down
Loading
Loading