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

Trie (non)-membership proofs #7509

Closed
wants to merge 9 commits into from

Conversation

blasrodri
Copy link
Contributor

Adding changes suggested by @mina86
Following up the discussion from #7205

@blasrodri blasrodri marked this pull request as ready for review August 30, 2022 13:58
@blasrodri blasrodri requested a review from a team as a code owner August 30, 2022 13:58
Copy link
Contributor

@mina86 mina86 left a comment

Choose a reason for hiding this comment

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

The two things we still need is the change to iterator I’ve mentioned which would replace seek with something like seek_prefix and cause the iterator to stop as soon as it’s done with the prefix and addition of include_proof field to the request. Those two could be done with separate PRs to make it simpler to manage.

core/primitives/src/views.rs Show resolved Hide resolved
core/store/src/trie/iterator.rs Outdated Show resolved Hide resolved
Comment on lines -618 to 632
fn retrieve_node(&self, hash: &CryptoHash) -> Result<TrieNodeWithSize, StorageError> {
/// Retrieves decoded node alongside with its raw bytes representation.
///
/// Note that because Empty nodes (those which are referenced by
/// [`Self::EMPTY_ROOT`] hash) aren’t stored in the database, they don’t
/// have a bytes representation. For those nodes the first return value
/// will be `None`.
fn retrieve_node(
&self,
hash: &CryptoHash,
) -> Result<(Option<std::sync::Arc<[u8]>>, TrieNodeWithSize), StorageError> {
match self.retrieve_raw_node(hash)? {
None => Ok(TrieNodeWithSize::empty()),
Some((_bytes, node)) => Ok(TrieNodeWithSize::from_raw(node)),
None => Ok((None, TrieNodeWithSize::empty())),
Some((bytes, node)) => Ok((Some(bytes), TrieNodeWithSize::from_raw(node))),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be best to push this change as separate PR. That would make this PR smaller and easier to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm unsure of what to do here.

Copy link
Contributor

Choose a reason for hiding this comment

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

It’s just a matter of separating this diff hunk and all the places where retrieve_node is called into a new commit and submitting as separate PR. It will get this PR smaller.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's not super trivial as far as I see. Need to also modify descend_into_node. Can't we just keep it as it is?

Copy link
Contributor

Choose a reason for hiding this comment

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

It should be rather simple mechanical change. In that separate PR, the change to desdend_into_node will be change from self.trie.retrieve_node(hash)? to self.trie.retrieve_node(hash)?.1.

Copy link
Contributor

Choose a reason for hiding this comment

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

That will happen in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry @mina86 but I'm truly not following you on this one

Copy link
Contributor

Choose a reason for hiding this comment

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

There are three separate PRs here:

  1. PR changing retrieve_node to return (bytes, TrieNodeWithSize). All that PR does is changes the return type and updates all the call sites to do retrieve_node(...)?.1. This is quite mechanical and boring change but thanks to that it should be easy to write, review and merge. This PR is not concerned with the overall feature.
  2. PR changing TrieIterator::seek to TrieIterator::seek_prefix and makes changes the iterator such that it stops once everything within the prefix has been traversed. This can be done by adding a prefix_boundary: bool to Crumb and changing Crumb::increment such that if that flag is set, it always moves to Exiting status. The purpose of this change is to make sure that when iterating over a prefix, the iterator does not fetch spurious nodes. Currently I believe that returned proof includes unnecessary nodes. There may be some smarter way of dealing with this but I’m not seeing it just now.
  3. Once 1 and 2 are done, this PR can be rebased and will be ready to go.

1 and 2 can be done in parallel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For (2) I've created ComposableFi#11 Can you please review it there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For (1) #7535

core/store/src/trie/mod.rs Outdated Show resolved Hide resolved
integration-tests/src/tests/runtime/state_viewer.rs Outdated Show resolved Hide resolved
integration-tests/src/tests/runtime/state_viewer.rs Outdated Show resolved Hide resolved
core/store/src/trie/mod.rs Outdated Show resolved Hide resolved
core/store/src/trie/mod.rs Outdated Show resolved Hide resolved
runtime/runtime/src/state_viewer/mod.rs Show resolved Hide resolved
blasrodri added a commit to ComposableFi/nearcore that referenced this pull request Sep 2, 2022
near-bulldozer bot pushed a commit that referenced this pull request Sep 6, 2022
This will be needed in future commit where we will need access to the
raw bytes of the node.  See #7509.
@blasrodri blasrodri mentioned this pull request Sep 7, 2022
@mina86
Copy link
Contributor

mina86 commented Sep 8, 2022

Finally, I think we’re on the home straight. \o/ Once #7585 gets merged this can be merged or rebased and I think everything here should be fine.

There’s only one detail I’m still wondering about. JSON RPC is public API so I want to get it right the first time around ;) I think we do want an option to enable or disable including the proof. So that would be done by adding #[serde(default)] include_proof: bool to QueryRequest::ViewState and then adding include_proof: bool argument to view_state function. Though I’m not sure if this has to be done in this PR or if I can deal with it separately. I’ll have to think it through a bit.

@mina86
Copy link
Contributor

mina86 commented Sep 9, 2022

You’re gonna need to allow maintainers to edit here as well. It’s just how our merge bot operates. Otherwise it’s kinda annoying to merge manually.

@blasrodri
Copy link
Contributor Author

Opening it up again from my own repo

@blasrodri blasrodri closed this Sep 9, 2022
nikurt pushed a commit that referenced this pull request Nov 9, 2022
This will be needed in future commit where we will need access to the
raw bytes of the node.  See #7509.
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.

3 participants