Skip to content

feat: implement get_proof for Trie#419

Merged
fmoletta merged 22 commits into
mainfrom
get_proof
Sep 19, 2024
Merged

feat: implement get_proof for Trie#419
fmoletta merged 22 commits into
mainfrom
get_proof

Conversation

@fmoletta

@fmoletta fmoletta commented Sep 18, 2024

Copy link
Copy Markdown
Contributor

Motivation
Adding support for Trie::get_proof so we can use it in rpc endpoint etc_getProof

Description

  • Add Trie method get_proof
  • Add protests for Trie::get_proof

Other:

  • Replace NodeHasher with NodeEncoder, which behaves similarly, but instead of building up the node's hash, it builds up the node's encoded format, leaving the hashing to a later instance

  • Add method encode_raw for all node variants

  • Add NodeHash method from_encoded_raw which will hash the encoded node returned by the NodeEncoder

Closes None, but is needed in order to implement #291

@fmoletta fmoletta changed the title feat: [WIP] implement get_proof for Trie feat: implement get_proof for Trie Sep 19, 2024
@fmoletta fmoletta marked this pull request as ready for review September 19, 2024 15:02
@fmoletta fmoletta requested a review from a team as a code owner September 19, 2024 15:02
Comment thread crates/storage/trie.rs
/// The proof will contain all the encoded nodes traversed until reaching the node where the path is stored (including this last node).
/// The proof will still be constructed even if the path is not stored in the trie, proving its absence.
#[allow(unused)]
pub fn get_proof(&self, path: &PathRLP) -> Result<Vec<Vec<u8>>, StoreError> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

would it make sense to return a vec of nodes instead, so that the type is more explicit? Then the caller can convert it trivially to vec of u8

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The encoding for the nodes is standard, the structure of the node itself is not, returning the nodes would mean exposing our internal node structure which is private and not relevant to the user

@mpaulucci mpaulucci left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🚀

@fmoletta fmoletta added this pull request to the merge queue Sep 19, 2024
Merged via the queue into main with commit 851dda4 Sep 19, 2024
@fmoletta fmoletta deleted the get_proof branch September 19, 2024 17:34
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