This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
forked from dominant-strategies/go-quai
-
Notifications
You must be signed in to change notification settings - Fork 0
Implementation of Snap sync #95
Open
alejoacosta74
wants to merge
6
commits into
dominant-strategies:main
Choose a base branch
from
alejoacosta74:ft/core-snapsync
base: main
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.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3a23c80
add core event to handle requests to start a snap sync
alejoacosta74 a966794
add functionality into 'trie' package to handle request/response of t…
alejoacosta74 c1cb2fb
refactor SetSyncTarget to avoid header nil pointer
alejoacosta74 e11525a
implement TriggerSnapSync API
alejoacosta74 03aaefd
define basic downloader functionality to handler snap sync requests
alejoacosta74 d17f113
implement GetTrieNode on responder side
alejoacosta74 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package downloader | ||
|
||
import ( | ||
"sync" | ||
|
||
"bytes" | ||
|
||
"github.com/dominant-strategies/go-quai/common" | ||
"github.com/dominant-strategies/go-quai/crypto" | ||
"github.com/dominant-strategies/go-quai/ethdb" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type Downloader struct { | ||
p2pNode P2PNode | ||
f *fetcher | ||
} | ||
|
||
func NewDownloader(p2pNode P2PNode, chainDb ethdb.Database, quitCh chan struct{}) *Downloader { | ||
f := &fetcher{ | ||
p2pNode: p2pNode, | ||
db: chainDb, | ||
mu: sync.Mutex{}, | ||
quitCh: quitCh, | ||
} | ||
return &Downloader{ | ||
p2pNode: p2pNode, | ||
f: f, | ||
} | ||
} | ||
|
||
func (d *Downloader) StartSnapSync(loc common.Location, blockNumber uint64) error { | ||
block, err := d.f.fetchBlock(loc, blockNumber) | ||
if err != nil { | ||
return errors.Errorf("failed to fetch block %d: %v", blockNumber, err) | ||
} | ||
|
||
err = d.f.fetchStateTrie(block.Hash(), block.Header().EVMRoot()) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to fetch state trie") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// VerifyNodeHash verifies a expected hash against the RLP encoding of the received trie node | ||
func verifyNodeHash(rlpBytes []byte, expectedHash []byte) bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed yesterday, I think this can be handled entirely by libp2p, since it hashes every packet it receives. Please leverage that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to have @gameofpointers view on this as well. Since the above was agreed with him |
||
hash := crypto.Keccak256(rlpBytes) | ||
return bytes.Equal(hash, expectedHash) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this used? We need to tell the node which block to snap to, but this seems to tell the node which node to sync to.
e.g. if we have the following chain:
Region should use this method should tell the zone to sync to 10002, but when snap syncing we want to tell the node to start with a snapshot at 800 or something (some number of prime blocks before the tip).
Am I misunderstanding this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I am trying to ensure is that all nodes in a slice snapshot to the same prime block. They cannot decide on independent snap targets