-
Notifications
You must be signed in to change notification settings - Fork 289
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
[Stream] Add downloader module #3584
Conversation
a65e783
to
effcd6c
Compare
eaeddf0
to
efe1f35
Compare
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.
LGTM in general, a few comments and questions.
} | ||
|
||
// DownloadAsync triggers the download async. If there is already a download task that is | ||
// in progress, return ErrDownloadInProgress. |
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.
I didn't see an error returned? is this comment outdated?
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.
Right. It's an out-of-date comment. Let me remove this
if err != nil { | ||
return nil, err | ||
} | ||
decider.UpdateParticipants(pubKeys) |
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.
no lock is needed?
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.
No, I don't think lock is needed here. verifyAndInsertBlock
is called sequentially in doLongRangeSync
and doShortRangeSync
. Moreover, decider is created for each epoch. So there shall be no race condition as far as I see.
return nil | ||
} | ||
|
||
func computeBNMaxVote(votes map[sttypes.StreamID]uint64) uint64 { |
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.
no comments on the intention of this function?
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.
OK. Added comment, and changed function names.
} | ||
} | ||
|
||
func validateGetBlocksResult(requested []uint64, result []*types.Block) error { |
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.
you have assumed the order of the number in the input list, how do you know the input list will be sorted based on the numberu64?
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.
This is the result get from remote node as the response for a request which well defines which number is expecting (as requested
. If the remote node runs honestly, the response should always have the same number as requested
. If the remote node does not give the exact block or mess up with the sequence, the remote stream is marked as dishonest and removed.
return requestBNs | ||
} | ||
|
||
func (gbm *getBlocksManager) getBatchFromUnprocessed(cap int) []uint64 { |
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.
better add comments on the intention of this function and when to call it.
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.
OK. Let me add it.
if len(blocks) != len(hashes) { | ||
return errors.New("unexpected number of getBlocksByHashes result") | ||
} | ||
for i, block := range blocks { |
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.
assumed sorted list, how to guarantee that?
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.
Because the hashChain
was assumed to be sorted. If the given hashChain is not sorted, remote node can be malicious and need to be killed.
Description
This is a break down pr of #3535 and is rebased on #3583.
1. downloader and downloaders
Downloaders is the aggregation of downloader. Each downloader is responsible for syncing for one specific shard. Each downloader will host its own
sync.Protocol
on a specific topic.2. Downloader modes
Downloader has two modes:
3. beaconHelper
beaconHelper
is the submodule of downloader, which aims to aid the block synchronization of beacon chain for shard chain nodes. Basically, it takes blocks from beacon client pub-sub, add to memory andInsertChain
when it see appropriate.Additionally, the
InsertHook
function is to broadcast crosslinks when the node is a leader (will be included in next PR).4. insertHelper
insertHelper
is to do some extra verification onblock.commitSigAndBitmap
field. The block will only be inserted when current sig verification passes.