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

[WIP]: improve snapshot generation #22465

Closed
wants to merge 28 commits into from

Conversation

rjl493456442
Copy link
Member

@rjl493456442 rjl493456442 commented Mar 9, 2021

Implements https://gist.github.com/rjl493456442/85832a0c760f2bafe2a69e33efe68c60, a better snapshot generation mechanism.

The range-proving based snapshot generation can be used in lots of different purposes.

  • It can speed up the initial snapshot generation after the snap sync, by using the existent flat state received during the sync
  • It can do a quick snapshot rebuild(after the corruption for example) by using the existent flat state persisted previously

So that the snapshot UX can be improved a bit.

@holiman
Copy link
Contributor

holiman commented Mar 9, 2021

This is a neat idea, and I'm sure we'll iterate on it a bit.
One thing that we might want to add later (but maybe first get the basic version working), is to also update the snapshot layer when we do trie healing, for any accounts that are updated. Theoretically, we will then get a pristine snapshot layer, where the only errors are due to

  1. accounts that were deleted during the sync
  2. storage slots that were cleared during the sync (I think)

I'd expect this to decrease the error-margin of the snap layer probably by an order of magnitude or more.

core/state/snapshot/generate.go Outdated Show resolved Hide resolved
core/state/snapshot/generate.go Outdated Show resolved Hide resolved
accTrie, err := trie.NewSecure(dl.root, dl.triedb)
// Verify the state segment with range prover, ensure that all flat states
// in this range correspond to merkle trie.
_, _, _, cont, err := trie.VerifyRangeProof(root, origin, last, keys, vals, proof)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you ignore the db here, it would be neat to use a version of the range prover which uses the stacktrie instead of the full trie.
OTOH it doesn't matter a whole lot, since you're only using a few hundred key/values per iteration

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually the stacktrie is not suitable for range prove. Stacktrie expects all the inputs from the most left side and to the most right side. It won't accept the segment in the middle, even the segment is continuous.

core/state/snapshot/generate.go Outdated Show resolved Hide resolved
eth/protocols/snap/sync.go Outdated Show resolved Hide resolved
rjl493456442 and others added 4 commits March 12, 2021 11:05
* core/state/snapshot: refactor

* core/state/snapshot: tiny fix and polish

Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
rjl493456442 and others added 6 commits March 15, 2021 10:29
core/state/snapshot: less copy

core/state/snapshot: revert split loop

core/state/snapshot: handle storage becoming empty, improve test robustness

core/state: test modified codehash

core/state/snapshot: polish
@holiman
Copy link
Contributor

holiman commented Mar 18, 2021

Can we close this in favour of #22504 ?

@holiman holiman closed this Mar 18, 2021
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