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

Updated minimum staking related logic #920

Merged
merged 12 commits into from
Apr 26, 2021

Conversation

jeongkyun-oh
Copy link
Contributor

@jeongkyun-oh jeongkyun-oh commented Mar 12, 2021

Proposed changes

  • Updated the minimum staking update flag available
  • Removed the validators who do not have minimum staking amount of KLAY from committees/proposers
    • Case 1. Some members do not have enough KLAYs
      • Members who do not have enough KLAYs cannot be committee as well as proposers
    • Case 2. No validator has enough KLAYs
      • All members become the committee and a proposer is chosen from them
    • Case 3. Governing node in single mode doesn't have enough KLAYs
      • No one can vote until governing node has enough KLAYs
      • This case will be handled in another PR. In single mode, the governing node will always be in proposers/committee.
  • Updated for backward-incompatible change

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

Case 3. Governing node in single mode doesn't have enough KLAYs

  • No one can vote until governing node has enough KLAYs

@KimKyungup @jeongkyun-oh The third policy probably becomes a huddle for Service Chain or Private Chain operators. How about letting "Governing node in single mode" propose a block?

blockchain/genesis.go Outdated Show resolved Hide resolved
params/config.go Outdated Show resolved Hide resolved
@KimKyungup
Copy link
Contributor

The third policy probably becomes a huddle for Service Chain or Private Chain operators. How about letting "Governing node in single mode" propose a block?

@jeongkyun-oh @aidan-kwon
Does this feature affect to all governing modes?
If the default minimum staking amount is zero, I think it's ok. But the feature of governing mode should be documented and discussed.

@jeongkyun-oh jeongkyun-oh force-pushed the KLT-273-remove-poor-validator3 branch from 1aac62b to 077152e Compare March 22, 2021 07:41
Comment on lines 913 to 915
if minimumStakingAmount, ok := new(big.Int).SetString(gov.MinimumStake(), 10); ok {
params.SetMinimumStakingAmount(minimumStakingAmount)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as updateMinimumStakingAmount?

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, but updateMinimumStakingAmount is a trigger function for voting. There is no proper key and value for this.

consensus/istanbul/validator/weighted.go Outdated Show resolved Hide resolved
// they will not be in the committee as well as the proposer candidates list.
pHeader := chain.GetHeaderByNumber(params.CalcStakingBlockNumber(snap.Number + 1))
if pHeader != nil {
if err := snap.ValSet.TransitionValidators(pHeader.Hash(), pHeader.Number.Uint64()); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this an error we can ignore and does not make any problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logic is updated and moved to into Refresh function. Please take another look.

consensus/istanbul/validator/weighted.go Show resolved Hide resolved
}

if len(newWeightedValidators) <= 0 {
return newWeightedDemoted, newDemotedStaking, []*weightedValidator{}, []float64{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we return demoted validators and their staking info in this place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If no validator has enough KLAYs, the demoted validators can still propose blocks to prevent them from not creating blocks.

This comment was marked as resolved.

consensus/istanbul/validator/weighted.go Outdated Show resolved Hide resolved
@@ -607,17 +656,62 @@ func (valSet *weightedCouncil) Refresh(hash common.Hash, blockNum uint64) error
return nil
}

// updateValidators converts weighted validator slice to istanbul.Validators and sets them to the council.
func (valSet *weightedCouncil) updateValidators(validators []*weightedValidator, demoted []*weightedValidator) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a minor comment, but I think set would be more appropriate in this case.

  • set -> does nothing or little inside the function
  • update -> does something inside the 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.

Updated. Thanks!

consensus/istanbul/validator/weighted.go Show resolved Hide resolved
@jeongkyun-oh jeongkyun-oh force-pushed the KLT-273-remove-poor-validator3 branch 5 times, most recently from 63db488 to 2c8e809 Compare March 29, 2021 06:13
@jeongkyun-oh
Copy link
Contributor Author

jeongkyun-oh commented Apr 13, 2021

@aidan-kwon As we talked f2f, I will update the following cases.

  1. Comment: The method NewValidatorSet shouldn't be called.
  2. Comment: The validatorMu is used for validators and demotedValidators.
  3. The Refresh method should be called for every block, so it would be better to move into apply method.
  4. The unit test for snapshot is added.

@jeongkyun-oh
Copy link
Contributor Author

Comment on lines 181 to +198
snap.ValSet, snap.Votes, snap.Tally = gov.HandleGovernanceVote(snap.ValSet, snap.Votes, snap.Tally, header, validator, addr)
if policy == uint64(params.WeightedRandom) {
// Snapshot of block N (Snapshot_N) should contain proposers for N+1 and following blocks.
// And proposers for Block N+1 can be calculated from the nearest previous proposersUpdateInterval block.
// Let's refresh proposers in Snapshot_N using previous proposersUpdateInterval block for N+1, if not updated yet.
pHeader := chain.GetHeaderByNumber(params.CalcProposerBlockNumber(number + 1))
if pHeader != nil {
if err := snap.ValSet.Refresh(pHeader.Hash(), pHeader.Number.Uint64(), chain.Config()); err != nil {
// There are three error cases and they just don't refresh proposers
// (1) no validator at all
// (2) invalid formatted hash
// (3) no staking info available
logger.Trace("Skip refreshing proposers while creating snapshot", "snap.Number", snap.Number, "pHeader.Number", pHeader.Number.Uint64(), "err", err)
}
} else {
logger.Trace("Can't refreshing proposers while creating snapshot due to lack of required header", "snap.Number", snap.Number)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need a lock for atomicity of snap.ValSet? @jeongkyun-oh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think no need to lock snap.ValSet which is accessed synchronously.snap.ValSet is an interface for weightedCouncil. If you worry about the validators and demotedValidators, the validatorsMu protects them in weightedCouncil.

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