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

chore(trie): add MerkleValue method and functions #2602

Merged
merged 5 commits into from
Aug 11, 2022

Conversation

qdm12
Copy link
Contributor

@qdm12 qdm12 commented Jun 14, 2022

Changes

ℹ️ this is needed for the proof code in #2604 so we use the same functions to get the Merkle value for nodes.

  • Add MerkleValue function to produce the Merkle value for non-root nodes from the node encoding
  • Add MerkleValueRoot function to produce the Merkle value for root nodes from the node encoding
  • Add CalculateMerkleValue method to node.Node to return the Merkle value
  • Add CalculateRootMerkleValue method to node.Node to return the root node Merkle value
  • Remove duplicate code function hashNode
  • EncodeAndHashRoot only uses cached Merkle value if it's 32 bytes
  • Use CalculateMerkleValue instead of EncodeAndHash when appropriate
  • Use CalculateRootMerkleValue instead of EncodeAndHashRoot when appropriate
  • Proof generation uses MerkleValue
  • Proof verification buildTrie uses MerkleValueRoot
  • Proof generation and verification use sync.Pool digest buffers

Tests

go test ./internal/trie/... ./lib/trie/...

Issues

Related to #2418

Primary Reviewer

@timwu20

internal/trie/node/hash.go Outdated Show resolved Hide resolved
@qdm12 qdm12 force-pushed the qdm12/trie/split-encodeandhash branch from 9d55d9c to 9691124 Compare June 30, 2022 17:48
@qdm12 qdm12 changed the title chore(trie): add MerkleValue method and function chore(trie): add MerkleValue method and functions Jul 1, 2022
internal/trie/node/hash.go Outdated Show resolved Hide resolved
@qdm12 qdm12 force-pushed the qdm12/trie/split-encodeandhash branch 4 times, most recently from 6a35c63 to f46e4b4 Compare July 8, 2022 14:52
@qdm12 qdm12 force-pushed the qdm12/trie/split-encodeandhash branch 3 times, most recently from dddcea6 to 9982267 Compare July 22, 2022 14:11
@timwu20
Copy link
Contributor

timwu20 commented Jul 27, 2022

@qdm12 can you resolve the conflicts on this.

@qdm12 qdm12 force-pushed the qdm12/trie/split-encodeandhash branch 4 times, most recently from ef713c4 to 74dffdf Compare August 2, 2022 13:35
@qdm12
Copy link
Contributor Author

qdm12 commented Aug 5, 2022

Conflicts resolved 😉

internal/trie/node/hash.go Outdated Show resolved Hide resolved
Copy link
Contributor

@noot noot left a comment

Choose a reason for hiding this comment

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

basically looks fine, just one comment about removing duplicate code

- Add `CalculateMerkleValue` node method
- Add `MerkleValue` function
- Add `MerkleValueRoot` function
- Use pool of hashers in Merkle value functions
- Use `EncodeAndHash` method in branch child encoding `scaleEncodeHash` function
- Add TODO comment about using io.Writer to use sync.Pool buffers
@qdm12 qdm12 force-pushed the qdm12/trie/split-encodeandhash branch from 74dffdf to 6d7881b Compare August 11, 2022 00:03
@qdm12 qdm12 merged commit 6d663aa into development Aug 11, 2022
@qdm12 qdm12 deleted the qdm12/trie/split-encodeandhash branch August 11, 2022 13:24
@github-actions
Copy link

🎉 This PR is included in version 0.7.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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.

4 participants