-
Notifications
You must be signed in to change notification settings - Fork 146
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: attempt to use upstream snap sync #771
Draft
darioush
wants to merge
32
commits into
libevm
Choose a base branch
from
libevm-upstream-sync
base: libevm
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
eth/protocols/snap: This is mostly the eth code, with some minor changes
sync.go
: this file is the "client" portion of the sync and is mostly untouched, except for omtting this check:rawdb.HasTrieNode(s.db, res.hashes[i], nil, account.Root, s.scheme)
handler.go
: I modifiedServiceGetAccountRangeQuery
andServiceGetStorageRangesQuery
to "patch in" the existing mechanism for responding to state sync requests, just to get the key/values. We need this because in upstream, there areS
snapshot layers kept in memory (I thinkS=128
), and then the disk layer matcheshead - S + 1
or something of that sort. In coreth/subnet-evm, the disk snapshot matches the last accepted block. We may want to match upstream behavior here, so this is another "chapter" of this project.it, err := chain.Snapshots().AccountIterator(req.Root, req.Origin, false)
with a call to how we do it now:NewResponseBuilder
tosync/handlers/leafs_request.go
, as the responseBuilder is unexported without this change.For proof of concept we can keep the code copied in coreth, but for productionizing it ideally the eth/protocols/snap package is used from libevm.
Glue code: To connect the avalanchego p2p layer to the eth sync protocol, I used some basic shim layers for the client in
plugin/evm/statesync/connector.go
and for the handler inplugin/evm/statesync/handler.go
. These contain panics on unexpeted code paths, but we should handle all failures correctly especially those that can be triggered by incoming peer messages.Modifications to existing state sync handler:
handler.go
as to whether the response needs a proof. This helps emulate theabort
variable behavior in case there is a partial storage response.Putting it all together:
state-sync-use-upstream
to plugin/evm/config/config.govm.Network
in vm.gouseUpstream
option is set, replaces the step that syncs eth trieclient.syncStateTrie
with the newsyncer.Sync
stateSyncNodes
is set, registers the explicitly specified peers to sync from to the syncer,Note when stateSyncNodes is explicitly set (in the config.json), they should also be passed to the avalanchego using the --state-sync-ids and --state-sync-ips options, to also use those nodes to determine the "sync summary" i.e., where to start syncing from.