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

fix(group): Update TresholdDecisionPolicy to handle threshold>totalWeight #11325

Merged
merged 6 commits into from
Mar 8, 2022

Conversation

amaury1093
Copy link
Contributor

@amaury1093 amaury1093 commented Mar 4, 2022

Description

Closes: #10945

In ThresholdDecisionPolicy, allow the threshold to be arbitrarily big (e.g. bigger than the group total weight). In that case, in Allow(), the tally result is compared against min(threshold,total_weight).


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@@ -185,6 +185,11 @@ func (k Keeper) UpdateGroupMembers(goCtx context.Context, req *group.MsgUpdateGr
// Update group in the groupTable.
g.TotalWeight = totalWeight.String()
g.Version++

if err := k.validateDecisionPolicies(ctx, *g); err != nil {
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'm adding DecisionPolicy.Validate() calls in a few places in the msg server:

  • MsgCreateGroupPolicy and MsgCreateGroupWithPolicy
  • MsgUpdateDecisionPolicy
  • MsgLeaveGroup
  • MsgUpdateGroupMembers

anywhere else you think we need to add validation?

x/group/types.go Outdated Show resolved Hide resolved
@amaury1093 amaury1093 marked this pull request as ready for review March 4, 2022 17:35
@amaury1093 amaury1093 requested review from blushi, cmwaters, likhita-809, atheeshp and aleem1314 and removed request for aaronc and alexanderbez March 4, 2022 17:35
Copy link
Collaborator

@anilcse anilcse left a comment

Choose a reason for hiding this comment

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

lgtm

Just a thought, can we use if allYesVotes instead of min(threshold,total_weight), that sounds safe for me.

Copy link
Contributor

@atheeshp atheeshp left a comment

Choose a reason for hiding this comment

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

Lgtm

@amaury1093
Copy link
Contributor Author

Just a thought, can we use if allYesVotes instead of min(threshold,total_weight), that sounds safe for me.

@anilcse Could you explain your change in more details? e.g. which line?

// and the threshold doesn't, we can end up with threshold > total_weight.
// In this case, as long as everyone votes yes (in which case
// `yesCount`==`realThreshold`), then the proposal still passes.
realThreshold := min(threshold, totalPowerDec)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@AmauryM here can we just check if everyone voted yes instead of checking against realThreshold?

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 see. There are 2 scenarios:

  • if threshold>totalPower, then we should check that everyone votes yes
  • if threshold<totalPower, we don't need everyone to vote yes

In the 2nd cases, we don't check everyone voted yes. The realThreshold is used to share logic to avoid having an if then else case, but I can introduce that if it's clearer.

Copy link
Collaborator

@anilcse anilcse Mar 8, 2022

Choose a reason for hiding this comment

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

Ah yes. I don't have a strong preference now. Let's go with this unless anyone are strongly in favor of checking all-yes-votes for the special case. @blushi @robert-zaremba wdyt?

@amaury1093 amaury1093 added the A:automerge Automatically merge PR once all prerequisites pass. label Mar 8, 2022
@mergify mergify bot merged commit 68f6c8b into master Mar 8, 2022
@mergify mergify bot deleted the am/10945-threshold branch March 8, 2022 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle group member weight updates that break threshold decision policy
4 participants