-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle Extension-nodes in Iterator #430
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a204177
Make MerkleStream handle branches with values
richardpringle 4efdd14
Stop prefetching next node in iterator
richardpringle 4119d2c
Make MerkleKeyValueStream fused
richardpringle fb67626
Cleanup apis for stream
richardpringle cc3b0e2
Use boxed-slice as key
richardpringle 980fed5
Rename parents to visited_node_path
richardpringle 9a77439
Fix doc
richardpringle 821a8b1
Remove dead code
richardpringle 5800ccd
Remove TODO that was implemented
richardpringle 9300305
Merge branch 'main' into move-merkle-stream
richardpringle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ pub use node::{ | |
NodeType, PartialPath, | ||
}; | ||
pub use proof::{Proof, ProofError}; | ||
use stream::IteratorState; | ||
pub use stream::MerkleKeyValueStream; | ||
pub use trie_hash::{TrieHash, TRIE_HASH_LEN}; | ||
|
||
|
@@ -1221,16 +1220,16 @@ impl<S: ShaleStore<Node> + Send + Sync, T> Merkle<S, T> { | |
self.store.flush_dirty() | ||
} | ||
|
||
pub(crate) fn get_iter<K: AsRef<[u8]>>( | ||
pub(crate) fn iter(&self, root: DiskAddress) -> MerkleKeyValueStream<'_, S, T> { | ||
MerkleKeyValueStream::new(self, root) | ||
} | ||
|
||
pub(crate) fn iter_from( | ||
&self, | ||
key: Option<K>, | ||
root: DiskAddress, | ||
) -> Result<MerkleKeyValueStream<'_, S, T>, MerkleError> { | ||
Ok(MerkleKeyValueStream { | ||
key_state: IteratorState::new(key), | ||
merkle_root: root, | ||
merkle: self, | ||
}) | ||
key: Box<[u8]>, | ||
) -> MerkleKeyValueStream<'_, S, T> { | ||
MerkleKeyValueStream::from_key(self, root, key) | ||
} | ||
|
||
pub(super) async fn range_proof<K: api::KeyType + Send + Sync>( | ||
|
@@ -1241,13 +1240,15 @@ impl<S: ShaleStore<Node> + Send + Sync, T> Merkle<S, T> { | |
limit: Option<usize>, | ||
) -> Result<Option<api::RangeProof<Vec<u8>, Vec<u8>>>, api::Error> { | ||
// limit of 0 is always an empty RangeProof | ||
if let Some(0) = limit { | ||
if limit == Some(0) { | ||
return Ok(None); | ||
} | ||
|
||
let mut stream = self | ||
.get_iter(first_key, root) | ||
.map_err(|e| api::Error::InternalError(Box::new(e)))?; | ||
let mut stream = match first_key { | ||
// TODO: fix the call-site to force the caller to do the allocation | ||
Some(key) => self.iter_from(root, key.as_ref().to_vec().into_boxed_slice()), | ||
None => self.iter(root), | ||
}; | ||
|
||
// fetch the first key from the stream | ||
let first_result = stream.next().await; | ||
|
@@ -1264,7 +1265,7 @@ impl<S: ShaleStore<Node> + Send + Sync, T> Merkle<S, T> { | |
.map_err(|e| api::Error::InternalError(Box::new(e)))?; | ||
let limit = limit.map(|old_limit| old_limit - 1); | ||
|
||
let mut middle = vec![(first_key, first_data)]; | ||
let mut middle = vec![(first_key.into_vec(), first_data)]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure about this, but we can change it later. |
||
|
||
// we stop streaming if either we hit the limit or the key returned was larger | ||
// than the largest key requested | ||
|
@@ -1283,8 +1284,9 @@ impl<S: ShaleStore<Node> + Send + Sync, T> Merkle<S, T> { | |
}; | ||
|
||
// keep going if the key returned is less than the last key requested | ||
ready(kv.0.as_slice() <= last_key.as_ref()) | ||
ready(&*kv.0 <= last_key.as_ref()) | ||
}) | ||
.map(|kv_result| kv_result.map(|(k, v)| (k.into_vec(), v))) | ||
.try_collect::<Vec<(Vec<u8>, Vec<u8>)>>() | ||
.await?, | ||
); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a significant improvement to the API. It was such a pain specifying the type on the
None
when it could be any number of things. It's too bad there's nodefault
generic, like with structs and enums.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I like that.