Skip to content
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

Closed
wants to merge 13 commits into from

Conversation

Jasleen1
Copy link
Contributor

@Jasleen1 Jasleen1 commented Jun 8, 2022

Working through the checklist detailed here: #189 (comment)

eozturk1 and others added 2 commits June 1, 2022 22:43
* 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
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 8, 2022
Copy link
Contributor

@slawlor slawlor left a 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,
Copy link
Contributor

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?

// really you shouldn't even be here. Later do error checking
return Ok((unchanged, leaves));
}
// if node.get_birth_epoch() > end_epoch {
Copy link
Contributor

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?

@@ -725,6 +680,37 @@ mod tests {
Ok(())
}

#[tokio::test]
#[allow(dead_code)]
Copy link
Contributor

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 {

...
}

@@ -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,
Copy link
Contributor

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)?

) -> 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() {
Copy link
Contributor

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()

}
debug!("END insert single leaf (dir_self = None)");
Ok(())
let result = match child_node {
Copy link
Contributor

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.

}

/// 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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just delete this

// birth epoch but we're less than the "last" epoch.
// db query is necessary
None
panic!(
Copy link
Contributor

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.
Copy link
Contributor

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.

@Jasleen1
Copy link
Contributor Author

Jasleen1 commented Jun 9, 2022

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!

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)

@eozturk1
Copy link
Contributor

eozturk1 commented Jun 9, 2022

Created #207 to track the next steps (replaces the comment in #189 ).

@eozturk1
Copy link
Contributor

eozturk1 commented Jun 9, 2022

@slawlor I'll re-iterate over the deleted/commented out tests and bring the ones we will need back. Tracked in #208.

@@ -790,6 +787,66 @@ mod tests {
Ok(())
}

#[tokio::test]
#[allow(dead_code)]
async fn test_nonmembership_proof_v_small() -> Result<(), AkdError> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: very small?

Comment on lines +793 to +806
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);
}
Copy link
Contributor

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?

Copy link
Contributor

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);
Copy link
Contributor

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?

Comment on lines 791 to 792
#[allow(dead_code)]
async fn test_nonmembership_proof_v_small() -> Result<(), AkdError> {
Copy link
Contributor

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?

Comment on lines 820 to 821
#[allow(dead_code)]
async fn test_nonmembership_proof_small() -> Result<(), AkdError> {
Copy link
Contributor

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)
Copy link
Contributor

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)]
Copy link
Contributor

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())
Copy link
Contributor

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())
Copy link
Contributor

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

@eozturk1 eozturk1 mentioned this pull request Jun 11, 2022
@Jasleen1 Jasleen1 marked this pull request as ready for review June 15, 2022 23:02
@Jasleen1
Copy link
Contributor Author

This PR addresses #144 and #207, except the last task in the checklist of #207.

Copy link
Contributor

@kevinlewi kevinlewi left a 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
Copy link
Contributor

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?

Copy link
Contributor Author

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

@@ -392,6 +407,7 @@ async fn test_history_proof_multiple_epochs() -> Result<(), AkdError> {
}

#[tokio::test]
#[allow(dead_code)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this?

Copy link
Contributor

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.

@@ -436,6 +449,7 @@ async fn test_history_proof_single_epoch() -> Result<(), AkdError> {
}

#[tokio::test]
#[allow(dead_code)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this?

@kevinlewi
Copy link
Contributor

Ok cool. Also, we want to merge this into the eozturk1/optimized-azks branch, not main, right?

@Jasleen1 Jasleen1 closed this Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants