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

Governance Abstain vote #2128

Merged
merged 8 commits into from
Nov 11, 2023
Merged

Governance Abstain vote #2128

merged 8 commits into from
Nov 11, 2023

Conversation

grarco
Copy link
Contributor

@grarco grarco commented Nov 8, 2023

Describe your changes

Closes #2090.

Implements the Abstain governance vote. Also reviews the tally process for the different proposal types.

Indicate on which release or other PRs this topic is based on

Commit 3a0ecd8 on base (v0.25.0)

Checklist before merging to draft

  • I have added a changelog
  • Git history is in acceptable state

@grarco grarco changed the title Introduces governance Abstain vote and adjusts tally Governance Abstain vote Nov 8, 2023
grarco added a commit that referenced this pull request Nov 8, 2023
@grarco grarco marked this pull request as ready for review November 8, 2023 12:33
let at_least_two_thirds_voted = self.total_yay_power
+ self.total_nay_power
+ self.total_abstain_power
>= self.total_voting_power / 3 * 2;
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
>= self.total_voting_power / 3 * 2;
>= self.total_voting_power * 2 / 3;

in general, we should practice multiply-then-divide

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 the operators precedence in Rust already evaluates multiplications before divisions, but I can change it. Do you think at this point it's better to split the fraction among the two sides of the inequality an be (yay + nay + abstain) * 3 >= total * 2?

Copy link
Contributor

Choose a reason for hiding this comment

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

how you have it is fine, I just prefer * 3 / 2. admittedly this is somewhat of an aesthetic choice

>= self.total_voting_power / 3 * 2;

let at_least_two_thirds_nay = self.total_nay_power
>= (self.total_nay_power + self.total_yay_power) / 3 * 2;
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
>= (self.total_nay_power + self.total_yay_power) / 3 * 2;
>= (self.total_nay_power + self.total_yay_power) * 2 / 3;

(TallyVote::Offline(vote), TallyVote::Offline(other_vote)) => {
vote.is_same_side(other_vote)
}
_ => false,
Copy link
Contributor

Choose a reason for hiding this comment

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

when would this case happen? shouldn't this be impossible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Never, it's just the the method is implemented on the TallyVote enum which contains two variants, one for the on-chain votes and the other one for off-chain votes and we still need the pattern matching to be exhaustive, so we need to cover also the case in which the two instances are actually two different variants. We can return an error instead of false to make it more clear

Copy link
Contributor

Choose a reason for hiding this comment

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

wherever a case isn't expected to happen, we should return an error

nay_voting_power += vote_power;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

vote.is_abstain() would be more defensive, in case we add another voting option in the future

} else {
if validator_vote.is_nay() {
nay_voting_power -= voting_power;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

yay_voting_power -= voting_power;
if validator_vote.is_yay() {
yay_voting_power -= voting_power;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

abstain_voting_power += voting_power;
if validator_vote.is_yay() {
yay_voting_power -= voting_power;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

nay_voting_power += voting_power;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@@ -2095,7 +2095,7 @@ fn proposal_submission() -> Result<()> {
let mut client = run!(test, Bin::Client, query_proposal, Some(15))?;
client.exp_string("Proposal Id: 0")?;
client.exp_string(
"passed with 120900.000000 yay votes and 0.000000 nay votes (0.%)",
"passed with 120000.000000 yay votes and 900.000000 nay votes (0.%)",
Copy link
Contributor

Choose a reason for hiding this comment

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

why did this change? 🤔

Copy link
Contributor Author

@grarco grarco Nov 8, 2023

Choose a reason for hiding this comment

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

In test we submit two votes, a yay with the validator (120000 voting power) and a nay with a delegator (900 voting power) and previously we were not seeing the nay votes before because of a bug in the is_same_side function. I've tagged you at the wrong line

Copy link
Contributor

Choose a reason for hiding this comment

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

ah

/// Rappresent an invalid proposal vote
/// Represent an abstain proposal vote
Abstain,
/// Represent an invalid proposal vote
Invalid,
Copy link
Contributor

Choose a reason for hiding this comment

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

when does this case happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually nowhere, I'm removing it thanks!

let both_yay = self.is_yay() && other.is_yay();
let both_nay = !self.is_yay() && !other.is_yay();

both_yay || !both_nay
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cwgoes here's the bug for the wrong e2e tally, it should have been both_yay || both_nay

@grarco grarco mentioned this pull request Nov 8, 2023
@grarco grarco force-pushed the grarco/governance-abstain-vote branch from c79675f to 20dc3b3 Compare November 8, 2023 16:26
@grarco grarco requested a review from cwgoes November 8, 2023 16:58
Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

lgtm

@grarco grarco merged commit 0de7638 into main Nov 11, 2023
13 of 14 checks passed
@grarco grarco deleted the grarco/governance-abstain-vote branch November 11, 2023 20:05
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.

Implement an Abstain vote option in governance
2 participants