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: support proof generation from the iterator #16722

Merged
merged 1 commit into from
May 23, 2018

Conversation

karalabe
Copy link
Member

I'm in a bit of a salvage mission here, trying to extract any useful standalone code from my bit rotted leaf-sync work. This PR adds support to the trie iterator to generate proofs of the leaf nodes it visits.

In theory this functionality could be fully covered by trie.Prove(it.LeafKey()). The reason that's not viable is because trie.Prove traverses the path manually, pulling the data from the database. However, the iterator already has all that data available in-memory in its iteration stack. Supporting this functionality from the iterator allows us to do it almost freely, without the extra database overhead.

The second question that begs answering is whether we could then replace trie.Prove with the iterator approach trie.NewIterator(t.NodeIterator(key)).Prove()? In theory both do the same thing, so a targeted iterator should be adequate enough to replace the simple prover. Unfortunately trie.Prove also supports proving non-existence of nodes, whereas the iterator obviously cannot position itself on top of a non existing item to prove it.

Based on the logic above, both ways of proving a leaf is useful, so the PR also expands the proof tests to cross-reference the two implementation between one another.


The original code that used this PR was my leaf-sync extension to fast sync, which retrieves trie leaves directly instead of subtries. If these trie leaves are larger than our packet allowance, we can't send the entire sub-trie, so we send partial leaves + the boundary leaf proofs. I'm not fully sure this logic will survive the new sync ideas, but proving an iterated trie node fast seems useful enough to merge in itself too.

@karalabe
Copy link
Member Author

@zsfelfoldi PTAL?

@karalabe karalabe requested a review from zsfelfoldi May 10, 2018 10:17
@karalabe karalabe force-pushed the trie-iterator-proofs branch from 3ee6561 to 11eec6e Compare May 23, 2018 09:57
@karalabe karalabe force-pushed the trie-iterator-proofs branch from 11eec6e to c934c06 Compare May 23, 2018 10:02
@karalabe karalabe added this to the 1.8.9 milestone May 23, 2018
@karalabe karalabe merged commit 56de337 into ethereum:master May 23, 2018
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.

1 participant