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

[Stream] Add downloader module #3584

Merged
merged 3 commits into from
Mar 13, 2021
Merged

Conversation

JackyWYX
Copy link
Contributor

@JackyWYX JackyWYX commented Mar 12, 2021

Description

This is a break down pr of #3535 and is rebased on #3583.

  • Added downloader module to download block at time ticks or triggered by other modules.

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:

  1. Long range sync: aimed to sync for long range. Long range will happen the first time when the downloader does download task. The target block number of each long-range-sync iteration is set with a max vote, and it does not necessarily to be the latest.
  2. Short range sync: aimed to sync for a short range. After the bootstrap range range sync, short range sync is awaken periodically or by consensus triggers the download logic. The short range sync sync 10 blocks at one iteration, and aims to sync to the longest chain.

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 and InsertChain when it see appropriate.

Additionally, the InsertHook function is to broadcast crosslinks when the node is a leader (will be included in next PR).

func (node *Node) BeaconSyncHook() {
	if node.Consensus.IsLeader() {
		node.BroadcastCrossLink()
	}
}

4. insertHelper

insertHelper is to do some extra verification on block.commitSigAndBitmap field. The block will only be inserted when current sig verification passes.

@JackyWYX JackyWYX force-pushed the stream_download branch 3 times, most recently from a65e783 to effcd6c Compare March 12, 2021 20:42
@rlan35 rlan35 merged commit 7e2302d into harmony-one:main Mar 13, 2021
Copy link
Contributor

@LeoHChen LeoHChen left a 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.
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

no lock is needed?

Copy link
Contributor Author

@JackyWYX JackyWYX Mar 17, 2021

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

@JackyWYX JackyWYX Mar 17, 2021

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

JackyWYX added a commit to JackyWYX/harmony that referenced this pull request Mar 17, 2021
JackyWYX added a commit to JackyWYX/harmony that referenced this pull request Mar 17, 2021
JackyWYX added a commit to JackyWYX/harmony that referenced this pull request Mar 17, 2021
LeoHChen pushed a commit that referenced this pull request 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.

3 participants