This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Modify MMR generate_proof API to accept a vector of leaf indexes#10625
Closed
Wizdave97 wants to merge 0 commit intoparitytech:masterfrom
Closed
Modify MMR generate_proof API to accept a vector of leaf indexes#10625Wizdave97 wants to merge 0 commit intoparitytech:masterfrom
Wizdave97 wants to merge 0 commit intoparitytech:masterfrom
Conversation
seunlanlege
reviewed
Jan 10, 2022
bin/node/runtime/src/lib.rs
Outdated
Comment on lines
+1616
to
+1626
| let leaves = { | ||
| let mut decoded_leaves = Vec::new(); | ||
| for l in &leaves { | ||
| let leaf: mmr::Leaf = l.clone() | ||
| .into_opaque_leaf() | ||
| .try_decode() | ||
| .ok_or(mmr::Error::Verify)?; | ||
| decoded_leaves.push(leaf); | ||
| } | ||
| decoded_leaves | ||
| }; |
Contributor
There was a problem hiding this comment.
rust has a cool feature for this
Suggested change
| let leaves = { | |
| let mut decoded_leaves = Vec::new(); | |
| for l in &leaves { | |
| let leaf: mmr::Leaf = l.clone() | |
| .into_opaque_leaf() | |
| .try_decode() | |
| .ok_or(mmr::Error::Verify)?; | |
| decoded_leaves.push(leaf); | |
| } | |
| decoded_leaves | |
| }; | |
| let leaves = leaves.into_iter() | |
| .map(|l| { | |
| l.into_opaque_leaf() | |
| .try_decode() | |
| .ok_or(mmr::Error::Verify) | |
| }) | |
| .collect::<Result<Vec<mmr::Leaf>, mmr::Error>>()?; |
seunlanlege
reviewed
Jan 10, 2022
| let is_valid = leaves.iter().all(|leaf| { | ||
| let mut res = false; | ||
| for pos in &positions { | ||
| match p.verify(Node::Hash(root.clone()), vec![(*pos, leaf.clone())]) { |
Contributor
There was a problem hiding this comment.
we should also modify primitives::Proof to take an array of nodes
seunlanlege
reviewed
Jan 10, 2022
| let leaf_count = self.leaves; | ||
| self.mmr | ||
| .gen_proof(vec![position]) | ||
| .gen_proof(positions) |
rphmeier
reviewed
Jan 10, 2022
bin/node/runtime/src/lib.rs
Outdated
| > for Runtime { | ||
| fn generate_proof(leaf_index: pallet_mmr::primitives::LeafIndex) | ||
| -> Result<(mmr::EncodableOpaqueLeaf, mmr::Proof<mmr::Hash>), mmr::Error> | ||
| fn generate_proof(leaf_indexes: Vec<pallet_mmr::primitives::LeafIndex>) |
Contributor
There was a problem hiding this comment.
the plural of index is 'indices', not 'indexes'
rphmeier
reviewed
Jan 10, 2022
| /// Generate MMR proof for a leaf under given index. | ||
| fn generate_proof(leaf_index: LeafIndex) -> Result<(EncodableOpaqueLeaf, Proof<Hash>), Error>; | ||
| /// Generate MMR proof for leaves under given indexes. | ||
| fn generate_proof(leaf_indexes: Vec<LeafIndex>) -> Result<(Vec<(LeafIndex, EncodableOpaqueLeaf)>, Proof<Hash>), Error>; |
Contributor
There was a problem hiding this comment.
This is not backwards compatible. I recommend adding new functions instead of updating the old ones.
3a97c5f to
daa4118
Compare
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Description
This PR modifies the generate_proof MMR Runtime API to accept an array of leaf indexes, this would allow generating a proof for multiple leaf indexes in one run if needed.