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

removes the vector allocation in shred::merkle::make_merkle_proof #4481

Merged
merged 1 commit into from
Jan 17, 2025

Conversation

behzadnouri
Copy link

Problem

shred::merkle::make_merkle_proof unnecessarily allocates a vector.

Summary of Changes

The commit returns an iterator from shred::merkle::make_merkle_proof. This iterator is then directly written to shred payload.

@behzadnouri behzadnouri force-pushed the make-merkle-proof-no-alloc branch from 2d45ebf to 1d1c4f4 Compare January 15, 2025 19:23
The commit returns an iterator from shred::merkle::make_merkle_proof.
This iterator is then directly written to shred payload.
@behzadnouri behzadnouri force-pushed the make-merkle-proof-no-alloc branch from 1d1c4f4 to ac4b372 Compare January 17, 2025 15:42
let entry = &node.as_ref()[..SIZE_OF_MERKLE_PROOF_ENTRY];
let entry = <&MerkleProofEntry>::try_from(entry).unwrap();
Some(Ok(entry))
} else if offset + 1 == tree.len() {

Choose a reason for hiding this comment

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

Looks correct, based on get_merkle_tree_size when size reaches 1, the offset will always fulfill this condition.

@behzadnouri behzadnouri merged commit 3904356 into anza-xyz:master Jan 17, 2025
47 checks passed
@behzadnouri behzadnouri deleted the make-merkle-proof-no-alloc branch January 17, 2025 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants