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
Fixing failing tests for optimized azks #206
Conversation
* Add left and right child for tree node * Add hash to HistoryTreeNode * Update set/get child * Update hash at parent * Update hashes in the tree * Add epoch to set_child for updating last updated epoch * Remove unnecessary last epoch update (already done in set_child) * Enable higher level tests * Update and pass leaf insertion tests * Pass tree insertion tests * Remove commented out HistoryTreeNode tests * Remove commented out unused functions * Remove printlns * Remove printlns from AZKS * Remove storage from function when not needed * Fix warnings for cargo build and test * Remove HistoryNodeState and HistoryChildState * Remove get_epoch_lte_epoch * Remove HistoryNodeState and HistoryChildState from storage layer * Remove get_epoch_lte_epoch usage * Format * Fix clippy warnings * Remove birth_epoch * Disable tests to merge * Remove needless question mark * Disable mysql tests * Disable test_mysql_db test
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.
So generally, it seems like we've either deleted a lot of tests or at least disabled them. Is this considered WIP? Like eventually we'll restore them right?
Otherwise it's just a lot of tiny styling nits and whatnot, but this looks really, really good! Thanks!
@@ -297,26 +266,27 @@ impl Azks { | |||
&self, | |||
storage: &S, | |||
label: NodeLabel, | |||
epoch: u64, | |||
_epoch: u64, |
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.
nit: If we no longer need the epoch for these proofs (and it isn't going to be put back later) can we clean up the function signature?
akd/src/append_only_zks.rs
Outdated
// really you shouldn't even be here. Later do error checking | ||
return Ok((unchanged, leaves)); | ||
} | ||
// if node.get_birth_epoch() > end_epoch { |
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.
nit: From the comment it looks like this wasn't necessary anyways. Can we cleanup this artifact?
akd/src/append_only_zks.rs
Outdated
@@ -725,6 +680,37 @@ mod tests { | |||
Ok(()) | |||
} | |||
|
|||
#[tokio::test] | |||
#[allow(dead_code)] |
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.
nit: Do we need the dead code attribute? is it not in a #[cfg(test)]
block? If not can we move them to a
#[cfg(test)]
mod tests {
...
}
akd/src/history_tree_node.rs
Outdated
@@ -141,50 +157,24 @@ impl HistoryTreeNode { | |||
pub(crate) async fn get_from_storage<S: Storage + Send + Sync>( | |||
storage: &S, | |||
key: &NodeKey, | |||
current_epoch: u64, | |||
_current_epoch: u64, |
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.
nit: Remove the unused (unless we're going to add it back later)?
akd/src/history_tree_node.rs
Outdated
) -> Result<Vec<HistoryTreeNode>, StorageError> { | ||
let node_records: Vec<DbRecord> = storage.batch_get::<HistoryTreeNode>(keys).await?; | ||
let mut nodes = Vec::<HistoryTreeNode>::new(); | ||
for (i, node) in node_records.into_iter().enumerate() { | ||
for (_i, node) in node_records.into_iter().enumerate() { |
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.
nit: Don't enumerate if we don't need the iterator index. so just for node in node_records.into_iter()
akd/src/history_tree_node.rs
Outdated
} | ||
debug!("END insert single leaf (dir_self = None)"); | ||
Ok(()) | ||
let result = match child_node { |
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.
nit: Remove the assignment of result, and just have the match statement end the fn.
akd/src/history_tree_node.rs
Outdated
} | ||
|
||
/// Inserts a child into this node, adding the state to the state at this epoch, | ||
/// without updating its own hash. | ||
#[async_recursion] | ||
pub(crate) async fn set_child<S: Storage + Sync + Send, H: Hasher>( | ||
// #[async_recursion] |
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.
nit: just delete this
akd/src/history_tree_node.rs
Outdated
// birth epoch but we're less than the "last" epoch. | ||
// db query is necessary | ||
None | ||
panic!( |
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.
nit: can we return AkdError
instead of panicing?
@@ -20,8 +19,8 @@ pub enum StorageType { | |||
Azks = 1, | |||
/// HistoryTreeNode | |||
HistoryTreeNode = 2, | |||
/// HistoryNodeState | |||
HistoryNodeState = 3, | |||
/// EOZ: HistoryNodeState = 3 was removed from here. |
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.
To answer the question in the comment: We're going to do a DB break anyways, we can update this to 3. If we were adding types and trying for a db upgrade, then yeah. But until we release "version 1" we don't have much to worry about if we're going to break all backwards compat.
Thanks a lot for looking it over already! Yes, it's a WIP, I'm working on fixing all the tests @eozturk1 highlighted in #189 (comment) |
Created #207 to track the next steps (replaces the comment in #189 ). |
akd/src/append_only_zks.rs
Outdated
@@ -790,6 +787,66 @@ mod tests { | |||
Ok(()) | |||
} | |||
|
|||
#[tokio::test] | |||
#[allow(dead_code)] | |||
async fn test_nonmembership_proof_v_small() -> Result<(), AkdError> { |
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.
nit: very small?
let num_nodes = 2; | ||
|
||
let mut insertion_set: Vec<Node<Blake3>> = vec![]; | ||
|
||
for i in 0..num_nodes { | ||
let mut label_arr = [0u8; 32]; | ||
label_arr[31] = u8::from(i); | ||
let label = NodeLabel::new(label_arr, 256u32); | ||
let mut input = [0u8; 32]; | ||
input[31] = u8::from(i); | ||
let hash = Blake3Digest::new(input); | ||
let node = Node::<Blake3> { label, hash }; | ||
insertion_set.push(node); | ||
} |
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.
Could we move this part to a separate helper function?
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.
What about generate_random_node()
?
If we want a specific property for the node, let's add this as a comment.
|
||
for i in 0..num_nodes { | ||
let mut label_arr = [0u8; 32]; | ||
label_arr[31] = u8::from(i); |
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.
Why do we do this?
akd/src/append_only_zks.rs
Outdated
#[allow(dead_code)] | ||
async fn test_nonmembership_proof_v_small() -> Result<(), AkdError> { |
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.
Can you remove #[allow(dead_code)]
and add a description for the test?
akd/src/append_only_zks.rs
Outdated
#[allow(dead_code)] | ||
async fn test_nonmembership_proof_small() -> Result<(), AkdError> { |
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.
Same as above function.
.await?; | ||
let commitment_label = self | ||
.vrf | ||
.get_node_label_from_vrf_pf::<H>(existence_vrf) |
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.
nit: We can keep this as proof
, no need to shorten :)
akd/src/tests.rs
Outdated
@@ -57,7 +57,7 @@ async fn test_simple_publish() -> Result<(), AkdError> { | |||
Ok(()) | |||
} | |||
|
|||
// #[tokio::test] | |||
#[tokio::test] | |||
#[allow(dead_code)] |
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.
We should remove #[allow(dead_code)]
s since we have enabled the tests.
value: &AkdValue, | ||
) -> H::Digest { | ||
let proof = get_commitment_proof::<H>(commitment_key, label, version, value); | ||
let proof = get_commitment_proof::<H>(commitment_key, label, value); | ||
H::hash(&[i2osp_array(value), i2osp_array(&proof.as_bytes())].concat()) |
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.
Should we use i2osp_array
before each hash operation?
let db = AsyncInMemoryDatabase::new(); | ||
let mut azks = Azks::new::<_, Blake3>(&db).await?; | ||
let search_label = insertion_set[0].label; | ||
azks.batch_insert_leaves::<_, Blake3>(&db, insertion_set.clone()[1..2].to_vec()) |
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.
Let's separate the node we are searching for from the nodes we are inserting into the tree.
let node_to_search = generate_random_node();
let insertion_set = generate_nodes(); // uses generate_random_node()
azks.batch_insert_leaves(insertion_set);
let proof = azks.get_non_membership_proof(node_to_search.label);
// Verify proof
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.
There are a couple of allow(dead_code)'s. Can they be removed?
pub epochs: Vec<u64>, | ||
} | ||
|
||
// FIXME: need to fix the documentation |
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.
Does this still need to be addressed?
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.
Will be addressing in a cleanup PR
akd_client/src/tests.rs
Outdated
@@ -392,6 +407,7 @@ async fn test_history_proof_multiple_epochs() -> Result<(), AkdError> { | |||
} | |||
|
|||
#[tokio::test] | |||
#[allow(dead_code)] |
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.
Can we remove this?
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.
All #[allow(dead_code)]
s should be removed after enabling the tests. I mentioned this in a few other places. @Jasleen1 said she would do a clean up before merging.
akd_client/src/tests.rs
Outdated
@@ -436,6 +449,7 @@ async fn test_history_proof_single_epoch() -> Result<(), AkdError> { | |||
} | |||
|
|||
#[tokio::test] | |||
#[allow(dead_code)] |
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.
Can we remove this?
Ok cool. Also, we want to merge this into the |
Working through the checklist detailed here: #189 (comment)