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

Refine SubList and SubListWithProposer #551

Merged
merged 7 commits into from
Jun 24, 2020
Merged

Conversation

aidan-kwon
Copy link
Member

Proposed changes

Refine SubList and SubListWithProposer.

  • Define common logics to functions: ConvertHashToSeed, SelectRandomCommittee
  • More validation and error handling related to committeeSize in SubListWithProposer
  • More validation and error handling in SetSubGroupSize

I tried to maintain the semantic of the SubListWithProposer except for invalid input handling.

Types of changes

Please put an x in the boxes related to your change.

  • Bugfix
  • New feature or enhancement
  • Others

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING GUIDELINES doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes ($ make test)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

@aidan-kwon
Copy link
Member Author

aidan-kwon commented Jun 19, 2020

The last commit revoked changes in the previous commit restricting committee size.
The last commit allows committee sizes bigger than a validator size as it was since it is more useful to operate Klaytn core cell network.

Comment on lines 332 to 334
if committeeSize >= validatorSize {
return validators
}
Copy link
Contributor

Choose a reason for hiding this comment

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

how about moving these codes to top of the function.
we can just return if the commiteeSize is bigger than validatorSize

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you. I moved it!

// seed will be used to select a random committee
seed, err := ConvertHashToSeed(prevHash)
if err != nil {
logger.Error("failed to covert hash to seed", "prevHash", prevHash, "err", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger.Error("failed to covert hash to seed", "prevHash", prevHash, "err", err)
logger.Error("failed to convert hash to seed", "prevHash", prevHash, "err", err)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

@aidan-kwon
Copy link
Member Author

Reviewers, please take a look.

// SelectRandomCommittee composes a committee selecting validators randomly based on the seed value.
// It returns nil if the given committeeSize is bigger than validatorSize or proposer indexes are invalid.
func SelectRandomCommittee(validators []istanbul.Validator, committeeSize uint64, seed int64, proposerIdx int, nextProposerIdx int) []istanbul.Validator {
// ensure validator indexes are valid
Copy link
Contributor

@KimKyungup KimKyungup Jun 23, 2020

Choose a reason for hiding this comment

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

Suggested change
// ensure validator indexes are valid
// ensure proposer indexes are valid

Copy link
Member Author

Choose a reason for hiding this comment

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

I think "validator" is good to go because the index is indexes of validators variable

func (valSet *weightedCouncil) SetSubGroupSize(size uint64) {
if size == 0 {
logger.Error("cannot assign committee size to 0")
Copy link
Contributor

Choose a reason for hiding this comment

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

Crit?

Suggested change
logger.Error("cannot assign committee size to 0")
logger.Crit("cannot assign committee size to 0")

Copy link
Member Author

Choose a reason for hiding this comment

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

I think error is enough. It doesn't change valSet.subSize value when size is 0.

Copy link
Contributor

@KimKyungup KimKyungup left a comment

Choose a reason for hiding this comment

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

LGTM.

@KimKyungup
Copy link
Contributor

@ehnuje PTAL. :)

@KimKyungup KimKyungup merged commit bece88a into klaytn:dev Jun 24, 2020
@aidan-kwon aidan-kwon deleted the 0618-valSet branch February 22, 2021 04:55
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.

None yet

5 participants