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

Statediffing mode for specific contract proofs #29

Closed
4 tasks done
i-norden opened this issue Oct 14, 2020 · 4 comments
Closed
4 tasks done

Statediffing mode for specific contract proofs #29

i-norden opened this issue Oct 14, 2020 · 4 comments
Assignees
Labels

Comments

@i-norden
Copy link
Collaborator

i-norden commented Oct 14, 2020

Mode for the statediffing service that returns a state object with only the nodes required for accessing and proving data in the specified contract(s)

Provided a set of contract addresses, we want to:

  • Iterate down state trie only along paths to leaf nodes for the provided contracts, collecting all of the nodes along this path (which are required for generating a proof against the state root hash)

  • Iterate through the entire storage tries for these contracts, producing complete statediff objects for the specified contracts only

  • Unit and integration tests

  • Support both ipld-eth-indexer endpoints and direct indexing from inside geth (should be able to use same database)

@i-norden i-norden self-assigned this Oct 14, 2020
i-norden pushed a commit that referenced this issue Oct 16, 2020
#29)

* adding action to publish image to dockerhub on merge to testnet
@i-norden i-norden changed the title Statediffing mode for specific contract proofs VOC14 - Statediffing mode for specific contract proofs Oct 23, 2020
@i-norden i-norden changed the title VOC14 - Statediffing mode for specific contract proofs [VOC14] - Statediffing mode for specific contract proofs Oct 23, 2020
@i-norden i-norden changed the title [VOC14] - Statediffing mode for specific contract proofs Statediffing mode for specific contract proofs Nov 13, 2020
@i-norden i-norden closed this as completed Jun 7, 2022
@i-norden
Copy link
Collaborator Author

i-norden commented Jun 7, 2022

I will double check this is satisfied

@i-norden
Copy link
Collaborator Author

i-norden commented Jun 7, 2022

@AFDudley @ashwinphatak I don't think this is currently satisfied, if we watch a set of addresses the builder only diffs leaf nodes: https://github.com/vulcanize/go-ethereum/blob/v1.10.18-statediff-4.0.2-alpha/statediff/builder.go#L173

And rather than just a potentially vestigial comment, here is the code:

Only in createdAndUpdatedState do we filter on the addresses https://github.com/vulcanize/go-ethereum/blob/v1.10.18-statediff-4.0.2-alpha/statediff/builder.go#L318 whereas in createdAndUpdatedStateWithIntermediateNodes we do not https://github.com/vulcanize/go-ethereum/blob/v1.10.18-statediff-4.0.2-alpha/statediff/builder.go#L363

Instead, what we want is that when we specify a list of watched addresses we can diff only those associated leaf nodes and all the intermediate nodes along the paths to them (required to prove them).

Seems there are two approaches to this:

  1. Hold onto the full stack of parent nodes- at most 63; in practice probably 6-10 on average- during traversal to a leaf, once we get to the leaf when we check whether or not it is in the WatchedAddress list we either throw away the parent node stack or not (the simple approach we could take with the current iterator)
  2. Rewrite/modify the iterator so that it only ever traverses down the paths on interest in the first place (the ideal but more complex to implement approach)

2 would be a huge boon to performance as we would avoid traversing portions of the difference trie that we aren't actually interested in (instead of waiting til we get to a leaf to find out we didn't need to walk all the way down to said leaf).

@prathamesh0
Copy link
Collaborator

prathamesh0 commented Jun 21, 2022

@i-norden The suggested approach in cerc-io/ipld-eth-state-snapshot#46 (comment) to limit the trie traversal only to paths that lead to watched addresses requires the ability to restrict the descent down the trie when required.

In state trie iteration, this is allowed by the descend flag to the iterator.Next() method; whereas, in case of difference traversal done for statediffing, the difference iterator being used ignores the flag being passed to it's Next() method. So we can't readily avoid iterating the whole diff trie.

However, I think that checking paths as prefix for filtering out nodes is still a simpler approach than using a stack to hold on to intermediate nodes.

@prathamesh0
Copy link
Collaborator

Further optimization tracked in #252

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants